diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-24 15:10:37 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-24 15:11:17 +0200 |
commit | 7a3df06eb573d36142bd1a8e03c5ce8752d300b3 (patch) | |
tree | 70bfaea8884c374876f607774850a3a51c0cb381 /node_modules/selenium-webdriver | |
parent | aca1143cb9eed16cf37f04e475e4257418dd18ac (diff) |
fix build issues and add typedoc
Diffstat (limited to 'node_modules/selenium-webdriver')
17 files changed, 412 insertions, 63 deletions
diff --git a/node_modules/selenium-webdriver/CHANGES.md b/node_modules/selenium-webdriver/CHANGES.md index 1cdc96814..0260b0604 100644 --- a/node_modules/selenium-webdriver/CHANGES.md +++ b/node_modules/selenium-webdriver/CHANGES.md @@ -1,3 +1,28 @@ +## v3.4.0 + +### Notice + +This release requires [geckodriver 0.15.0](https://github.com/mozilla/geckodriver/releases/tag/v0.15.0) or newer. + +### API Changes + +* Added `Options#getTimeouts()` for retrieving the currently configured session + timeouts (i.e. implicit wait). This method will only work with W3C compatible + WebDriver implementations. +* Deprecated the `Timeouts` class in favor of `Options#setTimeouts()`, which + supports setting multiple timeouts at once. +* Added support for emulating different network conditions (e.g., offline, 2G, WiFi) on Chrome. + +### Changes for W3C WebDriver Spec Compliance + +* Fixed W3C response parsing, which expects response data to always be a JSON + object with a `value` key. +* Added W3C endpoints for interacting with various types of + [user prompts](https://w3c.github.io/webdriver/webdriver-spec.html#user-prompts). +* Added W3C endpoints for remotely executing scripts. +* Added W3C endpoints to get current window handle and all windows handles. + + ## v3.3.0 * Added warning log messages when the user creates new managed promises, or diff --git a/node_modules/selenium-webdriver/README.md b/node_modules/selenium-webdriver/README.md index 31708b186..2cf9ac924 100644 --- a/node_modules/selenium-webdriver/README.md +++ b/node_modules/selenium-webdriver/README.md @@ -193,7 +193,7 @@ the issue tracker - __Do not__ post empty "I see this too" or "Any updates?" comments. These provide no additional information and clutter the log. - __Do not__ report regressions on closed bugs as they are not actively - monitored for upates (especially bugs that are >6 months old). Please open a + monitored for updates (especially bugs that are >6 months old). Please open a new issue and reference the original bug in your report. ## License diff --git a/node_modules/selenium-webdriver/chrome.js b/node_modules/selenium-webdriver/chrome.js index 2dbc93351..b1e8a29e4 100644 --- a/node_modules/selenium-webdriver/chrome.js +++ b/node_modules/selenium-webdriver/chrome.js @@ -143,7 +143,9 @@ const CHROMEDRIVER_EXE = * @enum {string} */ const Command = { - LAUNCH_APP: 'launchApp' + LAUNCH_APP: 'launchApp', + GET_NETWORK_CONDITIONS: 'getNetworkConditions', + SET_NETWORK_CONDITIONS: 'setNetworkConditions' }; @@ -169,6 +171,14 @@ function configureExecutor(executor) { Command.LAUNCH_APP, 'POST', '/session/:sessionId/chromium/launch_app'); + executor.defineCommand( + Command.GET_NETWORK_CONDITIONS, + 'GET', + '/session/:sessionId/chromium/network_conditions'); + executor.defineCommand( + Command.SET_NETWORK_CONDITIONS, + 'POST', + '/session/:sessionId/chromium/network_conditions'); } @@ -727,6 +737,43 @@ class Driver extends webdriver.WebDriver { new command.Command(Command.LAUNCH_APP).setParameter('id', id), 'Driver.launchApp()'); } + + /** + * Schedules a command to get Chrome network emulation settings. + * @return {!promise.Thenable<T>} A promise that will be resolved + * when network emulation settings are retrievied. + */ + getNetworkConditions() { + return this.schedule( + new command.Command(Command.GET_NETWORK_CONDITIONS), + 'Driver.getNetworkConditions()'); + } + + /** + * Schedules a command to set Chrome network emulation settings. + * + * __Sample Usage:__ + * + * driver.setNetworkConditions({ + * offline: false, + * latency: 5, // Additional latency (ms). + * download_throughput: 500 * 1024, // Maximal aggregated download throughput. + * upload_throughput: 500 * 1024 // Maximal aggregated upload throughput. + * }); + * + * @param {Object} spec Defines the network conditions to set + * @return {!promise.Thenable<void>} A promise that will be resolved + * when network emulation settings are set. + */ + setNetworkConditions(spec) { + if (!spec || typeof spec !== 'object') { + throw TypeError('setNetworkConditions called with non-network-conditions parameter'); + } + + return this.schedule( + new command.Command(Command.SET_NETWORK_CONDITIONS).setParameter('network_conditions', spec), + 'Driver.setNetworkConditions(' + JSON.stringify(spec) + ')'); + } } diff --git a/node_modules/selenium-webdriver/example/google_search_test.js b/node_modules/selenium-webdriver/example/google_search_test.js index a29278258..0ca2f4370 100644 --- a/node_modules/selenium-webdriver/example/google_search_test.js +++ b/node_modules/selenium-webdriver/example/google_search_test.js @@ -41,7 +41,7 @@ test.describe('Google Search', function() { // You can write tests either using traditional promises. it('works with promises', function() { - return driver.get('http://www.google.com') + return driver.get('http://www.google.com/ncr') .then(_ => driver.findElement(By.name('q')).sendKeys('webdriver')) .then(_ => driver.findElement(By.name('btnG')).click()) .then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000)); diff --git a/node_modules/selenium-webdriver/lib/by.js b/node_modules/selenium-webdriver/lib/by.js index 8c718be64..fc74b2056 100644 --- a/node_modules/selenium-webdriver/lib/by.js +++ b/node_modules/selenium-webdriver/lib/by.js @@ -259,6 +259,14 @@ function check(locator) { if (locator instanceof By || typeof locator === 'function') { return locator; } + + if (locator + && typeof locator === 'object' + && typeof locator.using === 'string' + && typeof locator.value === 'string') { + return new By(locator.using, locator.value); + } + for (let key in locator) { if (locator.hasOwnProperty(key) && By.hasOwnProperty(key)) { return By[key](locator[key]); diff --git a/node_modules/selenium-webdriver/lib/command.js b/node_modules/selenium-webdriver/lib/command.js index c9a366e4e..39db8c451 100644 --- a/node_modules/selenium-webdriver/lib/command.js +++ b/node_modules/selenium-webdriver/lib/command.js @@ -150,6 +150,8 @@ const Name = { TAKE_ELEMENT_SCREENSHOT: 'takeElementScreenshot', IMPLICITLY_WAIT: 'implicitlyWait', SET_SCRIPT_TIMEOUT: 'setScriptTimeout', + + GET_TIMEOUT: 'getTimeout', SET_TIMEOUT: 'setTimeout', ACCEPT_ALERT: 'acceptAlert', diff --git a/node_modules/selenium-webdriver/lib/firefox/webdriver.xpi b/node_modules/selenium-webdriver/lib/firefox/webdriver.xpi Binary files differindex a7b0fa3a7..6c69f1d32 100644 --- a/node_modules/selenium-webdriver/lib/firefox/webdriver.xpi +++ b/node_modules/selenium-webdriver/lib/firefox/webdriver.xpi diff --git a/node_modules/selenium-webdriver/lib/http.js b/node_modules/selenium-webdriver/lib/http.js index 136a48e63..e141bf190 100644 --- a/node_modules/selenium-webdriver/lib/http.js +++ b/node_modules/selenium-webdriver/lib/http.js @@ -225,6 +225,7 @@ const COMMAND_MAP = new Map([ [cmd.Name.EXECUTE_SCRIPT, post('/session/:sessionId/execute')], [cmd.Name.EXECUTE_ASYNC_SCRIPT, post('/session/:sessionId/execute_async')], [cmd.Name.SCREENSHOT, get('/session/:sessionId/screenshot')], + [cmd.Name.GET_TIMEOUT, get('/session/:sessionId/timeouts')], [cmd.Name.SET_TIMEOUT, post('/session/:sessionId/timeouts')], [cmd.Name.MOVE_TO, post('/session/:sessionId/moveto')], [cmd.Name.CLICK, post('/session/:sessionId/click')], @@ -256,6 +257,10 @@ const COMMAND_MAP = new Map([ /** @const {!Map<string, (CommandSpec|CommandTransformer)>} */ const W3C_COMMAND_MAP = new Map([ [cmd.Name.GET_ACTIVE_ELEMENT, get('/session/:sessionId/element/active')], + [cmd.Name.GET_ALERT_TEXT, get('/session/:sessionId/alert/text')], + [cmd.Name.SET_ALERT_TEXT, post('/session/:sessionId/alert/text')], + [cmd.Name.ACCEPT_ALERT, post('/session/:sessionId/alert/accept')], + [cmd.Name.DISMISS_ALERT, post('/session/:sessionId/alert/dismiss')], [cmd.Name.GET_ELEMENT_ATTRIBUTE, (cmd) => { return toExecuteAtomCommand(cmd, Atom.GET_ATTRIBUTE, 'id', 'name'); }], @@ -264,11 +269,15 @@ const W3C_COMMAND_MAP = new Map([ [cmd.Name.IS_ELEMENT_DISPLAYED, (cmd) => { return toExecuteAtomCommand(cmd, Atom.IS_DISPLAYED, 'id'); }], + [cmd.Name.EXECUTE_SCRIPT, post('/session/:sessionId/execute/sync')], + [cmd.Name.EXECUTE_ASYNC_SCRIPT, post('/session/:sessionId/execute/async')], [cmd.Name.MAXIMIZE_WINDOW, post('/session/:sessionId/window/maximize')], [cmd.Name.GET_WINDOW_POSITION, get('/session/:sessionId/window/position')], [cmd.Name.SET_WINDOW_POSITION, post('/session/:sessionId/window/position')], [cmd.Name.GET_WINDOW_SIZE, get('/session/:sessionId/window/size')], [cmd.Name.SET_WINDOW_SIZE, post('/session/:sessionId/window/size')], + [cmd.Name.GET_CURRENT_WINDOW_HANDLE, get('/session/:sessionId/window')], + [cmd.Name.GET_WINDOW_HANDLES, get('/session/:sessionId/window/handles')], ]); @@ -428,34 +437,29 @@ class Executor { return doSend(this, request).then(response => { this.log_.finer(() => `>>>\n${request}\n<<<\n${response}`); - let parsed = - parseHttpResponse( - command, /** @type {!Response} */ (response), this.w3c); + let httpResponse = /** @type {!Response} */(response); + let {isW3C, value} = parseHttpResponse(command, httpResponse); if (command.getName() === cmd.Name.NEW_SESSION || command.getName() === cmd.Name.DESCRIBE_SESSION) { - if (!parsed || !parsed['sessionId']) { + if (!value || !value.sessionId) { throw new error.WebDriverError( - 'Unable to parse new session response: ' + response.body); + `Unable to parse new session response: ${response.body}`); } // The remote end is a W3C compliant server if there is no `status` // field in the response. This is not applicable for the DESCRIBE_SESSION // command, which is not defined in the W3C spec. if (command.getName() === cmd.Name.NEW_SESSION) { - this.w3c = this.w3c || !('status' in parsed); + this.w3c = this.w3c || isW3C; } - return new Session(parsed['sessionId'], parsed['value']); + // No implementations use the `capabilities` key yet... + let capabilities = value.capabilities || value.value; + return new Session(value.sessionId, capabilities); } - if (parsed - && typeof parsed === 'object' - && 'value' in parsed) { - let value = parsed['value']; - return typeof value === 'undefined' ? null : value; - } - return parsed; + return typeof value === 'undefined' ? null : value; }); }); } @@ -481,40 +485,45 @@ function tryParse(str) { * * @param {!cmd.Command} command The command the response is for. * @param {!Response} httpResponse The HTTP response to parse. - * @param {boolean} w3c Whether the response should be processed using the - * W3C wire protocol. - * @return {?} The parsed response. + * @return {{isW3C: boolean, value: ?}} An object describing the parsed + * response. This object will have two fields: `isW3C` indicates whether + * the response looks like it came from a remote end that conforms with the + * W3C WebDriver spec, and `value`, the actual response value. * @throws {WebDriverError} If the HTTP response is an error. */ -function parseHttpResponse(command, httpResponse, w3c) { - let parsed = tryParse(httpResponse.body); - if (parsed !== undefined) { - if (httpResponse.status < 200) { - // This should never happen, but throw the raw response so - // users report it. - throw new error.WebDriverError( - `Unexpected HTTP response:\n${httpResponse}`); - } +function parseHttpResponse(command, httpResponse) { + if (httpResponse.status < 200) { + // This should never happen, but throw the raw response so users report it. + throw new error.WebDriverError( + `Unexpected HTTP response:\n${httpResponse}`); + } - if (w3c) { - if (httpResponse.status > 399) { - error.throwDecodedError(parsed); + let parsed = tryParse(httpResponse.body); + if (parsed && typeof parsed === 'object') { + let value = parsed.value; + let isW3C = + value !== null && typeof value === 'object' + && typeof parsed.status === 'undefined'; + + if (!isW3C) { + error.checkLegacyResponse(parsed); + + // Adjust legacy new session responses to look like W3C to simplify + // later processing. + if (command.getName() === cmd.Name.NEW_SESSION + || command.getName() == cmd.Name.DESCRIBE_SESSION) { + value = parsed; } - return parsed; - } - // If this is a new session command, we need to check for a W3C compliant - // error object. This is necessary since a successful new session command - // is what puts the executor into W3C mode. - if (httpResponse.status > 399 - && (command.getName() == cmd.Name.NEW_SESSION - || command.getName() === cmd.Name.DESCRIBE_SESSION) - && error.isErrorResponse(parsed)) { - error.throwDecodedError(parsed); + } else if (httpResponse.status > 399) { + error.throwDecodedError(value); } - error.checkLegacyResponse(parsed); - return parsed; + return {isW3C, value}; + } + + if (parsed !== undefined) { + return {isW3C: false, value: parsed}; } let value = httpResponse.body.replace(/\r\n/g, '\n'); @@ -527,7 +536,7 @@ function parseHttpResponse(command, httpResponse, w3c) { throw new error.WebDriverError(value); } - return value || null; + return {isW3C: false, value: value || null}; } diff --git a/node_modules/selenium-webdriver/lib/test/data/click_tests/disabled_element.html b/node_modules/selenium-webdriver/lib/test/data/click_tests/disabled_element.html new file mode 100644 index 000000000..7113e1bc0 --- /dev/null +++ b/node_modules/selenium-webdriver/lib/test/data/click_tests/disabled_element.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html> +<head> + <title>Clicking on a disabled element</title> +</head> +<body> +<h1>See below</h1> +<form action="POST"> + <input name="disabled" disabled="disabled" /> +</form> +</body> +</html>
\ No newline at end of file diff --git a/node_modules/selenium-webdriver/lib/test/data/nestedElements.html b/node_modules/selenium-webdriver/lib/test/data/nestedElements.html index cf00083cf..88eda51fe 100644 --- a/node_modules/selenium-webdriver/lib/test/data/nestedElements.html +++ b/node_modules/selenium-webdriver/lib/test/data/nestedElements.html @@ -5,6 +5,15 @@ <div id="test_id_div"> <p id="test_id">inside</p> </div> + <div id="test_special_chars"> + <p id="white space">space</p> + <p id="css#.chars">css escapes</p> + </div> + <div id="test_special_chars_2"> + <p id="white space">second copy for testing plural findElements</p> + <p id="css#.chars">second copy</p> + </div> + <form method="get" action="resultPage.html" name="form1" style="display: block"> Here's a checkbox: <input type="checkbox" id="checky" name="checky" value="furrfu"/><br/> <select name="selectomatic" id="1"> @@ -152,4 +161,4 @@ <span class="oneother">But not me</span> </div> </body> -</html>
\ No newline at end of file +</html> diff --git a/node_modules/selenium-webdriver/lib/test/index.js b/node_modules/selenium-webdriver/lib/test/index.js index b3275ccbb..7dd1a1fc8 100644 --- a/node_modules/selenium-webdriver/lib/test/index.js +++ b/node_modules/selenium-webdriver/lib/test/index.js @@ -50,6 +50,7 @@ var NATIVE_BROWSERS = [ ]; +var noBuild = /^1|true$/i.test(process.env['SELENIUM_NO_BUILD']); var serverJar = process.env['SELENIUM_SERVER_JAR']; var remoteUrl = process.env['SELENIUM_REMOTE_URL']; var useLoopback = process.env['SELENIUM_USE_LOOP_BACK'] == '1'; @@ -225,7 +226,7 @@ function suite(fn, opt_options) { try { before(function() { - if (isDevMode) { + if (isDevMode && !noBuild) { return build.of( '//javascript/atoms/fragments:is-displayed', '//javascript/webdriver/atoms:getAttribute') diff --git a/node_modules/selenium-webdriver/lib/webdriver.js b/node_modules/selenium-webdriver/lib/webdriver.js index c8d04e82a..1c63112d7 100644 --- a/node_modules/selenium-webdriver/lib/webdriver.js +++ b/node_modules/selenium-webdriver/lib/webdriver.js @@ -1327,6 +1327,91 @@ class Options { } /** + * Schedules a command to fetch the timeouts currently configured for the + * current session. + * + * @return {!promise.Thenable<{script: number, + * pageLoad: number, + * implicit: number}>} A promise that will be + * resolved with the timeouts currently configured for the current + * session. + * @see #setTimeouts() + */ + getTimeouts() { + return this.driver_.schedule( + new command.Command(command.Name.GET_TIMEOUT), + `WebDriver.manage().getTimeouts()`) + } + + /** + * Schedules a command to set timeout durations associated with the current + * session. + * + * The following timeouts are supported (all timeouts are specified in + * milliseconds): + * + * - `implicit` specifies the maximum amount of time to wait for an element + * locator to succeed when {@linkplain WebDriver#findElement locating} + * {@linkplain WebDriver#findElements elements} on the page. + * Defaults to 0 milliseconds. + * + * - `pageLoad` specifies the maximum amount of time to wait for a page to + * finishing loading. Defaults to 300000 milliseconds. + * + * - `script` specifies the maximum amount of time to wait for an + * {@linkplain WebDriver#executeScript evaluated script} to run. If set to + * `null`, the script timeout will be indefinite. + * Defaults to 30000 milliseconds. + * + * @param {{script: (number|null|undefined), + * pageLoad: (number|null|undefined), + * implicit: (number|null|undefined)}} conf + * The desired timeout configuration. + * @return {!promise.Thenable<void>} A promise that will be resolved when the + * timeouts have been set. + * @throws {!TypeError} if an invalid options object is provided. + * @see #getTimeouts() + * @see <https://w3c.github.io/webdriver/webdriver-spec.html#dfn-set-timeouts> + */ + setTimeouts({script, pageLoad, implicit} = {}) { + let cmd = new command.Command(command.Name.SET_TIMEOUT); + + let valid = false; + function setParam(key, value) { + if (value === null || typeof value === 'number') { + valid = true; + cmd.setParameter(key, value); + } else if (typeof value !== 'undefined') { + throw TypeError( + 'invalid timeouts configuration:' + + ` expected "${key}" to be a number, got ${typeof value}`); + } + } + setParam('implicit', implicit); + setParam('pageLoad', pageLoad); + setParam('script', script); + + if (valid) { + return this.driver_.schedule(cmd, `WebDriver.manage().setTimeouts()`) + .catch(() => { + // Fallback to the legacy method. + let cmds = []; + if (typeof script === 'number') { + cmds.push(legacyTimeout(this.driver_, 'script', script)); + } + if (typeof implicit === 'number') { + cmds.push(legacyTimeout(this.driver_, 'implicit', implicit)); + } + if (typeof pageLoad === 'number') { + cmds.push(legacyTimeout(this.driver_, 'page load', pageLoad)); + } + return Promise.all(cmds); + }); + } + throw TypeError('no timeouts specified'); + } + + /** * @return {!Logs} The interface for managing driver * logs. */ @@ -1336,6 +1421,7 @@ class Options { /** * @return {!Timeouts} The interface for managing driver timeouts. + * @deprecated Use {@link #setTimeouts()} instead. */ timeouts() { return new Timeouts(this.driver_); @@ -1351,6 +1437,22 @@ class Options { /** + * @param {!WebDriver} driver + * @param {string} type + * @param {number} ms + * @return {!promise.Thenable<void>} + */ +function legacyTimeout(driver, type, ms) { + return driver.schedule( + new command.Command(command.Name.SET_TIMEOUT) + .setParameter('type', type) + .setParameter('ms', ms), + `WebDriver.manage().setTimeouts({${type}: ${ms}})`); +} + + + +/** * A record object describing a browser cookie. * * @record @@ -1432,6 +1534,9 @@ Options.Cookie.prototype.expiry; * * webdriver.manage().timeouts() * + * @deprecated This has been deprecated in favor of + * {@link Options#setTimeouts()}, which supports setting multiple timeouts + * at once. * @see WebDriver#manage() * @see Options#timeouts() */ @@ -1465,9 +1570,11 @@ class Timeouts { * @param {number} ms The amount of time to wait, in milliseconds. * @return {!promise.Thenable<void>} A promise that will be resolved * when the implicit wait timeout has been set. + * @deprecated Use {@link Options#setTimeouts() + * driver.manage().setTimeouts({implicit: ms})}. */ implicitlyWait(ms) { - return this._scheduleCommand(ms, 'implicit', 'implicitlyWait'); + return this.driver_.manage().setTimeouts({implicit: ms}); } /** @@ -1478,9 +1585,11 @@ class Timeouts { * @param {number} ms The amount of time to wait, in milliseconds. * @return {!promise.Thenable<void>} A promise that will be resolved * when the script timeout has been set. + * @deprecated Use {@link Options#setTimeouts() + * driver.manage().setTimeouts({script: ms})}. */ setScriptTimeout(ms) { - return this._scheduleCommand(ms, 'script', 'setScriptTimeout'); + return this.driver_.manage().setTimeouts({script: ms}); } /** @@ -1491,17 +1600,11 @@ class Timeouts { * @param {number} ms The amount of time to wait, in milliseconds. * @return {!promise.Thenable<void>} A promise that will be resolved * when the timeout has been set. + * @deprecated Use {@link Options#setTimeouts() + * driver.manage().setTimeouts({pageLoad: ms})}. */ 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', timeoutIdentifier). - setParameter('ms', ms), - `WebDriver.manage().timeouts().${timeoutName}(${ms})`); + return this.driver_.manage().setTimeouts({pageLoad: ms}); } } @@ -2083,6 +2186,7 @@ class WebElement { if (!this.driver_.fileDetector_) { return this.schedule_( new command.Command(command.Name.SEND_KEYS_TO_ELEMENT). + setParameter('text', keys). setParameter('value', keys), 'WebElement.sendKeys()'); } @@ -2098,6 +2202,7 @@ class WebElement { }).then(function(keys) { return element.schedule_( new command.Command(command.Name.SEND_KEYS_TO_ELEMENT). + setParameter('text', keys). setParameter('value', keys.split('')), 'WebElement.sendKeys()'); }); diff --git a/node_modules/selenium-webdriver/net/portprober.js b/node_modules/selenium-webdriver/net/portprober.js index 3ea33b2b3..311077b64 100644 --- a/node_modules/selenium-webdriver/net/portprober.js +++ b/node_modules/selenium-webdriver/net/portprober.js @@ -191,7 +191,7 @@ function findFreePort(opt_host) { } else { findPort(); } - }); + }, findPort); } }); }); diff --git a/node_modules/selenium-webdriver/package.json b/node_modules/selenium-webdriver/package.json index dfb557bf4..729871330 100644 --- a/node_modules/selenium-webdriver/package.json +++ b/node_modules/selenium-webdriver/package.json @@ -1,6 +1,6 @@ { "name": "selenium-webdriver", - "version": "3.3.0", + "version": "3.4.0", "description": "The official WebDriver JavaScript bindings from the Selenium project", "license": "Apache-2.0", "keywords": [ diff --git a/node_modules/selenium-webdriver/test/lib/by_test.js b/node_modules/selenium-webdriver/test/lib/by_test.js index 1669ec917..34314fbf8 100644 --- a/node_modules/selenium-webdriver/test/lib/by_test.js +++ b/node_modules/selenium-webdriver/test/lib/by_test.js @@ -88,6 +88,27 @@ describe('by', function() { }); describe('checkedLocator', function() { + it('accepts a By instance', function() { + let original = by.By.name('foo'); + let locator = by.checkedLocator(original); + assert.strictEqual(locator, original); + }); + + it('accepts custom locator functions', function() { + let original = function() {}; + let locator = by.checkedLocator(original); + assert.strictEqual(locator, original); + }); + + // See https://github.com/SeleniumHQ/selenium/issues/3056 + it('accepts By-like objects', function() { + let fakeBy = {using: 'id', value: 'foo'}; + let locator = by.checkedLocator(fakeBy); + assert.strictEqual(locator.constructor, by.By); + assert.equal(locator.using, 'id'); + assert.equal(locator.value, 'foo'); + }); + it('accepts class name', function() { let locator = by.checkedLocator({className: 'foo'}); assert.equal('css selector', locator.using); diff --git a/node_modules/selenium-webdriver/test/lib/http_test.js b/node_modules/selenium-webdriver/test/lib/http_test.js index 2dd27869d..7cb0050f7 100644 --- a/node_modules/selenium-webdriver/test/lib/http_test.js +++ b/node_modules/selenium-webdriver/test/lib/http_test.js @@ -293,7 +293,14 @@ describe('http', function() { }); it('auto-upgrades on W3C response', function() { - var rawResponse = {sessionId: 's123', value: {name: 'Bob'}}; + let rawResponse = { + value: { + sessionId: 's123', + value: { + name: 'Bob' + } + } + }; send.returns(Promise.resolve( new http.Response(200, {}, JSON.stringify(rawResponse)))); @@ -344,7 +351,8 @@ describe('http', function() { }); it('handles w3c new session failures', function() { - let rawResponse = {error: 'no such element', message: 'oops'}; + let rawResponse = + {value: {error: 'no such element', message: 'oops'}}; send.returns(Promise.resolve( new http.Response(500, {}, JSON.stringify(rawResponse)))); @@ -429,7 +437,7 @@ describe('http', function() { }); it('does not auto-upgrade on W3C response', function() { - var rawResponse = {sessionId: 's123', value: {name: 'Bob'}}; + var rawResponse = {value: {sessionId: 's123', value: {name: 'Bob'}}}; send.returns(Promise.resolve( new http.Response(200, {}, JSON.stringify(rawResponse)))); diff --git a/node_modules/selenium-webdriver/test/lib/webdriver_test.js b/node_modules/selenium-webdriver/test/lib/webdriver_test.js index 0a124530e..65fa5193a 100644 --- a/node_modules/selenium-webdriver/test/lib/webdriver_test.js +++ b/node_modules/selenium-webdriver/test/lib/webdriver_test.js @@ -1952,6 +1952,108 @@ describe('WebDriver', function() { }); }); + describe('manage()', function() { + describe('setTimeouts()', function() { + describe('throws if no timeouts are specified', function() { + let driver; + before(() => driver = new FakeExecutor().createDriver()); + + it('; no arguments', function() { + assert.throws(() => driver.manage().setTimeouts(), TypeError); + }); + + it('; ignores unrecognized timeout keys', function() { + assert.throws( + () => driver.manage().setTimeouts({foo: 123}), TypeError); + }); + + it('; ignores positional arguments', function() { + assert.throws( + () => driver.manage().setTimeouts(1234, 56), TypeError); + }); + }); + + describe('throws timeout is not a number, null, or undefined', () => { + let driver; + before(() => driver = new FakeExecutor().createDriver()); + + function checkError(e) { + return e instanceof TypeError + && /expected "(script|pageLoad|implicit)" to be a number/.test( + e.message); + } + + it('script', function() { + assert.throws( + () => driver.manage().setTimeouts({script: 'abc'}), + checkError); + }); + + it('pageLoad', function() { + assert.throws( + () => driver.manage().setTimeouts({pageLoad: 'abc'}), + checkError); + }); + + it('implicit', function() { + assert.throws( + () => driver.manage().setTimeouts({implicit: 'abc'}), + checkError); + }); + }); + + it('can set multiple timeouts', function() { + let executor = new FakeExecutor() + .expect(CName.SET_TIMEOUT, {script:1, pageLoad: 2, implicit: 3}) + .andReturnSuccess() + .end(); + let driver = executor.createDriver(); + return driver.manage() + .setTimeouts({script: 1, pageLoad: 2, implicit: 3}); + }); + + it('falls back to legacy wire format if W3C version fails', () => { + let executor = new FakeExecutor() + .expect(CName.SET_TIMEOUT, {implicit: 3}) + .andReturnError(Error('oops')) + .expect(CName.SET_TIMEOUT, {type: 'implicit', ms: 3}) + .andReturnSuccess() + .end(); + let driver = executor.createDriver(); + return driver.manage().setTimeouts({implicit: 3}); + }); + + describe('deprecated API calls setTimeouts()', function() { + it('implicitlyWait()', function() { + let executor = new FakeExecutor() + .expect(CName.SET_TIMEOUT, {implicit: 3}) + .andReturnSuccess() + .end(); + let driver = executor.createDriver(); + return driver.manage().timeouts().implicitlyWait(3); + }); + + it('setScriptTimeout()', function() { + let executor = new FakeExecutor() + .expect(CName.SET_TIMEOUT, {script: 3}) + .andReturnSuccess() + .end(); + let driver = executor.createDriver(); + return driver.manage().timeouts().setScriptTimeout(3); + }); + + it('pageLoadTimeout()', function() { + let executor = new FakeExecutor() + .expect(CName.SET_TIMEOUT, {pageLoad: 3}) + .andReturnSuccess() + .end(); + let driver = executor.createDriver(); + return driver.manage().timeouts().pageLoadTimeout(3); + }); + }); + }); + }); + describe('generator support', function() { var driver; |