UNPKG

40.8 kBTypeScriptView Raw
1import { WebSocket } from "ws";
2import {
3 Actions,
4 Capabilities,
5 IWebElementId,
6 Locator,
7 Logs,
8 Serializable,
9 Session,
10 WebElement,
11 WebElementPromise,
12 Window,
13} from "..";
14import { HttpResponse } from "../devtools/networkinterceptor";
15import { Command, Executor } from "./command";
16import { FileDetector } from "./input";
17export {};
18
19type ConditionFn<T> = (webdriver: WebDriver) => T | null | Promise<T | null>;
20
21export interface IWebDriverOptionsCookie {
22 /**
23 * The name of the cookie.
24 */
25 name: string;
26
27 /**
28 * The cookie value.
29 */
30 value: string;
31
32 /**
33 * The cookie path. Defaults to "/" when adding a cookie.
34 */
35 path?: string | undefined;
36
37 /**
38 * The domain the cookie is visible to. Defaults to the current browsing
39 * context's document's URL when adding a cookie.
40 */
41 domain?: string | undefined;
42
43 /**
44 * Whether the cookie is a secure cookie. Defaults to false when adding a new
45 * cookie.
46 */
47 secure?: boolean | undefined;
48
49 /**
50 * Whether the cookie is an HTTP only cookie. Defaults to false when adding a
51 * new cookie.
52 */
53 httpOnly?: boolean | undefined;
54
55 /**
56 * When the cookie expires.
57 *
58 * When {@linkplain Options#addCookie() adding a cookie}, this may be
59 * specified in _seconds_ since Unix epoch (January 1, 1970). The expiry will
60 * default to 20 years in the future if omitted.
61 *
62 * The expiry is always returned in seconds since epoch when
63 * {@linkplain Options#getCookies() retrieving cookies} from the browser.
64 */
65 expiry?: number | Date | undefined;
66
67 sameSite?: string;
68}
69
70export interface ITimeouts {
71 /**
72 * Defines when, in milliseconds, to interrupt a script that is being
73 * {@linkplain ./webdriver.IWebDriver#executeScript evaluated}.
74 */
75 script?: number | undefined;
76
77 /**
78 * The timeout, in milliseconds, to apply to navigation events along with the
79 * {@link PageLoadStrategy}.
80 */
81 pageLoad?: number | undefined;
82
83 /**
84 * The maximum amount of time, in milliseconds, to spend attempting to
85 * {@linkplain ./webdriver.IWebDriver#findElement locate} an element on the
86 * current page.
87 */
88 implicit?: number | undefined;
89}
90
91/**
92 * Defines a condition for use with WebDriver's {@linkplain WebDriver#wait wait
93 * command}.
94 */
95export class Condition<T> {
96 /**
97 * @param {string} message A descriptive error message. Should complete the
98 * sentence "Waiting [...]"
99 * @param {function(!WebDriver): OUT} fn The condition function to
100 * evaluate on each iteration of the wait loop.
101 */
102 constructor(message: string, fn: ConditionFn<T>);
103
104 /** @return {string} A description of this condition. */
105 description(): string;
106}
107
108/**
109 * Defines a condition that will result in a {@link WebElement}.
110 */
111export class WebElementCondition extends Condition<WebElement> {
112 /**
113 * @param {string} message A descriptive error message. Should complete the
114 * sentence "Waiting [...]"
115 * @param {function(!WebDriver): !(WebElement|IThenable<!WebElement>)}
116 * fn The condition function to evaluate on each iteration of the wait
117 * loop.
118 */
119 constructor(message: string, fn: ConditionFn<WebElement>);
120}
121
122/**
123 * An interface for changing the focus of the driver to another frame or window.
124 *
125 * This class should never be instantiated directly. Instead, obtain an
126 * instance with
127 *
128 * webdriver.switchTo()
129 *
130 * @see WebDriver#switchTo()
131 */
132export class TargetLocator {
133 /**
134 * @param {!WebDriver} driver The parent driver.
135 */
136 constructor(driver: WebDriver);
137
138 // endregion
139
140 // region Methods
141
142 /**
143 * Locates the DOM element on the current page that corresponds to
144 * `document.activeElement` or `document.body` if the active element is not
145 * available.
146 *
147 * @return {!WebElementPromise} The active element.
148 */
149 activeElement(): WebElementPromise;
150
151 /**
152 * Switches focus of all future commands to the topmost frame in the current
153 * window.
154 *
155 * @return {!Promise<void>} A promise that will be resolved
156 * when the driver has changed focus to the default content.
157 */
158 defaultContent(): Promise<void>;
159
160 /**
161 * Changes the focus of all future commands to another frame on the page. The
162 * target frame may be specified as one of the following:
163 *
164 * - A number that specifies a (zero-based) index into [window.frames](
165 * https://developer.mozilla.org/en-US/docs/Web/API/Window.frames).
166 * - A {@link WebElement} reference, which correspond to a `frame` or `iframe`
167 * DOM element.
168 * - The `null` value, to select the topmost frame on the page. Passing `null`
169 * is the same as calling {@link #defaultContent defaultContent()}.
170 *
171 * If the specified frame can not be found, the returned promise will be
172 * rejected with a {@linkplain error.NoSuchFrameError}.
173 *
174 * @param {(number|string|WebElement|null)} id The frame locator.
175 * @return {!Promise<void>} A promise that will be resolved
176 * when the driver has changed focus to the specified frame.
177 */
178 frame(id: number | string | WebElement | null): Promise<void>;
179
180 /**
181 * Changes the focus of all future commands to the parent frame of the
182 * currently selected frame. This command has no effect if the driver is
183 * already focused on the top-level browsing context.
184 *
185 * @return {!Promise<void>} A promise that will be resolved when the command
186 * has completed.
187 */
188 parentFrame(): Promise<void>;
189
190 /**
191 * Changes the focus of all future commands to another window. Windows may be
192 * specified by their {@code window.name} attribute or by its handle
193 * (as returned by {@link WebDriver#getWindowHandles}).
194 *
195 * If the specified window cannot be found, the returned promise will be
196 * rejected with a {@linkplain error.NoSuchWindowError}.
197 *
198 * @param {string} nameOrHandle The name or window handle of the window to
199 * switch focus to.
200 * @return {!Promise<void>} A promise that will be resolved
201 * when the driver has changed focus to the specified window.
202 */
203 window(nameOrHandle: string): Promise<void>;
204
205 /**
206 * Creates a new browser window and switches the focus for future
207 * commands of this driver to the new window.
208 *
209 * @param {string} typeHint 'window' or 'tab'. The created window is not
210 * guaranteed to be of the requested type; if the driver does not support
211 * the requested type, a new browser window will be created of whatever type
212 * the driver does support.
213 * @return {!Promise<void>} A promise that will be resolved
214 * when the driver has changed focus to the new window.
215 */
216 newWindow(typeHint: string): Promise<void>;
217
218 /**
219 * Changes focus to the active modal dialog, such as those opened by
220 * `window.alert()`, `window.confirm()`, and `window.prompt()`. The returned
221 * promise will be rejected with a
222 * {@linkplain error.NoSuchAlertError} if there are no open alerts.
223 *
224 * @return {!AlertPromise} The open alert.
225 */
226 alert(): AlertPromise;
227}
228
229/**
230 * Each WebDriver instance provides automated control over a browser session.
231 */
232export class WebDriver {
233 /**
234 * @param {!(./session.Session|IThenable<!./session.Session>)} session Either
235 * a known session or a promise that will be resolved to a session.
236 * @param {!Executor} executor The executor to use when sending
237 * commands to the browser.
238 * @param {(function(this: void): ?)=} onQuit A function to call, if any,
239 * when the session is terminated.
240 */
241 constructor(session: Session | Promise<Session>, executor: Executor, onQuit?: (this: void) => any);
242
243 /**
244 * Creates a new WebDriver session.
245 *
246 * This function will always return a WebDriver instance. If there is an error
247 * creating the session, such as the aforementioned SessionNotCreatedError,
248 * the driver will have a rejected {@linkplain #getSession session} promise.
249 * This rejection will propagate through any subsequent commands scheduled
250 * on the returned WebDriver instance.
251 *
252 * let required = Capabilities.firefox();
253 * let driver = WebDriver.createSession(executor, {required});
254 *
255 * // If the createSession operation failed, then this command will also
256 * // also fail, propagating the creation failure.
257 * driver.get('http://www.google.com').catch(e => console.log(e));
258 *
259 * @param {!Executor} executor The executor to create the new session
260 * with.
261 * @param {!Capabilities} capabilities The desired capabilities for the new
262 * session.
263 * @param {(function(this: void): ?)=} onQuit A callback to invoke when
264 * the newly created session is terminated. This should be used to clean
265 * up any resources associated with the session.
266 * @return {!WebDriver} The driver for the newly created session.
267 */
268 static createSession(...var_args: any[]): WebDriver;
269
270 /** @override */
271 execute(command: Command): Promise<void>;
272
273 /** @override */
274 setFileDetector(detector: FileDetector): void;
275
276 /** @override */
277 getExecutor(): Executor;
278
279 /** @override */
280 getSession(): Promise<Session>;
281
282 /** @override */
283 getCapabilities(): Promise<Capabilities>;
284
285 /** @override */
286 quit(): Promise<void>;
287
288 /** @override */
289 actions(options?: { async?: boolean | undefined; bridge?: boolean | undefined }): Actions;
290
291 /**
292 * Executes a snippet of JavaScript in the context of the currently selected
293 * frame or window. The script fragment will be executed as the body of an
294 * anonymous function. If the script is provided as a function object, that
295 * function will be converted to a string for injection into the target
296 * window.
297 *
298 * Any arguments provided in addition to the script will be included as script
299 * arguments and may be referenced using the `arguments` object. Arguments may
300 * be a boolean, number, string, or {@linkplain WebElement}. Arrays and
301 * objects may also be used as script arguments as long as each item adheres
302 * to the types previously mentioned.
303 *
304 * The script may refer to any variables accessible from the current window.
305 * Furthermore, the script will execute in the window's context, thus
306 * `document` may be used to refer to the current document. Any local
307 * variables will not be available once the script has finished executing,
308 * though global variables will persist.
309 *
310 * If the script has a return value (i.e. if the script contains a return
311 * statement), then the following steps will be taken for resolving this
312 * functions return value:
313 *
314 * - For a HTML element, the value will resolve to a {@linkplain WebElement}
315 * - Null and undefined return values will resolve to null</li>
316 * - Booleans, numbers, and strings will resolve as is</li>
317 * - Functions will resolve to their string representation</li>
318 * - For arrays and objects, each member item will be converted according to
319 * the rules above
320 *
321 * @param {!(string|Function)} script The script to execute.
322 * @param {...*} args The arguments to pass to the script.
323 * @return {!IThenable<T>} A promise that will resolve to the
324 * scripts return value.
325 * @template T
326 */
327 /** @override */
328 executeScript<T>(script: string | Function, ...args: any[]): Promise<T>;
329
330 /**
331 * Executes a snippet of asynchronous JavaScript in the context of the
332 * currently selected frame or window. The script fragment will be executed as
333 * the body of an anonymous function. If the script is provided as a function
334 * object, that function will be converted to a string for injection into the
335 * target window.
336 *
337 * Any arguments provided in addition to the script will be included as script
338 * arguments and may be referenced using the `arguments` object. Arguments may
339 * be a boolean, number, string, or {@linkplain WebElement}. Arrays and
340 * objects may also be used as script arguments as long as each item adheres
341 * to the types previously mentioned.
342 *
343 * Unlike executing synchronous JavaScript with {@link #executeScript},
344 * scripts executed with this function must explicitly signal they are
345 * finished by invoking the provided callback. This callback will always be
346 * injected into the executed function as the last argument, and thus may be
347 * referenced with `arguments[arguments.length - 1]`. The following steps
348 * will be taken for resolving this functions return value against the first
349 * argument to the script's callback function:
350 *
351 * - For a HTML element, the value will resolve to a {@link WebElement}
352 * - Null and undefined return values will resolve to null
353 * - Booleans, numbers, and strings will resolve as is
354 * - Functions will resolve to their string representation
355 * - For arrays and objects, each member item will be converted according to
356 * the rules above
357 *
358 * __Example #1:__ Performing a sleep that is synchronized with the currently
359 * selected window:
360 *
361 * var start = new Date().getTime();
362 * driver.executeAsyncScript(
363 * 'window.setTimeout(arguments[arguments.length - 1], 500);').
364 * then(function() {
365 * console.log(
366 * 'Elapsed time: ' + (new Date().getTime() - start) + ' ms');
367 * });
368 *
369 * __Example #2:__ Synchronizing a test with an AJAX application:
370 *
371 * var button = driver.findElement(By.id('compose-button'));
372 * button.click();
373 * driver.executeAsyncScript(
374 * 'var callback = arguments[arguments.length - 1];' +
375 * 'mailClient.getComposeWindowWidget().onload(callback);');
376 * driver.switchTo().frame('composeWidget');
377 * driver.findElement(By.id('to')).sendKeys('dog@example.com');
378 *
379 * __Example #3:__ Injecting a XMLHttpRequest and waiting for the result. In
380 * this example, the inject script is specified with a function literal. When
381 * using this format, the function is converted to a string for injection, so
382 * it should not reference any symbols not defined in the scope of the page
383 * under test.
384 *
385 * driver.executeAsyncScript(function() {
386 * var callback = arguments[arguments.length - 1];
387 * var xhr = new XMLHttpRequest();
388 * xhr.open("GET", "/resource/data.json", true);
389 * xhr.onreadystatechange = function() {
390 * if (xhr.readyState == 4) {
391 * callback(xhr.responseText);
392 * }
393 * };
394 * xhr.send('');
395 * }).then(function(str) {
396 * console.log(JSON.parse(str)['food']);
397 * });
398 *
399 * @param {!(string|Function)} script The script to execute.
400 * @param {...*} args The arguments to pass to the script.
401 * @return {!IThenable<T>} A promise that will resolve to the scripts return
402 * value.
403 * @template T
404 */
405 executeAsyncScript<T>(script: string | Function, ...args: any[]): Promise<T>;
406
407 wait(
408 condition: WebElementCondition,
409 timeout?: number,
410 message?: string,
411 pollTimeout?: number,
412 ): WebElementPromise;
413
414 /**
415 * Waits for a condition to evaluate to a "truthy" value. The condition may be
416 * specified by a {@link Condition}, as a custom function, or as any
417 * promise-like thenable.
418 *
419 * For a {@link Condition} or function, the wait will repeatedly
420 * evaluate the condition until it returns a truthy value. If any errors occur
421 * while evaluating the condition, they will be allowed to propagate. In the
422 * event a condition returns a {@linkplain Promise}, the polling loop will
423 * wait for it to be resolved and use the resolved value for whether the
424 * condition has been satisfied. The resolution time for a promise is always
425 * factored into whether a wait has timed out.
426 *
427 * If the provided condition is a {@link WebElementCondition}, then
428 * the wait will return a {@link WebElementPromise} that will resolve to the
429 * element that satisfied the condition.
430 *
431 * _Example:_ waiting up to 10 seconds for an element to be present on the
432 * page.
433 *
434 * async function example() {
435 * let button =
436 * await driver.wait(until.elementLocated(By.id('foo')), 10000);
437 * await button.click();
438 * }
439 *
440 * @param {!(IThenable<T>|
441 * Condition<T>|
442 * function(!WebDriver): T)} condition The condition to
443 * wait on, defined as a promise, condition object, or a function to
444 * evaluate as a condition.
445 * @param {number=} timeout The duration in milliseconds, how long to wait
446 * for the condition to be true.
447 * @param {(string|Function)=} message An optional message to use if the wait times out.
448 * @param {number=} pollTimeout The duration in milliseconds, how long to
449 * wait between polling the condition.
450 * @return {!(IThenable<T>|WebElementPromise)} A promise that will be
451 * resolved with the first truthy value returned by the condition
452 * function, or rejected if the condition times out. If the input
453 * condition is an instance of a {@link WebElementCondition},
454 * the returned value will be a {@link WebElementPromise}.
455 * @throws {TypeError} if the provided `condition` is not a valid type.
456 * @template T
457 */
458 wait<T>(
459 condition: PromiseLike<T> | Condition<T> | ((driver: WebDriver) => T | PromiseLike<T>) | Function,
460 timeout?: number,
461 message?: string,
462 pollTimeout?: number,
463 ): Promise<T>;
464
465 /**
466 * Makes the driver sleep for the given amount of time.
467 *
468 * @param {number} ms The amount of time, in milliseconds, to sleep.
469 * @return {!Promise<void>} A promise that will be resolved when the sleep has
470 * finished.
471 */
472 sleep(ms: number): Promise<void>;
473
474 /**
475 * Retrieves the current window handle.
476 *
477 * @return {!Promise<string>} A promise that will be resolved with the current
478 * window handle.
479 */
480 getWindowHandle(): Promise<string>;
481
482 /**
483 * Retrieves a list of all available window handles.
484 *
485 * @return {!Promise<!Array<string>>} A promise that will be resolved with an
486 * array of window handles.
487 */
488 getAllWindowHandles(): Promise<string[]>;
489
490 /**
491 * Retrieves the current page's source. The returned source is a representation
492 * of the underlying DOM: do not expect it to be formatted or escaped in the
493 * same way as the raw response sent from the web server.
494 *
495 * @return {!Promise<string>} A promise that will be resolved with the current
496 * page source.
497 */
498 getPageSource(): Promise<string>;
499
500 /**
501 * Closes the current window.
502 *
503 * @return {!Promise<void>} A promise that will be resolved when this command
504 * has completed.
505 */
506 close(): Promise<void>;
507
508 /**
509 * Navigates to the given URL.
510 *
511 * @param {string} url The fully qualified URL to open.
512 * @return {!Promise<void>} A promise that will be resolved when the document
513 * has finished loading.
514 */
515 get(url: string): Promise<void>;
516
517 /**
518 * Retrieves the URL for the current page.
519 *
520 * @return {!Promise<string>} A promise that will be resolved with the
521 * current URL.
522 */
523 getCurrentUrl(): Promise<string>;
524
525 /**
526 * Retrieves the current page title.
527 *
528 * @return {!Promise<string>} A promise that will be resolved with the current
529 * page's title.
530 */
531 getTitle(): Promise<string>;
532
533 /**
534 * Locates an element on the page. If the element cannot be found, a
535 * {@link error.NoSuchElementError} will be returned by the driver.
536 *
537 * This function should not be used to test whether an element is present on
538 * the page. Rather, you should use {@link #findElements}:
539 *
540 * driver.findElements(By.id('foo'))
541 * .then(found => console.log('Element found? %s', !!found.length));
542 *
543 * The search criteria for an element may be defined using one of the
544 * factories in the {@link webdriver.By} namespace, or as a short-hand
545 * {@link webdriver.By.Hash} object. For example, the following two statements
546 * are equivalent:
547 *
548 * var e1 = driver.findElement(By.id('foo'));
549 * var e2 = driver.findElement({id:'foo'});
550 *
551 * You may also provide a custom locator function, which takes as input this
552 * instance and returns a {@link WebElement}, or a promise that will resolve
553 * to a WebElement. If the returned promise resolves to an array of
554 * WebElements, WebDriver will use the first element. For example, to find the
555 * first visible link on a page, you could write:
556 *
557 * var link = driver.findElement(firstVisibleLink);
558 *
559 * function firstVisibleLink(driver) {
560 * var links = driver.findElements(By.tagName('a'));
561 * return promise.filter(links, function(link) {
562 * return link.isDisplayed();
563 * });
564 * }
565 *
566 * @param {!(by.By|Function)} locator The locator to use.
567 * @return {!WebElementPromise} A WebElement that can be used to issue
568 * commands against the located element. If the element is not found, the
569 * element will be invalidated and all scheduled commands aborted.
570 */
571 findElement(locator: Locator): WebElementPromise;
572
573 /**
574 * @param {!Function} webElementPromise The webElement in unresolved state
575 * @return {!Promise<!WebElement>} First single WebElement from array of resolved promises
576 */
577 normalize_(webElementPromise: Function): Promise<WebElement>;
578
579 /**
580 * @param {!Function} locatorFn The locator function to use.
581 * @param {!(WebDriver|WebElement)} context The search context.
582 * @return {!Promise<!WebElement>} A promise that will resolve to a list of
583 * WebElements.
584 */
585 findElementInternal_(locatorFn: Function, context: WebDriver | WebElement): Promise<WebElement>;
586
587 /**
588 * Search for multiple elements on the page. Refer to the documentation on
589 * {@link #findElement(by)} for information on element locator strategies.
590 *
591 * @param {!(by.By|Function)} locator The locator to use.
592 * @return {!Promise<!Array<!WebElement>>} A promise that will resolve to an
593 * array of WebElements.
594 */
595 findElements(locator: Locator): Promise<WebElement[]>;
596
597 /**
598 * @param {!Function} locatorFn The locator function to use.
599 * @param {!(WebDriver|WebElement)} context The search context.
600 * @return {!Promise<!Array<!WebElement>>} A promise that will resolve to an
601 * array of WebElements.
602 */
603 findElementsInternal_(locatorFn: Function, context: WebDriver | WebElement): Promise<WebElement[]>;
604
605 /**
606 * Takes a screenshot of the current page. The driver makes the best effort to
607 * return a screenshot of the following, in order of preference:
608 *
609 * 1. Entire page
610 * 2. Current window
611 * 3. Visible portion of the current frame
612 * 4. The entire display containing the browser
613 *
614 * @return {!Promise<string>} A promise that will be resolved to the
615 * screenshot as a base-64 encod ed PNG.
616 */
617 takeScreenshot(): Promise<string>;
618
619 /**
620 * @return {!Options} The options interface for this instance.
621 */
622 manage(): Options;
623
624 /**
625 * @return {!Navigation} The navigation interface for this instance.
626 */
627 navigate(): Navigation;
628
629 /**
630 * @return {!TargetLocator} The target locator interface for this
631 * instance.
632 */
633 switchTo(): TargetLocator;
634
635 /**
636 * Takes a PDF of the current page. The driver makes a best effort to
637 * return a PDF based on the provided parameters.
638 *
639 * @param {{orientation:(string|undefined),
640 * scale:(number|undefined),
641 * background:(boolean|undefined),
642 * width:(number|undefined),
643 * height:(number|undefined),
644 * top:(number|undefined),
645 * bottom:(number|undefined),
646 * left:(number|undefined),
647 * right:(number|undefined),
648 * shrinkToFit:(boolean|undefined),
649 * pageRanges:(Array|undefined)}} options
650 */
651 printPage(options: {
652 orientation: string | undefined;
653 scale: number | undefined;
654 background: boolean | undefined;
655 width: number | undefined;
656 height: number | undefined;
657 top: number | undefined;
658 bottom: number | undefined;
659 left: number | undefined;
660 right: number | undefined;
661 shrinkToFit: boolean | undefined;
662 pageRanges: [] | undefined;
663 }): void;
664
665 /**
666 * Creates a new WebSocket connection.
667 * @return {!Promise<resolved>} A new CDP instance.
668 */
669 createCDPConnection(target: string): Promise<any>;
670
671 /**
672 * Retrieves 'webSocketDebuggerUrl' by sending a http request using debugger address
673 * @param {string} debuggerAddress
674 * @param target
675 * @param caps
676 * @return {string} Returns parsed webSocketDebuggerUrl obtained from the http request
677 */
678 getWsUrl(debuggerAddress: string, target: string, caps: Capabilities): Promise<string>;
679
680 /**
681 * Sets a listener for Fetch.authRequired event from CDP
682 * If event is triggered, it enter username and password
683 * and allows the test to move forward
684 * @param {string} username
685 * @param {string} password
686 * @param connection CDP Connection
687 */
688 register(username: string, password: string, connection: any): Promise<void>;
689
690 /**
691 * Handle Network interception requests
692 * @param connection WebSocket connection to the browser
693 * @param httpResponse Object representing what we are intercepting
694 * as well as what should be returned.
695 * @param callback callback called when we intercept requests.
696 */
697 onIntercept(connection: WebSocket, httpResponse: HttpResponse, callback: () => void): Promise<void>;
698
699 /**
700 * @param connection
701 * @param callback
702 * @returns {Promise<void>}
703 */
704 onLogEvent(connection: WebSocket, callback: (event: any) => void): Promise<void>;
705
706 /**
707 * @param connection
708 * @param callback
709 * @returns {Promise<void>}
710 */
711 onLogException(connection: WebSocket, callback: (event: any) => void): Promise<void>;
712
713 /**
714 * @param connection
715 * @param callback
716 * @returns {Promise<void>}
717 */
718 logMutationEvents(connection: WebSocket, callback: (event: any) => void): Promise<void>;
719}
720
721/**
722 * Interface for navigating back and forth in the browser history.
723 *
724 * This class should never be instantiated directly. Instead, obtain an instance
725 * with
726 *
727 * webdriver.navigate()
728 *
729 * @see WebDriver#navigate()
730 */
731export class Navigation {
732 /**
733 * @param {!WebDriver} driver The parent driver.
734 */
735 constructor(driver: WebDriver);
736
737 /**
738 * Navigates to a new URL.
739 *
740 * @param {string} url The URL to navigate to.
741 * @return {!Promise<void>} A promise that will be resolved when the URL
742 * has been loaded.
743 */
744 to(url: string): Promise<void>;
745
746 /**
747 * Moves backwards in the browser history.
748 *
749 * @return {!Promise<void>} A promise that will be resolved when the
750 * navigation event has completed.
751 */
752 back(): Promise<void>;
753
754 /**
755 * Moves forwards in the browser history.
756 *
757 * @return {!Promise<void>} A promise that will be resolved when the
758 * navigation event has completed.
759 */
760 forward(): Promise<void>;
761
762 /**
763 * Refreshes the current page.
764 *
765 * @return {!Promise<void>} A promise that will be resolved when the
766 * navigation event has completed.
767 */
768 refresh(): Promise<void>;
769}
770
771/**
772 * Provides methods for managing browser and driver state.
773 *
774 * This class should never be instantiated directly. Instead, obtain an instance
775 * with {@linkplain WebDriver#manage() webdriver.manage()}.
776 */
777export class Options {
778 /**
779 * @param {!WebDriver} driver The parent driver.
780 */
781 constructor(driver: WebDriver);
782
783 /**
784 * Adds a cookie.
785 *
786 * __Sample Usage:__
787 *
788 * // Set a basic cookie.
789 * driver.manage().addCookie({name: 'foo', value: 'bar'});
790 *
791 * // Set a cookie that expires in 10 minutes.
792 * let expiry = new Date(Date.now() + (10 * 60 * 1000));
793 * driver.manage().addCookie({name: 'foo', value: 'bar', expiry});
794 *
795 * // The cookie expiration may also be specified in seconds since epoch.
796 * driver.manage().addCookie({
797 * name: 'foo',
798 * value: 'bar',
799 * expiry: Math.floor(Date.now() / 1000)
800 * });
801 *
802 * @param {!Options.Cookie} spec Defines the cookie to add.
803 * @return {!Promise<void>} A promise that will be resolved
804 * when the cookie has been added to the page.
805 * @throws {error.InvalidArgumentError} if any of the cookie parameters are
806 * invalid.
807 * @throws {TypeError} if `spec` is not a cookie object.
808 */
809 addCookie(spec: IWebDriverOptionsCookie): Promise<void>;
810
811 /**
812 * Deletes all cookies visible to the current page.
813 *
814 * @return {!Promise<void>} A promise that will be resolved
815 * when all cookies have been deleted.
816 */
817 deleteAllCookies(): Promise<void>;
818
819 /**
820 * Deletes the cookie with the given name. This command is a no-op if there is
821 * no cookie with the given name visible to the current page.
822 *
823 * @param {string} name The name of the cookie to delete.
824 * @return {!Promise<void>} A promise that will be resolved
825 * when the cookie has been deleted.
826 */
827 deleteCookie(name: string): Promise<void>;
828
829 /**
830 * Retrieves all cookies visible to the current page. Each cookie will be
831 * returned as a JSON object as described by the WebDriver wire protocol.
832 *
833 * @return {!Promise<!Array<!Options.Cookie>>} A promise that will be
834 * resolved with the cookies visible to the current browsing context.
835 */
836 getCookies(): Promise<IWebDriverOptionsCookie[]>;
837
838 /**
839 * Retrieves the cookie with the given name. Returns null if there is no such
840 * cookie. The cookie will be returned as a JSON object as described by the
841 * WebDriver wire protocol.
842 *
843 * @param {string} name The name of the cookie to retrieve.
844 * @return {!Promise<?Options.Cookie>} A promise that will be resolved
845 * with the named cookie
846 * @throws {error.NoSuchCookieError} if there is no such cookie.
847 */
848 getCookie(name: string): Promise<IWebDriverOptionsCookie>;
849
850 /**
851 * Fetches the timeouts currently configured for the current session.
852 *
853 * @return {!Promise<{script: number,
854 * pageLoad: number,
855 * implicit: number}>} A promise that will be
856 * resolved with the timeouts currently configured for the current
857 * session.
858 * @see #setTimeouts()
859 */
860 getTimeouts(): Promise<ITimeouts>;
861
862 /**
863 * Sets the timeout durations associated with the current session.
864 *
865 * The following timeouts are supported (all timeouts are specified in
866 * milliseconds):
867 *
868 * - `implicit` specifies the maximum amount of time to wait for an element
869 * locator to succeed when {@linkplain WebDriver#findElement locating}
870 * {@linkplain WebDriver#findElements elements} on the page.
871 * Defaults to 0 milliseconds.
872 *
873 * - `pageLoad` specifies the maximum amount of time to wait for a page to
874 * finishing loading. Defaults to 300000 milliseconds.
875 *
876 * - `script` specifies the maximum amount of time to wait for an
877 * {@linkplain WebDriver#executeScript evaluated script} to run. If set to
878 * `null`, the script timeout will be indefinite.
879 * Defaults to 30000 milliseconds.
880 *
881 * @param {{script: (number|null|undefined),
882 * pageLoad: (number|null|undefined),
883 * implicit: (number|null|undefined)}} conf
884 * The desired timeout configuration.
885 * @return {!Promise<void>} A promise that will be resolved when the timeouts
886 * have been set.
887 * @throws {!TypeError} if an invalid options object is provided.
888 * @see #getTimeouts()
889 * @see <https://w3c.github.io/webdriver/webdriver-spec.html#dfn-set-timeouts>
890 */
891 setTimeouts(timeouts: ITimeouts): Promise<void>;
892
893 /**
894 * @return {!Logs} The interface for managing driver logs.
895 */
896 logs(): Logs;
897
898 /**
899 * @return {!Window} The interface for managing the current window.
900 */
901 window(): Window;
902
903 /**
904 * @param {!WebDriver} driver
905 * @param {string} type
906 * @param {number} ms
907 * @return {!Promise<void>}
908 */
909 legacyTimeout(driver: WebDriver, type: string, ms: number): Promise<void>;
910}
911
912//////////////////////////////////////////////////////////////////////////////
913//
914// ShadowRoot
915//
916//////////////////////////////////////////////////////////////////////////////
917
918/**
919 * Represents a ShadowRoot of a {@link WebElement}. Provides functions to
920 * retrieve elements that live in the DOM below the ShadowRoot.
921 */
922export class ShadowRoot implements Serializable<IWebElementId> {
923 constructor(driver: WebDriver, id: string | Promise<string>);
924
925 /**
926 * Extracts the encoded ShadowRoot ID from the object.
927 *
928 * @param {?} obj The object to extract the ID from.
929 * @return {string} the extracted ID.
930 * @throws {TypeError} if the object is not a valid encoded ID.
931 */
932 static extractId(obj: any): string;
933
934 /**
935 * @param {?} obj the object to test.
936 * @return {boolean} whether the object is a valid encoded WebElement ID.
937 */
938 static isId(obj: any): boolean;
939
940 /** @override */
941 serialize(): Promise<IWebElementId>;
942
943 /**
944 * Schedules a command that targets this element with the parent WebDriver
945 * instance. Will ensure this element's ID is included in the command
946 * parameters under the "id" key.
947 *
948 * @param {!Command} command The command to schedule.
949 * @return {!Promise<T>} A promise that will be resolved with the result.
950 * @template T
951 * @see WebDriver#schedule
952 */
953 execute_<T>(command: Command): Promise<T>;
954
955 /**
956 * Schedule a command to find a descendant of this ShadowROot. If the element
957 * cannot be found, the returned promise will be rejected with a
958 * {@linkplain error.NoSuchElementError NoSuchElementError}.
959 *
960 * The search criteria for an element may be defined using one of the static
961 * factories on the {@link by.By} class, or as a short-hand
962 * {@link ./by.ByHash} object. For example, the following two statements
963 * are equivalent:
964 *
965 * var e1 = shadowroot.findElement(By.id('foo'));
966 * var e2 = shadowroot.findElement({id:'foo'});
967 *
968 * You may also provide a custom locator function, which takes as input this
969 * instance and returns a {@link WebElement}, or a promise that will resolve
970 * to a WebElement. If the returned promise resolves to an array of
971 * WebElements, WebDriver will use the first element. For example, to find the
972 * first visible link on a page, you could write:
973 *
974 * var link = element.findElement(firstVisibleLink);
975 *
976 * function firstVisibleLink(shadowRoot) {
977 * var links = shadowRoot.findElements(By.tagName('a'));
978 * return promise.filter(links, function(link) {
979 * return link.isDisplayed();
980 * });
981 * }
982 *
983 * @param {!(by.By|Function)} locator The locator strategy to use when
984 * searching for the element.
985 * @return {!WebElementPromise} A WebElement that can be used to issue
986 * commands against the located element. If the element is not found, the
987 * element will be invalidated and all scheduled commands aborted.
988 */
989 findElement(locator: Locator): WebElementPromise;
990
991 /**
992 * Locates all of the descendants of this element that match the given search
993 * criteria.
994 *
995 * @param {!(by.By|Function)} locator The locator strategy to use when
996 * searching for the element.
997 * @return {!Promise<!Array<!WebElement>>} A promise that will resolve to an
998 * array of WebElements.
999 */
1000 findElements(locator: Locator): Promise<WebElement[]>;
1001
1002 getId(): Promise<string>;
1003}
1004
1005/**
1006 * ShadowRootPromise is a promise that will be fulfilled with a WebElement.
1007 * This serves as a forward proxy on ShadowRoot, allowing calls to be
1008 * scheduled without directly on this instance before the underlying
1009 * ShadowRoot has been fulfilled.
1010 *
1011 * @final
1012 */
1013export interface ShadowRootPromise extends Promise<ShadowRoot> {}
1014
1015/**
1016 * Implement ShadowRootPromise
1017 */
1018export class ShadowRootPromise extends ShadowRoot {
1019 /**
1020 * @param {!WebDriver} driver The parent WebDriver instance for this
1021 * element.
1022 * @param {!Promise<!ShadowRoot>} shadow A promise
1023 * that will resolve to the promised element.
1024 */
1025 constructor(driver: WebDriver, shadow: Promise<ShadowRoot>);
1026}
1027
1028//////////////////////////////////////////////////////////////////////////////
1029//
1030// Alert
1031//
1032//////////////////////////////////////////////////////////////////////////////
1033
1034/**
1035 * Represents a modal dialog such as {@code alert}, {@code confirm}, or
1036 * {@code prompt}. Provides functions to retrieve the message displayed with
1037 * the alert, accept or dismiss the alert, and set the response text (in the
1038 * case of {@code prompt}).
1039 */
1040export class Alert {
1041 /**
1042 * @param {!WebDriver} driver The driver controlling the browser this alert
1043 * is attached to.
1044 * @param {string} text The message text displayed with this alert.
1045 */
1046 constructor(driver: WebDriver, text: string);
1047
1048 /**
1049 * Retrieves the message text displayed with this alert. For instance, if the
1050 * alert were opened with alert("hello"), then this would return "hello".
1051 *
1052 * @return {!Promise<string>} A promise that will be
1053 * resolved to the text displayed with this alert.
1054 */
1055 getText(): Promise<string>;
1056
1057 /**
1058 * Accepts this alert.
1059 *
1060 * @return {!Promise<void>} A promise that will be resolved
1061 * when this command has completed.
1062 */
1063 accept(): Promise<void>;
1064
1065 /**
1066 * Dismisses this alert.
1067 *
1068 * @return {!Promise<void>} A promise that will be resolved
1069 * when this command has completed.
1070 */
1071 dismiss(): Promise<void>;
1072
1073 /**
1074 * Sets the response text on this alert. This command will return an error if
1075 * the underlying alert does not support response text (e.g. window.alert and
1076 * window.confirm).
1077 *
1078 * @param {string} text The text to set.
1079 * @return {!Promise<void>} A promise that will be resolved
1080 * when this command has completed.
1081 */
1082 sendKeys(text: string): Promise<void>;
1083}
1084
1085/**
1086 * AlertPromise is a promise that will be fulfilled with an Alert. This promise
1087 * serves as a forward proxy on an Alert, allowing calls to be scheduled
1088 * directly on this instance before the underlying Alert has been fulfilled. In
1089 * other words, the following two statements are equivalent:
1090 *
1091 * driver.switchTo().alert().dismiss();
1092 * driver.switchTo().alert().then(function(alert) {
1093 * return alert.dismiss();
1094 * });
1095 *
1096 * @final
1097 */
1098export interface AlertPromise extends Promise<Alert> {}
1099
1100/**
1101 * Implement AlertPromise
1102 */
1103export class AlertPromise extends Alert {
1104 /**
1105 * @param {!WebDriver} driver The driver controlling the browser this
1106 * alert is attached to.
1107 * @param {!Promise<!Alert>} alert A thenable
1108 * that will be fulfilled with the promised alert.
1109 */
1110 constructor(driver: WebDriver, alert: Promise<Alert>);
1111}
1112
\No newline at end of file