1 | import { Executor } from "./http";
|
2 | import * as webdriver from "./index";
|
3 | import * as remote from "./remote";
|
4 |
|
5 | /**
|
6 | * Creates {@link selenium-webdriver/remote.DriverService} instances that manage
|
7 | * a WebDriver server in a child process.
|
8 | */
|
9 | export class ServiceBuilder extends remote.DriverService.Builder {
|
10 | /**
|
11 | * @param {string=} exe Path to the server executable to use. Subclasses
|
12 | * should ensure a valid path to the appropriate exe is provided.
|
13 | */
|
14 | constructor(exe?: string);
|
15 |
|
16 | /**
|
17 | * Sets which port adb is listening to. _The driver will connect to adb
|
18 | * if an { Options#androidPackage Android session} is requested, but
|
19 | * adb **must** be started beforehand._
|
20 | *
|
21 | * number} port Which port adb is running on.
{ |
22 | * {!ServiceBuilder} A self reference.
|
23 | */
|
24 | setAdbPort(port: number): ServiceBuilder;
|
25 |
|
26 | /**
|
27 | * Sets the path of the log file the driver should log to. If a log file is
|
28 | * not specified, the driver will log to stderr.
|
29 | * @param {string} path Path of the log file to use.
|
30 | * @return {!ServiceBuilder} A self reference.
|
31 | */
|
32 | loggingTo(path: string): ServiceBuilder;
|
33 |
|
34 | /**
|
35 | * Enables Chrome logging.
|
36 | * @returns {!ServiceBuilder} A self reference.
|
37 | */
|
38 | enableChromeLogging(): ServiceBuilder;
|
39 |
|
40 | /**
|
41 | * Enables verbose logging.
|
42 | * @return {!ServiceBuilder} A self reference.
|
43 | */
|
44 | enableVerboseLogging(): ServiceBuilder;
|
45 |
|
46 | /**
|
47 | * Sets the number of threads the driver should use to manage HTTP requests.
|
48 | * By default, the driver will use 4 threads.
|
49 | * @param {number} n The number of threads to use.
|
50 | * @return {!ServiceBuilder} A self reference.
|
51 | */
|
52 | setNumHttpThreads(n: number): ServiceBuilder;
|
53 |
|
54 | /**
|
55 | * @override
|
56 | */
|
57 | setPath(path: string): any;
|
58 | }
|
59 |
|
60 | /**
|
61 | * Class for managing WebDriver options specific to a Chromium-based browser.
|
62 | */
|
63 | export class Options extends webdriver.Capabilities {
|
64 | /**
|
65 | * @param {(Capabilities|Map<string, ?>|Object)=} other Another set of
|
66 | * capabilities to initialize this instance from.
|
67 | */
|
68 | constructor(other?: webdriver.Capabilities | Map<string, any> | object);
|
69 |
|
70 | /**
|
71 | * Add additional command line arguments to use when launching the browser.
|
72 | * Each argument may be specified with or without the "--" prefix
|
73 | * (e.g. "--foo" and "foo"). Arguments with an associated value should be
|
74 | * delimited by an "=": "foo=bar".
|
75 | *
|
76 | * @param {...(string|!Array<string>)} args The arguments to add.
|
77 | * {!Options} A self reference.
|
78 | */
|
79 | addArguments(...args: string[]): Options;
|
80 |
|
81 | /**
|
82 | * Sets the address of a Chromium remote debugging server to connect to.
|
83 | * Address should be of the form "{hostname|IP address}:port"
|
84 | * (e.g. "localhost:9222").
|
85 | *
|
86 | * @param {string} address The address to connect to.
|
87 | * @return {!Options} A self reference.
|
88 | */
|
89 | debuggerAddress(address: string): Options;
|
90 |
|
91 | /**
|
92 | * Sets the initial window size.
|
93 | *
|
94 | * @param {{width: number, height: number}} size The desired window size.
|
95 | * @return {!Options} A self reference.
|
96 | * @throws {TypeError} if width or height is unspecified, not a number, or
|
97 | * less than or equal to 0.
|
98 | */
|
99 | windowSize({ width, height }: { width: number; height: number }): Options;
|
100 |
|
101 | /**
|
102 | * List of Chrome command line switches to exclude that ChromeDriver by default
|
103 | * passes when starting Chrome. Do not prefix switches with "--".
|
104 | *
|
105 | * @param {...(string|!Array<string>)} args The switches to exclude.
|
106 | * @return {!Options} A self reference.
|
107 | */
|
108 | excludeSwitches(...args: string[]): Options;
|
109 |
|
110 | /**
|
111 | * Add additional extensions to install when launching the browser. Each extension
|
112 | * should be specified as the path to the packed CRX file, or a Buffer for an
|
113 | * extension.
|
114 | * @param {...(string|!Buffer|!Array<(string|!Buffer)>)} args The
|
115 | * extensions to add.
|
116 | * @return {!Options} A self reference.
|
117 | */
|
118 | addExtensions(...args: Array<string | Buffer>): Options;
|
119 |
|
120 | /**
|
121 | * Sets the path to the browser binary to use. On Mac OS X, this path should
|
122 | * reference the actual Chromium executable, not just the application binary
|
123 | * (e.g. "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome").
|
124 | *
|
125 | * The binary path can be absolute or relative to the WebDriver server
|
126 | * executable, but it must exist on the machine that will launch the browser.
|
127 | *
|
128 | * @param {string} path The path to the browser binary to use.
|
129 | * @return {!Options} A self reference.
|
130 | */
|
131 | setBinaryPath(path: string): Options;
|
132 |
|
133 | /**
|
134 | * Sets whether to leave the started browser process running if the controlling
|
135 | * driver service is killed before {@link webdriver.WebDriver#quit()} is
|
136 | * called.
|
137 | * @param {boolean} detach Whether to leave the browser running if the
|
138 | * driver service is killed before the session.
|
139 | * @return {!Options} A self reference.
|
140 | */
|
141 | detachDriver(detach: boolean): Options;
|
142 |
|
143 | /**
|
144 | * Sets the user preferences for Chrome's user profile. See the "Preferences"
|
145 | * file in Chrome's user data directory for examples.
|
146 | * @param {!Object} prefs Dictionary of user preferences to use.
|
147 | * @return {!Options} A self reference.
|
148 | */
|
149 | setUserPreferences(prefs: object): Options;
|
150 |
|
151 | /**
|
152 | * Sets the performance logging preferences. Options include:
|
153 | *
|
154 | * - `enableNetwork`: Whether or not to collect events from Network domain.
|
155 | * - `enablePage`: Whether or not to collect events from Page domain.
|
156 | * - `enableTimeline`: Whether or not to collect events from Timeline domain.
|
157 | * Note: when tracing is enabled, Timeline domain is implicitly disabled,
|
158 | * unless `enableTimeline` is explicitly set to true.
|
159 | * - `traceCategories`: A comma-separated string of Chromium tracing
|
160 | * categories for which trace events should be collected. An unspecified
|
161 | * or empty string disables tracing.
|
162 | * - `bufferUsageReportingInterval`: The requested number of milliseconds
|
163 | * between DevTools trace buffer usage events. For example, if 1000, then
|
164 | * once per second, DevTools will report how full the trace buffer is. If
|
165 | * a report indicates the buffer usage is 100%, a warning will be issued.
|
166 | *
|
167 | * @param {{enableNetwork: boolean,
|
168 | * enablePage: boolean,
|
169 | * enableTimeline: boolean,
|
170 | * traceCategories: string,
|
171 | * bufferUsageReportingInterval: number}} prefs The performance
|
172 | * logging preferences.
|
173 | * @return {!Options} A self reference.
|
174 | */
|
175 | setPerfLoggingPrefs(prefs: {
|
176 | enableNetwork: boolean;
|
177 | enablePage: boolean;
|
178 | enableTimeline: boolean;
|
179 | traceCategories: string;
|
180 | bufferUsageReportingInterval: number;
|
181 | }): Options;
|
182 |
|
183 | /**
|
184 | * Sets preferences for the "Local State" file in Chrome's user data
|
185 | * directory.
|
186 | * @param {!Object} state Dictionary of local state preferences.
|
187 | * @return {!Options} A self reference.
|
188 | */
|
189 | setLocalState(state: object): Options;
|
190 |
|
191 | /**
|
192 | * Sets the name of the activity hosting a Chrome-based Android WebView. This
|
193 | * option must be set to connect to an [Android WebView](
|
194 | * https://chromedriver.chromium.org/getting-started/getting-started---android)
|
195 | *
|
196 | * @param {string} name The activity name.
|
197 | * @return {!Options} A self reference.
|
198 | */
|
199 | androidActivity(name: string): Options;
|
200 |
|
201 | /**
|
202 | * Sets the device serial number to connect to via ADB. If not specified, the
|
203 | * WebDriver server will select an unused device at random. An error will be
|
204 | * returned if all devices already have active sessions.
|
205 | *
|
206 | * @param {string} serial The device serial number to connect to.
|
207 | * @return {!Options} A self reference.
|
208 | */
|
209 | androidDeviceSerial(serial: string): Options;
|
210 |
|
211 | /**
|
212 | * Sets the package name of the Chrome or WebView app.
|
213 | *
|
214 | * @param {?string} pkg The package to connect to, or `null` to disable Android
|
215 | * and switch back to using desktop browser.
|
216 | * @return {!Options} A self reference.
|
217 | */
|
218 | androidPackage(pkg: string | null): Options;
|
219 |
|
220 | /**
|
221 | * Sets the process name of the Activity hosting the WebView (as given by
|
222 | * `ps`). If not specified, the process name is assumed to be the same as
|
223 | * {@link #androidPackage}.
|
224 | *
|
225 | * @param {string} processName The main activity name.
|
226 | * @return {!Options} A self reference.
|
227 | */
|
228 | androidProcess(processName: string): Options;
|
229 |
|
230 | /**
|
231 | * Sets whether to connect to an already-running instead of the specified
|
232 | * {@linkplain #androidProcess app} instead of launching the app with a clean
|
233 | * data directory.
|
234 | *
|
235 | * @param {boolean} useRunning Whether to connect to a running instance.
|
236 | * @return {!Options} A self reference.
|
237 | */
|
238 | androidUseRunningApp(useRunning: boolean): Options;
|
239 |
|
240 | /**
|
241 | * Sets the path to the browser's log file. This path should exist on the machine
|
242 | * that will launch the browser.
|
243 | * @param {string} path Path to the log file to use.
|
244 | * @return {!Options} A self reference.
|
245 | */
|
246 | setBrowserLogFile(path: string): Options;
|
247 |
|
248 | /**
|
249 | * Sets the directory to store browser minidumps in. This option is only
|
250 | * supported when the driver is running on Linux.
|
251 | * @param {string} path The directory path.
|
252 | * @return {!Options} A self reference.
|
253 | */
|
254 | setBrowserMinidumpPath(path: string): Options;
|
255 |
|
256 | /**
|
257 | * Configures the browser to emulate a mobile device. For more information, refer
|
258 | * to the ChromeDriver project page on [mobile emulation][em]. Configuration
|
259 | * options include:
|
260 | *
|
261 | * - `deviceName`: The name of a pre-configured [emulated device][devem]
|
262 | * - `width`: screen width, in pixels
|
263 | * - `height`: screen height, in pixels
|
264 | * - `pixelRatio`: screen pixel ratio
|
265 | *
|
266 | * __Example 1: Using a Pre-configured Device__
|
267 | *
|
268 | * let options = new chrome.Options().setMobileEmulation(
|
269 | * {deviceName: 'Google Nexus 5'});
|
270 | *
|
271 | * let driver = chrome.Driver.createSession(options);
|
272 | *
|
273 | * __Example 2: Using Custom Screen Configuration__
|
274 | *
|
275 | * let options = new chrome.Options().setMobileEmulation({deviceMetrics: {
|
276 | * width: 360,
|
277 | * height: 640,
|
278 | * pixelRatio: 3.0
|
279 | * }});
|
280 | *
|
281 | * let driver = chrome.Driver.createSession(options);
|
282 | *
|
283 | * [em]: https://chromedriver.chromium.org/mobile-emulation
|
284 | * [devem]: https://developer.chrome.com/devtools/docs/device-mode
|
285 | *
|
286 | * @param {?({deviceName: string}|
|
287 | * {width: number, height: number, pixelRatio: number})} config The
|
288 | * mobile emulation configuration, or `null` to disable emulation.
|
289 | * @return {!Options} A self reference.
|
290 | */
|
291 | setMobileEmulation(
|
292 | config?:
|
293 | | { deviceName: string }
|
294 | | { width: number; height: number; pixelRatio: number },
|
295 | ): Options;
|
296 |
|
297 | /**
|
298 | * Sets a list of the window types that will appear when getting window
|
299 | * handles. For access to <webview> elements, include "webview" in the list.
|
300 | * @param {...(string|!Array<string>)} args The window types that will appear
|
301 | * when getting window handles.
|
302 | * @return {!Options} A self reference.
|
303 | */
|
304 | windowTypes(...args: string[]): Options;
|
305 |
|
306 | /**
|
307 | * Enable bidi connection
|
308 | * @returns {!Capabilities}
|
309 | */
|
310 | enableBidi(): webdriver.Capabilities;
|
311 | }
|
312 |
|
313 | /**
|
314 | * A list of extensions to install when launching the browser.
|
315 | */
|
316 | export class Extensions {
|
317 | constructor();
|
318 |
|
319 | /**
|
320 | * @return {number} The length of the extensions list.
|
321 | */
|
322 | length: number;
|
323 |
|
324 | /**
|
325 | * Add additional extensions to install when launching the browser. Each
|
326 | * extension should be specified as the path to the packed CRX file, or a
|
327 | * Buffer for an extension.
|
328 | *
|
329 | * @param {...(string|!Buffer|!Array<(string|!Buffer)>)} args The
|
330 | * extensions to add.
|
331 | */
|
332 | add(...args: Array<string | Buffer>): void;
|
333 | }
|
334 |
|
335 | /**
|
336 | * Creates a new WebDriver client for Chromium-based browsers.
|
337 | */
|
338 | export class ChromiumWebDriver extends webdriver.WebDriver {
|
339 | /**
|
340 | * Creates a new session with the WebDriver server.
|
341 | *
|
342 | * @param {(Capabilities|Options)=} caps The configuration options.
|
343 | * @param {(remote.DriverService|Executor)=} opt_serviceExecutor Either
|
344 | * a DriverService to use for the remote end, or a preconfigured executor
|
345 | * for an externally managed endpoint. If neither is provided, the
|
346 | * {@linkplain ##getDefaultService default service} will be used by
|
347 | * default.
|
348 | * @param vendorPrefix Either 'goog' or 'ms'
|
349 | * @param vendorCapabilityKey Either 'goog:chromeOptions' or 'ms:edgeOptions'
|
350 | * @return {!ChromiumWebDriver} A new driver instance.
|
351 | */
|
352 | static createSession(
|
353 | caps?: webdriver.Capabilities | Options,
|
354 | opt_serviceExecutor?: remote.DriverService | Executor,
|
355 | vendorPrefix?: string,
|
356 | vendorCapabilityKey?: string,
|
357 | ): ChromiumWebDriver;
|
358 |
|
359 | /**
|
360 | * This function is a no-op as file detectors are not supported by this
|
361 | * implementation.
|
362 | * @override
|
363 | */
|
364 | setFileDetector(): void;
|
365 |
|
366 | /**
|
367 | * Schedules a command to launch Chrome App with given ID.
|
368 | * @param {string} id ID of the App to launch.
|
369 | * @return {!Promise<void>} A promise that will be resolved
|
370 | * when app is launched.
|
371 | */
|
372 | launchApp(id: string): Promise<void>;
|
373 |
|
374 | /**
|
375 | * Schedules a command to get Chromium network emulation settings.
|
376 | * @return {!Promise} A promise that will be resolved when network
|
377 | * emulation settings are retrieved.
|
378 | */
|
379 | getNetworkConditions(): Promise<any>;
|
380 |
|
381 | /**
|
382 | * Schedules a command to delete Chromium network emulation settings.
|
383 | * @return {!Promise} A promise that will be resolved when network
|
384 | * emulation settings have been deleted.
|
385 | */
|
386 | deleteNetworkConditions(): Promise<any>;
|
387 |
|
388 | /**
|
389 | * Schedules a command to set Chromium network emulation settings.
|
390 | *
|
391 | * __Sample Usage:__
|
392 | *
|
393 | * driver.setNetworkConditions({
|
394 | * offline: false,
|
395 | * latency: 5, // Additional latency (ms).
|
396 | * download_throughput: 500 * 1024, // Maximal aggregated download throughput.
|
397 | * upload_throughput: 500 * 1024 // Maximal aggregated upload throughput.
|
398 | * });
|
399 | *
|
400 | * @param {Object} spec Defines the network conditions to set
|
401 | * @return {!Promise<void>} A promise that will be resolved when network
|
402 | * emulation settings are set.
|
403 | */
|
404 | setNetworkConditions(
|
405 | spec: { offline: boolean; latency: number; download_throughput: number; upload_throughput: number },
|
406 | ): Promise<void>;
|
407 |
|
408 | /**
|
409 | * Sends an arbitrary devtools command to the browser.
|
410 | *
|
411 | * @param {string} cmd The name of the command to send.
|
412 | * @param {Object=} params The command parameters.
|
413 | * @return {!Promise<void>} A promise that will be resolved when the command
|
414 | * has finished.
|
415 | * @see <https://chromedevtools.github.io/devtools-protocol/>
|
416 | */
|
417 | sendDevToolsCommand(cmd: string, params: object): Promise<void>;
|
418 |
|
419 | /**
|
420 | * Sends an arbitrary devtools command to the browser and get the result.
|
421 | *
|
422 | * @param {string} cmd The name of the command to send.
|
423 | * @param {Object=} params The command parameters.
|
424 | * @return {!Promise<string>} A promise that will be resolved when the command
|
425 | * has finished.
|
426 | * @see <https://chromedevtools.github.io/devtools-protocol/>
|
427 | */
|
428 | sendAndGetDevToolsCommand(cmd: string, params: object): Promise<string>;
|
429 |
|
430 | /**
|
431 | * Set a permission state to the given value.
|
432 | *
|
433 | * @param {string} name A name of the permission to update.
|
434 | * @param {('granted'|'denied'|'prompt')} state State to set permission to.
|
435 | * @returns {!Promise<Object>} A promise that will be resolved when the
|
436 | * command has finished.
|
437 | * @see <https://w3c.github.io/permissions/#permission-registry> for valid
|
438 | * names
|
439 | */
|
440 | setPermission(name: string, state: "granted" | "denied" | "prompt"): Promise<object>;
|
441 |
|
442 | /**
|
443 | * Sends a DevTools command to change the browser's download directory.
|
444 | *
|
445 | * @param {string} path The desired download directory.
|
446 | * @return {!Promise<void>} A promise that will be resolved when the command
|
447 | * has finished.
|
448 | * @see #sendDevToolsCommand
|
449 | */
|
450 | setDownloadPath(path: string): Promise<void>;
|
451 |
|
452 | /**
|
453 | * Returns the list of cast sinks (Cast devices) available to the Chrome media router.
|
454 | *
|
455 | * @return {!promise.Thenable<void>} A promise that will be resolved with an array of Strings
|
456 | * containing the friendly device names of available cast sink targets.
|
457 | */
|
458 | getCastSinks(): Promise<string[]>;
|
459 |
|
460 | /**
|
461 | * Selects a cast sink (Cast device) as the recipient of media router intents (connect or play).
|
462 | *
|
463 | * @param {String} deviceName name of the target device.
|
464 | * @return {!promise.Thenable<void>} A promise that will be resolved
|
465 | * when the target device has been selected to respond further webdriver commands.
|
466 | */
|
467 | setCastSinkToUse(deviceName: string): Promise<void>;
|
468 |
|
469 | /**
|
470 | * Initiates desktop mirroring for the current browser tab on the specified device.
|
471 | *
|
472 | * @param {String} deviceName name of the target device.
|
473 | * @return {!promise.Thenable<void>} A promise that will be resolved
|
474 | * when the mirror command has been issued to the device.
|
475 | */
|
476 | startDesktopMirroring(deviceName: string): Promise<void>;
|
477 |
|
478 | /**
|
479 | * Initiates tab mirroring for the current browser tab on the specified device.
|
480 | *
|
481 | * @param {String} deviceName name of the target device.
|
482 | * @return {!promise.Thenable<void>} A promise that will be resolved
|
483 | * when the mirror command has been issued to the device.
|
484 | */
|
485 | startCastTabMirroring(deviceName: string): Promise<void>;
|
486 |
|
487 | /**
|
488 | * Returns an error message when there is any issue in a Cast session.
|
489 | * @return {!promise.Thenable<void>} A promise that will be resolved
|
490 | * when the mirror command has been issued to the device.
|
491 | */
|
492 | getCastIssueMessage(): Promise<string>;
|
493 |
|
494 | /**
|
495 | * Stops casting from media router to the specified device, if connected.
|
496 | *
|
497 | * @param {String} deviceName name of the target device.
|
498 | * @return {!promise.Thenable<void>} A promise that will be resolved
|
499 | * when the stop command has been issued to the device.
|
500 | */
|
501 | stopCasting(deviceName: string): Promise<void>;
|
502 | }
|