1 | // Type definitions for Selenium WebDriverJS 4.0
|
2 | // Project: https://github.com/SeleniumHQ/selenium
|
3 | // Definitions by: Bill Armstrong <https://github.com/BillArmstrong>,
|
4 | // Yuki Kokubun <https://github.com/Kuniwak>,
|
5 | // Craig Nishina <https://github.com/cnishina>,
|
6 | // Simon Gellis <https://github.com/SupernaviX>,
|
7 | // Ben Dixon <https://github.com/bendxn>,
|
8 | // Ziyu <https://github.com/oddui>
|
9 | // Johann Wolf <https://github.com/beta-vulgaris>
|
10 | // Aleksey Chemakin <https://github.com/Dzenly>
|
11 | // David Burns <https://github.com/AutomatedTester>
|
12 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
13 | // TypeScript Version: 2.4
|
14 |
|
15 | import * as chrome from './chrome';
|
16 | import * as edge from './edge';
|
17 | import * as firefox from './firefox';
|
18 | import * as ie from './ie';
|
19 | import { By, ByHash } from './lib/by';
|
20 | import { Browser, Capability, Capabilities, ITimeouts } from './lib/capabilities';
|
21 | import * as command from './lib/command';
|
22 | import * as http from './http';
|
23 | import { Actions, Button, Key, Origin } from './lib/input';
|
24 | import { promise } from './lib/promise';
|
25 | import * as logging from './lib/logging';
|
26 | import * as until from './lib/until';
|
27 | import * as safari from './safari';
|
28 |
|
29 | export { By, ByHash } from './lib/by';
|
30 | export { Browser, Capability, Capabilities, ITimeouts } from './lib/capabilities';
|
31 | export { Actions, Button, Key, Origin } from './lib/input';
|
32 | export { promise } from './lib/promise';
|
33 | export { until };
|
34 | export { logging };
|
35 |
|
36 | /**
|
37 | * Typings for lib/error
|
38 | */
|
39 | export namespace error {
|
40 | class IError extends Error {
|
41 | constructor(message?: string);
|
42 | message: string;
|
43 | }
|
44 |
|
45 | /**
|
46 | * The base WebDriver error type. This error type is only used directly when a
|
47 | * more appropriate category is not defined for the offending error.
|
48 | */
|
49 | class WebDriverError extends IError {
|
50 | constructor(message?: string);
|
51 | remoteStacktrace?: string | undefined;
|
52 | }
|
53 |
|
54 | /**
|
55 | * Indicates a { ./webdriver.WebElement#click click command} could
|
56 | * not completed because the click target is obscured by other elements on the
|
57 | * page.
|
58 | */
|
59 | class ElementClickInterceptedError extends WebDriverError {
|
60 | constructor(message?: string);
|
61 | }
|
62 |
|
63 | /**
|
64 | * An attempt was made to select an element that cannot be selected.
|
65 | */
|
66 | class ElementNotSelectableError extends WebDriverError {
|
67 | constructor(message?: string);
|
68 | }
|
69 |
|
70 | /**
|
71 | * Indicates a command could not be completed because the target element is
|
72 | * not pointer or keyboard interactable. This will often occur if an element
|
73 | * is present in the DOM, but not rendered (i.e. its CSS style has
|
74 | * "display: none").
|
75 | */
|
76 |
|
77 | class ElementNotInteractableError extends WebDriverError {
|
78 | constructor(message?: string);
|
79 | }
|
80 |
|
81 | /**
|
82 | * Indicates a navigation event caused the browser to generate a certificate
|
83 | * warning. This is usually caused by an expired or invalid TLS certificate.
|
84 | */
|
85 | class InsecureCertificateError extends WebDriverError {
|
86 | constructor(message?: string);
|
87 | }
|
88 |
|
89 | /**
|
90 | * The arguments passed to a command are either invalid or malformed.
|
91 | */
|
92 | class InvalidArgumentError extends WebDriverError {
|
93 | constructor(message?: string);
|
94 | }
|
95 |
|
96 | /**
|
97 | * An illegal attempt was made to set a cookie under a different domain than
|
98 | * the current page.
|
99 | */
|
100 | class InvalidCookieDomainError extends WebDriverError {
|
101 | constructor(message?: string);
|
102 | }
|
103 |
|
104 | /**
|
105 | * The coordinates provided to an interactions operation are invalid.
|
106 | */
|
107 | class InvalidCoordinatesError extends WebDriverError {
|
108 | constructor(message?: string);
|
109 | }
|
110 |
|
111 | /**
|
112 | * An element command could not be completed because the element is in an
|
113 | * invalid state, e.g. attempting to click an element that is no longer
|
114 | * attached to the document.
|
115 | */
|
116 | class InvalidElementStateError extends WebDriverError {
|
117 | constructor(message?: string);
|
118 | }
|
119 |
|
120 | /**
|
121 | * Argument was an invalid selector.
|
122 | */
|
123 | class InvalidSelectorError extends WebDriverError {
|
124 | constructor(message?: string);
|
125 | }
|
126 |
|
127 | /**
|
128 | * Occurs when a command is directed to a session that does not exist.
|
129 | */
|
130 | class NoSuchSessionError extends WebDriverError {
|
131 | constructor(message?: string);
|
132 | }
|
133 |
|
134 | /**
|
135 | * An error occurred while executing JavaScript supplied by the user.
|
136 | */
|
137 | class JavascriptError extends WebDriverError {
|
138 | constructor(message?: string);
|
139 | }
|
140 |
|
141 | /**
|
142 | * The target for mouse interaction is not in the browser’s viewport and
|
143 | * cannot be brought into that viewport.
|
144 | */
|
145 | class MoveTargetOutOfBoundsError extends WebDriverError {
|
146 | constructor(message?: string);
|
147 | }
|
148 |
|
149 | /**
|
150 | * An attempt was made to operate on a modal dialog when one was not open.
|
151 | */
|
152 | class NoSuchAlertError extends WebDriverError {
|
153 | constructor(message?: string);
|
154 | }
|
155 |
|
156 | /**
|
157 | * Indicates a named cookie could not be found in the cookie jar for the
|
158 | * currently selected document.
|
159 | */
|
160 | class NoSuchCookieError extends WebDriverError {
|
161 | constructor(message?: string);
|
162 | }
|
163 |
|
164 | /**
|
165 | * An element could not be located on the page using the given search
|
166 | * parameters.
|
167 | */
|
168 | class NoSuchElementError extends WebDriverError {
|
169 | constructor(message?: string);
|
170 | }
|
171 |
|
172 | /**
|
173 | * A request to switch to a frame could not be satisfied because the frame
|
174 | * could not be found.
|
175 | */
|
176 | class NoSuchFrameError extends WebDriverError {
|
177 | constructor(message?: string);
|
178 | }
|
179 |
|
180 | /**
|
181 | * A request to switch to a window could not be satisfied because the window
|
182 | * could not be found.
|
183 | */
|
184 | class NoSuchWindowError extends WebDriverError {
|
185 | constructor(message?: string);
|
186 | }
|
187 |
|
188 | /**
|
189 | * A script did not complete before its timeout expired.
|
190 | */
|
191 | class ScriptTimeoutError extends WebDriverError {
|
192 | constructor(message?: string);
|
193 | }
|
194 |
|
195 | /**
|
196 | * A new session could not be created.
|
197 | */
|
198 | class SessionNotCreatedError extends WebDriverError {
|
199 | constructor(message?: string);
|
200 | }
|
201 |
|
202 | /**
|
203 | * An element command failed because the referenced element is no longer
|
204 | * attached to the DOM.
|
205 | */
|
206 | class StaleElementReferenceError extends WebDriverError {
|
207 | constructor(message?: string);
|
208 | }
|
209 |
|
210 | /**
|
211 | * An operation did not completErrorCodee before its timeout expired.
|
212 | */
|
213 | class TimeoutError extends WebDriverError {
|
214 | constructor(message?: string);
|
215 | }
|
216 |
|
217 | /**
|
218 | * A request to set a cookie’s value could not be satisfied.
|
219 | */
|
220 | class UnableToSetCookieError extends WebDriverError {
|
221 | constructor(message?: string);
|
222 | }
|
223 |
|
224 | /**
|
225 | * A screen capture operation was not possible.
|
226 | */
|
227 | class UnableToCaptureScreenError extends WebDriverError {
|
228 | constructor(message?: string);
|
229 | }
|
230 |
|
231 | /**
|
232 | * A modal dialog was open, blocking this operation.
|
233 | */
|
234 | class UnexpectedAlertOpenError extends WebDriverError {
|
235 | constructor(message?: string, openAlertText?: string);
|
236 | /**
|
237 | * @return {(string|undefined)} The text displayed with the unhandled alert,
|
238 | * if available.
|
239 | */
|
240 | getAlertText(): string;
|
241 | }
|
242 |
|
243 | /**
|
244 | * A command could not be executed because the remote end is not aware of it.
|
245 | */
|
246 | class UnknownCommandError extends WebDriverError {
|
247 | constructor(message?: string);
|
248 | }
|
249 |
|
250 | /**
|
251 | * The requested command matched a known URL but did not match an method for
|
252 | * that URL.
|
253 | */
|
254 | class UnknownMethodError extends WebDriverError {
|
255 | constructor(message?: string);
|
256 | }
|
257 |
|
258 | /**
|
259 | * Reports an unsupport operation.
|
260 | */
|
261 | class UnsupportedOperationError extends WebDriverError {
|
262 | constructor(message?: string);
|
263 | }
|
264 |
|
265 | interface Response {
|
266 | error: string|number;
|
267 | message: string;
|
268 | }
|
269 | /**
|
270 | * Checks a response object from a server that adheres to the W3C WebDriver
|
271 | * protocol.
|
272 | */
|
273 | function checkResponse(data: Response): Response;
|
274 |
|
275 | interface MaybeLegacyResponse {
|
276 | status?: number | undefined;
|
277 | value?: {message: string} | undefined;
|
278 | message?: string | undefined;
|
279 | getAlertText?(): string;
|
280 | }
|
281 |
|
282 | /**
|
283 | * Checks a legacy response from the Selenium 2.0 wire protocol for an error.
|
284 | */
|
285 | function checkLegacyResponse(response: MaybeLegacyResponse): MaybeLegacyResponse;
|
286 |
|
287 | interface ErrorData {
|
288 | error: string|number;
|
289 | message: string;
|
290 | [key: string]: string|number;
|
291 | }
|
292 |
|
293 | /**
|
294 | * Throws an error coded from the W3C protocol. A generic error will be thrown
|
295 | * if the provided `data` is not a valid encoded error.
|
296 | */
|
297 | function throwDecodedError(data: ErrorData|string): never;
|
298 |
|
299 | interface ErrorCodeType {
|
300 | [key: string]: number;
|
301 | }
|
302 |
|
303 | const ErrorCode: ErrorCodeType;
|
304 |
|
305 | /**
|
306 | * Lookup the err in table of errors.
|
307 | */
|
308 | function encodeError(err: any): {error: string, message: string};
|
309 | }
|
310 |
|
311 | type ConditionFn<T> = (webdriver: WebDriver) => T | null | Promise<T | null>;
|
312 |
|
313 | /**
|
314 | * Defines a condition for use with WebDriver's WebDriver#wait wait command.
|
315 | */
|
316 | export class Condition<T> {
|
317 | /**
|
318 | * @param {string} message A descriptive error message. Should complete the
|
319 | * sentence 'Waiting [...]'
|
320 | * @param {function(!WebDriver): OUT} fn The condition function to
|
321 | * evaluate on each iteration of the wait loop.
|
322 | * @constructor
|
323 | */
|
324 | constructor(message: string, fn: ConditionFn<T>);
|
325 |
|
326 | /** @return {string} A description of this condition. */
|
327 | description(): string;
|
328 |
|
329 | /** @type {function(!WebDriver): OUT} */
|
330 | fn(webdriver: WebDriver): ConditionFn<T>;
|
331 | }
|
332 |
|
333 | /**
|
334 | * Defines a condition that will result in a {@link WebElement}.
|
335 | *
|
336 | * @extends {Condition<!(WebElement|IThenable<!WebElement>)>}
|
337 | */
|
338 | export class WebElementCondition extends Condition<WebElement> {
|
339 | // add an unused private member so the compiler treats this
|
340 | // class distinct from other Conditions
|
341 | private _nominal: undefined;
|
342 | }
|
343 |
|
344 | /**
|
345 | * x,y
|
346 | */
|
347 | export interface ILocation {
|
348 | x: number;
|
349 | y: number;
|
350 | }
|
351 |
|
352 | /**
|
353 | * width, height
|
354 | */
|
355 | export interface ISize {
|
356 | width: number;
|
357 | height: number;
|
358 | }
|
359 |
|
360 | /**
|
361 | * x,y,w,h
|
362 | */
|
363 | export interface IRectangle {
|
364 | x: number;
|
365 | y: number;
|
366 | width: number;
|
367 | height: number;
|
368 | }
|
369 |
|
370 | /**
|
371 | * Class for defining sequences of user touch interactions. Each sequence
|
372 | * will not be executed until {@link #perform} is called.
|
373 | *
|
374 | * Example:
|
375 | *
|
376 | * new TouchSequence(driver).
|
377 | * tapAndHold({x: 0, y: 0}).
|
378 | * move({x: 3, y: 4}).
|
379 | * release({x: 10, y: 10}).
|
380 | * perform();
|
381 | */
|
382 | export class TouchSequence {
|
383 | /*
|
384 | * @param {!WebDriver} driver The driver instance to use.
|
385 | * @constructor
|
386 | */
|
387 | constructor(driver: WebDriver);
|
388 |
|
389 | /**
|
390 | * Executes this action sequence.
|
391 | * @return {!Promise} A promise that will be resolved once
|
392 | * this sequence has completed.
|
393 | */
|
394 | perform(): Promise<void>;
|
395 |
|
396 | /**
|
397 | * Taps an element.
|
398 | *
|
399 | * @param {!WebElement} elem The element to tap.
|
400 | * @return {!TouchSequence} A self reference.
|
401 | */
|
402 | tap(elem: WebElement): TouchSequence;
|
403 |
|
404 | /**
|
405 | * Double taps an element.
|
406 | *
|
407 | * @param {!WebElement} elem The element to double tap.
|
408 | * @return {!TouchSequence} A self reference.
|
409 | */
|
410 | doubleTap(elem: WebElement): TouchSequence;
|
411 |
|
412 | /**
|
413 | * Long press on an element.
|
414 | *
|
415 | * @param {!WebElement} elem The element to long press.
|
416 | * @return {!TouchSequence} A self reference.
|
417 | */
|
418 | longPress(elem: WebElement): TouchSequence;
|
419 |
|
420 | /**
|
421 | * Touch down at the given location.
|
422 | *
|
423 | * @param {{ x: number, y: number }} location The location to touch down at.
|
424 | * @return {!TouchSequence} A self reference.
|
425 | */
|
426 | tapAndHold(location: ILocation): TouchSequence;
|
427 |
|
428 | /**
|
429 | * Move a held {@linkplain #tapAndHold touch} to the specified location.
|
430 | *
|
431 | * @param {{x: number, y: number}} location The location to move to.
|
432 | * @return {!TouchSequence} A self reference.
|
433 | */
|
434 | move(location: ILocation): TouchSequence;
|
435 |
|
436 | /**
|
437 | * Release a held {@linkplain #tapAndHold touch} at the specified location.
|
438 | *
|
439 | * @param {{x: number, y: number}} location The location to release at.
|
440 | * @return {!TouchSequence} A self reference.
|
441 | */
|
442 | release(location: ILocation): TouchSequence;
|
443 |
|
444 | /**
|
445 | * Scrolls the touch screen by the given offset.
|
446 | *
|
447 | * @param {{x: number, y: number}} offset The offset to scroll to.
|
448 | * @return {!TouchSequence} A self reference.
|
449 | */
|
450 | scroll(offset: IOffset): TouchSequence;
|
451 |
|
452 | /**
|
453 | * Scrolls the touch screen, starting on `elem` and moving by the specified
|
454 | * offset.
|
455 | *
|
456 | * @param {!WebElement} elem The element where scroll starts.
|
457 | * @param {{x: number, y: number}} offset The offset to scroll to.
|
458 | * @return {!TouchSequence} A self reference.
|
459 | */
|
460 | scrollFromElement(elem: WebElement, offset: IOffset): TouchSequence;
|
461 |
|
462 | /**
|
463 | * Flick, starting anywhere on the screen, at speed xspeed and yspeed.
|
464 | *
|
465 | * @param {{xspeed: number, yspeed: number}} speed The speed to flick in each
|
466 | * direction, in pixels per second.
|
467 | * @return {!TouchSequence} A self reference.
|
468 | */
|
469 | flick(speed: ISpeed): TouchSequence;
|
470 |
|
471 | /**
|
472 | * Flick starting at elem and moving by x and y at specified speed.
|
473 | *
|
474 | * @param {!WebElement} elem The element where flick starts.
|
475 | * @param {{x: number, y: number}} offset The offset to flick to.
|
476 | * @param {number} speed The speed to flick at in pixels per second.
|
477 | * @return {!TouchSequence} A self reference.
|
478 | */
|
479 | flickElement(elem: WebElement, offset: IOffset, speed: number): TouchSequence;
|
480 | }
|
481 |
|
482 | /**
|
483 | * x.y again
|
484 | */
|
485 | export interface IOffset {
|
486 | x: number;
|
487 | y: number;
|
488 | }
|
489 |
|
490 | /**
|
491 | * delta x,y
|
492 | */
|
493 | export interface ISpeed {
|
494 | xspeed: number;
|
495 | yspeed: number;
|
496 | }
|
497 |
|
498 | /**
|
499 | * Represents a modal dialog such as {@code alert}, {@code confirm}, or
|
500 | * {@code prompt}. Provides functions to retrieve the message displayed with
|
501 | * the alert, accept or dismiss the alert, and set the response text (in the
|
502 | * case of {@code prompt}).
|
503 | */
|
504 | export class Alert {
|
505 | /**
|
506 | * @param {!WebDriver} driver The driver controlling the browser this alert
|
507 | * is attached to.
|
508 | * @param {string} text The message text displayed with this alert.
|
509 | */
|
510 | constructor(driver: WebDriver, text: string);
|
511 |
|
512 | // region Methods
|
513 |
|
514 | /**
|
515 | * Retrieves the message text displayed with this alert. For instance, if the
|
516 | * alert were opened with alert('hello'), then this would return 'hello'.
|
517 | * @return {!Promise} A promise that will be resolved to the
|
518 | * text displayed with this alert.
|
519 | */
|
520 | getText(): Promise<string>;
|
521 |
|
522 | /**
|
523 | * Sets the username and password in an alert prompting for credentials (such
|
524 | * as a Basic HTTP Auth prompt). This method will implicitly
|
525 | * {@linkplain #accept() submit} the dialog.
|
526 | *
|
527 | * @param {string} username The username to send.
|
528 | * @param {string} password The password to send.
|
529 | * @return {!Promise<void>} A promise that will be resolved when this
|
530 | * command has completed.
|
531 | */
|
532 | authenticateAs(username: string, password: string): Promise<void>;
|
533 |
|
534 | /**
|
535 | * Accepts this alert.
|
536 | * @return {!Promise} A promise that will be resolved when
|
537 | * this command has completed.
|
538 | */
|
539 | accept(): Promise<void>;
|
540 |
|
541 | /**
|
542 | * Dismisses this alert.
|
543 | * @return {!Promise} A promise that will be resolved when
|
544 | * this command has completed.
|
545 | */
|
546 | dismiss(): Promise<void>;
|
547 |
|
548 | /**
|
549 | * Sets the response text on this alert. This command will return an error if
|
550 | * the underlying alert does not support response text (e.g. window.alert and
|
551 | * window.confirm).
|
552 | * @param {string} text The text to set.
|
553 | * @return {!Promise} A promise that will be resolved when
|
554 | * this command has completed.
|
555 | */
|
556 | sendKeys(text: string): Promise<void>;
|
557 |
|
558 | // endregion
|
559 | }
|
560 |
|
561 | /**
|
562 | * AlertPromise is a promise that will be fulfilled with an Alert. This promise
|
563 | * serves as a forward proxy on an Alert, allowing calls to be scheduled
|
564 | * directly on this instance before the underlying Alert has been fulfilled. In
|
565 | * other words, the following two statements are equivalent:
|
566 | *
|
567 | * driver.switchTo().alert().dismiss();
|
568 | * driver.switchTo().alert().then(function(alert) {
|
569 | * return alert.dismiss();
|
570 | * });
|
571 | *
|
572 | * @implements {promise.Thenable.<!Alert>}
|
573 | * @final
|
574 | */
|
575 | export interface AlertPromise extends Promise<Alert> {}
|
576 |
|
577 | /**
|
578 | * Implement AlertPromise
|
579 | */
|
580 | export class AlertPromise extends Alert {
|
581 | /**
|
582 | * @param {!WebDriver} driver The driver controlling the browser this
|
583 | * alert is attached to.
|
584 | * @param {!promise.Thenable<!Alert>} alert A thenable
|
585 | * that will be fulfilled with the promised alert.
|
586 | */
|
587 | constructor(driver: WebDriver, alert: Promise<Alert>);
|
588 | }
|
589 |
|
590 | /**
|
591 | * ProxyConfig
|
592 | */
|
593 | export interface ProxyConfig {
|
594 | proxyType: string;
|
595 | proxyAutoconfigUrl?: string | undefined;
|
596 | ftpProxy?: string | undefined;
|
597 | httpProxy?: string | undefined;
|
598 | sslProxy?: string | undefined;
|
599 | noProxy?: string | undefined;
|
600 | socksProxy?: string | undefined;
|
601 | socksUsername?: string | undefined;
|
602 | socksPassword?: string | undefined;
|
603 | }
|
604 |
|
605 | /**
|
606 | * Creates new {@link WebDriver WebDriver} instances. The environment
|
607 | * variables listed below may be used to override a builder's configuration,
|
608 | * allowing quick runtime changes.
|
609 | *
|
610 | * - {@code SELENIUM_BROWSER}: defines the target browser in the form
|
611 | * {@code browser[:version][:platform]}.
|
612 | *
|
613 | * - {@code SELENIUM_REMOTE_URL}: defines the remote URL for all builder
|
614 | * instances. This environment variable should be set to a fully qualified
|
615 | * URL for a WebDriver server (e.g. http://localhost:4444/wd/hub). This
|
616 | * option always takes precedence over {@code SELENIUM_SERVER_JAR}.
|
617 | *
|
618 | * - {@code SELENIUM_SERVER_JAR}: defines the path to the
|
619 | * <a href='http://selenium-release.storage.googleapis.com/index.html'>
|
620 | * standalone Selenium server</a> jar to use. The server will be started the
|
621 | * first time a WebDriver instance and be killed when the process exits.
|
622 | *
|
623 | * Suppose you had mytest.js that created WebDriver with
|
624 | *
|
625 | * var driver = new Builder()
|
626 | * .forBrowser('chrome')
|
627 | * .build();
|
628 | *
|
629 | * This test could be made to use Firefox on the local machine by running with
|
630 | * `SELENIUM_BROWSER=firefox node mytest.js`. Rather than change the code to
|
631 | * target Google Chrome on a remote machine, you can simply set the
|
632 | * `SELENIUM_BROWSER` and `SELENIUM_REMOTE_URL` environment variables:
|
633 | *
|
634 | * SELENIUM_BROWSER=chrome:36:LINUX \
|
635 | * SELENIUM_REMOTE_URL=http://www.example.com:4444/wd/hub \
|
636 | * node mytest.js
|
637 | *
|
638 | * You could also use a local copy of the standalone Selenium server:
|
639 | *
|
640 | * SELENIUM_BROWSER=chrome:36:LINUX \
|
641 | * SELENIUM_SERVER_JAR=/path/to/selenium-server-standalone.jar \
|
642 | * node mytest.js
|
643 | */
|
644 | export class Builder {
|
645 | // region Constructors
|
646 |
|
647 | /**
|
648 | * @constructor
|
649 | */
|
650 | constructor();
|
651 |
|
652 | // endregion
|
653 |
|
654 | // region Methods
|
655 |
|
656 | /**
|
657 | * Configures this builder to ignore any environment variable overrides and to
|
658 | * only use the configuration specified through this instance's API.
|
659 | *
|
660 | * @return {!Builder} A self reference.
|
661 | */
|
662 | disableEnvironmentOverrides(): Builder;
|
663 |
|
664 | /**
|
665 | * Creates a new WebDriver client based on this builder's current
|
666 | * configuration.
|
667 | *
|
668 | * This method will return a {@linkplain ThenableWebDriver} instance, allowing
|
669 | * users to issue commands directly without calling `then()`. The returned
|
670 | * thenable wraps a promise that will resolve to a concrete
|
671 | * {@linkplain webdriver.WebDriver WebDriver} instance. The promise will be
|
672 | * rejected if the remote end fails to create a new session.
|
673 | *
|
674 | * @return {!ThenableWebDriver} A new WebDriver instance.
|
675 | * @throws {Error} If the current configuration is invalid.
|
676 | */
|
677 | build(): ThenableWebDriver;
|
678 |
|
679 | /**
|
680 | * Configures the target browser for clients created by this instance.
|
681 | * Any calls to {@link #withCapabilities} after this function will
|
682 | * overwrite these settings.
|
683 | *
|
684 | * <p>You may also define the target browser using the {@code
|
685 | * SELENIUM_BROWSER} environment variable. If set, this environment variable
|
686 | * should be of the form {@code browser[:[version][:platform]]}.
|
687 | *
|
688 | * @param {(string|Browser)} name The name of the target browser;
|
689 | * common defaults are available on the {@link Browser} enum.
|
690 | * @param {string=} opt_version A desired version; may be omitted if any
|
691 | * version should be used.
|
692 | * @param {string=} opt_platform The desired platform; may be omitted if any
|
693 | * version may be used.
|
694 | * @return {!Builder} A self reference.
|
695 | */
|
696 | forBrowser(name: string, opt_version?: string, opt_platform?: string): Builder;
|
697 |
|
698 | /**
|
699 | * Returns the base set of capabilities this instance is currently configured
|
700 | * to use.
|
701 | * @return {!Capabilities} The current capabilities for this builder.
|
702 | */
|
703 | getCapabilities(): Capabilities;
|
704 |
|
705 | /**
|
706 | * @return {string} The URL of the WebDriver server this instance is
|
707 | * configured to use.
|
708 | */
|
709 | getServerUrl(): string;
|
710 |
|
711 | /**
|
712 | * @return {?string} The URL of the proxy server to use for the WebDriver's
|
713 | * HTTP connections, or `null` if not set.
|
714 | */
|
715 | getWebDriverProxy(): string|null;
|
716 |
|
717 | /**
|
718 | * Sets the default action to take with an unexpected alert before returning
|
719 | * an error.
|
720 | * @param {string} beahvior The desired behavior; should be 'accept',
|
721 | * 'dismiss', or 'ignore'. Defaults to 'dismiss'.
|
722 | * @return {!Builder} A self reference.
|
723 | */
|
724 | setAlertBehavior(behavior?: string): Builder;
|
725 |
|
726 | /**
|
727 | * Sets Chrome-specific options for drivers created by this builder. Any
|
728 | * logging or proxy settings defined on the given options will take precedence
|
729 | * over those set through {@link #setLoggingPrefs} and {@link #setProxy},
|
730 | * respectively.
|
731 | *
|
732 | * @param {!chrome.Options} options The ChromeDriver options to use.
|
733 | * @return {!Builder} A self reference.
|
734 | */
|
735 | setChromeOptions(options: chrome.Options): Builder;
|
736 |
|
737 | /**
|
738 | * @return {chrome.Options} the Chrome specific options currently configured
|
739 | * for this builder.
|
740 | */
|
741 | getChromeOptions(): chrome.Options;
|
742 |
|
743 | /**
|
744 | * Sets the service builder to use for managing the chromedriver child process
|
745 | * when creating new Chrome sessions.
|
746 | *
|
747 | * @param {chrome.ServiceBuilder} service the service to use.
|
748 | * @return {!Builder} A self reference.
|
749 | */
|
750 | setChromeService(service: chrome.ServiceBuilder): Builder;
|
751 |
|
752 | /**
|
753 | * Set {@linkplain edge.Options options} specific to Microsoft's Edge browser
|
754 | * for drivers created by this builder. Any proxy settings defined on the
|
755 | * given options will take precedence over those set through
|
756 | * {@link #setProxy}.
|
757 | *
|
758 | * @param {!edge.Options} options The MicrosoftEdgeDriver options to use.
|
759 | * @return {!Builder} A self reference.
|
760 | */
|
761 | setEdgeOptions(options: edge.Options): Builder;
|
762 |
|
763 | /**
|
764 | * Sets the {@link edge.ServiceBuilder} to use to manage the
|
765 | * MicrosoftEdgeDriver child process when creating sessions locally.
|
766 | *
|
767 | * @param {edge.ServiceBuilder} service the service to use.
|
768 | * @return {!Builder} a self reference.
|
769 | */
|
770 | setEdgeService(service: edge.ServiceBuilder): Builder;
|
771 |
|
772 | /**
|
773 | * Sets Firefox-specific options for drivers created by this builder. Any
|
774 | * logging or proxy settings defined on the given options will take precedence
|
775 | * over those set through {@link #setLoggingPrefs} and {@link #setProxy},
|
776 | * respectively.
|
777 | *
|
778 | * @param {!firefox.Options} options The FirefoxDriver options to use.
|
779 | * @return {!Builder} A self reference.
|
780 | */
|
781 | setFirefoxOptions(options: firefox.Options): Builder;
|
782 |
|
783 | /**
|
784 | * @return {firefox.Options} the Firefox specific options currently configured
|
785 | * for this instance.
|
786 | */
|
787 | getFirefoxOptions(): firefox.Options;
|
788 |
|
789 | /**
|
790 | * Sets the {@link firefox.ServiceBuilder} to use to manage the geckodriver
|
791 | * child process when creating Firefox sessions locally.
|
792 | *
|
793 | * @param {firefox.ServiceBuilder} service the service to use.
|
794 | * @return {!Builder} a self reference.
|
795 | */
|
796 | setFirefoxService(service: firefox.ServiceBuilder): Builder;
|
797 |
|
798 | /**
|
799 | * Set Internet Explorer specific {@linkplain ie.Options options} for drivers
|
800 | * created by this builder. Any proxy settings defined on the given options
|
801 | * will take precedence over those set through {@link #setProxy}.
|
802 | *
|
803 | * @param {!ie.Options} options The IEDriver options to use.
|
804 | * @return {!Builder} A self reference.
|
805 | */
|
806 | setIeOptions(options: ie.Options): Builder;
|
807 |
|
808 | /**
|
809 | * Sets the {@link ie.ServiceBuilder} to use to manage the geckodriver
|
810 | * child process when creating IE sessions locally.
|
811 | *
|
812 | * @param {ie.ServiceBuilder} service the service to use.
|
813 | * @return {!Builder} a self reference.
|
814 | */
|
815 | setIeService(service: ie.ServiceBuilder): Builder;
|
816 |
|
817 | /**
|
818 | * Sets the logging preferences for the created session. Preferences may be
|
819 | * changed by repeated calls, or by calling {@link #withCapabilities}.
|
820 | * @param {!(logging.Preferences|Object.<string, string>)} prefs The
|
821 | * desired logging preferences.
|
822 | * @return {!Builder} A self reference.
|
823 | */
|
824 | setLoggingPrefs(prefs: logging.Preferences|{}): Builder;
|
825 |
|
826 | /**
|
827 | * Sets the proxy configuration to use for WebDriver clients created by this
|
828 | * builder. Any calls to {@link #withCapabilities} after this function will
|
829 | * overwrite these settings.
|
830 | * @param {!capabilities.ProxyConfig} config The configuration to use.
|
831 | * @return {!Builder} A self reference.
|
832 | */
|
833 | setProxy(config: ProxyConfig): Builder;
|
834 |
|
835 | /**
|
836 | * Sets Safari specific {@linkplain safari.Options options} for drivers
|
837 | * created by this builder. Any logging settings defined on the given options
|
838 | * will take precedence over those set through {@link #setLoggingPrefs}.
|
839 | *
|
840 | * @param {!safari.Options} options The Safari options to use.
|
841 | * @return {!Builder} A self reference.
|
842 | */
|
843 | setSafariOptions(options: safari.Options): Builder;
|
844 |
|
845 | /**
|
846 | * @return {safari.Options} the Safari specific options currently configured
|
847 | * for this instance.
|
848 | */
|
849 | getSafariOptions(): safari.Options;
|
850 |
|
851 | /**
|
852 | * Sets the http agent to use for each request.
|
853 | * If this method is not called, the Builder will use http.globalAgent by
|
854 | * default.
|
855 | *
|
856 | * @param {http.Agent} agent The agent to use for each request.
|
857 | * @return {!Builder} A self reference.
|
858 | */
|
859 | usingHttpAgent(agent: any): Builder;
|
860 |
|
861 | /**
|
862 | * @return {http.Agent} The http agent used for each request
|
863 | */
|
864 | getHttpAgent(): any|null;
|
865 |
|
866 | /**
|
867 | * Sets the URL of a remote WebDriver server to use. Once a remote URL has
|
868 | * been specified, the builder direct all new clients to that server. If this
|
869 | * method is never called, the Builder will attempt to create all clients
|
870 | * locally.
|
871 | *
|
872 | * <p>As an alternative to this method, you may also set the
|
873 | * {@code SELENIUM_REMOTE_URL} environment variable.
|
874 | *
|
875 | * @param {string} url The URL of a remote server to use.
|
876 | * @return {!Builder} A self reference.
|
877 | */
|
878 | usingServer(url: string): Builder;
|
879 |
|
880 | /**
|
881 | * Sets the URL of the proxy to use for the WebDriver's HTTP connections.
|
882 | * If this method is never called, the Builder will create a connection
|
883 | * without a proxy.
|
884 | *
|
885 | * @param {string} proxy The URL of a proxy to use.
|
886 | * @return {!Builder} A self reference.
|
887 | */
|
888 | usingWebDriverProxy(proxy: string): Builder;
|
889 |
|
890 | /**
|
891 | * Sets the desired capabilities when requesting a new session. This will
|
892 | * overwrite any previously set capabilities.
|
893 | * @param {!(Object|Capabilities)} capabilities The desired
|
894 | * capabilities for a new session.
|
895 | * @return {!Builder} A self reference.
|
896 | */
|
897 | withCapabilities(capabilities: {}|Capabilities): Builder;
|
898 |
|
899 | // endregion
|
900 | }
|
901 |
|
902 | export type Locator = By | Function | ByHash;
|
903 |
|
904 | /**
|
905 | * Describes an event listener registered on an {@linkplain EventEmitter}.
|
906 | */
|
907 | export class Listener {
|
908 | /**
|
909 | * @param {!Function} fn The acutal listener function.
|
910 | * @param {(Object|undefined)} scope The object in whose scope to invoke the
|
911 | * listener.
|
912 | * @param {boolean} oneshot Whether this listener should only be used once.
|
913 | */
|
914 | constructor(fn: Function, scope: {}, oneshot: boolean);
|
915 | }
|
916 |
|
917 | /**
|
918 | * Object that can emit events for others to listen for. This is used instead
|
919 | * of Closure's event system because it is much more light weight. The API is
|
920 | * based on Node's EventEmitters.
|
921 | */
|
922 | export class EventEmitter {
|
923 | // region Constructors
|
924 |
|
925 | /**
|
926 | * @constructor
|
927 | */
|
928 | constructor();
|
929 |
|
930 | // endregion
|
931 |
|
932 | // region Methods
|
933 |
|
934 | /**
|
935 | * Fires an event and calls all listeners.
|
936 | * @param {string} type The type of event to emit.
|
937 | * arguments to pass to each listener.
{...*} var_args Any |
938 | */
|
939 | emit(type: string, ...var_args: any[]): void;
|
940 |
|
941 | /**
|
942 | * Returns a mutable list of listeners for a specific type of event.
|
943 | * @param {string} type The type of event to retrieve the listeners for.
|
944 | * @return {!Set<!Listener>} The registered listeners for the given event
|
945 | * type.
|
946 | */
|
947 | listeners(type: string): any;
|
948 |
|
949 | /**
|
950 | * Registers a listener.
|
951 | * @param {string} type The type of event to listen for.
|
952 | * @param {!Function} fn The function to invoke when the event is fired.
|
953 | * @param {Object=} opt_self The object in whose scope to invoke the listener.
|
954 | * @param {boolean=} opt_oneshot Whether the listener should b (e removed
|
955 | * after
|
956 | * the first event is fired.
|
957 | * @return {!EventEmitter} A self reference.
|
958 | * @private
|
959 | */
|
960 | addListener(type: string, fn: Function, opt_scope?: any, opt_oneshot?: boolean): EventEmitter;
|
961 |
|
962 | /**
|
963 | * Registers a one-time listener which will be called only the first time an
|
964 | * event is emitted, after which it will be removed.
|
965 | * @param {string} type The type of event to listen for.
|
966 | * @param {!Function} fn The function to invoke when the event is fired.
|
967 | * @param {Object=} opt_scope The object in whose scope to invoke the
|
968 | * listener.
|
969 | * @return {!EventEmitter} A self reference.
|
970 | */
|
971 | once(type: string, fn: any, opt_scope?: any): EventEmitter;
|
972 |
|
973 | /**
|
974 | * An alias for {@code #addListener()}.
|
975 | * @param {string} type The type of event to listen for.
|
976 | * @param {!Function} fn The function to invoke when the event is fired.
|
977 | * @param {Object=} opt_scope The object in whose scope to invoke the
|
978 | * listener.
|
979 | * @return {!EventEmitter} A self reference.
|
980 | */
|
981 | on(type: string, fn: Function, opt_scope?: any): EventEmitter;
|
982 |
|
983 | /**
|
984 | * Removes a previously registered event listener.
|
985 | * @param {string} type The type of event to unregister.
|
986 | * @param {!Function} listenerFn The handler function to remove.
|
987 | * @return {!EventEmitter} A self reference.
|
988 | */
|
989 | removeListener(type: string, listenerFn: Function): EventEmitter;
|
990 |
|
991 | /**
|
992 | * Removes all listeners for a specific type of event. If no event is
|
993 | * specified, all listeners across all types will be removed.
|
994 | * @param {string=} opt_type The type of event to remove listeners from.
|
995 | * @return {!EventEmitter} A self reference.
|
996 | */
|
997 | removeAllListeners(opt_type?: string): EventEmitter;
|
998 |
|
999 | // endregion
|
1000 | }
|
1001 |
|
1002 | /**
|
1003 | * Interface for navigating back and forth in the browser history.
|
1004 | */
|
1005 | export class Navigation {
|
1006 | // region Constructors
|
1007 |
|
1008 | /**
|
1009 | * Interface for navigating back and forth in the browser history.
|
1010 | *
|
1011 | * This class should never be instantiated directly. Insead, obtain an
|
1012 | * instance with
|
1013 | *
|
1014 | * navigate()
|
1015 | *
|
1016 | * @see WebDriver#navigate()
|
1017 | */
|
1018 | constructor(driver: WebDriver);
|
1019 |
|
1020 | // endregion
|
1021 |
|
1022 | // region Methods
|
1023 |
|
1024 | /**
|
1025 | * Schedules a command to navigate to a new URL.
|
1026 | * @param {string} url The URL to navigate to.
|
1027 | * Promise.<void>} A promise that will be resolved
{! |
1028 | * when the URL has been loaded.
|
1029 | */
|
1030 | to(url: string): Promise<void>;
|
1031 |
|
1032 | /**
|
1033 | * Schedules a command to move backwards in the browser history.
|
1034 | * @return {!Promise.<void>} A promise that will be resolved
|
1035 | * when the navigation event has completed.
|
1036 | */
|
1037 | back(): Promise<void>;
|
1038 |
|
1039 | /**
|
1040 | * Schedules a command to move forwards in the browser history.
|
1041 | * @return {!Promise.<void>} A promise that will be resolved
|
1042 | * when the navigation event has completed.
|
1043 | */
|
1044 | forward(): Promise<void>;
|
1045 |
|
1046 | /**
|
1047 | * Schedules a command to refresh the current page.
|
1048 | * @return {!Promise.<void>} A promise that will be resolved
|
1049 | * when the navigation event has completed.
|
1050 | */
|
1051 | refresh(): Promise<void>;
|
1052 |
|
1053 | // endregion
|
1054 | }
|
1055 |
|
1056 | export interface IWebDriverOptionsCookie {
|
1057 | /**
|
1058 | * The name of the cookie.
|
1059 | */
|
1060 | name: string;
|
1061 |
|
1062 | /**
|
1063 | * The cookie value.
|
1064 | */
|
1065 | value: string;
|
1066 |
|
1067 | /**
|
1068 | * The cookie path. Defaults to "/" when adding a cookie.
|
1069 | */
|
1070 | path?: string | undefined;
|
1071 |
|
1072 | /**
|
1073 | * The domain the cookie is visible to. Defaults to the current browsing
|
1074 | * context's document's URL when adding a cookie.
|
1075 | */
|
1076 | domain?: string | undefined;
|
1077 |
|
1078 | /**
|
1079 | * Whether the cookie is a secure cookie. Defaults to false when adding a new
|
1080 | * cookie.
|
1081 | */
|
1082 | secure?: boolean | undefined;
|
1083 |
|
1084 | /**
|
1085 | * Whether the cookie is an HTTP only cookie. Defaults to false when adding a
|
1086 | * new cookie.
|
1087 | */
|
1088 | httpOnly?: boolean | undefined;
|
1089 |
|
1090 | /**
|
1091 | * When the cookie expires.
|
1092 | *
|
1093 | * When {@linkplain Options#addCookie() adding a cookie}, this may be
|
1094 | * specified in _seconds_ since Unix epoch (January 1, 1970). The expiry will
|
1095 | * default to 20 years in the future if omitted.
|
1096 | *
|
1097 | * The expiry is always returned in seconds since epoch when
|
1098 | * {@linkplain Options#getCookies() retrieving cookies} from the browser.
|
1099 | *
|
1100 | * @type {(!Date|number|undefined)}
|
1101 | */
|
1102 | expiry?: number|Date | undefined;
|
1103 | }
|
1104 |
|
1105 | export interface IWebDriverCookie extends IWebDriverOptionsCookie {
|
1106 | /**
|
1107 | * When the cookie expires.
|
1108 | *
|
1109 | * The expiry is always returned in seconds since epoch when
|
1110 | * {@linkplain Options#getCookies() retrieving cookies} from the browser.
|
1111 | *
|
1112 | * @type {(!number|undefined)}
|
1113 | */
|
1114 | expiry?: number | undefined;
|
1115 | }
|
1116 |
|
1117 | /**
|
1118 | * Provides methods for managing browser and driver state.
|
1119 | */
|
1120 | export class Options {
|
1121 | // region Constructors
|
1122 |
|
1123 | /**
|
1124 | * @param {!WebDriver} driver The parent driver.
|
1125 | * @constructor
|
1126 | */
|
1127 | constructor(driver: WebDriver);
|
1128 |
|
1129 | // endregion
|
1130 |
|
1131 | // region Methods
|
1132 |
|
1133 | /**
|
1134 | * Schedules a command to add a cookie.
|
1135 | * @param {IWebDriverOptionsCookie} spec Defines the cookie to add.
|
1136 | * Promise<void>} A promise that will be resolved
{! |
1137 | * when the cookie has been added to the page.
|
1138 | * if any of the cookie parameters are
{error.InvalidArgumentError} |
1139 | * invalid.
|
1140 | * TypeError} if `spec` is not a cookie object.
{ |
1141 | */
|
1142 | addCookie(spec: IWebDriverOptionsCookie): Promise<void>;
|
1143 |
|
1144 | /**
|
1145 | * Schedules a command to delete all cookies visible to the current page.
|
1146 | * @return {!Promise} A promise that will be resolved when all
|
1147 | * cookies have been deleted.
|
1148 | */
|
1149 | deleteAllCookies(): Promise<void>;
|
1150 |
|
1151 | /**
|
1152 | * Schedules a command to delete the cookie with the given name. This command
|
1153 | * is a no-op if there is no cookie with the given name visible to the current
|
1154 | * page.
|
1155 | * @param {string} name The name of the cookie to delete.
|
1156 | * @return {!Promise} A promise that will be resolved when the
|
1157 | * cookie has been deleted.
|
1158 | */
|
1159 | deleteCookie(name: string): Promise<void>;
|
1160 |
|
1161 | /**
|
1162 | * Schedules a command to retrieve all cookies visible to the current page.
|
1163 | * Each cookie will be returned as a JSON object as described by the WebDriver
|
1164 | * wire protocol.
|
1165 | * @return {!Promise} A promise that will be resolved with the
|
1166 | * cookies visible to the current page.
|
1167 | * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object
|
1168 | */
|
1169 | getCookies(): Promise<IWebDriverCookie[]>;
|
1170 |
|
1171 | /**
|
1172 | * Schedules a command to retrieve the cookie with the given name. Returns
|
1173 | * null if there is no such cookie. The cookie will be returned as a JSON
|
1174 | * object as described by the WebDriver wire protocol.
|
1175 | * @param {string} name The name of the cookie to retrieve.
|
1176 | * @return {!Promise} A promise that will be resolved with the
|
1177 | * named cookie, or {@code null} if there is no such cookie.
|
1178 | * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object
|
1179 | */
|
1180 | getCookie(name: string): Promise<IWebDriverCookie>;
|
1181 |
|
1182 | /**
|
1183 | * @return {!Logs} The interface for managing driver
|
1184 | * logs.
|
1185 | */
|
1186 | logs(): Logs;
|
1187 |
|
1188 | /**
|
1189 | * The current timeouts
|
1190 | */
|
1191 | getTimeouts(): Promise<ITimeouts>;
|
1192 |
|
1193 | /**
|
1194 | * Set current timeouts
|
1195 | */
|
1196 | setTimeouts(timeouts: ITimeouts): Promise<void>;
|
1197 |
|
1198 | /**
|
1199 | * @return {!Window} The interface for managing the
|
1200 | * current window.
|
1201 | */
|
1202 | window(): Window;
|
1203 |
|
1204 | // endregion
|
1205 | }
|
1206 |
|
1207 | /**
|
1208 | * An interface for managing the current window.
|
1209 | */
|
1210 | export class Window {
|
1211 | // region Constructors
|
1212 |
|
1213 | /**
|
1214 | * @param {!WebDriver} driver The parent driver.
|
1215 | * @constructor
|
1216 | */
|
1217 | constructor(driver: WebDriver);
|
1218 |
|
1219 | // endregion
|
1220 |
|
1221 | // region Methods
|
1222 |
|
1223 | /**
|
1224 | * Retrieves the window's current position, relative to the top left corner of
|
1225 | * the screen.
|
1226 | * @return {!Promise} A promise that will be resolved with the
|
1227 | * window's position in the form of a {x:number, y:number} object literal.
|
1228 | */
|
1229 | getPosition(): Promise<ILocation>;
|
1230 |
|
1231 | /**
|
1232 | * Repositions the current window.
|
1233 | * @param {number} x The desired horizontal position, relative to the left
|
1234 | * side of the screen.
|
1235 | * @param {number} y The desired vertical position, relative to the top of the
|
1236 | * of the screen.
|
1237 | * @return {!Promise} A promise that will be resolved when the
|
1238 | * command has completed.
|
1239 | */
|
1240 | setPosition(x: number, y: number): Promise<void>;
|
1241 |
|
1242 | /**
|
1243 | * Retrieves the window's current size.
|
1244 | * @return {!Promise} A promise that will be resolved with the
|
1245 | * window's size in the form of a {width:number, height:number} object
|
1246 | * literal.
|
1247 | */
|
1248 | getSize(): Promise<ISize>;
|
1249 |
|
1250 | /**
|
1251 | * Resizes the current window.
|
1252 | * @param {number} width The desired window width.
|
1253 | * @param {number} height The desired window height.
|
1254 | * @return {!Promise} A promise that will be resolved when the
|
1255 | * command has completed.
|
1256 | */
|
1257 | setSize(width: number, height: number): Promise<void>;
|
1258 |
|
1259 | /**
|
1260 | * Returns the current top-level window's size and position.
|
1261 | */
|
1262 | getRect(): Promise<IRectangle>;
|
1263 |
|
1264 | /**
|
1265 | * Sets the current top-level window's size and position. You may update
|
1266 | * just the size by omitting `x` & `y`, or just the position by omitting
|
1267 | * `width` & `height` options.
|
1268 | */
|
1269 | setRect({x, y, width, height}: Partial<IRectangle>): Promise<IRectangle>;
|
1270 |
|
1271 | /**
|
1272 | * Maximizes the current window. The exact behavior of this command is
|
1273 | * specific to individual window managers, but typically involves increasing
|
1274 | * the window to the maximum available size without going full-screen.
|
1275 | * @return {!Promise} A promise that will be resolved when the
|
1276 | * command has completed.
|
1277 | */
|
1278 | maximize(): Promise<void>;
|
1279 |
|
1280 | /**
|
1281 | * Minimizes the current window. The exact behavior of this command is
|
1282 | * specific to individual window managers, but typically involves hiding
|
1283 | * the window in the system tray.
|
1284 | * @return {!Promise} A promise that will be resolved when the
|
1285 | * command has completed.
|
1286 | */
|
1287 | minimize(): Promise<void>;
|
1288 |
|
1289 | /**
|
1290 | * Invokes the "full screen" operation on the current window. The exact
|
1291 | * behavior of this command is specific to individual window managers, but
|
1292 | * this will typically increase the window size to the size of the physical
|
1293 | * display and hide the browser chrome.
|
1294 | *
|
1295 | * @return {!Promise<void>} A promise that will be resolved when the command
|
1296 | * has completed.
|
1297 | * @see <https://fullscreen.spec.whatwg.org/#fullscreen-an-element>
|
1298 | */
|
1299 | fullsceen(): Promise<void>;
|
1300 |
|
1301 | // endregion
|
1302 | }
|
1303 |
|
1304 | /**
|
1305 | * Interface for managing WebDriver log records.
|
1306 | */
|
1307 | export class Logs {
|
1308 | // region Constructors
|
1309 |
|
1310 | /**
|
1311 | * @param {!WebDriver} driver The parent driver.
|
1312 | * @constructor
|
1313 | */
|
1314 | constructor(driver: WebDriver);
|
1315 |
|
1316 | // endregion
|
1317 |
|
1318 | // region
|
1319 |
|
1320 | /**
|
1321 | * Fetches available log entries for the given type.
|
1322 | *
|
1323 | * <p/>Note that log buffers are reset after each call, meaning that
|
1324 | * available log entries correspond to those entries not yet returned for a
|
1325 | * given log type. In practice, this means that this call will return the
|
1326 | * available log entries since the last call, or from the start of the
|
1327 | * session.
|
1328 | *
|
1329 | * @param {!logging.Type} type The desired log type.
|
1330 | * Promise.<!Array.<!logging.Entry>>} A
{! |
1331 | * promise that will resolve to a list of log entries for the specified
|
1332 | * type.
|
1333 | */
|
1334 | get(type: string): Promise<logging.Entry[]>;
|
1335 |
|
1336 | /**
|
1337 | * Retrieves the log types available to this driver.
|
1338 | * @return {!Promise.<!Array.<!logging.Type>>} A
|
1339 | * promise that will resolve to a list of available log types.
|
1340 | */
|
1341 | getAvailableLogTypes(): Promise<string[]>;
|
1342 |
|
1343 | // endregion
|
1344 | }
|
1345 |
|
1346 | /**
|
1347 | * An interface for changing the focus of the driver to another frame or window.
|
1348 | */
|
1349 | export class TargetLocator {
|
1350 | // region Constructors
|
1351 |
|
1352 | /**
|
1353 | * @param {!WebDriver} driver The parent driver.
|
1354 | * @constructor
|
1355 | */
|
1356 | constructor(driver: WebDriver);
|
1357 |
|
1358 | // endregion
|
1359 |
|
1360 | // region Methods
|
1361 |
|
1362 | /**
|
1363 | * Schedules a command retrieve the {document.activeElement} element on
|
1364 | * the current document, or { document.body} if activeElement is not
|
1365 | * available.
|
1366 | * {!WebElement} The active element.
|
1367 | */
|
1368 | activeElement(): WebElementPromise;
|
1369 |
|
1370 | /**
|
1371 | * Schedules a command to switch focus of all future commands to the first
|
1372 | * frame on the page.
|
1373 | * @return {!Promise} A promise that will be resolved when the
|
1374 | * driver has changed focus to the default content.
|
1375 | */
|
1376 | defaultContent(): Promise<void>;
|
1377 |
|
1378 | /**
|
1379 | * Changes the focus of all future commands to another frame on the page. The
|
1380 | * target frame may be specified as one of the following:
|
1381 | *
|
1382 | * - A number that specifies a (zero-based) index into [window.frames](
|
1383 | * https://developer.mozilla.org/en-US/docs/Web/API/Window.frames).
|
1384 | * - A {@link WebElement} reference, which correspond to a `frame` or `iframe`
|
1385 | * DOM element.
|
1386 | * - The `null` value, to select the topmost frame on the page. Passing `null`
|
1387 | * is the same as calling {@link #defaultContent defaultContent()}.
|
1388 | *
|
1389 | * If the specified frame can not be found, the returned promise will be
|
1390 | * rejected with a {@linkplain error.NoSuchFrameError}.
|
1391 | *
|
1392 | * @param {(number|WebElement|null)} id The frame locator.
|
1393 | * @return {!Promise<void>} A promise that will be resolved
|
1394 | * when the driver has changed focus to the specified frame.
|
1395 | */
|
1396 | frame(id: number|WebElement|null): Promise<void>;
|
1397 |
|
1398 | /**
|
1399 | * Changes the focus of all future commands to the parent frame of the
|
1400 | * currently selected frame. This command has no effect if the driver is
|
1401 | * already focused on the top-level browsing context.
|
1402 | *
|
1403 | * @return {!Promise<void>} A promise that will be resolved when the command
|
1404 | * has completed.
|
1405 | */
|
1406 | parentFrame(): Promise<void>;
|
1407 |
|
1408 | /**
|
1409 | * Schedules a command to switch the focus of all future commands to another
|
1410 | * window. Windows may be specified by their {@code window.name} attribute or
|
1411 | * by its handle (as returned by {@link WebDriver#getWindowHandles}).
|
1412 | *
|
1413 | * If the specified window cannot be found, the returned promise will be
|
1414 | * rejected with a {@linkplain error.NoSuchWindowError}.
|
1415 | *
|
1416 | * @param {string} nameOrHandle The name or window handle of the window to
|
1417 | * switch focus to.
|
1418 | * @return {!Promise<void>} A promise that will be resolved
|
1419 | * when the driver has changed focus to the specified window.
|
1420 | */
|
1421 | window(nameOrHandle: string): Promise<void>;
|
1422 |
|
1423 | /**
|
1424 | * Creates a new browser window and switches the focus for future
|
1425 | * commands of this driver to the new window.
|
1426 | *
|
1427 | * @param {string} typeHint 'window' or 'tab'. The created window is not
|
1428 | * guaranteed to be of the requested type; if the driver does not support
|
1429 | * the requested type, a new browser window will be created of whatever type
|
1430 | * the driver does support.
|
1431 | * @return {!Promise<void>} A promise that will be resolved
|
1432 | * when the driver has changed focus to the new window.
|
1433 | */
|
1434 | newWindow(typeHint: string): Promise<void>;
|
1435 |
|
1436 | /**
|
1437 | * Schedules a command to change focus to the active modal dialog, such as
|
1438 | * those opened by `window.alert()`, `window.confirm()`, and
|
1439 | * `window.prompt()`. The returned promise will be rejected with a
|
1440 | * {@linkplain error.NoSuchAlertError} if there are no open alerts.
|
1441 | *
|
1442 | * @return {!AlertPromise} The open alert.
|
1443 | */
|
1444 | alert(): AlertPromise;
|
1445 |
|
1446 | // endregion
|
1447 | }
|
1448 |
|
1449 | /**
|
1450 | * Used with {@link WebElement#sendKeys WebElement#sendKeys} on file
|
1451 | * input elements ({@code <input type='file'>}) to detect when the entered key
|
1452 | * sequence defines the path to a file.
|
1453 | *
|
1454 | * By default, {@linkplain WebElement WebElement's} will enter all
|
1455 | * key sequences exactly as entered. You may set a
|
1456 | * {@linkplain WebDriver#setFileDetector file detector} on the parent
|
1457 | * WebDriver instance to define custom behavior for handling file elements. Of
|
1458 | * particular note is the {@link selenium-webdriver/remote.FileDetector}, which
|
1459 | * should be used when running against a remote
|
1460 | * [Selenium Server](http://docs.seleniumhq.org/download/).
|
1461 | */
|
1462 | export class FileDetector {
|
1463 | /** @constructor */
|
1464 | constructor();
|
1465 |
|
1466 | /**
|
1467 | * Handles the file specified by the given path, preparing it for use with
|
1468 | * the current browser. If the path does not refer to a valid file, it will
|
1469 | * be returned unchanged, otherwisee a path suitable for use with the current
|
1470 | * browser will be returned.
|
1471 | *
|
1472 | * This default implementation is a no-op. Subtypes may override this
|
1473 | * function for custom tailored file handling.
|
1474 | *
|
1475 | * @param {!WebDriver} driver The driver for the current browser.
|
1476 | * string} path The path to process.
{ |
1477 | * Promise<string>} A promise for the processed
{! |
1478 | * file path.
|
1479 | *
|
1480 | */
|
1481 | handleFile(driver: WebDriver, path: string): Promise<string>;
|
1482 | }
|
1483 |
|
1484 | export type CreateSessionCapabilities =
|
1485 | Capabilities | {desired?: Capabilities | undefined, required?: Capabilities | undefined};
|
1486 |
|
1487 | /**
|
1488 | * Creates a new WebDriver client, which provides control over a browser.
|
1489 | *
|
1490 | * Every WebDriver command returns a {@code Promise} that
|
1491 | * represents the result of that command. Callbacks may be registered on this
|
1492 | * object to manipulate the command result or catch an expected error. Any
|
1493 | * commands scheduled with a callback are considered sub-commands and will
|
1494 | * execute before the next command in the current frame. For example:
|
1495 | *
|
1496 | * var message = [];
|
1497 | * driver.call(message.push, message, 'a').then(function() {
|
1498 | * driver.call(message.push, message, 'b');
|
1499 | * });
|
1500 | * driver.call(message.push, message, 'c');
|
1501 | * driver.call(function() {
|
1502 | * alert('message is abc? ' + (message.join('') == 'abc'));
|
1503 | * });
|
1504 | *
|
1505 | */
|
1506 | export class WebDriver {
|
1507 | // region Constructors
|
1508 |
|
1509 | /**
|
1510 | * @param {!(Session|Promise<!Session>)} session Either a
|
1511 | * known session or a promise that will be resolved to a session.
|
1512 | * @param {!command.Executor} executor The executor to use when sending
|
1513 | * commands to the browser.
|
1514 | */
|
1515 | constructor(session: Session|Promise<Session>, executor: http.Executor);
|
1516 |
|
1517 | // endregion
|
1518 |
|
1519 | // region StaticMethods
|
1520 |
|
1521 | /**
|
1522 | * Creates a new WebDriver session.
|
1523 | *
|
1524 | * By default, the requested session `capabilities` are merely "desired" and
|
1525 | * the remote end will still create a new session even if it cannot satisfy
|
1526 | * all of the requested capabilities. You can query which capabilities a
|
1527 | * session actually has using the
|
1528 | * { #getCapabilities() getCapabilities()} method on the returned
|
1529 | * WebDriver instance.
|
1530 | *
|
1531 | * To define _required capabilities_, provide the `capabilities` as an object
|
1532 | * literal with `required` and `desired` keys. The `desired` key may be
|
1533 | * omitted if all capabilities are required, and vice versa. If the server
|
1534 | * cannot create a session with all of the required capabilities, it will
|
1535 | * return an { error.SessionNotCreatedError}.
|
1536 | *
|
1537 | * let required = new Capabilities().set('browserName', 'firefox');
|
1538 | * let desired = new Capabilities().set('version', '45');
|
1539 | * let driver = WebDriver.createSession(executor, {required, desired});
|
1540 | *
|
1541 | * This function will always return a WebDriver instance. If there is an error
|
1542 | * creating the session, such as the aforementioned SessionNotCreatedError,
|
1543 | * the driver will have a rejected { #getSession session} promise.
|
1544 | * It is recommended that this promise is left _unhandled_ so it will
|
1545 | * propagate through the { promise.ControlFlow control flow} and
|
1546 | * cause subsequent commands to fail.
|
1547 | *
|
1548 | * let required = Capabilities.firefox();
|
1549 | * let driver = WebDriver.createSession(executor, {required});
|
1550 | *
|
1551 | * // If the createSession operation failed, then this command will also
|
1552 | * // also fail, propagating the creation failure.
|
1553 | * driver.get('http://www.google.com').catch(e => console.log(e));
|
1554 | *
|
1555 | * new session
{!command.Executor} executor The executor to create the |
1556 | * with.
|
1557 | * {(!Capabilities|
|
1558 | * {desired: (Capabilities|undefined),
|
1559 | * required: (Capabilities|undefined)})} capabilities The desired
|
1560 | * capabilities for the new session.
|
1561 | * {promise.ControlFlow=} opt_flow The control flow all driver
|
1562 | * commands should execute under, including the initial session creation.
|
1563 | * Defaults to the { promise.controlFlow() currently active}
|
1564 | * control flow.
|
1565 | * function(new: WebDriver,
{( |
1566 | * !IThenable<!Session>,
|
1567 | * !command.Executor,
|
1568 | * promise.ControlFlow=))=} opt_ctor
|
1569 | * A reference to the constructor of the specific type of WebDriver client
|
1570 | * to instantiate. Will create a vanilla { WebDriver} instance
|
1571 | * if a constructor is not provided.
|
1572 | * @param {(function(this: void): ?)=} opt_onQuit A callback to invoke when
|
1573 | * the newly created session is terminated. This should be used to clean
|
1574 | * up any resources associated with the session.
|
1575 | * @return {!WebDriver} The driver for the newly created session.
|
1576 | */
|
1577 | // This method's arguments are untyped so that its overloads can have correct
|
1578 | // types. Typescript doesn't allow static methods to be overridden with
|
1579 | // incompatible signatures.
|
1580 | static createSession(...var_args: any[]): WebDriver;
|
1581 |
|
1582 | // endregion
|
1583 |
|
1584 | // region Methods
|
1585 |
|
1586 | /**
|
1587 | * Schedules a {@link command.Command} to be executed by this driver's
|
1588 | * {@link command.Executor}.
|
1589 | *
|
1590 | * @param {!command.Command} command The command to schedule.
|
1591 | * @param {string} description A description of the command for debugging.
|
1592 | * @return {!Promise<T>} A promise that will be resolved
|
1593 | * with the command result.
|
1594 | * @template T
|
1595 | */
|
1596 | execute<T>(command: command.Command, description?: string): Promise<T>;
|
1597 |
|
1598 | /**
|
1599 | * Sets the {@linkplain input.FileDetector file detector} that should be
|
1600 | * used with this instance.
|
1601 | * @param {input.FileDetector} detector The detector to use or {@code null}.
|
1602 | */
|
1603 | setFileDetector(detector: FileDetector): void;
|
1604 |
|
1605 | getExecutor(): command.Executor;
|
1606 |
|
1607 | /**
|
1608 | * @return {!Promise.<!Session>} A promise for this
|
1609 | * client's session.
|
1610 | */
|
1611 | getSession(): Promise<Session>;
|
1612 |
|
1613 | /**
|
1614 | * @return {!Promise.<!Capabilities>} A promise
|
1615 | * that will resolve with the this instance's capabilities.
|
1616 | */
|
1617 | getCapabilities(): Promise<Capabilities>;
|
1618 |
|
1619 | /**
|
1620 | * Schedules a command to quit the current session. After calling quit, this
|
1621 | * instance will be invalidated and may no longer be used to issue commands
|
1622 | * against the browser.
|
1623 | * @return {!Promise.<void>} A promise that will be resolved
|
1624 | * when the command has completed.
|
1625 | */
|
1626 | quit(): Promise<void>;
|
1627 |
|
1628 | /**
|
1629 | * Creates a new action sequence using this driver. The sequence will not be
|
1630 | * scheduled for execution until {@link actions.ActionSequence#perform} is
|
1631 | * called. Example:
|
1632 | *
|
1633 | * driver.actions().
|
1634 | * mouseDown(element1).
|
1635 | * mouseMove(element2).
|
1636 | * mouseUp().
|
1637 | * perform();
|
1638 | *
|
1639 | * @return {!actions.ActionSequence} A new action sequence for this instance.
|
1640 | */
|
1641 | actions(options?: {async: boolean, bridge: boolean}|{async: boolean}|{bridge: boolean}): Actions;
|
1642 |
|
1643 | /**
|
1644 | * Schedules a command to execute JavaScript in the context of the currently
|
1645 | * selected frame or window. The script fragment will be executed as the body
|
1646 | * of an anonymous function. If the script is provided as a function object,
|
1647 | * that function will be converted to a string for injection into the target
|
1648 | * window.
|
1649 | *
|
1650 | * Any arguments provided in addition to the script will be included as script
|
1651 | * arguments and may be referenced using the {@code arguments} object.
|
1652 | * Arguments may be a boolean, number, string, or {@code WebElement}.
|
1653 | * Arrays and objects may also be used as script arguments as long as each
|
1654 | * item adheres to the types previously mentioned.
|
1655 | *
|
1656 | * The script may refer to any variables accessible from the current window.
|
1657 | * Furthermore, the script will execute in the window's context, thus
|
1658 | * {@code document} may be used to refer to the current document. Any local
|
1659 | * variables will not be available once the script has finished executing,
|
1660 | * though global variables will persist.
|
1661 | *
|
1662 | * If the script has a return value (i.e. if the script contains a return
|
1663 | * statement), then the following steps will be taken for resolving this
|
1664 | * functions return value:
|
1665 | *
|
1666 | * - For a HTML element, the value will resolve to a
|
1667 | * {@link WebElement}
|
1668 | * - Null and undefined return values will resolve to null</li>
|
1669 | * - Booleans, numbers, and strings will resolve as is</li>
|
1670 | * - Functions will resolve to their string representation</li>
|
1671 | * - For arrays and objects, each member item will be converted according to
|
1672 | * the rules above
|
1673 | *
|
1674 | * @param {!(string|Function)} script The script to execute.
|
1675 | * @param {...*} var_args The arguments to pass to the script.
|
1676 | * @return {!Promise.<T>} A promise that will resolve to the
|
1677 | * scripts return value.
|
1678 | * @template T
|
1679 | */
|
1680 | executeScript<T>(script: string|Function, ...var_args: any[]): Promise<T>;
|
1681 |
|
1682 | /**
|
1683 | * Schedules a command to execute asynchronous JavaScript in the context of
|
1684 | * the currently selected frame or window. The script fragment will be
|
1685 | * executed as the body of an anonymous function. If the script is provided as
|
1686 | * a function object, that function will be converted to a string for
|
1687 | * injection into the target window.
|
1688 | *
|
1689 | * Any arguments provided in addition to the script will be included as script
|
1690 | * arguments and may be referenced using the {@code arguments} object.
|
1691 | * Arguments may be a boolean, number, string, or {@code WebElement}.
|
1692 | * Arrays and objects may also be used as script arguments as long as each
|
1693 | * item adheres to the types previously mentioned.
|
1694 | *
|
1695 | * Unlike executing synchronous JavaScript with {@link #executeScript},
|
1696 | * scripts executed with this function must explicitly signal they are
|
1697 | * finished by invoking the provided callback. This callback will always be
|
1698 | * injected into the executed function as the last argument, and thus may be
|
1699 | * referenced with {@code arguments[arguments.length - 1]}. The following
|
1700 | * steps will be taken for resolving this functions return value against the
|
1701 | * first argument to the script's callback function:
|
1702 | *
|
1703 | * - For a HTML element, the value will resolve to a
|
1704 | * {@link WebElement}
|
1705 | * - Null and undefined return values will resolve to null
|
1706 | * - Booleans, numbers, and strings will resolve as is
|
1707 | * - Functions will resolve to their string representation
|
1708 | * - For arrays and objects, each member item will be converted according to
|
1709 | * the rules above
|
1710 | *
|
1711 | * __Example #1:__ Performing a sleep that is synchronized with the currently
|
1712 | * selected window:
|
1713 | *
|
1714 | * var start = new Date().getTime();
|
1715 | * driver.executeAsyncScript(
|
1716 | * 'window.setTimeout(arguments[arguments.length - 1], 500);').
|
1717 | * then(function() {
|
1718 | * console.log(
|
1719 | * 'Elapsed time: ' + (new Date().getTime() - start) + ' ms');
|
1720 | * });
|
1721 | *
|
1722 | * __Example #2:__ Synchronizing a test with an AJAX application:
|
1723 | *
|
1724 | * var button = driver.findElement(By.id('compose-button'));
|
1725 | * button.click();
|
1726 | * driver.executeAsyncScript(
|
1727 | * 'var callback = arguments[arguments.length - 1];' +
|
1728 | * 'mailClient.getComposeWindowWidget().onload(callback);');
|
1729 | * driver.switchTo().frame('composeWidget');
|
1730 | * driver.findElement(By.id('to')).sendKeys('dog@example.com');
|
1731 | *
|
1732 | * __Example #3:__ Injecting a XMLHttpRequest and waiting for the result. In
|
1733 | * this example, the inject script is specified with a function literal. When
|
1734 | * using this format, the function is converted to a string for injection, so
|
1735 | * it should not reference any symbols not defined in the scope of the page
|
1736 | * under test.
|
1737 | *
|
1738 | * driver.executeAsyncScript(function() {
|
1739 | * var callback = arguments[arguments.length - 1];
|
1740 | * var xhr = new XMLHttpRequest();
|
1741 | * xhr.open('GET', '/resource/data.json', true);
|
1742 | * xhr.onreadystatechange = function() {
|
1743 | * if (xhr.readyState == 4) {
|
1744 | * callback(xhr.responseText);
|
1745 | * }
|
1746 | * }
|
1747 | * xhr.send('');
|
1748 | * }).then(function(str) {
|
1749 | * console.log(JSON.parse(str)['food']);
|
1750 | * });
|
1751 | *
|
1752 | * @param {!(string|Function)} script The script to execute.
|
1753 | * @param {...*} var_args The arguments to pass to the script.
|
1754 | * @return {!Promise.<T>} A promise that will resolve to the
|
1755 | * scripts return value.
|
1756 | * @template T
|
1757 | */
|
1758 | executeAsyncScript<T>(script: string|Function, ...var_args: any[]): Promise<T>;
|
1759 |
|
1760 | /**
|
1761 | * Schedules a command to wait for a condition to hold. The condition may be
|
1762 | * specified by a {@link Condition}, as a custom function, or
|
1763 | * as a {@link Promise}.
|
1764 | *
|
1765 | * For a {@link Condition} or function, the wait will repeatedly
|
1766 | * evaluate the condition until it returns a truthy value. If any errors occur
|
1767 | * while evaluating the condition, they will be allowed to propagate. In the
|
1768 | * event a condition returns a {@link Promise promise}, the
|
1769 | * polling loop will wait for it to be resolved and use the resolved value for
|
1770 | * whether the condition has been satisified. Note the resolution time for
|
1771 | * a promise is factored into whether a wait has timed out.
|
1772 | *
|
1773 | * Note, if the provided condition is a {@link WebElementCondition}, then
|
1774 | * the wait will return a {@link WebElementPromise} that will resolve to the
|
1775 | * element that satisified the condition.
|
1776 | *
|
1777 | * *Example:* waiting up to 10 seconds for an element to be present and
|
1778 | * visible on the page.
|
1779 | *
|
1780 | * var button = driver.wait(until.elementLocated(By.id('foo'), 10000);
|
1781 | * button.click();
|
1782 | *
|
1783 | * This function may also be used to block the command flow on the resolution
|
1784 | * of a {@link Promise promise}. When given a promise, the
|
1785 | * command will simply wait for its resolution before completing. A timeout
|
1786 | * may be provided to fail the command if the promise does not resolve before
|
1787 | * the timeout expires.
|
1788 | *
|
1789 | * *Example:* Suppose you have a function, `startTestServer`, that returns a
|
1790 | * promise for when a server is ready for requests. You can block a
|
1791 | * `WebDriver` client on this promise with:
|
1792 | *
|
1793 | * var started = startTestServer();
|
1794 | * driver.wait(started, 5 * 1000, 'Server should start within 5 seconds');
|
1795 | * driver.get(getServerUrl());
|
1796 | *
|
1797 | * @param {!WebElementCondition} condition The condition to
|
1798 | * wait on, defined as a promise, condition object, or a function to
|
1799 | * evaluate as a condition.
|
1800 | * @param {number=} opt_timeout How long to wait for the condition to be true.
|
1801 | * @param {string=} opt_message An optional message to use if the wait times
|
1802 | * out.
|
1803 | * @return {!WebElementPromise} A promise that will be fulfilled
|
1804 | * with the first truthy value returned by the condition function, or
|
1805 | * rejected if the condition times out.
|
1806 | * @template T
|
1807 | */
|
1808 | wait(condition: WebElementCondition, opt_timeout?: number, opt_message?: string):
|
1809 | WebElementPromise;
|
1810 |
|
1811 | /**
|
1812 | * Schedules a command to wait for a condition to hold. The condition may be
|
1813 | * specified by a {@link webdriver.Condition}, as a custom function, or
|
1814 | * as a {@link Promise}.
|
1815 | *
|
1816 | * For a {@link webdriver.Condition} or function, the wait will repeatedly
|
1817 | * evaluate the condition until it returns a truthy value. If any errors occur
|
1818 | * while evaluating the condition, they will be allowed to propagate. In the
|
1819 | * event a condition returns a {@link Promise promise}, the
|
1820 | * polling loop will wait for it to be resolved and use the resolved value for
|
1821 | * whether the condition has been satisified. Note the resolution time for
|
1822 | * a promise is factored into whether a wait has timed out.
|
1823 | *
|
1824 | * Note, if the provided condition is a {@link WebElementCondition}, then
|
1825 | * the wait will return a {@link WebElementPromise} that will resolve to the
|
1826 | * element that satisified the condition.
|
1827 | *
|
1828 | * *Example:* waiting up to 10 seconds for an element to be present and
|
1829 | * visible on the page.
|
1830 | *
|
1831 | * var button = driver.wait(until.elementLocated(By.id('foo'), 10000);
|
1832 | * button.click();
|
1833 | *
|
1834 | * This function may also be used to block the command flow on the resolution
|
1835 | * of a {@link Promise promise}. When given a promise, the
|
1836 | * command will simply wait for its resolution before completing. A timeout
|
1837 | * may be provided to fail the command if the promise does not resolve before
|
1838 | * the timeout expires.
|
1839 | *
|
1840 | * *Example:* Suppose you have a function, `startTestServer`, that returns a
|
1841 | * promise for when a server is ready for requests. You can block a
|
1842 | * `WebDriver` client on this promise with:
|
1843 | *
|
1844 | * var started = startTestServer();
|
1845 | * driver.wait(started, 5 * 1000, 'Server should start within 5 seconds');
|
1846 | * driver.get(getServerUrl());
|
1847 | *
|
1848 | * @param {!(Promise<T>|
|
1849 | * Condition<T>|
|
1850 | * function(!WebDriver): T)} condition The condition to
|
1851 | * wait on, defined as a promise, condition object, or a function to
|
1852 | * evaluate as a condition.
|
1853 | * @param {number=} opt_timeout How long to wait for the condition to be true.
|
1854 | * @param {string=} opt_message An optional message to use if the wait times
|
1855 | * out.
|
1856 | * @return {!Promise<T>} A promise that will be fulfilled
|
1857 | * with the first truthy value returned by the condition function, or
|
1858 | * rejected if the condition times out.
|
1859 | * @template T
|
1860 | */
|
1861 | wait<T>(
|
1862 | condition: PromiseLike<T>|Condition<T>|((driver: WebDriver) => T | PromiseLike<T>)|Function,
|
1863 | opt_timeout?: number, opt_message?: string): Promise<T>;
|
1864 |
|
1865 | /**
|
1866 | * Schedules a command to make the driver sleep for the given amount of time.
|
1867 | * @param {number} ms The amount of time, in milliseconds, to sleep.
|
1868 | * @return {!Promise.<void>} A promise that will be resolved
|
1869 | * when the sleep has finished.
|
1870 | */
|
1871 | sleep(ms: number): Promise<void>;
|
1872 |
|
1873 | /**
|
1874 | * Schedules a command to retrieve they current window handle.
|
1875 | * @return {!Promise.<string>} A promise that will be
|
1876 | * resolved with the current window handle.
|
1877 | */
|
1878 | getWindowHandle(): Promise<string>;
|
1879 |
|
1880 | /**
|
1881 | * Schedules a command to retrieve the current list of available window
|
1882 | * handles.
|
1883 | * @return {!Promise.<!Array.<string>>} A promise that will
|
1884 | * be resolved with an array of window handles.
|
1885 | */
|
1886 | getAllWindowHandles(): Promise<string[]>;
|
1887 |
|
1888 | /**
|
1889 | * Schedules a command to retrieve the current page's source. The page source
|
1890 | * returned is a representation of the underlying DOM: do not expect it to be
|
1891 | * formatted or escaped in the same way as the response sent from the web
|
1892 | * server.
|
1893 | * @return {!Promise.<string>} A promise that will be
|
1894 | * resolved with the current page source.
|
1895 | */
|
1896 | getPageSource(): Promise<string>;
|
1897 |
|
1898 | /**
|
1899 | * Schedules a command to close the current window.
|
1900 | * @return {!Promise.<void>} A promise that will be resolved
|
1901 | * when this command has completed.
|
1902 | */
|
1903 | close(): Promise<void>;
|
1904 |
|
1905 | /**
|
1906 | * Schedules a command to navigate to the given URL.
|
1907 | * @param {string} url The fully qualified URL to open.
|
1908 | * @return {!Promise.<void>} A promise that will be resolved
|
1909 | * when the document has finished loading.
|
1910 | */
|
1911 | get(url: string): Promise<void>;
|
1912 |
|
1913 | /**
|
1914 | * Schedules a command to retrieve the URL of the current page.
|
1915 | * @return {!Promise.<string>} A promise that will be
|
1916 | * resolved with the current URL.
|
1917 | */
|
1918 | getCurrentUrl(): Promise<string>;
|
1919 |
|
1920 | /**
|
1921 | * Schedules a command to retrieve the current page's title.
|
1922 | * @return {!Promise.<string>} A promise that will be
|
1923 | * resolved with the current page's title.
|
1924 | */
|
1925 | getTitle(): Promise<string>;
|
1926 |
|
1927 | /**
|
1928 | * Schedule a command to find an element on the page. If the element cannot be
|
1929 | * found, a {@link bot.ErrorCode.NO_SUCH_ELEMENT} result will be returned
|
1930 | * by the driver. Unlike other commands, this error cannot be suppressed. In
|
1931 | * other words, scheduling a command to find an element doubles as an assert
|
1932 | * that the element is present on the page. To test whether an element is
|
1933 | * present on the page, use {@link #findElements}.
|
1934 | *
|
1935 | * The search criteria for an element may be defined using one of the
|
1936 | * factories in the {@link By} namespace, or as a short-hand
|
1937 | * {@link By.Hash} object. For example, the following two statements
|
1938 | * are equivalent:
|
1939 | *
|
1940 | * var e1 = driver.findElement(By.id('foo'));
|
1941 | * var e2 = driver.findElement({id:'foo'});
|
1942 | *
|
1943 | * You may also provide a custom locator function, which takes as input this
|
1944 | * instance and returns a {@link WebElement}, or a promise that will resolve
|
1945 | * to a WebElement. If the returned promise resolves to an array of
|
1946 | * WebElements, WebDriver will use the first element. For example, to find the
|
1947 | * first visible link on a page, you could write:
|
1948 | *
|
1949 | * var link = driver.findElement(firstVisibleLink);
|
1950 | *
|
1951 | * function firstVisibleLink(driver) {
|
1952 | * var links = driver.findElements(By.tagName('a'));
|
1953 | * return promise.filter(links, function(link) {
|
1954 | * return link.isDisplayed();
|
1955 | * });
|
1956 | * }
|
1957 | *
|
1958 | * @param {!(by.By|Function)} locator The locator to use.
|
1959 | * @return {!WebElementPromise} A WebElement that can be used to issue
|
1960 | * commands against the located element. If the element is not found, the
|
1961 | * element will be invalidated and all scheduled commands aborted.
|
1962 | */
|
1963 | findElement(locator: Locator): WebElementPromise;
|
1964 |
|
1965 | /**
|
1966 | * Schedule a command to search for multiple elements on the page.
|
1967 | *
|
1968 | * @param {!(by.By|Function)} locator The locator to use.
|
1969 | * @return {!Promise.<!Array.<!WebElement>>} A
|
1970 | * promise that will resolve to an array of WebElements.
|
1971 | */
|
1972 | findElements(locator: Locator): Promise<WebElement[]>;
|
1973 |
|
1974 | /**
|
1975 | * Schedule a command to take a screenshot. The driver makes a best effort to
|
1976 | * return a screenshot of the following, in order of preference:
|
1977 | *
|
1978 | * 1. Entire page
|
1979 | * 2. Current window
|
1980 | * 3. Visible portion of the current frame
|
1981 | * 4. The entire display containing the browser
|
1982 | *
|
1983 | * @return {!Promise<string>} A promise that will be
|
1984 | * resolved to the screenshot as a base-64 encoded PNG.
|
1985 | */
|
1986 | takeScreenshot(): Promise<string>;
|
1987 |
|
1988 | /**
|
1989 | * @return {!Options} The options interface for this
|
1990 | * instance.
|
1991 | */
|
1992 | manage(): Options;
|
1993 |
|
1994 | /**
|
1995 | * @return {!Navigation} The navigation interface for this
|
1996 | * instance.
|
1997 | */
|
1998 | navigate(): Navigation;
|
1999 |
|
2000 | /**
|
2001 | * @return {!TargetLocator} The target locator interface for
|
2002 | * this instance.
|
2003 | */
|
2004 | switchTo(): TargetLocator;
|
2005 |
|
2006 | // endregion
|
2007 | }
|
2008 |
|
2009 | /**
|
2010 | * A thenable wrapper around a {@linkplain webdriver.IWebDriver IWebDriver}
|
2011 | * instance that allows commands to be issued directly instead of having to
|
2012 | * repeatedly call `then`:
|
2013 | *
|
2014 | * let driver = new Builder().build();
|
2015 | * driver.then(d => d.get(url)); // You can do this...
|
2016 | * driver.get(url); // ...or this
|
2017 | *
|
2018 | * If the driver instance fails to resolve (e.g. the session cannot be created),
|
2019 | * every issued command will fail.
|
2020 | *
|
2021 | * @extends {webdriver.IWebDriver}
|
2022 | * @extends {Promise<!webdriver.IWebDriver>}
|
2023 | * @interface
|
2024 | */
|
2025 | export interface ThenableWebDriver extends WebDriver, Promise<WebDriver> {}
|
2026 |
|
2027 | export interface IWebElementId { [ELEMENT: string]: string; }
|
2028 |
|
2029 | /**
|
2030 | * Represents a DOM element. WebElements can be found by searching from the
|
2031 | * document root using a {@code WebDriver} instance, or by searching
|
2032 | * under another {@code WebElement}:
|
2033 | * <pre><code>
|
2034 | * driver.get('http://www.google.com');
|
2035 | * var searchForm = driver.findElement(By.tagName('form'));
|
2036 | * var searchBox = searchForm.findElement(By.name('q'));
|
2037 | * searchBox.sendKeys('webdriver');
|
2038 | * </code></pre>
|
2039 | *
|
2040 | * The WebElement is implemented as a promise for compatibility with the promise
|
2041 | * API. It will always resolve itself when its internal state has been fully
|
2042 | * resolved and commands may be issued against the element. This can be used to
|
2043 | * catch errors when an element cannot be located on the page:
|
2044 | * <pre><code>
|
2045 | * driver.findElement(By.id('not-there')).then(function(element) {
|
2046 | * alert('Found an element that was not expected to be there!');
|
2047 | * }, function(error) {
|
2048 | * alert('The element was not found, as expected');
|
2049 | * });
|
2050 | * </code></pre>
|
2051 | */
|
2052 | export interface IWebElement {
|
2053 | // region Methods
|
2054 |
|
2055 | /**
|
2056 | * Schedules a command to click on this element.
|
2057 | * @return {!Promise} A promise that will be resolved when
|
2058 | * the click command has completed.
|
2059 | */
|
2060 | click(): Promise<void>;
|
2061 |
|
2062 | /**
|
2063 | * Schedules a command to type a sequence on the DOM element represented by
|
2064 | * this instance.
|
2065 | *
|
2066 | * Modifier keys (SHIFT, CONTROL, ALT, META) are stateful; once a modifier is
|
2067 | * processed in the key sequence, that key state is toggled until one of the
|
2068 | * following occurs:
|
2069 | *
|
2070 | * - The modifier key is encountered again in the sequence. At this point the
|
2071 | * state of the key is toggled (along with the appropriate keyup/down
|
2072 | * events).
|
2073 | * - The {@link input.Key.NULL} key is encountered in the sequence. When
|
2074 | * this key is encountered, all modifier keys current in the down state are
|
2075 | * released (with accompanying keyup events). The NULL key can be used to
|
2076 | * simulate common keyboard shortcuts:
|
2077 | *
|
2078 | * element.sendKeys('text was',
|
2079 | * Key.CONTROL, 'a', Key.NULL,
|
2080 | * 'now text is');
|
2081 | * // Alternatively:
|
2082 | * element.sendKeys('text was',
|
2083 | * Key.chord(Key.CONTROL, 'a'),
|
2084 | * 'now text is');
|
2085 | *
|
2086 | * - The end of the key sequence is encountered. When there are no more keys
|
2087 | * to type, all depressed modifier keys are released (with accompanying
|
2088 | * keyup events).
|
2089 | *
|
2090 | * If this element is a file input ({@code <input type='file'>}), the
|
2091 | * specified key sequence should specify the path to the file to attach to
|
2092 | * the element. This is analogous to the user clicking 'Browse...' and
|
2093 | * entering the path into the file select dialog.
|
2094 | *
|
2095 | * var form = driver.findElement(By.css('form'));
|
2096 | * var element = form.findElement(By.css('input[type=file]'));
|
2097 | * element.sendKeys('/path/to/file.txt');
|
2098 | * form.submit();
|
2099 | *
|
2100 | * For uploads to function correctly, the entered path must reference a file
|
2101 | * on the _browser's_ machine, not the local machine running this script. When
|
2102 | * running against a remote Selenium server, a {@link input.FileDetector}
|
2103 | * may be used to transparently copy files to the remote machine before
|
2104 | * attempting to upload them in the browser.
|
2105 | *
|
2106 | * __Note:__ On browsers where native keyboard events are not supported
|
2107 | * (e.g. Firefox on OS X), key events will be synthesized. Special
|
2108 | * punctuation keys will be synthesized according to a standard QWERTY en-us
|
2109 | * keyboard layout.
|
2110 | *
|
2111 | * @param {...(number|string|!IThenable<(number|string)>)} var_args The
|
2112 | * sequence of keys to type. Number keys may be referenced numerically or
|
2113 | * by string (1 or '1'). All arguments will be joined into a single
|
2114 | * sequence.
|
2115 | * @return {!Promise} A promise that will be resolved when all
|
2116 | * keys have been typed.
|
2117 | */
|
2118 | sendKeys(...var_args: Array<number|string|Promise<string|number>>): Promise<void>;
|
2119 |
|
2120 | /**
|
2121 | * Schedules a command to query for the tag/node name of this element.
|
2122 | * @return {!Promise} A promise that will be resolved with the
|
2123 | * element's tag name.
|
2124 | */
|
2125 | getTagName(): Promise<string>;
|
2126 |
|
2127 | /**
|
2128 | * Schedules a command to query for the computed style of the element
|
2129 | * represented by this instance. If the element inherits the named style from
|
2130 | * its parent, the parent will be queried for its value. Where possible,
|
2131 | * color values will be converted to their hex representation (e.g. #00ff00
|
2132 | * instead of rgb(0, 255, 0)). <p/> <em>Warning:</em> the value returned will
|
2133 | * be as the browser interprets it, so it may be tricky to form a proper
|
2134 | * assertion.
|
2135 | *
|
2136 | * @param {string} cssStyleProperty The name of the CSS style property to look
|
2137 | * up.
|
2138 | * @return {!Promise} A promise that will be resolved with the
|
2139 | * requested CSS value.
|
2140 | */
|
2141 | getCssValue(cssStyleProperty: string): Promise<string>;
|
2142 |
|
2143 | /**
|
2144 | * Schedules a command to query for the value of the given attribute of the
|
2145 | * element. Will return the current value even if it has been modified after
|
2146 | * the page has been loaded. More exactly, this method will return the value
|
2147 | * of the given attribute, unless that attribute is not present, in which case
|
2148 | * the value of the property with the same name is returned. If neither value
|
2149 | * is set, null is returned. The 'style' attribute is converted as best can be
|
2150 | * to a text representation with a trailing semi-colon. The following are
|
2151 | * deemed to be 'boolean' attributes and will be returned as thus:
|
2152 | *
|
2153 | * <p>async, autofocus, autoplay, checked, compact, complete, controls,
|
2154 | * declare, defaultchecked, defaultselected, defer, disabled, draggable,
|
2155 | * ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap,
|
2156 | * itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate,
|
2157 | * nowrap, open, paused, pubdate, readonly, required, reversed, scoped,
|
2158 | * seamless, seeking, selected, spellcheck, truespeed, willvalidate
|
2159 | *
|
2160 | * <p>Finally, the following commonly mis-capitalized attribute/property names
|
2161 | * are evaluated as expected:
|
2162 | * <ul>
|
2163 | * <li>'class'
|
2164 | * <li>'readonly'
|
2165 | * </ul>
|
2166 | * @param {string} attributeName The name of the attribute to query.
|
2167 | * @return {!Promise} A promise that will be resolved with the
|
2168 | * attribute's value.
|
2169 | */
|
2170 | getAttribute(attributeName: string): Promise<string>;
|
2171 |
|
2172 | /**
|
2173 | * Get the visible (i.e. not hidden by CSS) innerText of this element,
|
2174 | * including sub-elements, without any leading or trailing whitespace.
|
2175 | * @return {!Promise} A promise that will be resolved with the
|
2176 | * element's visible text.
|
2177 | */
|
2178 | getText(): Promise<string>;
|
2179 |
|
2180 | /**
|
2181 | * Schedules a command to compute the size of this element's bounding box, in
|
2182 | * pixels.
|
2183 | * @return {!Promise} A promise that will be resolved with the
|
2184 | * element's size as a {@code {width:number, height:number}} object.
|
2185 | */
|
2186 | getSize(): Promise<ISize>;
|
2187 |
|
2188 | /**
|
2189 | * Returns an object describing an element's location, in pixels relative to
|
2190 | * the document element, and the element's size in pixels.
|
2191 | */
|
2192 | getRect(): Promise<IRectangle>;
|
2193 |
|
2194 | /**
|
2195 | * Schedules a command to compute the location of this element in page space.
|
2196 | * @return {!Promise} A promise that will be resolved to the
|
2197 | * element's location as a {@code {x:number, y:number}} object.
|
2198 | */
|
2199 | getLocation(): Promise<ILocation>;
|
2200 |
|
2201 | /**
|
2202 | * Schedules a command to query whether the DOM element represented by this
|
2203 | * instance is enabled, as dicted by the {@code disabled} attribute.
|
2204 | * @return {!Promise} A promise that will be resolved with
|
2205 | * whether this element is currently enabled.
|
2206 | */
|
2207 | isEnabled(): Promise<boolean>;
|
2208 |
|
2209 | /**
|
2210 | * Schedules a command to query whether this element is selected.
|
2211 | * @return {!Promise} A promise that will be resolved with
|
2212 | * whether this element is currently selected.
|
2213 | */
|
2214 | isSelected(): Promise<boolean>;
|
2215 |
|
2216 | /**
|
2217 | * Schedules a command to submit the form containing this element (or this
|
2218 | * element if it is a FORM element). This command is a no-op if the element is
|
2219 | * not contained in a form.
|
2220 | * @return {!Promise} A promise that will be resolved when
|
2221 | * the form has been submitted.
|
2222 | */
|
2223 | submit(): Promise<void>;
|
2224 |
|
2225 | /**
|
2226 | * Schedules a command to clear the {@code value} of this element. This
|
2227 | * command has no effect if the underlying DOM element is neither a text INPUT
|
2228 | * element nor a TEXTAREA element.
|
2229 | * @return {!Promise} A promise that will be resolved when
|
2230 | * the element has been cleared.
|
2231 | */
|
2232 | clear(): Promise<void>;
|
2233 |
|
2234 | /**
|
2235 | * Schedules a command to test whether this element is currently displayed.
|
2236 | * @return {!Promise} A promise that will be resolved with
|
2237 | * whether this element is currently visible on the page.
|
2238 | */
|
2239 | isDisplayed(): Promise<boolean>;
|
2240 |
|
2241 | /**
|
2242 | * @return {!Promise.<WebElement.Id>} A promise
|
2243 | * that resolves to this element's JSON representation as defined by the
|
2244 | * WebDriver wire protocol.
|
2245 | * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol
|
2246 | */
|
2247 | getId(): Promise<IWebElementId>;
|
2248 |
|
2249 | // endregion
|
2250 | }
|
2251 |
|
2252 | export interface IWebElementFinders {
|
2253 | /**
|
2254 | * Schedule a command to find a descendant of this element. If the element
|
2255 | * cannot be found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will
|
2256 | * be returned by the driver. Unlike other commands, this error cannot be
|
2257 | * suppressed. In other words, scheduling a command to find an element doubles
|
2258 | * as an assert that the element is present on the page. To test whether an
|
2259 | * element is present on the page, use {@code #findElements}.
|
2260 | *
|
2261 | * <p>The search criteria for an element may be defined using one of the
|
2262 | * factories in the {@link By} namespace, or as a short-hand
|
2263 | * {@link By.Hash} object. For example, the following two statements
|
2264 | * are equivalent:
|
2265 | * <code><pre>
|
2266 | * var e1 = element.findElement(By.id('foo'));
|
2267 | * var e2 = element.findElement({id:'foo'});
|
2268 | * </pre></code>
|
2269 | *
|
2270 | * <p>You may also provide a custom locator function, which takes as input
|
2271 | * this WebDriver instance and returns a {@link WebElement}, or a
|
2272 | * promise that will resolve to a WebElement. For example, to find the first
|
2273 | * visible link on a page, you could write:
|
2274 | * <code><pre>
|
2275 | * var link = element.findElement(firstVisibleLink);
|
2276 | *
|
2277 | * function firstVisibleLink(element) {
|
2278 | * var links = element.findElements(By.tagName('a'));
|
2279 | * return promise.filter(links, function(link) {
|
2280 | * return links.isDisplayed();
|
2281 | * }).then(function(visibleLinks) {
|
2282 | * return visibleLinks[0];
|
2283 | * });
|
2284 | * }
|
2285 | * </pre></code>
|
2286 | *
|
2287 | * @param {!(Locator|By.Hash|Function)} locator The
|
2288 | * locator strategy to use when searching for the element.
|
2289 | * @return {!WebElement} A WebElement that can be used to issue
|
2290 | * commands against the located element. If the element is not found, the
|
2291 | * element will be invalidated and all scheduled commands aborted.
|
2292 | */
|
2293 | findElement(locator: Locator): WebElementPromise;
|
2294 |
|
2295 | /**
|
2296 | * Schedules a command to find all of the descendants of this element that
|
2297 | * match the given search criteria.
|
2298 | *
|
2299 | * @param {!(Locator|By.Hash|Function)} locator The
|
2300 | * locator strategy to use when searching for the elements.
|
2301 | * @return {!Promise.<!Array.<!WebElement>>} A
|
2302 | * promise that will resolve to an array of WebElements.
|
2303 | */
|
2304 | findElements(locator: Locator): Promise<WebElement[]>;
|
2305 | }
|
2306 |
|
2307 | /**
|
2308 | * Defines an object that can be asynchronously serialized to its WebDriver
|
2309 | * wire representation.
|
2310 | *
|
2311 | * @constructor
|
2312 | * @template T
|
2313 | */
|
2314 | export interface Serializable<T> {
|
2315 | /**
|
2316 | * Returns either this instance's serialized represention, if immediately
|
2317 | * available, or a promise for its serialized representation. This function is
|
2318 | * conceptually equivalent to objects that have a {@code toJSON()} property,
|
2319 | * except the serialize() result may be a promise or an object containing a
|
2320 | * promise (which are not directly JSON friendly).
|
2321 | *
|
2322 | * @return {!(T|IThenable.<!T>)} This instance's serialized wire format.
|
2323 | */
|
2324 | serialize(): T|Promise<T>;
|
2325 | }
|
2326 |
|
2327 | /**
|
2328 | * Represents a DOM element. WebElements can be found by searching from the
|
2329 | * document root using a {@link WebDriver} instance, or by searching
|
2330 | * under another WebElement:
|
2331 | *
|
2332 | * driver.get('http://www.google.com');
|
2333 | * var searchForm = driver.findElement(By.tagName('form'));
|
2334 | * var searchBox = searchForm.findElement(By.name('q'));
|
2335 | * searchBox.sendKeys('webdriver');
|
2336 | *
|
2337 | * The WebElement is implemented as a promise for compatibility with the promise
|
2338 | * API. It will always resolve itself when its internal state has been fully
|
2339 | * resolved and commands may be issued against the element. This can be used to
|
2340 | * catch errors when an element cannot be located on the page:
|
2341 | *
|
2342 | * driver.findElement(By.id('not-there')).then(function(element) {
|
2343 | * alert('Found an element that was not expected to be there!');
|
2344 | * }, function(error) {
|
2345 | * alert('The element was not found, as expected');
|
2346 | * });
|
2347 | *
|
2348 | * @extends {Serializable.<WebElement.Id>}
|
2349 | */
|
2350 | export class WebElement implements Serializable<IWebElementId> {
|
2351 | /**
|
2352 | * @param {!WebDriver} driver the parent WebDriver instance for this element.
|
2353 | * @param {(!IThenable<string>|string)} id The server-assigned opaque ID for
|
2354 | * the underlying DOM element.
|
2355 | */
|
2356 | constructor(driver: WebDriver, id: Promise<string>|string);
|
2357 |
|
2358 | /**
|
2359 | * @param {string} id The raw ID.
|
2360 | * @param {boolean=} opt_noLegacy Whether to exclude the legacy element key.
|
2361 | * @return {!Object} The element ID for use with WebDriver's wire protocol.
|
2362 | */
|
2363 | static buildId(id: string, opt_noLegacy?: boolean): IWebElementId;
|
2364 |
|
2365 | /**
|
2366 | * Extracts the encoded WebElement ID from the object.
|
2367 | *
|
2368 | * @param {?} obj The object to extract the ID from.
|
2369 | * @return {string} the extracted ID.
|
2370 | * @throws {TypeError} if the object is not a valid encoded ID.
|
2371 | */
|
2372 | static extractId(obj: IWebElementId): string;
|
2373 |
|
2374 | /**
|
2375 | * @param {?} obj the object to test.
|
2376 | * @return {boolean} whether the object is a valid encoded WebElement ID.
|
2377 | */
|
2378 | static isId(obj: IWebElementId): boolean;
|
2379 |
|
2380 | /**
|
2381 | * Compares two WebElements for equality.
|
2382 | *
|
2383 | * @param {!WebElement} a A WebElement.
|
2384 | * @param {!WebElement} b A WebElement.
|
2385 | * @return {!Promise<boolean>} A promise that will be
|
2386 | * resolved to whether the two WebElements are equal.
|
2387 | */
|
2388 | static equals(a: WebElement, b: WebElement): Promise<boolean>;
|
2389 |
|
2390 | /**
|
2391 | * @return {!WebDriver} The parent driver for this instance.
|
2392 | */
|
2393 | getDriver(): WebDriver;
|
2394 |
|
2395 | /**
|
2396 | * @return {!Promise<string>} A promise that resolves to
|
2397 | * the server-assigned opaque ID assigned to this element.
|
2398 | */
|
2399 | getId(): Promise<string>;
|
2400 |
|
2401 | /**
|
2402 | * Schedule a command to find a descendant of this element. If the element
|
2403 | * cannot be found, a {@link bot.ErrorCode.NO_SUCH_ELEMENT} result will
|
2404 | * be returned by the driver. Unlike other commands, this error cannot be
|
2405 | * suppressed. In other words, scheduling a command to find an element doubles
|
2406 | * as an assert that the element is present on the page. To test whether an
|
2407 | * element is present on the page, use {@link #findElements}.
|
2408 | *
|
2409 | * The search criteria for an element may be defined using one of the
|
2410 | * factories in the {@link By} namespace, or as a short-hand
|
2411 | * {@link By.Hash} object. For example, the following two statements
|
2412 | * are equivalent:
|
2413 | *
|
2414 | * var e1 = element.findElement(By.id('foo'));
|
2415 | * var e2 = element.findElement({id:'foo'});
|
2416 | *
|
2417 | * You may also provide a custom locator function, which takes as input
|
2418 | * this WebDriver instance and returns a {@link WebElement}, or a
|
2419 | * promise that will resolve to a WebElement. For example, to find the first
|
2420 | * visible link on a page, you could write:
|
2421 | *
|
2422 | * var link = element.findElement(firstVisibleLink);
|
2423 | *
|
2424 | * function firstVisibleLink(element) {
|
2425 | * var links = element.findElements(By.tagName('a'));
|
2426 | * return promise.filter(links, function(link) {
|
2427 | * return links.isDisplayed();
|
2428 | * }).then(function(visibleLinks) {
|
2429 | * return visibleLinks[0];
|
2430 | * });
|
2431 | * }
|
2432 | *
|
2433 | * @param {!(by.By|Function)} locator The locator strategy to use when
|
2434 | * searching for the element.
|
2435 | * @return {!WebElementPromise} A WebElement that can be used to issue
|
2436 | * commands against the located element. If the element is not found, the
|
2437 | * element will be invalidated and all scheduled commands aborted.
|
2438 | */
|
2439 | findElement(locator: Locator): WebElementPromise;
|
2440 |
|
2441 | /**
|
2442 | * Schedules a command to find all of the descendants of this element that
|
2443 | * match the given search criteria.
|
2444 | *
|
2445 | * @param {!(by.By|Function)} locator The locator strategy to use when
|
2446 | * searching for the element.
|
2447 | * @return {!Promise<!Array<!WebElement>>} A
|
2448 | * promise that will resolve to an array of WebElements.
|
2449 | */
|
2450 | findElements(locator: Locator): Promise<WebElement[]>;
|
2451 |
|
2452 | /**
|
2453 | * Schedules a command to click on this element.
|
2454 | * @return {!Promise.<void>} A promise that will be resolved
|
2455 | * when the click command has completed.
|
2456 | */
|
2457 | click(): Promise<void>;
|
2458 |
|
2459 | /**
|
2460 | * Schedules a command to type a sequence on the DOM element represented by
|
2461 | * this promsieinstance.
|
2462 | *
|
2463 | * Modifier keys (SHIFT, CONTROL, ALT, META) are stateful; once a modifier is
|
2464 | * processed in the keysequence, that key state is toggled until one of the
|
2465 | * following occurs:
|
2466 | *
|
2467 | * - The modifier key is encountered again in the sequence. At this point the
|
2468 | * state of the key is toggled (along with the appropriate keyup/down
|
2469 | * events).
|
2470 | * - The {@link Key.NULL} key is encountered in the sequence. When
|
2471 | * this key is encountered, all modifier keys current in the down state are
|
2472 | * released (with accompanying keyup events). The NULL key can be used to
|
2473 | * simulate common keyboard shortcuts:
|
2474 | *
|
2475 | * element.sendKeys('text was',
|
2476 | * Key.CONTROL, 'a', Key.NULL,
|
2477 | * 'now text is');
|
2478 | * // Alternatively:
|
2479 | * element.sendKeys('text was',
|
2480 | * Key.chord(Key.CONTROL, 'a'),
|
2481 | * 'now text is');
|
2482 | *
|
2483 | * - The end of the keysequence is encountered. When there are no more keys
|
2484 | * to type, all depressed modifier keys are released (with accompanying
|
2485 | * keyup events).
|
2486 | *
|
2487 | * If this element is a file input ({@code <input type='file'>}), the
|
2488 | * specified key sequence should specify the path to the file to attach to
|
2489 | * the element. This is analgous to the user clicking 'Browse...' and entering
|
2490 | * the path into the file select dialog.
|
2491 | *
|
2492 | * var form = driver.findElement(By.css('form'));
|
2493 | * var element = form.findElement(By.css('input[type=file]'));
|
2494 | * element.sendKeys('/path/to/file.txt');
|
2495 | * form.submit();
|
2496 | *
|
2497 | * For uploads to function correctly, the entered path must reference a file
|
2498 | * on the _browser's_ machine, not the local machine running this script. When
|
2499 | * running against a remote Selenium server, a {@link FileDetector}
|
2500 | * may be used to transparently copy files to the remote machine before
|
2501 | * attempting to upload them in the browser.
|
2502 | *
|
2503 | * __Note:__ On browsers where native keyboard events are not supported
|
2504 | * (e.g. Firefox on OS X), key events will be synthesized. Special
|
2505 | * punctionation keys will be synthesized according to a standard QWERTY en-us
|
2506 | * keyboard layout.
|
2507 | *
|
2508 | * @param {...(string|!Promise<string>)} var_args The sequence
|
2509 | * of keys to type. All arguments will be joined into a single sequence.
|
2510 | * @return {!Promise.<void>} A promise that will be resolved
|
2511 | * when all keys have been typed.
|
2512 | */
|
2513 | sendKeys(...var_args: Array<string|number|Promise<string|number>>): Promise<void>;
|
2514 |
|
2515 | /**
|
2516 | * Schedules a command to query for the tag/node name of this element.
|
2517 | * @return {!Promise.<string>} A promise that will be
|
2518 | * resolved with the element's tag name.
|
2519 | */
|
2520 | getTagName(): Promise<string>;
|
2521 |
|
2522 | /**
|
2523 | * Schedules a command to query for the computed style of the element
|
2524 | * represented by this instance. If the element inherits the named style from
|
2525 | * its parent, the parent will be queried for its value. Where possible,
|
2526 | * color values will be converted to their hex representation (e.g. #00ff00
|
2527 | * instead of rgb(0, 255, 0)).
|
2528 | *
|
2529 | * _Warning:_ the value returned will be as the browser interprets it, so
|
2530 | * it may be tricky to form a proper assertion.
|
2531 | *
|
2532 | * @param {string} cssStyleProperty The name of the CSS style property to look
|
2533 | * up.
|
2534 | * @return {!Promise<string>} A promise that will be
|
2535 | * resolved with the requested CSS value.
|
2536 | */
|
2537 | getCssValue(cssStyleProperty: string): Promise<string>;
|
2538 |
|
2539 | /**
|
2540 | * Schedules a command to query for the value of the given attribute of the
|
2541 | * element. Will return the current value, even if it has been modified after
|
2542 | * the page has been loaded. More exactly, this method will return the value
|
2543 | * of the given attribute, unless that attribute is not present, in which case
|
2544 | * the value of the property with the same name is returned. If neither value
|
2545 | * is set, null is returned (for example, the 'value' property of a textarea
|
2546 | * element). The 'style' attribute is converted as best can be to a
|
2547 | * text representation with a trailing semi-colon. The following are deemed to
|
2548 | * be 'boolean' attributes and will return either 'true' or null:
|
2549 | *
|
2550 | * async, autofocus, autoplay, checked, compact, complete, controls, declare,
|
2551 | * defaultchecked, defaultselected, defer, disabled, draggable, ended,
|
2552 | * formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope,
|
2553 | * loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open,
|
2554 | * paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
|
2555 | * selected, spellcheck, truespeed, willvalidate
|
2556 | *
|
2557 | * Finally, the following commonly mis-capitalized attribute/property names
|
2558 | * are evaluated as expected:
|
2559 | *
|
2560 | * - 'class'
|
2561 | * - 'readonly'
|
2562 | *
|
2563 | * @param {string} attributeName The name of the attribute to query.
|
2564 | * @return {!Promise.<?string>} A promise that will be
|
2565 | * resolved with the attribute's value. The returned value will always be
|
2566 | * either a string or null.
|
2567 | */
|
2568 | getAttribute(attributeName: string): Promise<string>;
|
2569 |
|
2570 | /**
|
2571 | * Get the visible (i.e. not hidden by CSS) innerText of this element,
|
2572 | * including sub-elements, without any leading or trailing whitespace.
|
2573 | * @return {!Promise.<string>} A promise that will be
|
2574 | * resolved with the element's visible text.
|
2575 | */
|
2576 | getText(): Promise<string>;
|
2577 |
|
2578 | /**
|
2579 | * DEPRECATED 3.0
|
2580 | * Schedules a command to compute the size of this element's bounding box, in
|
2581 | * pixels.
|
2582 | * @return {!Promise.<{width: number, height: number}>} A
|
2583 | * promise that will be resolved with the element's size as a
|
2584 | * {@code {width:number, height:number}} object.
|
2585 | */
|
2586 | getSize(): Promise<ISize>;
|
2587 |
|
2588 | /**
|
2589 | * Returns an object describing an element's location, in pixels relative to
|
2590 | * the document element, and the element's size in pixels.
|
2591 | */
|
2592 | getRect(): Promise<IRectangle>;
|
2593 |
|
2594 | /**
|
2595 | * DEPRECATED 3.0
|
2596 | * Schedules a command to compute the location of this element in page space.
|
2597 | * @return {!Promise.<{x: number, y: number}>} A promise that
|
2598 | * will be resolved to the element's location as a
|
2599 | * {@code {x:number, y:number}} object.
|
2600 | */
|
2601 | getLocation(): Promise<ILocation>;
|
2602 |
|
2603 | /**
|
2604 | * Schedules a command to query whether the DOM element represented by this
|
2605 | * instance is enabled, as dicted by the {@code disabled} attribute.
|
2606 | * @return {!Promise.<boolean>} A promise that will be
|
2607 | * resolved with whether this element is currently enabled.
|
2608 | */
|
2609 | isEnabled(): Promise<boolean>;
|
2610 |
|
2611 | /**
|
2612 | * Schedules a command to query whether this element is selected.
|
2613 | * @return {!Promise.<boolean>} A promise that will be
|
2614 | * resolved with whether this element is currently selected.
|
2615 | */
|
2616 | isSelected(): Promise<boolean>;
|
2617 |
|
2618 | /**
|
2619 | * Schedules a command to submit the form containing this element (or this
|
2620 | * element if it is a FORM element). This command is a no-op if the element is
|
2621 | * not contained in a form.
|
2622 | * @return {!Promise.<void>} A promise that will be resolved
|
2623 | * when the form has been submitted.
|
2624 | */
|
2625 | submit(): Promise<void>;
|
2626 |
|
2627 | /**
|
2628 | * Schedules a command to clear the `value` of this element. This command has
|
2629 | * no effect if the underlying DOM element is neither a text INPUT element
|
2630 | * nor a TEXTAREA element.
|
2631 | * @return {!Promise<void>} A promise that will be resolved
|
2632 | * when the element has been cleared.
|
2633 | */
|
2634 | clear(): Promise<void>;
|
2635 |
|
2636 | /**
|
2637 | * Schedules a command to test whether this element is currently displayed.
|
2638 | * @return {!Promise.<boolean>} A promise that will be
|
2639 | * resolved with whether this element is currently visible on the page.
|
2640 | */
|
2641 | isDisplayed(): Promise<boolean>;
|
2642 |
|
2643 | /**
|
2644 | * Take a screenshot of the visible region encompassed by this element's
|
2645 | * bounding rectangle.
|
2646 | *
|
2647 | * @param {boolean=} opt_scroll Optional argument that indicates whether the
|
2648 | * element should be scrolled into view before taking a screenshot.
|
2649 | * Defaults to false.
|
2650 | * @return {!Promise<string>} A promise that will be
|
2651 | * resolved to the screenshot as a base-64 encoded PNG.
|
2652 | */
|
2653 | takeScreenshot(opt_scroll?: boolean): Promise<string>;
|
2654 |
|
2655 | /** @override */
|
2656 | serialize(): Promise<IWebElementId>;
|
2657 | }
|
2658 |
|
2659 | /**
|
2660 | * WebElementPromise is a promise that will be fulfilled with a WebElement.
|
2661 | * This serves as a forward proxy on WebElement, allowing calls to be
|
2662 | * scheduled without directly on this instance before the underlying
|
2663 | * WebElement has been fulfilled. In other words, the following two statements
|
2664 | * are equivalent:
|
2665 | * <pre><code>
|
2666 | * driver.findElement({id: 'my-button'}).click();
|
2667 | * driver.findElement({id: 'my-button'}).then(function(el) {
|
2668 | * return el.click();
|
2669 | * });
|
2670 | * </code></pre>
|
2671 | *
|
2672 | * @param {!WebDriver} driver The parent WebDriver instance for this
|
2673 | * element.
|
2674 | * @param {!Promise.<!WebElement>} el A promise
|
2675 | * that will resolve to the promised element.
|
2676 | * @constructor
|
2677 | * @extends {WebElement}
|
2678 | * @implements {promise.Thenable.<!WebElement>}
|
2679 | * @final
|
2680 | */
|
2681 | export interface WebElementPromise extends Promise<WebElement> {}
|
2682 |
|
2683 | /**
|
2684 | * Implement WebElementPromise
|
2685 | */
|
2686 | export class WebElementPromise extends WebElement {
|
2687 | /**
|
2688 | * @param {!WebDriver} driver The parent WebDriver instance for this
|
2689 | * element.
|
2690 | * @param {!Promise<!WebElement>} el A promise
|
2691 | * that will resolve to the promised element.
|
2692 | */
|
2693 | constructor(driver: WebDriver, el: Promise<WebElement>);
|
2694 | }
|
2695 |
|
2696 | /**
|
2697 | * Contains information about a WebDriver session.
|
2698 | */
|
2699 | export class Session {
|
2700 | // region Constructors
|
2701 |
|
2702 | /**
|
2703 | * @param {string} id The session ID.
|
2704 | * @param {!(Object|Capabilities)} capabilities The session
|
2705 | * capabilities.
|
2706 | * @constructor
|
2707 | */
|
2708 | constructor(id: string, capabilities: Capabilities|{});
|
2709 |
|
2710 | // endregion
|
2711 |
|
2712 | // region Methods
|
2713 |
|
2714 | /**
|
2715 | * @return {string} This session's ID.
|
2716 | */
|
2717 | getId(): string;
|
2718 |
|
2719 | /**
|
2720 | * @return {!Capabilities} This session's capabilities.
|
2721 | */
|
2722 | getCapabilities(): Capabilities;
|
2723 |
|
2724 | /**
|
2725 | * Retrieves the value of a specific capability.
|
2726 | * @param {string} key The capability to retrieve.
|
2727 | * @return {*} The capability value.
|
2728 | */
|
2729 | getCapability(key: string): any;
|
2730 |
|
2731 | /**
|
2732 | * Returns the JSON representation of this object, which is just the string
|
2733 | * session ID.
|
2734 | * @return {string} The JSON representation of this Session.
|
2735 | */
|
2736 | toJSON(): string;
|
2737 |
|
2738 | // endregion
|
2739 | }
|
2740 |
|
\ | No newline at end of file |