1 | import { WebSocket } from "ws";
|
2 | import {
|
3 | Actions,
|
4 | Capabilities,
|
5 | IWebElementId,
|
6 | Locator,
|
7 | Logs,
|
8 | Serializable,
|
9 | Session,
|
10 | WebElement,
|
11 | WebElementPromise,
|
12 | Window,
|
13 | } from "..";
|
14 | import { HttpResponse } from "../devtools/networkinterceptor";
|
15 | import { Command, Executor } from "./command";
|
16 | import { FileDetector } from "./input";
|
17 | export {};
|
18 |
|
19 | type ConditionFn<T> = (webdriver: WebDriver) => T | null | Promise<T | null>;
|
20 |
|
21 | export interface IWebDriverOptionsCookie {
|
22 | |
23 |
|
24 |
|
25 | name: string;
|
26 |
|
27 | |
28 |
|
29 |
|
30 | value: string;
|
31 |
|
32 | |
33 |
|
34 |
|
35 | path?: string | undefined;
|
36 |
|
37 | |
38 |
|
39 |
|
40 |
|
41 | domain?: string | undefined;
|
42 |
|
43 | |
44 |
|
45 |
|
46 |
|
47 | secure?: boolean | undefined;
|
48 |
|
49 | |
50 |
|
51 |
|
52 |
|
53 | httpOnly?: boolean | undefined;
|
54 |
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | expiry?: number | Date | undefined;
|
66 |
|
67 | sameSite?: string;
|
68 | }
|
69 |
|
70 | export interface ITimeouts {
|
71 | |
72 |
|
73 |
|
74 |
|
75 | script?: number | undefined;
|
76 |
|
77 | |
78 |
|
79 |
|
80 |
|
81 | pageLoad?: number | undefined;
|
82 |
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 | implicit?: number | undefined;
|
89 | }
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | export class Condition<T> {
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | constructor(message: string, fn: ConditionFn<T>);
|
103 |
|
104 | /** @return {string} A description of this condition. */
|
105 | description(): string;
|
106 | }
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | export class WebElementCondition extends Condition<WebElement> {
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
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 | */
|
132 | export class TargetLocator {
|
133 | |
134 |
|
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 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | defaultContent(): Promise<void>;
|
159 |
|
160 | |
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | frame(id: number | string | WebElement | null): Promise<void>;
|
179 |
|
180 | |
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | parentFrame(): Promise<void>;
|
189 |
|
190 | |
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | window(nameOrHandle: string): Promise<void>;
|
204 |
|
205 | |
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | newWindow(typeHint: string): Promise<void>;
|
217 |
|
218 | |
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | alert(): AlertPromise;
|
227 | }
|
228 |
|
229 |
|
230 |
|
231 |
|
232 | export class WebDriver {
|
233 | |
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
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 | *
|
256 | *
|
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 |
|
271 | execute(command: Command): Promise<void>;
|
272 |
|
273 |
|
274 | setFileDetector(detector: FileDetector): void;
|
275 |
|
276 |
|
277 | getExecutor(): Executor;
|
278 |
|
279 |
|
280 | getSession(): Promise<Session>;
|
281 |
|
282 |
|
283 | getCapabilities(): Promise<Capabilities>;
|
284 |
|
285 |
|
286 | quit(): Promise<void>;
|
287 |
|
288 |
|
289 | actions(options?: { async?: boolean | undefined; bridge?: boolean | undefined }): Actions;
|
290 |
|
291 | |
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 | executeScript<T>(script: string | Function, ...args: any[]): Promise<T>;
|
329 |
|
330 | |
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
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 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
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 | */
|
731 | export 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 | */
|
777 | export 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 | */
|
922 | export 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 | */
|
1013 | export interface ShadowRootPromise extends Promise<ShadowRoot> {}
|
1014 |
|
1015 | /**
|
1016 | * Implement ShadowRootPromise
|
1017 | */
|
1018 | export 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 | */
|
1040 | export 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 | */
|
1098 | export interface AlertPromise extends Promise<Alert> {}
|
1099 |
|
1100 | /**
|
1101 | * Implement AlertPromise
|
1102 | */
|
1103 | export 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 |