From ed3aa1e7766456110aa993e09c0500a6e02be270 Mon Sep 17 00:00:00 2001 From: Oleksii Date: Tue, 6 Nov 2018 21:53:28 +0200 Subject: [PATCH] [nodejs] add pollTimeout argument to wait() in WebDriver class (#6520) 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. --- javascript/node/selenium-webdriver/CHANGES.md | 4 ++++ .../node/selenium-webdriver/lib/webdriver.js | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) 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); };