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

javascript interface not working with setTimeout #363

Closed
soarez opened this issue Mar 24, 2015 · 3 comments
Closed

javascript interface not working with setTimeout #363

soarez opened this issue Mar 24, 2015 · 3 comments
Assignees
Labels

Comments

@soarez
Copy link

soarez commented Mar 24, 2015

e.g.

var fs = require('fs');
var webdriver = require('selenium-webdriver');

var remote = new webdriver
  .Builder()
  .withCapabilities({ browserName: 'phantomjs' })
  .build();

remote.manage().window().setSize(1024, 900);

remote.get('http://google.com');

setTimeout(function() {
  remote.executeScript('return true').then(log, onError);
}, 500);

function log(res) { console.log(res); }

function onError(e) { throw e; }

This small program gets stuck and never ends, but it we move the line remote.executeScript('return true').then(log, onError); out of the setTimeout callback then it starts working as expected.

Shouldn't the executeScript call schedule the operation regardless of when it is called?

I'm using selenium-webdriver@2.45.1

@GCheung55
Copy link

++

The same issue occurs if the setTimeout wraps remote.get in my scenario.

I'm using selenium-webdriver@2.45.1 in Buster.JS's test runner to drive embedded Chromium. It's possible that webdriver code is executed in a setTimeout or some other delayed mechanism in the test runner.

@GCheung55
Copy link

I did some digging and so far I've only determined that reverting back to https://github.com/SeleniumHQ/selenium/blob/ecfefd32aba140f79f62986b0c7944c197c3ff03/javascript/webdriver/promise.js allows the code to continue.

@jleyba
Copy link
Contributor

jleyba commented Apr 22, 2015

Problem is the flow gets confused and deadlocks itself when a command is scheduled asynchronously when there's a dependency on the running task. Basic repo case:

var selenium = require('selenium-webdriver');
var flow = selenium.promise.controlFlow();

var task1 = flow.execute(function() {
  console.log('Inside task 1:\n' + flow);
  return selenium.promise.delayed(10);
}, 'task 1');

setTimeout(function() {
  flow.execute(function() {
    console.log('Inside task 2:\n' + flow);
    return task1;  // Create dependency on task 1 result.
  }, 'task 2');
  console.log('Scheduled task 2:\n' + flow);
}, 0);

flow.once('idle', function() {
  console.log('All done');
});

Output:

Inside task 1:
ControlFlow::1
| Frame::4
| | (pending) Task::3<task 1>
| | | (active) Frame::5
Scheduled task 2:
ControlFlow::1
| Frame::4
| | (pending) Task::3<task 1>
| | | (active) Frame::5
| | | | Task::12<task 2>
Inside task 2:
ControlFlow::1
| Frame::4
| | (pending) Task::3<task 1>
| | | Frame::5
| | | | (pending) Task::12<task 2>
| | | | | (active) Frame::13

Need to update the flow to differentiate between this and legit sub-commands.

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

4 participants