Skip to content

Commit

Permalink
[js] Fix timeouts' url (#2185)
Browse files Browse the repository at this point in the history
* [js] Fix timeouts' url

POST URLs now comply with http://w3c.github.io/webdriver/webdriver-spec.html\#set-timeout
  • Loading branch information
JohanLorenzo authored and jleyba committed Jun 7, 2016
1 parent 3f8481b commit 4e77374
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
1 change: 1 addition & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
`until.urlMatches()`
* Added work around for [GeckoDriver bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1274924) raising a type conversion error
* Removed the mandatory use of Firefox Dev Edition, when using Marionette driver
* Fixed timeouts' URL

## v2.53.2

Expand Down
2 changes: 0 additions & 2 deletions javascript/node/selenium-webdriver/lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ const COMMAND_MAP = new Map([
[cmd.Name.EXECUTE_ASYNC_SCRIPT, post('/session/:sessionId/execute_async')],
[cmd.Name.SCREENSHOT, get('/session/:sessionId/screenshot')],
[cmd.Name.SET_TIMEOUT, post('/session/:sessionId/timeouts')],
[cmd.Name.SET_SCRIPT_TIMEOUT, post('/session/:sessionId/timeouts/async_script')],
[cmd.Name.IMPLICITLY_WAIT, post('/session/:sessionId/timeouts/implicit_wait')],
[cmd.Name.MOVE_TO, post('/session/:sessionId/moveto')],
[cmd.Name.CLICK, post('/session/:sessionId/click')],
[cmd.Name.DOUBLE_CLICK, post('/session/:sessionId/doubleclick')],
Expand Down
18 changes: 8 additions & 10 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,10 +1284,7 @@ class Timeouts {
* when the implicit wait timeout has been set.
*/
implicitlyWait(ms) {
return this.driver_.schedule(
new command.Command(command.Name.IMPLICITLY_WAIT).
setParameter('ms', ms < 0 ? 0 : ms),
'WebDriver.manage().timeouts().implicitlyWait(' + ms + ')');
return this._scheduleCommand(ms, 'implicit', 'implicitlyWait');
}

/**
Expand All @@ -1300,10 +1297,7 @@ class Timeouts {
* when the script timeout has been set.
*/
setScriptTimeout(ms) {
return this.driver_.schedule(
new command.Command(command.Name.SET_SCRIPT_TIMEOUT).
setParameter('ms', ms < 0 ? 0 : ms),
'WebDriver.manage().timeouts().setScriptTimeout(' + ms + ')');
return this._scheduleCommand(ms, 'script', 'setScriptTimeout');
}

/**
Expand All @@ -1316,11 +1310,15 @@ class Timeouts {
* when the timeout has been set.
*/
pageLoadTimeout(ms) {
return this._scheduleCommand(ms, 'page load', 'pageLoadTimeout');
}

_scheduleCommand(ms, timeoutIdentifier, timeoutName) {
return this.driver_.schedule(
new command.Command(command.Name.SET_TIMEOUT).
setParameter('type', 'page load').
setParameter('type', timeoutIdentifier).
setParameter('ms', ms),
'WebDriver.manage().timeouts().pageLoadTimeout(' + ms + ')');
`WebDriver.manage().timeouts().${timeoutName}(${ms})`);
}
}

Expand Down
16 changes: 16 additions & 0 deletions javascript/node/selenium-webdriver/test/element_finding_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ test.suite(function(env) {
});
});

test.it('should implicitly wait', function() {
var TIMEOUT_IN_MS = 1000;
var EPSILON = TIMEOUT_IN_MS / 2;

driver.manage().timeouts().implicitlyWait(TIMEOUT_IN_MS);
driver.get(Pages.formPage);

var start = new Date();
driver.findElement(By.id('nonExistantButton')).
then(fail, function(e) {
var end = new Date();
assert(e).instanceOf(error.NoSuchElementError);
assert(end - start).closeTo(TIMEOUT_IN_MS, EPSILON);
});
});

test.it('should be able to find multiple matches', function() {
driver.get(Pages.xhtmlTestPage);
driver.findElements(By.className('nameC')).then(function(elements) {
Expand Down
33 changes: 33 additions & 0 deletions javascript/node/selenium-webdriver/test/execute_script_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'use strict';

var path = require('path');
var fail = require('assert').fail;

var webdriver = require('..'),
Browser = webdriver.Browser,
Expand Down Expand Up @@ -322,6 +323,38 @@ test.suite(function(env) {
.equalTo('<div class="request">GET /common/echo HTTP/1.1</div>');
});
});

describe('async timeouts', function() {
var TIMEOUT_IN_MS = 200;
var ACCEPTABLE_WAIT = TIMEOUT_IN_MS / 10;
var TOO_LONG_WAIT = TIMEOUT_IN_MS * 10;

before(function() {
return driver.manage().timeouts().setScriptTimeout(TIMEOUT_IN_MS)
});

test.it('does not fail if script execute in time', function() {
return executeTimeOutScript(ACCEPTABLE_WAIT);
});

test.it('fails if script took too long', function() {
return executeTimeOutScript(TOO_LONG_WAIT)
.then(function() {
fail('it should have timed out');
}).catch(function(e) {
assert(e.name).equalTo('ScriptTimeoutError');
assert(e.message).contains('Timed out waiting for async script \
result after');
});
});

function executeTimeOutScript(sleepTime) {
return driver.executeAsyncScript(function(sleepTime) {
var callback = arguments[arguments.length - 1];
setTimeout(callback, sleepTime)
}, sleepTime);
}
})
});

function verifyJson(expected) {
Expand Down

0 comments on commit 4e77374

Please sign in to comment.