selenium-webdriver 3.0.1 → 3.5.0

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 (67) hide show
  1. package/CHANGES.md +92 -0
  2. package/NOTICE +1 -1
  3. package/README.md +11 -14
  4. package/chrome.js +125 -36
  5. package/edge.js +3 -3
  6. package/example/async_await_test.js +68 -0
  7. package/example/chrome_headless.js +47 -0
  8. package/example/chrome_mobile_emulation.js +1 -1
  9. package/example/firefox_channels.js +73 -0
  10. package/example/google_search_test.js +1 -1
  11. package/firefox/binary.js +114 -57
  12. package/firefox/extension.js +118 -81
  13. package/firefox/index.js +67 -135
  14. package/firefox/profile.js +13 -49
  15. package/ie.js +2 -2
  16. package/index.js +6 -3
  17. package/io/index.js +59 -0
  18. package/io/zip.js +214 -0
  19. package/lib/README +2 -3
  20. package/lib/actions.js +4 -4
  21. package/lib/atoms/getAttribute.js +9 -11
  22. package/lib/atoms/is-displayed.js +102 -0
  23. package/lib/by.js +9 -1
  24. package/lib/capabilities.js +5 -5
  25. package/lib/command.js +2 -0
  26. package/lib/error.js +29 -4
  27. package/lib/events.js +1 -1
  28. package/lib/firefox/webdriver.json +2 -1
  29. package/lib/http.js +84 -69
  30. package/lib/input.js +1 -1
  31. package/lib/promise.js +205 -81
  32. package/lib/symbols.js +1 -1
  33. package/lib/test/data/click_tests/disabled_element.html +12 -0
  34. package/lib/test/data/firefox/webextension.xpi +0 -0
  35. package/lib/test/data/key_logger.html +34 -0
  36. package/lib/test/data/nestedElements.html +10 -1
  37. package/lib/test/data/single_text_input.html +12 -0
  38. package/lib/test/index.js +9 -35
  39. package/lib/until.js +1 -1
  40. package/lib/webdriver.js +130 -34
  41. package/net/portprober.js +1 -1
  42. package/opera.js +2 -2
  43. package/package.json +2 -2
  44. package/phantomjs.js +2 -2
  45. package/remote/index.js +17 -11
  46. package/safari.js +47 -8
  47. package/test/firefox/extension_test.js +41 -17
  48. package/test/firefox/firefox_test.js +70 -23
  49. package/test/firefox/profile_test.js +14 -59
  50. package/test/http/http_test.js +18 -0
  51. package/test/{io_test.js → io/io_test.js} +40 -1
  52. package/test/io/zip_test.js +128 -0
  53. package/test/lib/by_test.js +21 -0
  54. package/test/lib/error_test.js +20 -1
  55. package/test/lib/http_test.js +41 -2
  56. package/test/lib/promise_test.js +19 -0
  57. package/test/lib/until_test.js +28 -13
  58. package/test/lib/webdriver_test.js +107 -3
  59. package/test/page_loading_test.js +0 -6
  60. package/test/rect_test.js +60 -0
  61. package/test/remote_test.js +3 -3
  62. package/test/session_test.js +68 -23
  63. package/testing/index.js +16 -5
  64. package/lib/atoms/isDisplayed.js +0 -106
  65. package/lib/firefox/amd64/libnoblur64.so +0 -0
  66. package/lib/firefox/i386/libnoblur.so +0 -0
  67. package/lib/firefox/webdriver.xpi +0 -0
package/CHANGES.md CHANGED
@@ -1,3 +1,95 @@
1
+ ## v3.5.0
2
+
3
+ ### Notice
4
+
5
+ Native support for Firefox 45 (ESR) has been removed. Users will have to connect
6
+ to a remote Selenium server that supports Firefox 45.
7
+
8
+ ### Changes
9
+
10
+ * Removed native support for Firefox 46 and older.
11
+ - The `SELENIUM_MARIONETTE` enviornment variable no longer has an effect.
12
+ - `selenium-webdriver/firefox.Capability.MARIONETTE` is deprecated.
13
+ - `selenium-webdriver/firefox.Options#useGeckoDriver()` is deprecated and now a no-op.
14
+ * `firefox.Options` will no longer discard the `"moz:firefoxOptions"` set in
15
+ user provided capabilities (via `Builder.withCapabilities({})`). When both
16
+ are used, the settings in `firefox.Options` will be applied _last_.
17
+ * Added `chrome.Options#headless()` and `chrome.Options#windowSize()`, which
18
+ may be used to start Chrome in headless mode (requires Chrome 59+) and to set
19
+ the initial window size, respectively.
20
+
21
+
22
+ ### Changes for W3C WebDriver Spec Compliance
23
+
24
+ * Added `error.WebDriverError#remoteStacktrace` to capture the stacktrace
25
+ reported by a remote WebDriver endpoint (if any).
26
+ * Fixed `WebElement#sendKeys` to send text as a string instead of an array of
27
+ strings.
28
+
29
+ ## v3.4.0
30
+
31
+ ### Notice
32
+
33
+ This release requires [geckodriver 0.15.0](https://github.com/mozilla/geckodriver/releases/tag/v0.15.0) or newer.
34
+
35
+ ### API Changes
36
+
37
+ * Added `Options#getTimeouts()` for retrieving the currently configured session
38
+ timeouts (i.e. implicit wait). This method will only work with W3C compatible
39
+ WebDriver implementations.
40
+ * Deprecated the `Timeouts` class in favor of `Options#setTimeouts()`, which
41
+ supports setting multiple timeouts at once.
42
+ * Added support for emulating different network conditions (e.g., offline, 2G, WiFi) on Chrome.
43
+
44
+ ### Changes for W3C WebDriver Spec Compliance
45
+
46
+ * Fixed W3C response parsing, which expects response data to always be a JSON
47
+ object with a `value` key.
48
+ * Added W3C endpoints for interacting with various types of
49
+ [user prompts](https://w3c.github.io/webdriver/webdriver-spec.html#user-prompts).
50
+ * Added W3C endpoints for remotely executing scripts.
51
+ * Added W3C endpoints to get current window handle and all windows handles.
52
+
53
+
54
+ ## v3.3.0
55
+
56
+ * Added warning log messages when the user creates new managed promises, or
57
+ schedules unchained tasks. Users may opt in to printing these log messages
58
+ with
59
+
60
+ ```js
61
+ const {logging} = require('selenium-webdriver');
62
+ logging.installConsoleHandler();
63
+ logging.getLogger('promise.ControlFlow').setLevel(logging.Level.WARNING);
64
+ ```
65
+ * If the `JAVA_HOME` environment variable is set, use it to locate java.exe.
66
+
67
+
68
+ ## v3.2.0
69
+
70
+ * Release skipped to stay in sync with the main Selenium project.
71
+
72
+
73
+ ## v3.1.0
74
+
75
+ * The `lib` package is once again platform agnostic (excluding `lib/devmode`).
76
+ * Deprecated `promise.when(value, callback, errback)`.
77
+ Use `promise.fulfilled(value).then(callback, errback)`
78
+ * Changed `promise.fulfilled(value)`, `promise.rejected(reason)` and
79
+ `promise.defer()` to all use native promises when the promise manager is
80
+ disabled.
81
+ * Properly handle W3C error responses to new session commands.
82
+ * Updated `selenium-webdriver/testing` to export `describe.only` along with
83
+ `describe.skip`.
84
+ * Fixed `selenium-webdriver/lib/until.ableToSwitchToFrame`. It was previously
85
+ dropping arguments and would never work.
86
+ * Added the ability to use Firefox Nightly
87
+ * If Firefox cannot be found in the default location, look for it on the PATH
88
+ * Allow SafariDriver to use Safari Technology Preview.
89
+ * Use the proper wire command for WebElement.getLocation() and
90
+ WebElement.getSize() for W3C compliant drivers.
91
+
92
+
1
93
  ## v3.0.1
2
94
 
3
95
  * More API adjustments to align with native Promises
package/NOTICE CHANGED
@@ -1,2 +1,2 @@
1
- Copyright 2011-2016 Software Freedom Conservancy
1
+ Copyright 2011-2017 Software Freedom Conservancy
2
2
  Copyright 2004-2011 Selenium committers
package/README.md CHANGED
@@ -17,16 +17,13 @@ be placed on your system [PATH]. Apple's safaridriver is shipped with
17
17
  Safari 10 for OS X El Capitan and macOS Sierra. You will need to enable Remote
18
18
  Automation in the Develop menu of Safari 10 before testing.
19
19
 
20
- > **NOTE:** Mozilla's [geckodriver] is only required for Firefox 47+.
21
- > Everything you need for Firefox 38-46 is included with this package.
22
-
23
20
 
24
21
  | Browser | Component |
25
22
  | ----------------- | ---------------------------------- |
26
23
  | Chrome | [chromedriver(.exe)][chrome] |
27
24
  | Internet Explorer | [IEDriverServer.exe][release] |
28
25
  | Edge | [MicrosoftWebDriver.msi][edge] |
29
- | Firefox 47+ | [geckodriver(.exe)][geckodriver] |
26
+ | Firefox | [geckodriver(.exe)][geckodriver] |
30
27
  | PhantomJS | [phantomjs(.exe)][phantomjs] |
31
28
  | Opera | [operadriver(.exe)][opera] |
32
29
  | Safari | [safaridriver] |
@@ -136,16 +133,16 @@ will also have "best effort" support. Releases older than the latest LTS,
136
133
  _semver-major_ releases, and all unstable release branches (e.g. "v.Next")
137
134
  are considered strictly unsupported.
138
135
 
139
- For example, suppose the current LTS and stable releases are v4.2.4 and v5.4.1,
136
+ For example, suppose the current LTS and stable releases are v6.9.5 and v7.5.0,
140
137
  respectively. Then a Selenium release would have the following support levels:
141
138
 
142
139
  | Version | Support |
143
140
  | ------- | ------------- |
144
- | <= 4.1 | _unsupported_ |
145
- | 4.2 | supported |
146
- | 5.0-3 | best effort |
147
- | 5.4 | supported |
148
- | >= 5.5 | best effort |
141
+ | <= 6.8 | _unsupported_ |
142
+ | 6.9 | supported |
143
+ | 7.0-4 | best effort |
144
+ | 7.5 | supported |
145
+ | >= 7.5 | best effort |
149
146
  | v.Next | _unsupported_ |
150
147
 
151
148
  ### Support Level Definitions
@@ -168,11 +165,11 @@ months, the support window for selenium-webdriver will be roughly:
168
165
 
169
166
  | Date | LTS | Stable |
170
167
  | --------- | ---: | -----: |
171
- | (current) | 4.2 | 5.0 |
172
- | 2016-04 | 4.2 | 6.0 |
173
- | 2016-10 | 6.0 | 7.0 |
168
+ | (current) | 6.9 | 7.5 |
174
169
  | 2017-04 | 6.0 | 8.0 |
175
170
  | 2017-10 | 8.0 | 9.0 |
171
+ | 2018-04 | 8.0 | 10.0 |
172
+ | 2018-10 | 10.0 | 11.0 |
176
173
 
177
174
  ## Issues
178
175
 
@@ -193,7 +190,7 @@ the issue tracker
193
190
  - __Do not__ post empty "I see this too" or "Any updates?" comments. These
194
191
  provide no additional information and clutter the log.
195
192
  - __Do not__ report regressions on closed bugs as they are not actively
196
- monitored for upates (especially bugs that are >6 months old). Please open a
193
+ monitored for updates (especially bugs that are >6 months old). Please open a
197
194
  new issue and reference the original bug in your report.
198
195
 
199
196
  ## License
package/chrome.js CHANGED
@@ -36,6 +36,20 @@
36
36
  * a unique browser session with a clean user profile (unless otherwise
37
37
  * configured through the {@link Options} class).
38
38
  *
39
+ * __Headless Chrome__ <a id="headless"></a>
40
+ *
41
+ * To start Chrome in headless mode, simply call
42
+ * {@linkplain Options#headless Options.headless()}. Note, starting in headless
43
+ * mode currently also disables GPU acceleration.
44
+ *
45
+ * let chrome = require('selenium-webdriver/chrome');
46
+ * let {Builder} = require('selenium-webdriver');
47
+ *
48
+ * let driver = new Builder()
49
+ * .forBrowser('chrome')
50
+ * .setChromeOptions(new chrome.Options().headless())
51
+ * .build();
52
+ *
39
53
  * __Customizing the ChromeDriver Server__ <a id="custom-server"></a>
40
54
  *
41
55
  * By default, every Chrome session will use a single driver service, which is
@@ -59,7 +73,7 @@
59
73
  * let options = new chrome.Options();
60
74
  * // configure browser options ...
61
75
  *
62
- * let driver = new chrome.Driver(options, service);
76
+ * let driver = chrome.Driver.createSession(options, service);
63
77
  *
64
78
  * Users should only instantiate the {@link Driver} class directly when they
65
79
  * need a custom driver service configuration (as shown above). For normal
@@ -114,19 +128,19 @@
114
128
 
115
129
  'use strict';
116
130
 
117
- const fs = require('fs'),
118
- util = require('util');
131
+ const fs = require('fs');
132
+ const util = require('util');
119
133
 
120
- const http = require('./http'),
121
- io = require('./io'),
122
- {Capabilities, Capability} = require('./lib/capabilities'),
123
- command = require('./lib/command'),
124
- logging = require('./lib/logging'),
125
- promise = require('./lib/promise'),
126
- Symbols = require('./lib/symbols'),
127
- webdriver = require('./lib/webdriver'),
128
- portprober = require('./net/portprober'),
129
- remote = require('./remote');
134
+ const http = require('./http');
135
+ const io = require('./io');
136
+ const {Capabilities, Capability} = require('./lib/capabilities');
137
+ const command = require('./lib/command');
138
+ const logging = require('./lib/logging');
139
+ const promise = require('./lib/promise');
140
+ const Symbols = require('./lib/symbols');
141
+ const webdriver = require('./lib/webdriver');
142
+ const portprober = require('./net/portprober');
143
+ const remote = require('./remote');
130
144
 
131
145
 
132
146
  /**
@@ -143,7 +157,9 @@ const CHROMEDRIVER_EXE =
143
157
  * @enum {string}
144
158
  */
145
159
  const Command = {
146
- LAUNCH_APP: 'launchApp'
160
+ LAUNCH_APP: 'launchApp',
161
+ GET_NETWORK_CONDITIONS: 'getNetworkConditions',
162
+ SET_NETWORK_CONDITIONS: 'setNetworkConditions'
147
163
  };
148
164
 
149
165
 
@@ -169,6 +185,14 @@ function configureExecutor(executor) {
169
185
  Command.LAUNCH_APP,
170
186
  'POST',
171
187
  '/session/:sessionId/chromium/launch_app');
188
+ executor.defineCommand(
189
+ Command.GET_NETWORK_CONDITIONS,
190
+ 'GET',
191
+ '/session/:sessionId/chromium/network_conditions');
192
+ executor.defineCommand(
193
+ Command.SET_NETWORK_CONDITIONS,
194
+ 'POST',
195
+ '/session/:sessionId/chromium/network_conditions');
172
196
  }
173
197
 
174
198
 
@@ -283,11 +307,7 @@ function getDefaultService() {
283
307
  }
284
308
 
285
309
 
286
- /**
287
- * @type {string}
288
- * @const
289
- */
290
- let OPTIONS_CAPABILITY_KEY = 'chromeOptions';
310
+ const OPTIONS_CAPABILITY_KEY = 'chromeOptions';
291
311
 
292
312
 
293
313
  /**
@@ -352,28 +372,61 @@ class Options {
352
372
  * browser. Each argument may be specified with or without the "--" prefix
353
373
  * (e.g. "--foo" and "foo"). Arguments with an associated value should be
354
374
  * delimited by an "=": "foo=bar".
355
- * @param {...(string|!Array<string>)} var_args The arguments to add.
375
+ *
376
+ * @param {...(string|!Array<string>)} args The arguments to add.
356
377
  * @return {!Options} A self reference.
357
378
  */
358
- addArguments(var_args) {
359
- let args = this.options_.args || [];
360
- args = args.concat.apply(args, arguments);
361
- if (args.length) {
362
- this.options_.args = args;
379
+ addArguments(...args) {
380
+ let newArgs = (this.options_.args || []).concat(...args);
381
+ if (newArgs.length) {
382
+ this.options_.args = newArgs;
363
383
  }
364
384
  return this;
365
385
  }
366
386
 
387
+ /**
388
+ * Configures the chromedriver to start Chrome in headless mode.
389
+ *
390
+ * > __NOTE:__ Resizing the browser window in headless mode is only supported
391
+ * > in Chrome 60. Users are encouraged to set an initial window size with
392
+ * > the {@link #windowSize windowSize({width, height})} option.
393
+ *
394
+ * @return {!Options} A self reference.
395
+ */
396
+ headless() {
397
+ // TODO(jleyba): Remove `disable-gpu` once head Chrome no longer requires
398
+ // that to be set.
399
+ return this.addArguments('headless', 'disable-gpu');
400
+ }
401
+
402
+ /**
403
+ * Sets the initial window size.
404
+ *
405
+ * @param {{width: number, height: number}} size The desired window size.
406
+ * @return {!Options} A self reference.
407
+ * @throws {TypeError} if width or height is unspecified, not a number, or
408
+ * less than or equal to 0.
409
+ */
410
+ windowSize({width, height}) {
411
+ function checkArg(arg) {
412
+ if (typeof arg !== 'number' || arg <= 0) {
413
+ throw TypeError('Arguments must be {width, height} with numbers > 0');
414
+ }
415
+ }
416
+ checkArg(width);
417
+ checkArg(height);
418
+ return this.addArguments(`window-size=${width},${height}`);
419
+ }
420
+
367
421
  /**
368
422
  * List of Chrome command line switches to exclude that ChromeDriver by default
369
423
  * passes when starting Chrome. Do not prefix switches with "--".
370
424
  *
371
- * @param {...(string|!Array<string>)} var_args The switches to exclude.
425
+ * @param {...(string|!Array<string>)} args The switches to exclude.
372
426
  * @return {!Options} A self reference.
373
427
  */
374
- excludeSwitches(var_args) {
375
- let switches = this.options_.excludeSwitches || [];
376
- switches = switches.concat.apply(switches, arguments);
428
+ excludeSwitches(...args) {
429
+ let switches = (this.options_.excludeSwitches || []).concat(...args);
377
430
  if (switches.length) {
378
431
  this.options_.excludeSwitches = switches;
379
432
  }
@@ -384,13 +437,12 @@ class Options {
384
437
  * Add additional extensions to install when launching Chrome. Each extension
385
438
  * should be specified as the path to the packed CRX file, or a Buffer for an
386
439
  * extension.
387
- * @param {...(string|!Buffer|!Array<(string|!Buffer)>)} var_args The
440
+ * @param {...(string|!Buffer|!Array<(string|!Buffer)>)} args The
388
441
  * extensions to add.
389
442
  * @return {!Options} A self reference.
390
443
  */
391
- addExtensions(var_args) {
392
- this.extensions_ =
393
- this.extensions_.concat.apply(this.extensions_, arguments);
444
+ addExtensions(...args) {
445
+ this.extensions_ = this.extensions_.concat(...args);
394
446
  return this;
395
447
  }
396
448
 
@@ -595,7 +647,7 @@ class Options {
595
647
  * let options = new chrome.Options().setMobileEmulation(
596
648
  * {deviceName: 'Google Nexus 5'});
597
649
  *
598
- * let driver = new chrome.Driver(options);
650
+ * let driver = chrome.Driver.createSession(options);
599
651
  *
600
652
  * __Example 2: Using Custom Screen Configuration__
601
653
  *
@@ -605,7 +657,7 @@ class Options {
605
657
  * pixelRatio: 3.0
606
658
  * });
607
659
  *
608
- * let driver = new chrome.Driver(options);
660
+ * let driver = chrome.Driver.createSession(options);
609
661
  *
610
662
  *
611
663
  * [em]: https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation
@@ -706,7 +758,7 @@ class Driver extends webdriver.WebDriver {
706
758
  (opt_config || Capabilities.chrome());
707
759
 
708
760
  return /** @type {!Driver} */(
709
- webdriver.WebDriver.createSession(executor, caps, opt_flow, this));
761
+ super.createSession(executor, caps, opt_flow));
710
762
  }
711
763
 
712
764
  /**
@@ -727,6 +779,43 @@ class Driver extends webdriver.WebDriver {
727
779
  new command.Command(Command.LAUNCH_APP).setParameter('id', id),
728
780
  'Driver.launchApp()');
729
781
  }
782
+
783
+ /**
784
+ * Schedules a command to get Chrome network emulation settings.
785
+ * @return {!promise.Thenable<T>} A promise that will be resolved
786
+ * when network emulation settings are retrievied.
787
+ */
788
+ getNetworkConditions() {
789
+ return this.schedule(
790
+ new command.Command(Command.GET_NETWORK_CONDITIONS),
791
+ 'Driver.getNetworkConditions()');
792
+ }
793
+
794
+ /**
795
+ * Schedules a command to set Chrome network emulation settings.
796
+ *
797
+ * __Sample Usage:__
798
+ *
799
+ * driver.setNetworkConditions({
800
+ * offline: false,
801
+ * latency: 5, // Additional latency (ms).
802
+ * download_throughput: 500 * 1024, // Maximal aggregated download throughput.
803
+ * upload_throughput: 500 * 1024 // Maximal aggregated upload throughput.
804
+ * });
805
+ *
806
+ * @param {Object} spec Defines the network conditions to set
807
+ * @return {!promise.Thenable<void>} A promise that will be resolved
808
+ * when network emulation settings are set.
809
+ */
810
+ setNetworkConditions(spec) {
811
+ if (!spec || typeof spec !== 'object') {
812
+ throw TypeError('setNetworkConditions called with non-network-conditions parameter');
813
+ }
814
+
815
+ return this.schedule(
816
+ new command.Command(Command.SET_NETWORK_CONDITIONS).setParameter('network_conditions', spec),
817
+ 'Driver.setNetworkConditions(' + JSON.stringify(spec) + ')');
818
+ }
730
819
  }
731
820
 
732
821
 
package/edge.js CHANGED
@@ -58,7 +58,7 @@
58
58
  * var options = new edge.Options();
59
59
  * // configure browser options ...
60
60
  *
61
- * var driver = new edge.Driver(options, service);
61
+ * var driver = edge.Driver.createSession(options, service);
62
62
  *
63
63
  * Users should only instantiate the {@link Driver} class directly when they
64
64
  * need a custom driver service configuration (as shown above). For normal
@@ -278,8 +278,8 @@ class Driver extends webdriver.WebDriver {
278
278
  opt_config instanceof Options ? opt_config.toCapabilities() :
279
279
  (opt_config || capabilities.Capabilities.edge());
280
280
 
281
- return /** @type {!Driver} */(webdriver.WebDriver.createSession(
282
- executor, caps, opt_flow, this, () => service.kill()));
281
+ return /** @type {!Driver} */(super.createSession(
282
+ executor, caps, opt_flow, () => service.kill()));
283
283
  }
284
284
 
285
285
  /**
@@ -0,0 +1,68 @@
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 Example Mocha tests using async/await.
20
+ *
21
+ * Usage:
22
+ *
23
+ * mocha -t 20000 --harmony_async_await \
24
+ * selenium-webdriver/example/async_await_test.js
25
+ *
26
+ * You can change which browser is started with the SELENIUM_BROWSER environment
27
+ * variable:
28
+ *
29
+ * SELENIUM_BROWSER=chrome \
30
+ * mocha -t 20000 --harmony_async_await \
31
+ * selenium-webdriver/example/async_await_test.js
32
+ */
33
+
34
+ 'use strict';
35
+
36
+ const assert = require('assert');
37
+ const {Builder, By, promise, until} = require('..');
38
+
39
+ // async/await do not work well when the promise manager is enabled.
40
+ // See https://github.com/SeleniumHQ/selenium/issues/3037
41
+ //
42
+ // 3037 does not impact these specific examples, but it is still recommended
43
+ // that you disable the promise manager when using async/await.
44
+ promise.USE_PROMISE_MANAGER = false;
45
+
46
+ describe('Google Search', function() {
47
+ let driver;
48
+
49
+ beforeEach(async function() {
50
+ driver = await new Builder().forBrowser('firefox').build();
51
+ });
52
+
53
+ afterEach(async function() {
54
+ await driver.quit();
55
+ });
56
+
57
+ it('example', async function() {
58
+ await driver.get('https://www.google.com/ncr');
59
+
60
+ await driver.findElement(By.name('q')).sendKeys('webdriver');
61
+ await driver.findElement(By.name('btnG')).click();
62
+
63
+ await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
64
+
65
+ let url = await driver.getCurrentUrl();
66
+ assert.equal(url, 'https://www.google.com/#q=webdriver');
67
+ });
68
+ });
@@ -0,0 +1,47 @@
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 An example of running Chrome in headless mode.
20
+ *
21
+ * Before running this script, ensure you have Chrome 59+ installed and that
22
+ * chromedriver 2.30+ is present on your system PATH:
23
+ * <https://sites.google.com/a/chromium.org/chromedriver/downloads>
24
+ *
25
+ * Usage:
26
+ * node selenium-webdriver/example/chrome_headless.js
27
+ */
28
+
29
+ const chrome = require('../chrome');
30
+ const {Builder, By, until} = require('..');
31
+
32
+ const width = 640;
33
+ const height = 480;
34
+
35
+ let driver = new Builder()
36
+ .forBrowser('chrome')
37
+ .setChromeOptions(
38
+ new chrome.Options().headless().windowSize({width, height}))
39
+ .build();
40
+
41
+ driver.get('http://www.google.com/ncr')
42
+ .then(_ => driver.findElement(By.name('q')).sendKeys('webdriver'))
43
+ .then(_ => driver.findElement(By.name('btnG')).click())
44
+ .then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
45
+ .then(
46
+ _ => driver.quit(),
47
+ e => driver.quit().then(() => { throw e; }));
@@ -31,7 +31,7 @@ promise.consume(function* () {
31
31
  driver = yield new Builder()
32
32
  .forBrowser('chrome')
33
33
  .setChromeOptions(
34
- new Options().setMobileEmulation({deviceName: 'Google Nexus 5'}))
34
+ new Options().setMobileEmulation({deviceName: 'Nexus 5X'}))
35
35
  .build();
36
36
  yield driver.get('http://www.google.com/ncr');
37
37
  yield driver.findElement(By.name('q')).sendKeys('webdriver');
@@ -0,0 +1,73 @@
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 This is an example of working with the different Firefox
20
+ * release channels. Before running this example, you will need to have
21
+ * installed Firefox's release, nightly, and developer editions:
22
+ *
23
+ * - https://www.mozilla.org/en-US/firefox/channel/desktop/#aurora
24
+ * - https://www.mozilla.org/en-US/firefox/channel/desktop/#nightly
25
+ */
26
+
27
+
28
+ 'use strict';
29
+
30
+ const {Builder, By, promise, until} = require('..');
31
+ const {Channel, Options} = require('../firefox');
32
+
33
+ let i = 0;
34
+ function resposition(driver) {
35
+ return driver.manage().window().setSize(600, 400)
36
+ .then(_ => driver.manage().window().setPosition(300 * (i++), 0));
37
+ }
38
+
39
+ function doSearch(driver) {
40
+ // Start on the base about page.
41
+ return driver.get('about:')
42
+ // Reposition so users can see the three windows.
43
+ .then(_ => resposition(driver))
44
+ // Pause so users can see the magic.
45
+ .then(_ => promise.delayed(750))
46
+ // Now do the rest.
47
+ .then(_ => driver.get('http://www.google.com/ncr'))
48
+ .then(_ => driver.findElement(By.name('q')).sendKeys('webdriver'))
49
+ .then(_ => driver.findElement(By.name('btnG')).click())
50
+ .then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
51
+ .then(_ => driver.quit());
52
+ }
53
+
54
+ function createDriver(channel) {
55
+ let options = new Options().setBinary(channel);
56
+ return new Builder().forBrowser('firefox').setFirefoxOptions(options).build();
57
+ }
58
+
59
+ // NOTE: disabling the promise manager so searches all run concurrently.
60
+ // For more on the promise manager and its pending deprecation, see
61
+ // https://github.com/SeleniumHQ/selenium/issues/2969
62
+ promise.USE_PROMISE_MANAGER = false;
63
+
64
+ Promise.all([
65
+ doSearch(createDriver(Channel.RELEASE)),
66
+ doSearch(createDriver(Channel.AURORA)), // Developer Edition.
67
+ doSearch(createDriver(Channel.NIGHTLY)),
68
+ ]).then(_ => {
69
+ console.log('Success!');
70
+ }, err => {
71
+ console.error('An error occured! ' + err);
72
+ setTimeout(() => {throw err}, 0);
73
+ });
@@ -41,7 +41,7 @@ test.describe('Google Search', function() {
41
41
 
42
42
  // You can write tests either using traditional promises.
43
43
  it('works with promises', function() {
44
- return driver.get('http://www.google.com')
44
+ return driver.get('http://www.google.com/ncr')
45
45
  .then(_ => driver.findElement(By.name('q')).sendKeys('webdriver'))
46
46
  .then(_ => driver.findElement(By.name('btnG')).click())
47
47
  .then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000));