selenium-webdriver 4.0.0-alpha.3 → 4.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGES.md +9 -2
  2. package/README.md +2 -4
  3. package/chrome.js +19 -527
  4. package/chromium.js +762 -0
  5. package/edge.js +97 -58
  6. package/firefox.js +23 -5
  7. package/http/index.js +4 -0
  8. package/io/index.js +1 -1
  9. package/lib/actions.js +1 -1
  10. package/lib/atoms/get-attribute.js +1 -2
  11. package/lib/atoms/is-displayed.js +5 -6
  12. package/lib/atoms/make-atoms-module.js +17 -0
  13. package/lib/capabilities.js +17 -4
  14. package/lib/command.js +1 -0
  15. package/lib/http.js +8 -3
  16. package/lib/input.js +6 -6
  17. package/lib/logging.js +1 -1
  18. package/lib/webdriver.js +33 -3
  19. package/net/portprober.js +1 -1
  20. package/package.json +8 -9
  21. package/BUILD.bazel +0 -88
  22. package/example/chrome_android.js +0 -42
  23. package/example/chrome_mobile_emulation.js +0 -42
  24. package/example/firefox_channels.js +0 -77
  25. package/example/google_search.js +0 -50
  26. package/example/google_search_test.js +0 -72
  27. package/example/headless.js +0 -55
  28. package/example/logging.js +0 -68
  29. package/jasmine.json +0 -11
  30. package/lib/atoms/BUILD.bazel +0 -28
  31. package/lib/test/bootstrap_jasmine.js +0 -28
  32. package/lib/test/build.js +0 -156
  33. package/lib/test/data/actions/click.html +0 -24
  34. package/lib/test/data/actions/drag.html +0 -77
  35. package/lib/test/data/actions/record_click.html +0 -21
  36. package/lib/test/data/chrome/download.html +0 -2
  37. package/lib/test/data/firefox/webextension.xpi +0 -0
  38. package/lib/test/fileserver.js +0 -337
  39. package/lib/test/httpserver.js +0 -120
  40. package/lib/test/index.js +0 -87
  41. package/lib/test/resources.js +0 -40
  42. package/test/actions_test.js +0 -206
  43. package/test/builder_test.js +0 -106
  44. package/test/chrome/devtools_test.js +0 -93
  45. package/test/chrome/options_test.js +0 -121
  46. package/test/chrome/service_test.js +0 -45
  47. package/test/cookie_test.js +0 -210
  48. package/test/element_finding_test.js +0 -431
  49. package/test/execute_script_test.js +0 -355
  50. package/test/fingerprint_test.js +0 -63
  51. package/test/firefox_test.js +0 -233
  52. package/test/frame_test.js +0 -45
  53. package/test/http/http_test.js +0 -229
  54. package/test/http/util_test.js +0 -178
  55. package/test/io/io_test.js +0 -364
  56. package/test/io/zip_test.js +0 -126
  57. package/test/lib/by_test.js +0 -160
  58. package/test/lib/capabilities_test.js +0 -129
  59. package/test/lib/error_test.js +0 -333
  60. package/test/lib/http_test.js +0 -576
  61. package/test/lib/input_test.js +0 -1379
  62. package/test/lib/logging_test.js +0 -272
  63. package/test/lib/promise_test.js +0 -674
  64. package/test/lib/testutil.js +0 -90
  65. package/test/lib/until_test.js +0 -478
  66. package/test/lib/webdriver_test.js +0 -1692
  67. package/test/logging_test.js +0 -160
  68. package/test/net/index_test.js +0 -60
  69. package/test/net/portprober_test.js +0 -128
  70. package/test/page_loading_test.js +0 -156
  71. package/test/proxy_test.js +0 -167
  72. package/test/rect_test.js +0 -51
  73. package/test/remote_test.js +0 -98
  74. package/test/safari_test.js +0 -44
  75. package/test/stale_element_test.js +0 -60
  76. package/test/upload_test.js +0 -78
  77. package/test/window_test.js +0 -168
  78. package/testing/index.js +0 -498
  79. package/tools/init_jasmine.js +0 -7
package/testing/index.js DELETED
@@ -1,498 +0,0 @@
1
- // Licensed to the Software Freedom Conservancy (SFC) under one
2
- // or more contributor license agreements. See the NOTICE file
3
- // distributed with this work for additional information
4
- // regarding copyright ownership. The SFC licenses this file
5
- // to you under the Apache License, Version 2.0 (the
6
- // "License"); you may not use this file except in compliance
7
- // with the License. You may obtain a copy of the License at
8
- //
9
- // http://www.apache.org/licenses/LICENSE-2.0
10
- //
11
- // Unless required by applicable law or agreed to in writing,
12
- // software distributed under the License is distributed on an
13
- // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- // KIND, either express or implied. See the License for the
15
- // specific language governing permissions and limitations
16
- // under the License.
17
-
18
- /**
19
- * @fileoverview Provides extensions for
20
- * [Jasmine](https://jasmine.github.io) and [Mocha](https://mochajs.org).
21
- *
22
- * You may conditionally suppress a test function using the exported
23
- * "ignore" function. If the provided predicate returns true, the attached
24
- * test case will be skipped:
25
- *
26
- * test.ignore(maybe()).it('is flaky', function() {
27
- * if (Math.random() < 0.5) throw Error();
28
- * });
29
- *
30
- * function maybe() { return Math.random() < 0.5; }
31
- */
32
-
33
- 'use strict';
34
-
35
- const {isatty} = require('tty');
36
-
37
- const chrome = require('../chrome');
38
- const edge = require('../edge');
39
- const firefox = require('../firefox');
40
- const ie = require('../ie');
41
- const remote = require('../remote');
42
- const safari = require('../safari');
43
- const {Browser} = require('../lib/capabilities');
44
- const {Builder} = require('../index');
45
-
46
-
47
- /**
48
- * Describes a browser targetted by a {@linkplain suite test suite}.
49
- * @record
50
- */
51
- function TargetBrowser() {}
52
-
53
- /**
54
- * The {@linkplain Browser name} of the targetted browser.
55
- * @type {string}
56
- */
57
- TargetBrowser.prototype.name;
58
-
59
- /**
60
- * The specific version of the targetted browser, if any.
61
- * @type {(string|undefined)}
62
- */
63
- TargetBrowser.prototype.version;
64
-
65
- /**
66
- * The specific {@linkplain ../lib/capabilities.Platform platform} for the
67
- * targetted browser, if any.
68
- * @type {(string|undefined)}.
69
- */
70
- TargetBrowser.prototype.platform;
71
-
72
-
73
- /** @suppress {checkTypes} */
74
- function color(c, s) {
75
- return isatty(process.stdout) ? `\u001b[${c}m${s}\u001b[0m` : s;
76
- }
77
- function green(s) { return color(32, s); }
78
- function cyan(s) { return color(36, s); }
79
- function info(msg) { console.info(`${green('[INFO]')} ${msg}`); }
80
- function warn(msg) { console.warn(`${cyan('[WARNING]')} ${msg}`); }
81
-
82
-
83
- /**
84
- * Extracts the browsers for a test suite to target from the `SELENIUM_BROWSER`
85
- * environment variable.
86
- *
87
- * @return {!Array<!TargetBrowser>} the browsers to target.
88
- */
89
- function getBrowsersToTestFromEnv() {
90
- let browsers = process.env['SELENIUM_BROWSER'];
91
- if (!browsers) {
92
- return [];
93
- }
94
- return browsers.split(',').map(spec => {
95
- const parts = spec.split(/:/, 3);
96
- let name = parts[0];
97
- if (name === 'ie') {
98
- name = Browser.IE;
99
- } else if (name === 'edge') {
100
- name = Browser.EDGE;
101
- }
102
- let version = parts[1];
103
- let platform = parts[2];
104
- return {name, version, platform};
105
- });
106
- }
107
-
108
-
109
- /**
110
- * @return {!Array<!TargetBrowser>} the browsers available for testing on this
111
- * system.
112
- */
113
- function getAvailableBrowsers() {
114
- info(`Searching for WebDriver executables installed on the current system...`);
115
-
116
- let targets = [
117
- [chrome.locateSynchronously, Browser.CHROME],
118
- [edge.locateSynchronously, Browser.EDGE],
119
- [firefox.locateSynchronously, Browser.FIREFOX],
120
- [ie.locateSynchronously, Browser.IE],
121
- [safari.locateSynchronously, Browser.SAFARI],
122
- ];
123
-
124
- let availableBrowsers = [];
125
- for (let pair of targets) {
126
- const fn = pair[0];
127
- const name = pair[1];
128
- if (fn()) {
129
- info(`... located ${name}`);
130
- availableBrowsers.push({name});
131
- }
132
- }
133
-
134
- if (availableBrowsers.length === 0) {
135
- warn(`Unable to locate any WebDriver executables for testing`);
136
- }
137
-
138
- return availableBrowsers;
139
- }
140
-
141
- let wasInit;
142
- let targetBrowsers;
143
- let seleniumJar;
144
- let seleniumUrl;
145
- let seleniumServer;
146
-
147
- /**
148
- * Initializes this module by determining which browsers a
149
- * {@linkplain ./index.suite test suite} should run against. The default
150
- * behavior is to run tests against every browser with a WebDriver executables
151
- * (chromedriver, firefoxdriver, etc.) are installed on the system by `PATH`.
152
- *
153
- * Specific browsers can be selected at runtime by setting the
154
- * `SELENIUM_BROWSER` environment variable. This environment variable has the
155
- * same semantics as with the WebDriver {@link ../index.Builder Builder},
156
- * except you may use a comma-delimited list to run against multiple browsers:
157
- *
158
- * SELENIUM_BROWSER=chrome,firefox mocha --recursive tests/
159
- *
160
- * The `SELENIUM_REMOTE_URL` environment variable may be set to configure tests
161
- * to run againt an externally managed (usually remote) Selenium server. When
162
- * set, the WebDriver builder provided by each
163
- * {@linkplain TestEnvironment#builder TestEnvironment} will automatically be
164
- * configured to use this server instead of starting a browser drively locally.
165
- *
166
- * The `SELENIUM_SERVER_JAR` environment variable may be set to the path of a
167
- * standalone Selenium server on the local machine that should be used for
168
- * WebDriver sessions. When set, the WebDriver builder provided by each
169
- * {@linkplain TestEnvironment} will automatically be configured to use the
170
- * started server instead of using a browser driver directly. It should only be
171
- * necessary to set the `SELENIUM_SERVER_JAR` when testing locally against
172
- * browsers not natively supported by the WebDriver
173
- * {@link ../index.Builder Builder}.
174
- *
175
- * When either of the `SELENIUM_REMOTE_URL` or `SELENIUM_SERVER_JAR` environment
176
- * variables are set, the `SELENIUM_BROWSER` variable must also be set.
177
- *
178
- * @param {boolean=} force whether to force this module to re-initialize and
179
- * scan `process.env` again to determine which browsers to run tests
180
- * against.
181
- */
182
- function init(force = false) {
183
- if (wasInit && !force) {
184
- return;
185
- }
186
- wasInit = true;
187
-
188
- // If force re-init, kill the current server if there is one.
189
- if (seleniumServer) {
190
- seleniumServer.kill();
191
- seleniumServer = null;
192
- }
193
-
194
- seleniumJar = process.env['SELENIUM_SERVER_JAR'];
195
- seleniumUrl = process.env['SELENIUM_REMOTE_URL'];
196
- if (seleniumJar) {
197
- info(`Using Selenium server jar: ${seleniumJar}`);
198
- }
199
-
200
- if (seleniumUrl) {
201
- info(`Using Selenium remote end: ${seleniumUrl}`);
202
- }
203
-
204
- if (seleniumJar && seleniumUrl) {
205
- throw Error(
206
- 'Ambiguous test configuration: both SELENIUM_REMOTE_URL'
207
- + ' && SELENIUM_SERVER_JAR environment variables are set');
208
- }
209
-
210
- const envBrowsers = getBrowsersToTestFromEnv();
211
- if ((seleniumJar || seleniumUrl) && envBrowsers.length === 0) {
212
- throw Error(
213
- 'Ambiguous test configuration: when either the SELENIUM_REMOTE_URL or'
214
- + ' SELENIUM_SERVER_JAR environment variable is set, the'
215
- + ' SELENIUM_BROWSER variable must also be set.');
216
- }
217
-
218
- targetBrowsers =
219
- envBrowsers.length > 0 ? envBrowsers : getAvailableBrowsers();
220
- info(`Running tests against [${targetBrowsers.map(b => b.name).join(', ')}]`);
221
-
222
- after(function() {
223
- if (seleniumServer) {
224
- return seleniumServer.kill();
225
- }
226
- });
227
- }
228
-
229
-
230
-
231
- const TARGET_MAP = /** !WeakMap<!Environment, !TargetBrowser> */new WeakMap;
232
- const URL_MAP =
233
- /** !WeakMap<!Environment, ?(string|remote.SeleniumServer)> */new WeakMap;
234
-
235
-
236
- /**
237
- * Defines the environment a {@linkplain suite test suite} is running against.
238
- * @final
239
- */
240
- class Environment {
241
-
242
- /**
243
- * @param {!TargetBrowser} browser the browser targetted in this environment.
244
- * @param {?(string|remote.SeleniumServer)=} url remote URL of an existing
245
- * Selenium server to test against.
246
- */
247
- constructor(browser, url = undefined) {
248
- browser =
249
- /** @type {!TargetBrowser} */(Object.seal(Object.assign({}, browser)));
250
-
251
- TARGET_MAP.set(this, browser);
252
- URL_MAP.set(this, url || null);
253
- }
254
-
255
- /** @return {!TargetBrowser} the target browser for this test environment. */
256
- get browser() {
257
- return TARGET_MAP.get(this);
258
- }
259
-
260
- /**
261
- * Returns a predicate function that will suppress tests in this environment
262
- * if the {@linkplain #browser current browser} is in the list of
263
- * `browsersToIgnore`.
264
- *
265
- * @param {...(string|!Browser)} browsersToIgnore the browsers that should
266
- * be ignored.
267
- * @return {function(): boolean} a new predicate function.
268
- */
269
- browsers(...browsersToIgnore) {
270
- return () => browsersToIgnore.indexOf(this.browser.name) != -1;
271
- }
272
-
273
- /**
274
- * @return {!Builder} a new WebDriver builder configured to target this
275
- * environment's {@linkplain #browser browser}.
276
- */
277
- builder() {
278
- const browser = this.browser;
279
- const urlOrServer = URL_MAP.get(this);
280
-
281
- const builder = new Builder();
282
- builder.disableEnvironmentOverrides();
283
-
284
- const realBuild = builder.build;
285
- builder.build = function() {
286
- builder.forBrowser(browser.name, browser.version, browser.platform);
287
- if (typeof urlOrServer === 'string') {
288
- builder.usingServer(urlOrServer);
289
- } else if (urlOrServer) {
290
- builder.usingServer(urlOrServer.address());
291
- }
292
- return realBuild.call(builder);
293
- };
294
-
295
- return builder;
296
- }
297
- }
298
-
299
-
300
- /**
301
- * Configuration options for a {@linkplain ./index.suite test suite}.
302
- * @record
303
- */
304
- function SuiteOptions() {}
305
-
306
- /**
307
- * The browsers to run the test suite against.
308
- * @type {!Array<!(Browser|TargetBrowser)>}
309
- */
310
- SuiteOptions.prototype.browsers;
311
-
312
-
313
- let inSuite = false;
314
-
315
-
316
- /**
317
- * Defines a test suite by calling the provided function once for each of the
318
- * target browsers. If a suite is not limited to a specific set of browsers in
319
- * the provided {@linkplain ./index.SuiteOptions suite options}, the suite will
320
- * be configured to run against each of the {@linkplain ./index.init runtime
321
- * target browsers}.
322
- *
323
- * Sample usage:
324
- *
325
- * const {By, Key, until} = require('selenium-webdriver');
326
- * const {suite} = require('selenium-webdriver/testing');
327
- *
328
- * suite(function(env) {
329
- * describe('Google Search', function() {
330
- * let driver;
331
- *
332
- * before(async function() {
333
- * driver = await env.builder().build();
334
- * });
335
- *
336
- * after(() => driver.quit());
337
- *
338
- * it('demo', async function() {
339
- * await driver.get('http://www.google.com/ncr');
340
- *
341
- * let q = await driver.findElement(By.name('q'));
342
- * await q.sendKeys('webdriver', Key.RETURN);
343
- * await driver.wait(
344
- * until.titleIs('webdriver - Google Search'), 1000);
345
- * });
346
- * });
347
- * });
348
- *
349
- * By default, this example suite will run against every WebDriver-enabled
350
- * browser on the current system. Alternatively, the `SELENIUM_BROWSER`
351
- * environment variable may be used to run against a specific browser:
352
- *
353
- * SELENIUM_BROWSER=firefox mocha -t 120000 example_test.js
354
- *
355
- * @param {function(!Environment)} fn the function to call to build the test
356
- * suite.
357
- * @param {SuiteOptions=} options configuration options.
358
- */
359
- function suite(fn, options = undefined) {
360
- if (inSuite) {
361
- throw Error('Calls to suite() may not be nested');
362
- }
363
- try {
364
- init();
365
- inSuite = true;
366
-
367
- const suiteBrowsers = new Map;
368
- if (options && options.browsers) {
369
- for (let browser of options.browsers) {
370
- if (typeof browser === 'string') {
371
- suiteBrowsers.set(browser, {name: browser});
372
- } else {
373
- suiteBrowsers.set(browser.name, browser);
374
- }
375
- }
376
- }
377
-
378
- for (let browser of targetBrowsers) {
379
- if (suiteBrowsers.size > 0 && !suiteBrowsers.has(browser.name)) {
380
- continue;
381
- }
382
-
383
- describe(`[${browser.name}]`, function() {
384
- if (!seleniumUrl && seleniumJar && !seleniumServer) {
385
- seleniumServer = new remote.SeleniumServer(seleniumJar);
386
-
387
- const startTimeout = 65 * 1000;
388
- function startSelenium() {
389
- if (typeof this.timeout === 'function') {
390
- this.timeout(startTimeout); // For mocha.
391
- }
392
-
393
- info(`Starting selenium server ${seleniumJar}`);
394
- return seleniumServer.start(60 * 1000);
395
- }
396
-
397
- const /** !Function */beforeHook = global.beforeAll || global.before;
398
- beforeHook(startSelenium, startTimeout);
399
- }
400
-
401
- fn(new Environment(browser, seleniumUrl || seleniumServer));
402
- });
403
- }
404
- } finally {
405
- inSuite = false;
406
- }
407
- }
408
-
409
-
410
-
411
- /**
412
- * Returns an object with wrappers for the standard mocha/jasmine test
413
- * functions: `describe` and `it`, which will redirect to `xdescribe` and `xit`,
414
- * respectively, if provided predicate function returns false.
415
- *
416
- * Sample usage:
417
- *
418
- * const {Browser} = require('selenium-webdriver');
419
- * const {suite, ignore} = require('selenium-webdriver/testing');
420
- *
421
- * suite(function(env) {
422
- *
423
- * // Skip tests the current environment targets Chrome.
424
- * ignore(env.browsers(Browser.CHROME)).
425
- * describe('something', async function() {
426
- * let driver = await env.builder().build();
427
- * // etc.
428
- * });
429
- * });
430
- *
431
- * @param {function(): boolean} predicateFn A predicate to call to determine
432
- * if the test should be suppressed. This function MUST be synchronous.
433
- * @return {{describe: !Function, it: !Function}} an object with wrapped
434
- * versions of the `describe` and `it` wtest functions.
435
- */
436
- function ignore(predicateFn) {
437
- const isJasmine = global.jasmine && typeof global.jasmine === 'object';
438
-
439
- const hooks = {
440
- describe: getTestHook('describe'),
441
- xdescribe: getTestHook('xdescribe'),
442
- it: getTestHook('it'),
443
- xit: getTestHook('xit')
444
- };
445
- hooks.fdescribe = isJasmine ? getTestHook('fdescribe') : hooks.describe.only;
446
- hooks.fit = isJasmine ? getTestHook('fit') : hooks.it.only;
447
-
448
- let describe = wrap(hooks.xdescribe, hooks.describe);
449
- let fdescribe = wrap(hooks.xdescribe, hooks.fdescribe);
450
- describe.only = fdescribe;
451
-
452
- let it = wrap(hooks.xit, hooks.it);
453
- let fit = wrap(hooks.xit, hooks.fit);
454
- it.only = fit;
455
-
456
- return {describe, it};
457
-
458
- function wrap(onSkip, onRun) {
459
- return function(...args) {
460
- if (predicateFn()) {
461
- onSkip(...args);
462
- } else {
463
- onRun(...args);
464
- }
465
- };
466
- }
467
- }
468
-
469
-
470
- /**
471
- * @param {string} name
472
- * @return {!Function}
473
- * @throws {TypeError}
474
- */
475
- function getTestHook(name) {
476
- let fn = global[name];
477
- let type = typeof fn;
478
- if (type !== 'function') {
479
- throw TypeError(
480
- `Expected global.${name} to be a function, but is ${type}.`
481
- + ' This can happen if you try using this module when running with'
482
- + ' node directly instead of using jasmine or mocha');
483
- }
484
- return fn;
485
- }
486
-
487
-
488
- // PUBLIC API
489
-
490
-
491
- module.exports = {
492
- Environment,
493
- TargetBrowser,
494
- SuiteOptions,
495
- init,
496
- ignore,
497
- suite
498
- };
@@ -1,7 +0,0 @@
1
- // Initialize `global.jasmine` so it can be patched
2
- require('@bazel/jasmine').boot();
3
-
4
- global.after = global.afterAll;
5
- global.before = global.beforeAll;
6
-
7
- global.jasmine.DEFAULT_TIMEOUT_INTERVAL = 120 * 1000;