selenium-webdriver 4.0.0-alpha.8 → 4.0.0-beta.4

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 (53) hide show
  1. package/CHANGES.md +41 -1
  2. package/LICENSE +202 -0
  3. package/NOTICE +2 -0
  4. package/README.md +0 -0
  5. package/chrome.js +0 -0
  6. package/chromium.js +23 -202
  7. package/devtools/CDPConnection.js +16 -18
  8. package/edge.js +89 -130
  9. package/example/chrome_android.js +45 -0
  10. package/{lib/atoms/make-atoms-module.js → example/chrome_mobile_emulation.js} +26 -15
  11. package/example/firefox_channels.js +84 -0
  12. package/example/google_search.js +50 -0
  13. package/example/google_search_test.js +70 -0
  14. package/example/headless.js +63 -0
  15. package/example/logging.js +64 -0
  16. package/firefox.js +10 -9
  17. package/http/index.js +0 -0
  18. package/http/util.js +3 -3
  19. package/ie.js +0 -0
  20. package/index.js +2 -2
  21. package/io/exec.js +3 -3
  22. package/io/index.js +12 -13
  23. package/io/zip.js +5 -6
  24. package/lib/atoms/find-elements.js +78 -78
  25. package/lib/atoms/get-attribute.js +64 -68
  26. package/lib/atoms/is-displayed.js +27 -27
  27. package/lib/atoms/mutation-listener.js +55 -0
  28. package/lib/by.js +1 -1
  29. package/lib/capabilities.js +2 -3
  30. package/lib/command.js +2 -15
  31. package/lib/error.js +0 -0
  32. package/lib/http.js +17 -30
  33. package/lib/input.js +2 -286
  34. package/lib/logging.js +0 -0
  35. package/lib/promise.js +4 -16
  36. package/lib/proxy.js +0 -0
  37. package/lib/session.js +0 -0
  38. package/lib/symbols.js +0 -0
  39. package/lib/until.js +17 -15
  40. package/lib/webdriver.js +336 -16
  41. package/net/index.js +0 -0
  42. package/net/portprober.js +8 -8
  43. package/opera.js +0 -0
  44. package/package.json +13 -13
  45. package/proxy.js +0 -0
  46. package/remote/index.js +6 -7
  47. package/safari.js +0 -0
  48. package/testing/index.js +504 -0
  49. package/.eslintrc.js +0 -27
  50. package/.prettierrc +0 -4
  51. package/devtools/generator/protocol-dts-generator.js +0 -429
  52. package/lib/README +0 -5
  53. package/lib/actions.js +0 -626
package/edge.js CHANGED
@@ -17,23 +17,19 @@
17
17
 
18
18
  /**
19
19
  * @fileoverview Defines a {@linkplain Driver WebDriver} client for
20
- * Microsoft's Edge web browser. Both Edge (Chromium), and Edge Legacy (EdgeHTML) are
21
- * supported. Before using this module, you must download and install the correct
22
- * [WebDriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/)
23
- * server.
20
+ * Microsoft's Edge web browser. Edge (Chromium) is supported and support
21
+ * for Edge Legacy (EdgeHTML) as part of https://github.com/SeleniumHQ/selenium/issues/9166.
22
+ * Before using this module, you must download and install the correct
23
+ * [WebDriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/) server.
24
24
  *
25
- * Ensure that the either MicrosoftWebDriver (EdgeHTML) or msedgedriver (Chromium)
26
- * is on your [PATH](http://en.wikipedia.org/wiki/PATH_%28variable%29). MicrosoftWebDriver
27
- * and Edge Legacy (EdgeHTML) will be used by default.
25
+ * Ensure that the msedgedriver (Chromium)
26
+ * is on your [PATH](http://en.wikipedia.org/wiki/PATH_%28variable%29).
28
27
  *
29
- * You may use {@link Options} to specify whether Edge Chromium should be used:
28
+ * You may use {@link Options} to specify whether Edge Chromium options should be used:
30
29
 
31
- * var options = new edge.Options();
32
- * options.useEdgeChromium(true);
33
- * // configure browser options ...
30
+ * const edge = require('selenium-webdriver/edge');
31
+ * const options = new edge.Options();
34
32
 
35
- * Note that Chromium-specific {@link Options} will be ignored when using Edge Legacy.
36
- *
37
33
  * There are three primary classes exported by this module:
38
34
  *
39
35
  * 1. {@linkplain ServiceBuilder}: configures the
@@ -60,134 +56,121 @@
60
56
  * You may also create a {@link Driver} with its own driver service. This is
61
57
  * useful if you need to capture the server's log output for a specific session:
62
58
  *
63
- * var edge = require('selenium-webdriver/edge');
59
+ * const edge = require('selenium-webdriver/edge');
64
60
  *
65
- * var service = new edge.ServiceBuilder()
61
+ * const service = new edge.ServiceBuilder()
66
62
  * .setPort(55555)
67
63
  * .build();
68
64
  *
69
- * var options = new edge.Options();
65
+ * let options = new edge.Options();
70
66
  * // configure browser options ...
71
67
  *
72
- * var driver = edge.Driver.createSession(options, service);
68
+ * let driver = edge.Driver.createSession(options, service);
73
69
  *
74
70
  * Users should only instantiate the {@link Driver} class directly when they
75
71
  * need a custom driver service configuration (as shown above). For normal
76
- * operation, users should start MicrosoftEdge using the
72
+ * operation, users should start msedgedriver using the
77
73
  * {@link ./builder.Builder selenium-webdriver.Builder}.
78
74
  *
79
- * [WebDriver (EdgeHTML)]: https://docs.microsoft.com/en-us/microsoft-edge/webdriver
80
75
  * [WebDriver (Chromium)]: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium
81
76
  */
82
77
 
83
78
  'use strict'
84
79
 
85
- const http = require('./http')
80
+ const { Browser } = require('./lib/capabilities')
86
81
  const io = require('./io')
87
- const webdriver = require('./lib/webdriver')
88
- const { Browser, Capabilities } = require('./lib/capabilities')
89
82
  const chromium = require('./chromium')
83
+ const http = require('./http')
84
+ const webdriver = require('./lib/webdriver')
90
85
 
91
- const EDGE_CHROMIUM_BROWSER_NAME = 'msedge'
92
- const EDGEDRIVER_LEGACY_EXE = 'MicrosoftWebDriver.exe'
86
+ /**
87
+ * Name of the EdgeDriver executable.
88
+ * @type {string}
89
+ * @const
90
+ */
93
91
  const EDGEDRIVER_CHROMIUM_EXE =
94
92
  process.platform === 'win32' ? 'msedgedriver.exe' : 'msedgedriver'
95
93
 
94
+ /** @type {remote.DriverService} */
95
+ let defaultService = null
96
+
96
97
  /**
97
- * _Synchronously_ attempts to locate the Edge driver executable
98
- * on the current system. Searches for the legacy MicrosoftWebDriver by default.
99
- *
100
- * @param {string=} browserName Name of the Edge driver executable to locate.
101
- * May be either 'msedge' to locate the Edge Chromium driver, or 'MicrosoftEdge' to
102
- * locate the Edge Legacy driver. If omitted, will attempt to locate Edge Legacy.
103
- * @return {?string} the located executable, or `null`.
98
+ * Creates {@link selenium-webdriver/remote.DriverService} instances that manage
99
+ * a [ChromeDriver](https://chromedriver.chromium.org/)
100
+ * server in a child process.
104
101
  */
105
- function locateSynchronously(browserName) {
106
- browserName = browserName || Browser.EDGE
107
-
108
- if (browserName === EDGE_CHROMIUM_BROWSER_NAME) {
109
- return io.findInPath(EDGEDRIVER_CHROMIUM_EXE, true)
102
+ class ServiceBuilder extends chromium.ServiceBuilder {
103
+ /**
104
+ * @param {string=} opt_exe Path to the server executable to use. If omitted,
105
+ * the builder will attempt to locate the msedgedriver on the current
106
+ * PATH.
107
+ * @throws {Error} If provided executable does not exist, or the msedgedriver
108
+ * cannot be found on the PATH.
109
+ */
110
+ constructor(opt_exe) {
111
+ let exe = opt_exe || locateSynchronously()
112
+ if (!exe) {
113
+ throw Error(
114
+ `The WebDriver for Edge could not be found on the current PATH. Please download the `+
115
+ `latest version of ${EDGEDRIVER_CHROMIUM_EXE} from `+
116
+ `https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ `+
117
+ `and ensure it can be found on your PATH.`
118
+ )
119
+ }
120
+ super(exe)
121
+ this.setLoopback(true)
110
122
  }
111
-
112
- return process.platform === 'win32'
113
- ? io.findInPath(EDGEDRIVER_LEGACY_EXE, true)
114
- : null
115
123
  }
116
124
 
117
125
  /**
118
- * Class for managing Edge specific options.
126
+ * Class for managing edge chromium specific options.
119
127
  */
120
128
  class Options extends chromium.Options {
121
129
  /**
122
- * Instruct the EdgeDriver to use Edge Chromium if true.
123
- * Otherwise, use Edge Legacy (EdgeHTML). Defaults to using Edge Legacy.
130
+ * Sets the path to the edge binary to use
131
+ *
132
+ * The binary path be absolute or relative to the msedgedriver server
133
+ * executable, but it must exist on the machine that will launch edge chromium.
124
134
  *
125
- * @param {boolean} useEdgeChromium
135
+ * @param {string} path The path to the edgedriver binary to use.
126
136
  * @return {!Options} A self reference.
127
137
  */
128
- setEdgeChromium(useEdgeChromium) {
129
- this.set(Options.USE_EDGE_CHROMIUM, !!useEdgeChromium)
130
- return this
138
+ setEdgeChromiumBinaryPath(path) {
139
+ return this.setBinaryPath(path)
131
140
  }
132
141
  }
133
142
 
134
- Options.USE_EDGE_CHROMIUM = 'ms:edgeChromium'
135
- Options.prototype.BROWSER_NAME_VALUE = Browser.EDGE
136
- Options.prototype.CAPABILITY_KEY = 'ms:edgeOptions'
137
- Options.prototype.VENDOR_CAPABILITY_PREFIX = 'ms'
138
-
139
143
  /**
140
- * @param {(Capabilities|Object<string, *>)=} o The options object
141
- * @return {boolean}
144
+ * Creates a new WebDriver client for Microsoft's Edge.
142
145
  */
143
- function useEdgeChromium(o) {
144
- if (o instanceof Capabilities) {
145
- return !!o.get(Options.USE_EDGE_CHROMIUM)
146
- }
146
+ class Driver extends webdriver.WebDriver {
147
+ /**
148
+ * Creates a new browser session for Microsoft's Edge browser.
149
+ *
150
+ * @param {(Capabilities|Options)=} options The configuration options.
151
+ * @param {remote.DriverService=} opt_service The service to use; will create
152
+ * a new Legacy or Chromium service based on {@linkplain Options} by default.
153
+ * @return {!Driver} A new driver instance.
154
+ */
155
+ static createSession(options, opt_service) {
156
+ options = options || new Options()
157
+ let service = opt_service || getDefaultService()
158
+ let client = service.start().then((url) => new http.HttpClient(url))
159
+ let executor = new http.Executor(client)
147
160
 
148
- if (o && typeof o === 'object') {
149
- return !!o[Options.USE_EDGE_CHROMIUM]
161
+ return /** @type {!Driver} */ (super.createSession(executor, options, () =>
162
+ service.kill()
163
+ ))
150
164
  }
151
165
 
152
- return false
153
- }
154
-
155
- /**
156
- * Creates {@link remote.DriverService} instances that manage a
157
- * WebDriver server in a child process. Used for driving both
158
- * Microsoft Edge Legacy and Chromium. A ServiceBuilder constructed
159
- * with default parameters will launch a MicrosoftWebDriver child
160
- * process for driving Edge Legacy. You may pass in a path to
161
- * msedgedriver.exe to use Edge Chromium instead.
162
- */
163
- class ServiceBuilder extends chromium.ServiceBuilder {
164
166
  /**
165
- * @param {string=} opt_exe Path to the server executable to use. If omitted,
166
- * the builder will attempt to locate MicrosoftWebDriver on the current
167
- * PATH.
168
- * @throws {Error} If provided executable does not exist, or the
169
- * MicrosoftWebDriver cannot be found on the PATH.
167
+ * This function is a no-op as file detectors are not supported by this
168
+ * implementation.
169
+ * @override
170
170
  */
171
- constructor(opt_exe) {
172
- let exe = opt_exe || locateSynchronously()
173
- if (!exe) {
174
- throw Error(
175
- 'The WebDriver for Edge could not be found on the current PATH. Please ' +
176
- 'download the latest version of ' +
177
- EDGEDRIVER_LEGACY_EXE +
178
- ' from ' +
179
- 'https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ and ' +
180
- 'ensure it can be found on your PATH.'
181
- )
182
- }
183
-
184
- super(exe)
185
- }
171
+ setFileDetector() {}
186
172
  }
187
173
 
188
- /** @type {remote.DriverService} */
189
- var defaultService = null
190
-
191
174
  /**
192
175
  * Sets the default service to use for new Edge instances.
193
176
  * @param {!remote.DriverService} service The service to use.
@@ -197,7 +180,7 @@ function setDefaultService(service) {
197
180
  if (defaultService && defaultService.isRunning()) {
198
181
  throw Error(
199
182
  'The previously configured EdgeDriver service is still running. ' +
200
- 'You must shut it down before you may adjust its configuration.'
183
+ 'You must shut it down before you may adjust its configuration.'
201
184
  )
202
185
  }
203
186
  defaultService = service
@@ -216,45 +199,21 @@ function getDefaultService() {
216
199
  return defaultService
217
200
  }
218
201
 
219
- function createServiceFromCapabilities(options) {
220
- let exe
221
- if (useEdgeChromium(options)) {
222
- exe = locateSynchronously(EDGE_CHROMIUM_BROWSER_NAME)
223
- }
224
- return new ServiceBuilder(exe).build()
225
- }
226
202
 
227
203
  /**
228
- * Creates a new WebDriver client for Microsoft's Edge.
204
+ * _Synchronously_ attempts to locate the chromedriver executable on the current
205
+ * system.
206
+ *
207
+ * @return {?string} the located executable, or `null`.
229
208
  */
230
- class Driver extends webdriver.WebDriver {
231
- /**
232
- * Creates a new browser session for Microsoft's Edge browser.
233
- *
234
- * @param {(Capabilities|Options)=} options The configuration options.
235
- * @param {remote.DriverService=} opt_service The service to use; will create
236
- * a new Legacy or Chromium service based on {@linkplain Options} by default.
237
- * @return {!Driver} A new driver instance.
238
- */
239
- static createSession(options, opt_service) {
240
- options = options || new Options()
241
- let service = opt_service || createServiceFromCapabilities(options)
242
- let client = service.start().then((url) => new http.HttpClient(url))
243
- let executor = new http.Executor(client)
244
-
245
- return /** @type {!Driver} */ (super.createSession(executor, options, () =>
246
- service.kill()
247
- ))
248
- }
249
-
250
- /**
251
- * This function is a no-op as file detectors are not supported by this
252
- * implementation.
253
- * @override
254
- */
255
- setFileDetector() {}
209
+ function locateSynchronously() {
210
+ return io.findInPath(EDGEDRIVER_CHROMIUM_EXE, true)
256
211
  }
257
212
 
213
+ Options.prototype.BROWSER_NAME_VALUE = Browser.EDGE
214
+ Options.prototype.CAPABILITY_KEY = 'ms:edgeOptions'
215
+ Driver.prototype.VENDOR_CAPABILITY_PREFIX = 'ms'
216
+
258
217
  // PUBLIC API
259
218
 
260
219
  exports.Driver = Driver
@@ -0,0 +1,45 @@
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 A basic example of working with Chrome on Android. Before
20
+ * running this example, you must start adb and connect a device (or start an
21
+ * AVD).
22
+ */
23
+
24
+ 'use strict'
25
+
26
+ const { Builder, By, Key, until } = require('..')
27
+ const { Options } = require('../chrome')
28
+
29
+ ;(async function () {
30
+ let driver
31
+ try {
32
+ driver = await new Builder()
33
+ .forBrowser('chrome')
34
+ .setChromeOptions(new Options().androidChrome())
35
+ .build()
36
+ await driver.get('http://www.google.com/ncr')
37
+ await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
38
+ await driver.wait(until.titleIs('webdriver - Google Search'), 1000)
39
+ } finally {
40
+ ;(await driver) && driver.quit()
41
+ }
42
+ })().then(
43
+ (_) => console.log('SUCCESS'),
44
+ (err) => console.error('ERROR: ' + err)
45
+ )
@@ -15,21 +15,32 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
- const fs = require('fs')
19
- const path = require('path')
18
+ /**
19
+ * @fileoverview This is an example of emulating a mobile device using the
20
+ * ChromeDriver.
21
+ */
20
22
 
21
- if (process.argv.length < 3) {
22
- process.stderr.write(
23
- `Usage: node ${path.basename(__filename)} <src file> <dst file>\n`
24
- )
25
- // eslint-disable-next-line no-process-exit
26
- process.exit(-1)
27
- }
23
+ 'use strict'
28
24
 
29
- const buffer = fs.readFileSync(process.argv[2])
30
- fs.writeFileSync(
31
- process.argv[3],
32
- `// GENERATED CODE - DO NOT EDIT
33
- module.exports = ${buffer.toString('utf8').trim()};
34
- `
25
+ const { Builder, By, Key, until } = require('..')
26
+ const { Options } = require('../chrome')
27
+
28
+ ;(async function () {
29
+ let driver
30
+ try {
31
+ driver = await new Builder()
32
+ .forBrowser('chrome')
33
+ .setChromeOptions(
34
+ new Options().setMobileEmulation({ deviceName: 'Nexus 5X' })
35
+ )
36
+ .build()
37
+ await driver.get('http://www.google.com/ncr')
38
+ await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
39
+ await driver.wait(until.titleIs('webdriver - Google Search'), 1000)
40
+ } finally {
41
+ ;(await driver) && driver.quit()
42
+ }
43
+ })().then(
44
+ (_) => console.log('SUCCESS'),
45
+ (err) => console.error('ERROR: ' + err)
35
46
  )
@@ -0,0 +1,84 @@
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
+ 'use strict'
28
+
29
+ const { Builder, By, Key, promise, until } = require('..')
30
+ const { Channel, Options } = require('../firefox')
31
+
32
+ let i = 0
33
+ function resposition(driver) {
34
+ return driver
35
+ .manage()
36
+ .window()
37
+ .setRect({
38
+ width: 600,
39
+ height: 400,
40
+ x: 300 * i++,
41
+ y: 0,
42
+ })
43
+ }
44
+
45
+ async function doSearch(driver) {
46
+ try {
47
+ // Start on the base about page.
48
+ await driver.get('about:')
49
+ // Reposition so users can see the three windows.
50
+ await resposition(driver)
51
+ // Pause so users can see the magic.
52
+ await promise.delayed(750)
53
+ // Now do the rest.
54
+ await driver.get('http://www.google.com/ncr')
55
+ await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
56
+ await driver.wait(until.titleIs('webdriver - Google Search'), 1000)
57
+ console.log('Success!')
58
+ } catch (ex) {
59
+ console.log('An error occured! ' + ex)
60
+ } finally {
61
+ await driver.quit()
62
+ }
63
+ }
64
+
65
+ function createDriver(channel) {
66
+ let options = new Options().setBinary(channel)
67
+ return new Builder().forBrowser('firefox').setFirefoxOptions(options).build()
68
+ }
69
+
70
+ Promise.all([
71
+ doSearch(createDriver(Channel.RELEASE)),
72
+ doSearch(createDriver(Channel.AURORA)), // Developer Edition.
73
+ doSearch(createDriver(Channel.NIGHTLY)),
74
+ ]).then(
75
+ (_) => {
76
+ console.log('All done!')
77
+ },
78
+ (err) => {
79
+ console.error('An error occured! ' + err)
80
+ setTimeout(() => {
81
+ throw err
82
+ }, 0)
83
+ }
84
+ )
@@ -0,0 +1,50 @@
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 WebDriver script.
20
+ *
21
+ * Before running this script, ensure that Mozilla's geckodriver is present on
22
+ * your system PATH: <https://github.com/mozilla/geckodriver/releases>
23
+ *
24
+ * Usage:
25
+ * // Default behavior
26
+ * node selenium-webdriver/example/google_search.js
27
+ *
28
+ * // Target Chrome locally; the chromedriver must be on your PATH
29
+ * SELENIUM_BROWSER=chrome node selenium-webdriver/example/google_search.js
30
+ *
31
+ * // Use a local copy of the standalone Selenium server
32
+ * SELENIUM_SERVER_JAR=/path/to/selenium-server-standalone.jar \
33
+ * node selenium-webdriver/example/google_search.js
34
+ *
35
+ * // Target a remote Selenium server
36
+ * SELENIUM_REMOTE_URL=http://www.example.com:4444/wd/hub \
37
+ * node selenium-webdriver/example/google_search.js
38
+ */
39
+
40
+ const { Builder, By, Key, until } = require('..')
41
+
42
+ var driver = new Builder().forBrowser('firefox').build()
43
+
44
+ driver
45
+ .get('http://www.google.com/ncr')
46
+ .then((_) =>
47
+ driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
48
+ )
49
+ .then((_) => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
50
+ .then((_) => driver.quit())
@@ -0,0 +1,70 @@
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 test that may be run using Mocha.
20
+ *
21
+ * This example uses the `selenium-webdriver/testing.suite` function, which will
22
+ * automatically run tests against every available WebDriver browser on the
23
+ * current system. Alternatively, you may use the `SELENIUM_BROWSER`
24
+ * environment variable to narrow the scope at runtime.
25
+ *
26
+ * Usage:
27
+ *
28
+ * # Automatically determine which browsers to run against.
29
+ * mocha -t 10000 selenium-webdriver/example/google_search_test.js
30
+ *
31
+ * # Configure tests to only run against Google Chrome.
32
+ * SELENIUM_BROWSER=chrome \
33
+ * mocha -t 10000 selenium-webdriver/example/google_search_test.js
34
+ */
35
+
36
+ const { Browser, By, Key, until } = require('..')
37
+ const { ignore, suite } = require('../testing')
38
+
39
+ suite(function (env) {
40
+ describe('Google Search', function () {
41
+ let driver
42
+
43
+ before(async function () {
44
+ // env.builder() returns a Builder instance preconfigured for the
45
+ // envrionment's target browser (you may still define browser specific
46
+ // options if necessary (i.e. firefox.Options or chrome.Options)).
47
+ driver = await env.builder().build()
48
+ })
49
+
50
+ it('demo', async function () {
51
+ await driver.get('https://www.google.com/ncr')
52
+ await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
53
+ await driver.wait(until.titleIs('webdriver - Google Search'), 1000)
54
+ })
55
+
56
+ // The ignore function returns wrappers around describe & it that will
57
+ // suppress tests if the provided predicate returns true. You may provide
58
+ // any synchronous predicate. The env.browsers(...) function generates a
59
+ // predicate that will suppress tests if the env targets one of the
60
+ // specified browsers.
61
+ //
62
+ // This example is always configured to skip Chrome.
63
+ ignore(env.browsers(Browser.CHROME)).it('demo 2', async function () {
64
+ await driver.get('https://www.google.com/ncr')
65
+ await driver.wait(until.urlIs('https://www.google.com/'), 1500)
66
+ })
67
+
68
+ after(() => driver && driver.quit())
69
+ })
70
+ })
@@ -0,0 +1,63 @@
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 or Firefox in headless mode.
20
+ *
21
+ * To run with Chrome, ensure you have Chrome 59+ installed and that
22
+ * chromedriver 2.30+ is present on your system PATH:
23
+ * <https://chromedriver.chromium.org/downloads>
24
+ *
25
+ * SELENIUM_BROWSER=chrome node selenium-webdriver/example/headless.js
26
+ *
27
+ * To run with Firefox, ensure you have Firefox 57+ installed and that
28
+ * geckodriver 0.19.0+ is present on your system PATH:
29
+ * <https://github.com/mozilla/geckodriver/releases>
30
+ *
31
+ * SELENIUM_BROWSER=firefox node selenium-webdriver/example/headless.js
32
+ */
33
+
34
+ const chrome = require('../chrome')
35
+ const firefox = require('../firefox')
36
+ const { Builder, By, Key, until } = require('..')
37
+
38
+ const width = 640
39
+ const height = 480
40
+
41
+ let driver = new Builder()
42
+ .forBrowser('chrome')
43
+ .setChromeOptions(
44
+ new chrome.Options().headless().windowSize({ width, height })
45
+ )
46
+ .setFirefoxOptions(
47
+ new firefox.Options().headless().windowSize({ width, height })
48
+ )
49
+ .build()
50
+
51
+ driver
52
+ .get('http://www.google.com/ncr')
53
+ .then((_) =>
54
+ driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
55
+ )
56
+ .then((_) => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
57
+ .then(
58
+ (_) => driver.quit(),
59
+ (e) =>
60
+ driver.quit().then(() => {
61
+ throw e
62
+ })
63
+ )