Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Node.js] webdriver.get not open browser window with promise.then #2233

Closed
huan opened this issue Jun 8, 2016 · 8 comments
Closed

[Node.js] webdriver.get not open browser window with promise.then #2233

huan opened this issue Jun 8, 2016 · 8 comments
Assignees
Labels

Comments

@huan
Copy link

huan commented Jun 8, 2016

Meta - driver.get not open the browser window

OS: linux & win32

Selenium Version: 2.53.2

Browser: chrome

Browser Version: 50.0.2661.102 m

Expected Behavior -

use the following javascript code to open browser window

const WebDriver     = require('selenium-webdriver')

var driver = new WebDriver.Builder()
.setAlertBehavior('ignore')
.forBrowser('chrome')
.build()

function bug() {
  console.log('bug: `driver.get` will hang\n' + '\n' + bug + '\n')
  Promise.resolve()
  .then(() => 'test')
  .then(() => driver.get('about:blank'))
}

bug()

Actual Behavior -

after run, there's no window opened by webdriver. the program hang.

I run this code under nodejs v6.0.0

Steps to reproduce -

I had experienced a very strange bug with nodejs & selenium-webdriver recently. It looks related with nodejs event loop / promise / selenium-webdriver.

In short: webdriver.get call will hang when use with some promise.then.

First, let's see a piece of javascript code which works well:

const WebDriver     = require('selenium-webdriver')

var driver = new WebDriver.Builder()
.setAlertBehavior('ignore')
.forBrowser('chrome')
.build()

function ok() {
  console.log('ok: driver.get will open a browser window\n' + '\n' + ok + '\n')
  driver.get('about:blank')
}

ok()

This code will open a browser window, which works as expected.

But all of the following code will show strange behaviour.

Bug - driver.get will hang

after add a dummy .then(() => 'test')

function bug() {
  console.log('bug: `driver.get` will hang\n' + '\n' + bug + '\n')
  Promise.resolve()
  .then(() => 'test')
  .then(() => driver.get('about:blank'))
}

Fix1 - delete the 1st then call

function fire1() {
  console.log('fix1: delete the `then` call\n' + '\n' + fire1 + '\n')
  Promise.resolve()
  .then(() => driver.get('about:blank'))
}

Fix2 - or add a catch call

function fire2() {
  console.log('fix2: add a `catch` call\n' + '\n' + fire2 + '\n')
  Promise.resolve()
  .then(() => 'test')
  .catch(e => console.error(e))
  .then(() => driver.get('about:blank'))
}

Fix3 - or resolve the promise with a setTimeout instead of resolve directly

function fire3() {
  console.log('fix3: resolve promise with a `setTimeout` call\n' + '\n' + fire3 + '\n')
  new Promise((resolve, reject) => {
    setTimeout(resolve, 0)
  })
  .then(() => 'test')
  .then(() => driver.get('about:blank'))
}

All of the above code is tested under nodejs v6.0.0.

Has there anybody met this kind of problem before? What's the reason behind this?

I thought it maybe related with the nodejs event loop, or native promise implementation... but I'm dont know how to dig deeper any more.

Code in Gist: https://gist.github.com/zixia/77896cbd446c7282f760c60a025fee17
Stackoverflow: https://stackoverflow.com/questions/37692364/selenium-webdriver-hang-in-very-simple-javascript-code-with-promise-then

@jleyba jleyba added the C-nodejs label Jun 8, 2016
@jleyba jleyba self-assigned this Jun 8, 2016
@jleyba
Copy link
Contributor

jleyba commented Jun 9, 2016

I haven't found the actual bug, but I did fix this specific instance of it with the cleanup in 0342309

@huan
Copy link
Author

huan commented Jun 10, 2016

Wow, it's a lot of cleanups. I'll try the dev branch code later and post feedback here.

@jleyba
Copy link
Contributor

jleyba commented Jun 12, 2016

I squashed 5 or 6 commits into one before pushing. The changes that actually "fixed" this were all in lib/webdriver.js

@huan
Copy link
Author

huan commented Jun 12, 2016

aha~ I use the last version of lib/webdriver.js to replace it in my node_modules/selenium/lib/webdriver.js , then everything went ok.

looks this bug had gone. 👍

but I'm still want to know what is the root reason caused this bug, do you know which part of the old code is wrong?

@jleyba
Copy link
Contributor

jleyba commented Jun 12, 2016

I haven't closed this bug because I haven't found the bug yet. I can see where the promise manager gets stuck in the logs, I just don't understand why yet.

@huan
Copy link
Author

huan commented Jun 13, 2016

looking forward to hear from you when you found this bug. thanks!

@jleyba
Copy link
Contributor

jleyba commented Nov 3, 2016

This has the same underlying cause as #3037, so closing this to consolidate tracking.

@huan
Copy link
Author

huan commented Nov 4, 2016

@jleyba thank you for noticing me that, appreciate.

@lock lock bot locked and limited conversation to collaborators Aug 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants