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

Unable to handle errors with try/catch #279

Open
just-boris opened this issue Sep 6, 2017 · 5 comments · May be fixed by #311
Open

Unable to handle errors with try/catch #279

just-boris opened this issue Sep 6, 2017 · 5 comments · May be fixed by #311

Comments

@just-boris
Copy link

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?

@garywu
Copy link

garywu commented Sep 11, 2017

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

@martijn189
Copy link

Same issue here

@xdamman
Copy link

xdamman commented Oct 5, 2017

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.

@cwohlman
Copy link

cwohlman commented Oct 5, 2017

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.

@bpb27
Copy link

bpb27 commented Jun 25, 2018

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

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

Successfully merging a pull request may close this issue.

6 participants