chromeless
chromeless copied to clipboard
Unable to handle errors with try/catch
I have the following code (same in playground)
try {
await chromeless.goto('https://www.graph.cool')
await chromeless.click('.no-such-selector')
} catch(e) {
console.log('Failed to click an element')
const screenshot = await chromeless.screenshot()
console.log(screenshot)
}
await chromeless.end()
When element is not found on the page, I expect an Exception to be thrown, that I can handle in catch
and make a screenshot. But instead I am seeing an globally thrown error Error: wait(".no-such-selector") timed out after 10000ms
that I cannot catch.
How should I handle such case and dump screenshot of the page, if anything goes wrong?
I'm experiencing the same with wait('.no-such-selector')
Same issue here
Same issue here. Would love to be able to make a screenshot when a step fails.
I think this is related:
(node:10804) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: wait("input[name='website']") timed out after 10000ms
(node:10804) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I'm running into this issue & finding that the error is actually thrown from the second invocation of .screenshot() in other words it seems like the click (or wait) action is still queued and trying to run a second time.
Having the same issue. Doing await chromeless.queue.end()
in a catch block seems to work (taken from the source here).
Full example:
const { Chromeless } = require('chromeless')
const chromeless = new Chromeless({ waitTimeout: 5000 });
const twitterUsername = "xxx"
const twitterPassword = "xxx"
async function run() {
const screenshot = await chromeless
.goto('https://twitter.com/login/')
.type(twitterUsername, '.js-username-field')
.type(twitterPassword, '.js-password-field')
.click('button[type="submit"]')
.wait('.status')
.screenshot()
await chromeless.end()
}
run().catch(async (error) => {
console.log(error);
await chromeless.queue.end()
})
Without that the node process continues forever on an error...