selenium-webdriver 4.0.0-alpha.7 → 4.0.0-beta.3
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.
- package/CHANGES.md +56 -0
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +2 -0
- package/chrome.js +69 -79
- package/chromium.js +231 -164
- package/{lib/atoms/make-atoms-module.js → devtools/CDPConnection.js} +15 -9
- package/edge.js +104 -146
- package/example/chrome_android.js +45 -0
- package/example/chrome_mobile_emulation.js +46 -0
- package/example/firefox_channels.js +84 -0
- package/example/google_search.js +50 -0
- package/example/google_search_test.js +70 -0
- package/example/headless.js +63 -0
- package/example/logging.js +64 -0
- package/firefox.js +199 -200
- package/http/index.js +128 -116
- package/http/util.js +56 -64
- package/ie.js +180 -104
- package/index.js +246 -199
- package/io/exec.js +35 -40
- package/io/index.js +146 -157
- package/io/zip.js +75 -66
- package/lib/atoms/find-elements.js +123 -0
- package/lib/atoms/get-attribute.js +75 -59
- package/lib/atoms/is-displayed.js +72 -72
- package/lib/atoms/mutation-listener.js +55 -0
- package/lib/by.js +192 -65
- package/lib/capabilities.js +76 -86
- package/lib/command.js +19 -35
- package/lib/error.js +134 -168
- package/lib/http.js +308 -232
- package/lib/input.js +192 -453
- package/lib/logging.js +126 -137
- package/lib/promise.js +53 -71
- package/lib/proxy.js +31 -41
- package/lib/session.js +12 -15
- package/lib/symbols.js +3 -4
- package/lib/until.js +162 -160
- package/lib/webdriver.js +1014 -549
- package/net/index.js +30 -36
- package/net/portprober.js +30 -143
- package/opera.js +406 -0
- package/package.json +15 -7
- package/proxy.js +2 -2
- package/remote/index.js +189 -187
- package/safari.js +40 -49
- package/testing/index.js +504 -0
- package/lib/README +0 -5
- package/lib/actions.js +0 -609
|
@@ -15,15 +15,21 @@
|
|
|
15
15
|
// specific language governing permissions and limitations
|
|
16
16
|
// under the License.
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
class CDPConnection {
|
|
19
|
+
constructor(wsConnection) {
|
|
20
|
+
this._wsConnection = wsConnection
|
|
21
|
+
}
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
execute(method, id, params, callback) {
|
|
24
|
+
const message = {
|
|
25
|
+
method,
|
|
26
|
+
id: id,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const mergedMessage = Object.assign({ params: params }, message)
|
|
30
|
+
|
|
31
|
+
this._wsConnection.send(JSON.stringify(mergedMessage), callback)
|
|
32
|
+
}
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
|
|
27
|
-
fs.writeFileSync(process.argv[3], `// GENERATED CODE - DO NOT EDIT
|
|
28
|
-
module.exports = ${buffer.toString('utf8').trim()};
|
|
29
|
-
`);
|
|
35
|
+
exports.CdpConnection = CDPConnection
|
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.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
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
|
|
26
|
-
* is on your [PATH](http://en.wikipedia.org/wiki/PATH_%28variable%29).
|
|
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
|
-
*
|
|
32
|
-
* options.
|
|
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
|
-
*
|
|
59
|
+
* const edge = require('selenium-webdriver/edge');
|
|
64
60
|
*
|
|
65
|
-
*
|
|
61
|
+
* const service = new edge.ServiceBuilder()
|
|
66
62
|
* .setPort(55555)
|
|
67
63
|
* .build();
|
|
68
64
|
*
|
|
69
|
-
*
|
|
65
|
+
* let options = new edge.Options();
|
|
70
66
|
* // configure browser options ...
|
|
71
67
|
*
|
|
72
|
-
*
|
|
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
|
|
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
|
-
'use strict'
|
|
78
|
+
'use strict'
|
|
84
79
|
|
|
85
|
-
const
|
|
86
|
-
const io = require('./io')
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const chromium = require('./chromium');
|
|
80
|
+
const { Browser } = require('./lib/capabilities')
|
|
81
|
+
const io = require('./io')
|
|
82
|
+
const chromium = require('./chromium')
|
|
83
|
+
const http = require('./http')
|
|
84
|
+
const webdriver = require('./lib/webdriver')
|
|
91
85
|
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Name of the EdgeDriver executable.
|
|
88
|
+
* @type {string}
|
|
89
|
+
* @const
|
|
90
|
+
*/
|
|
94
91
|
const EDGEDRIVER_CHROMIUM_EXE =
|
|
95
|
-
|
|
92
|
+
process.platform === 'win32' ? 'msedgedriver.exe' : 'msedgedriver'
|
|
93
|
+
|
|
94
|
+
/** @type {remote.DriverService} */
|
|
95
|
+
let defaultService = null
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* @param {string=} browserName Name of the Edge driver executable to locate.
|
|
102
|
-
* May be either 'msedge' to locate the Edge Chromium driver, or 'MicrosoftEdge' to
|
|
103
|
-
* locate the Edge Legacy driver. If omitted, will attempt to locate Edge Legacy.
|
|
104
|
-
* @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.
|
|
105
101
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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)
|
|
111
122
|
}
|
|
112
|
-
|
|
113
|
-
return process.platform === 'win32'
|
|
114
|
-
? io.findInPath(EDGEDRIVER_LEGACY_EXE, true) : null;
|
|
115
123
|
}
|
|
116
124
|
|
|
117
|
-
|
|
118
125
|
/**
|
|
119
|
-
* Class for managing
|
|
126
|
+
* Class for managing edge chromium specific options.
|
|
120
127
|
*/
|
|
121
128
|
class Options extends chromium.Options {
|
|
122
129
|
/**
|
|
123
|
-
*
|
|
124
|
-
* Otherwise, use Edge Legacy (EdgeHTML). Defaults to using Edge Legacy.
|
|
130
|
+
* Sets the path to the edge binary to use
|
|
125
131
|
*
|
|
126
|
-
*
|
|
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.
|
|
134
|
+
*
|
|
135
|
+
* @param {string} path The path to the edgedriver binary to use.
|
|
127
136
|
* @return {!Options} A self reference.
|
|
128
137
|
*/
|
|
129
|
-
|
|
130
|
-
this.
|
|
131
|
-
return this;
|
|
138
|
+
setEdgeChromiumBinaryPath(path) {
|
|
139
|
+
return this.setBinaryPath(path)
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
142
|
|
|
135
|
-
Options.USE_EDGE_CHROMIUM = 'ms:edgeChromium';
|
|
136
|
-
Options.prototype.BROWSER_NAME_VALUE = Browser.EDGE;
|
|
137
|
-
Options.prototype.CAPABILITY_KEY = 'ms:edgeOptions';
|
|
138
|
-
Options.prototype.VENDOR_CAPABILITY_PREFIX = 'ms';
|
|
139
|
-
|
|
140
143
|
/**
|
|
141
|
-
*
|
|
142
|
-
* @return {boolean}
|
|
144
|
+
* Creates a new WebDriver client for Microsoft's Edge.
|
|
143
145
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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)
|
|
160
|
+
|
|
161
|
+
return /** @type {!Driver} */ (super.createSession(executor, options, () =>
|
|
162
|
+
service.kill()
|
|
163
|
+
))
|
|
151
164
|
}
|
|
152
165
|
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Creates {@link remote.DriverService} instances that manage a
|
|
159
|
-
* WebDriver server in a child process. Used for driving both
|
|
160
|
-
* Microsoft Edge Legacy and Chromium. A ServiceBuilder constructed
|
|
161
|
-
* with default parameters will launch a MicrosoftWebDriver child
|
|
162
|
-
* process for driving Edge Legacy. You may pass in a path to
|
|
163
|
-
* msedgedriver.exe to use Edge Chromium instead.
|
|
164
|
-
*/
|
|
165
|
-
class ServiceBuilder extends chromium.ServiceBuilder {
|
|
166
166
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* @throws {Error} If provided executable does not exist, or the
|
|
171
|
-
* 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
|
|
172
170
|
*/
|
|
173
|
-
|
|
174
|
-
let exe = opt_exe || locateSynchronously();
|
|
175
|
-
if (!exe) {
|
|
176
|
-
throw Error('The WebDriver for Edge could not be found on the current PATH. Please ' +
|
|
177
|
-
'download the latest version of ' + EDGEDRIVER_LEGACY_EXE + ' from ' +
|
|
178
|
-
'https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ and ' +
|
|
179
|
-
'ensure it can be found on your PATH.');
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
super(exe);
|
|
183
|
-
}
|
|
171
|
+
setFileDetector() {}
|
|
184
172
|
}
|
|
185
173
|
|
|
186
|
-
|
|
187
|
-
/** @type {remote.DriverService} */
|
|
188
|
-
var defaultService = null;
|
|
189
|
-
|
|
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,70 +180,45 @@ 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.'
|
|
184
|
+
)
|
|
201
185
|
}
|
|
202
|
-
defaultService = service
|
|
186
|
+
defaultService = service
|
|
203
187
|
}
|
|
204
188
|
|
|
205
|
-
|
|
206
189
|
/**
|
|
207
|
-
|
|
190
|
+
* Returns the default Microsoft Edge driver service. If such a service has
|
|
208
191
|
* not been configured, one will be constructed using the default configuration
|
|
209
192
|
* for a MicrosoftWebDriver executable found on the system PATH.
|
|
210
193
|
* @return {!remote.DriverService} The default Microsoft Edge driver service.
|
|
211
194
|
*/
|
|
212
195
|
function getDefaultService() {
|
|
213
196
|
if (!defaultService) {
|
|
214
|
-
defaultService = new ServiceBuilder().build()
|
|
197
|
+
defaultService = new ServiceBuilder().build()
|
|
215
198
|
}
|
|
216
|
-
return defaultService
|
|
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
|
-
*
|
|
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
|
-
|
|
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=} 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(
|
|
246
|
-
executor, options, () => service.kill()));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* This function is a no-op as file detectors are not supported by this
|
|
251
|
-
* implementation.
|
|
252
|
-
* @override
|
|
253
|
-
*/
|
|
254
|
-
setFileDetector() {}
|
|
209
|
+
function locateSynchronously() {
|
|
210
|
+
return io.findInPath(EDGEDRIVER_CHROMIUM_EXE, true)
|
|
255
211
|
}
|
|
256
212
|
|
|
213
|
+
Options.prototype.BROWSER_NAME_VALUE = Browser.EDGE
|
|
214
|
+
Options.prototype.CAPABILITY_KEY = 'ms:edgeOptions'
|
|
215
|
+
Driver.prototype.VENDOR_CAPABILITY_PREFIX = 'ms'
|
|
257
216
|
|
|
258
217
|
// PUBLIC API
|
|
259
218
|
|
|
260
|
-
|
|
261
|
-
exports.
|
|
262
|
-
exports.
|
|
263
|
-
exports.
|
|
264
|
-
exports.
|
|
265
|
-
exports.
|
|
266
|
-
exports.locateSynchronously = locateSynchronously;
|
|
219
|
+
exports.Driver = Driver
|
|
220
|
+
exports.Options = Options
|
|
221
|
+
exports.ServiceBuilder = ServiceBuilder
|
|
222
|
+
exports.getDefaultService = getDefaultService
|
|
223
|
+
exports.setDefaultService = setDefaultService
|
|
224
|
+
exports.locateSynchronously = locateSynchronously
|
|
@@ -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
|
+
)
|
|
@@ -0,0 +1,46 @@
|
|
|
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 emulating a mobile device using the
|
|
20
|
+
* ChromeDriver.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
'use strict'
|
|
24
|
+
|
|
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)
|
|
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
|
+
})
|