Skip to content

Commit 4e77374

Browse files
JohanLorenzojleyba
authored andcommitted
[js] Fix timeouts' url (#2185)
* [js] Fix timeouts' url POST URLs now comply with http://w3c.github.io/webdriver/webdriver-spec.html\#set-timeout
1 parent 3f8481b commit 4e77374

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
`until.urlMatches()`
77
* Added work around for [GeckoDriver bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1274924) raising a type conversion error
88
* Removed the mandatory use of Firefox Dev Edition, when using Marionette driver
9+
* Fixed timeouts' URL
910

1011
## v2.53.2
1112

javascript/node/selenium-webdriver/lib/http.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ const COMMAND_MAP = new Map([
168168
[cmd.Name.EXECUTE_ASYNC_SCRIPT, post('/session/:sessionId/execute_async')],
169169
[cmd.Name.SCREENSHOT, get('/session/:sessionId/screenshot')],
170170
[cmd.Name.SET_TIMEOUT, post('/session/:sessionId/timeouts')],
171-
[cmd.Name.SET_SCRIPT_TIMEOUT, post('/session/:sessionId/timeouts/async_script')],
172-
[cmd.Name.IMPLICITLY_WAIT, post('/session/:sessionId/timeouts/implicit_wait')],
173171
[cmd.Name.MOVE_TO, post('/session/:sessionId/moveto')],
174172
[cmd.Name.CLICK, post('/session/:sessionId/click')],
175173
[cmd.Name.DOUBLE_CLICK, post('/session/:sessionId/doubleclick')],

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,10 +1284,7 @@ class Timeouts {
12841284
* when the implicit wait timeout has been set.
12851285
*/
12861286
implicitlyWait(ms) {
1287-
return this.driver_.schedule(
1288-
new command.Command(command.Name.IMPLICITLY_WAIT).
1289-
setParameter('ms', ms < 0 ? 0 : ms),
1290-
'WebDriver.manage().timeouts().implicitlyWait(' + ms + ')');
1287+
return this._scheduleCommand(ms, 'implicit', 'implicitlyWait');
12911288
}
12921289

12931290
/**
@@ -1300,10 +1297,7 @@ class Timeouts {
13001297
* when the script timeout has been set.
13011298
*/
13021299
setScriptTimeout(ms) {
1303-
return this.driver_.schedule(
1304-
new command.Command(command.Name.SET_SCRIPT_TIMEOUT).
1305-
setParameter('ms', ms < 0 ? 0 : ms),
1306-
'WebDriver.manage().timeouts().setScriptTimeout(' + ms + ')');
1300+
return this._scheduleCommand(ms, 'script', 'setScriptTimeout');
13071301
}
13081302

13091303
/**
@@ -1316,11 +1310,15 @@ class Timeouts {
13161310
* when the timeout has been set.
13171311
*/
13181312
pageLoadTimeout(ms) {
1313+
return this._scheduleCommand(ms, 'page load', 'pageLoadTimeout');
1314+
}
1315+
1316+
_scheduleCommand(ms, timeoutIdentifier, timeoutName) {
13191317
return this.driver_.schedule(
13201318
new command.Command(command.Name.SET_TIMEOUT).
1321-
setParameter('type', 'page load').
1319+
setParameter('type', timeoutIdentifier).
13221320
setParameter('ms', ms),
1323-
'WebDriver.manage().timeouts().pageLoadTimeout(' + ms + ')');
1321+
`WebDriver.manage().timeouts().${timeoutName}(${ms})`);
13241322
}
13251323
}
13261324

javascript/node/selenium-webdriver/test/element_finding_test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ test.suite(function(env) {
235235
});
236236
});
237237

238+
test.it('should implicitly wait', function() {
239+
var TIMEOUT_IN_MS = 1000;
240+
var EPSILON = TIMEOUT_IN_MS / 2;
241+
242+
driver.manage().timeouts().implicitlyWait(TIMEOUT_IN_MS);
243+
driver.get(Pages.formPage);
244+
245+
var start = new Date();
246+
driver.findElement(By.id('nonExistantButton')).
247+
then(fail, function(e) {
248+
var end = new Date();
249+
assert(e).instanceOf(error.NoSuchElementError);
250+
assert(end - start).closeTo(TIMEOUT_IN_MS, EPSILON);
251+
});
252+
});
253+
238254
test.it('should be able to find multiple matches', function() {
239255
driver.get(Pages.xhtmlTestPage);
240256
driver.findElements(By.className('nameC')).then(function(elements) {

javascript/node/selenium-webdriver/test/execute_script_test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'use strict';
1919

2020
var path = require('path');
21+
var fail = require('assert').fail;
2122

2223
var webdriver = require('..'),
2324
Browser = webdriver.Browser,
@@ -322,6 +323,38 @@ test.suite(function(env) {
322323
.equalTo('<div class="request">GET /common/echo HTTP/1.1</div>');
323324
});
324325
});
326+
327+
describe('async timeouts', function() {
328+
var TIMEOUT_IN_MS = 200;
329+
var ACCEPTABLE_WAIT = TIMEOUT_IN_MS / 10;
330+
var TOO_LONG_WAIT = TIMEOUT_IN_MS * 10;
331+
332+
before(function() {
333+
return driver.manage().timeouts().setScriptTimeout(TIMEOUT_IN_MS)
334+
});
335+
336+
test.it('does not fail if script execute in time', function() {
337+
return executeTimeOutScript(ACCEPTABLE_WAIT);
338+
});
339+
340+
test.it('fails if script took too long', function() {
341+
return executeTimeOutScript(TOO_LONG_WAIT)
342+
.then(function() {
343+
fail('it should have timed out');
344+
}).catch(function(e) {
345+
assert(e.name).equalTo('ScriptTimeoutError');
346+
assert(e.message).contains('Timed out waiting for async script \
347+
result after');
348+
});
349+
});
350+
351+
function executeTimeOutScript(sleepTime) {
352+
return driver.executeAsyncScript(function(sleepTime) {
353+
var callback = arguments[arguments.length - 1];
354+
setTimeout(callback, sleepTime)
355+
}, sleepTime);
356+
}
357+
})
325358
});
326359

327360
function verifyJson(expected) {

0 commit comments

Comments
 (0)