Skip to content

Commit

Permalink
[nodejs] add pollTimeout argument to wait() in WebDriver class (#6520)
Browse files Browse the repository at this point in the history
Currently, the poll timeout is constant and equal
to 0. In this way polling is as fast as it can.
Also, you can not customize this time.

In java this parameter is argument and by default
is 200 ms.
  • Loading branch information
CrispusDH authored and jleyba committed Nov 6, 2018
1 parent d54ebd7 commit ed3aa1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## v.next

### Changes

* add `pollTimeout` argument to the `wait()` method. Default value is `200`ms

### API Changes

* Export `lib/input.Origin` from the top level `selenium-webdriver` module.
Expand Down
15 changes: 11 additions & 4 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,11 @@ class IWebDriver {
* function(!WebDriver): T)} condition The condition to
* wait on, defined as a promise, condition object, or a function to
* evaluate as a condition.
* @param {number=} timeout How long to wait for the condition to be true.
* @param {number=} timeout The duration in milliseconds, how long to wait
* for the condition to be true.
* @param {string=} message An optional message to use if the wait times out.
* @param {number=} pollTimeout The duration in milliseconds, how long to
* wait between polling the condition.
* @return {!(IThenable<T>|WebElementPromise)} A promise that will be
* resolved with the first truthy value returned by the condition
* function, or rejected if the condition times out. If the input
Expand All @@ -456,7 +459,7 @@ class IWebDriver {
* @throws {TypeError} if the provided `condition` is not a valid type.
* @template T
*/
wait(condition, timeout = undefined, message = undefined) {}
wait(condition, timeout = undefined, message = undefined, pollTimeout = undefined) {}

/**
* Makes the driver sleep for the given amount of time.
Expand Down Expand Up @@ -778,11 +781,15 @@ class WebDriver {
}

/** @override */
wait(condition, timeout = 0, message = undefined) {
wait(condition, timeout = 0, message = undefined, pollTimeout = 200) {
if (typeof timeout !== 'number' || timeout < 0) {
throw TypeError('timeout must be a number >= 0: ' + timeout);
}

if (typeof pollTimeout !== 'number' || pollTimeout < 0) {
throw TypeError('pollTimeout must be a number >= 0: ' + pollTimeout);
}

if (promise.isPromise(condition)) {
return new Promise((resolve, reject) => {
if (!timeout) {
Expand Down Expand Up @@ -849,7 +856,7 @@ class WebDriver {
(message ? `${message}\n` : '')
+ `Wait timed out after ${elapsed}ms`));
} else {
setTimeout(pollCondition, 0);
setTimeout(pollCondition, pollTimeout);
}
}, reject);
};
Expand Down

0 comments on commit ed3aa1e

Please sign in to comment.