diff --git a/javascript/node/selenium-webdriver/CHANGES.md b/javascript/node/selenium-webdriver/CHANGES.md index 54560c48d7c67..cb3b504fc6f67 100644 --- a/javascript/node/selenium-webdriver/CHANGES.md +++ b/javascript/node/selenium-webdriver/CHANGES.md @@ -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. diff --git a/javascript/node/selenium-webdriver/lib/webdriver.js b/javascript/node/selenium-webdriver/lib/webdriver.js index 1aa06f2bb06e4..b68c127ae4f7b 100644 --- a/javascript/node/selenium-webdriver/lib/webdriver.js +++ b/javascript/node/selenium-webdriver/lib/webdriver.js @@ -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|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 @@ -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. @@ -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) { @@ -849,7 +856,7 @@ class WebDriver { (message ? `${message}\n` : '') + `Wait timed out after ${elapsed}ms`)); } else { - setTimeout(pollCondition, 0); + setTimeout(pollCondition, pollTimeout); } }, reject); };