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

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

@rippo

Description

@rippo

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 test3@test.com successfully', async function () {
        const href = await chromeless
            .type('test3@test.com', '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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions