chromeless icon indicating copy to clipboard operation
chromeless copied to clipboard

Unable to handle errors with try/catch

Open just-boris opened this issue 7 years ago • 5 comments

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?

just-boris avatar Sep 06 '17 12:09 just-boris

I'm experiencing the same with wait('.no-such-selector')

garywu avatar Sep 11 '17 14:09 garywu

Same issue here

martijn189 avatar Sep 22 '17 10:09 martijn189

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.

xdamman avatar Oct 05 '17 13:10 xdamman

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.

cwohlman avatar Oct 05 '17 16:10 cwohlman

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...

bpb27 avatar Jun 25 '18 21:06 bpb27