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