Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

Mocha fails to exit if we get stuck on *wait* #321

Open
rippo opened this issue Oct 22, 2017 · 2 comments
Open

Mocha fails to exit if we get stuck on *wait* #321

rippo opened this issue Oct 22, 2017 · 2 comments

Comments

@rippo
Copy link

rippo commented Oct 22, 2017

I have the following mocha test and having trouble if I wait for something that never exists.

In the example below I try to login as an invalid user and would expect a fail as the input[Value="Go"] never appears on the page!

const { Chromeless } = require('chromeless')
const { expect } = require('chai').use(require('chai-string'))
const options = require('yargs-parser')(process.argv.slice(2))


describe('When trying to login', function () {

    console.log(options.url)

    //increase as mocha has a 2 second set by default
    this.timeout(5000);
    var chromeless;

    before(async function () {
        chromeless = new Chromeless();
        await chromeless
            .goto(options.url + "/account")
            .setViewport({ width: 1200, height: 800, scale: 1 })
    })

    it('check we are on the login page /account', async function () {
        const href = await chromeless
            .evaluate(href => window.location.href)
        expect(href).to.endsWith('/account')
    })

    it('logs in [email protected] successfully', async function () {
        const href = await chromeless
            .type('[email protected]', 'input[Id="Username"]')
            .type('123', 'input[Id="Password"]')
            .click('input[type="submit"]')

            //This would fail AT THIS POINT  the input[Value="Go"] never appears on the page
            .wait('input[Value="Go"]')

            .evaluate(href => window.location.href)

        expect(href).to.endsWith('/account/search/1')
    })

    after(async function () {
        try {
            console.log("trying to stop chromeless")
            await chromeless.end()
            console.log("I never get here!")
        } catch (e) {
            console.log(e)
            done()
        }
    })

})

When running the script i get the following exception logged and the script does not exit

Error: wait("input[Value="Go"]") timed out after 10000ms
    at Object.<anonymous> (/data/node_modules/chromeless/dist/src/util.js:137:60)
    at step (/data/node_modules/chromeless/dist/src/util.js:40:23)
    at Object.next (/data/node_modules/chromeless/dist/src/util.js:21:53)
    at /data/node_modules/chromeless/dist/src/util.js:15:71
    at Promise (<anonymous>)
    at __awaiter (/data/node_modules/chromeless/dist/src/util.js:11:12)
    at Timeout.<anonymous> (/data/node_modules/chromeless/dist/src/util.js:130:81)
    at ontimeout (timers.js:469:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:264:5)

How should i wire it up so if a wait fails the script exits gracefully?

@rippo
Copy link
Author

rippo commented Oct 22, 2017

This might be related to #279

@feus4177
Copy link

feus4177 commented Nov 8, 2017

Until #311 or some other fix gets merged in you can hack it together for Mocha like this:

    afterEach(function () {
        chromeless.queue.comandQueue = {};
        chromeless.queue.lastWaitAll = null;
        chromeless.lastReturnPromise = null;
    });

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants