1 | import LogInspector = require("./bidi/logInspector");
|
2 | import BrowsingContext = require("./bidi/browsingContext");
|
3 | import * as chrome from "./chrome";
|
4 | import * as edge from "./edge";
|
5 | import * as firefox from "./firefox";
|
6 | import * as http from "./http";
|
7 | import * as ie from "./ie";
|
8 | import { By, ByHash, RelativeBy } from "./lib/by";
|
9 | import { Browser, Capabilities } from "./lib/capabilities";
|
10 | import { FileDetector, Key } from "./lib/input";
|
11 | import * as logging from "./lib/logging";
|
12 | import * as until from "./lib/until";
|
13 | import { ShadowRootPromise, WebDriver } from "./lib/webdriver";
|
14 | import * as safari from "./safari";
|
15 |
|
16 | export * as chromium from "./chromium";
|
17 | export * from "./lib/by";
|
18 | export { Browser, Capabilities, Capability, ITimeouts } from "./lib/capabilities";
|
19 | export { Actions, Button, FileDetector, Key, Origin } from "./lib/input";
|
20 | export { promise } from "./lib/promise";
|
21 | export {
|
22 | Alert,
|
23 | Condition,
|
24 | IWebDriverOptionsCookie,
|
25 | Navigation,
|
26 | Options,
|
27 | TargetLocator,
|
28 | WebDriver,
|
29 | WebElementCondition,
|
30 | } from "./lib/webdriver";
|
31 | export { BrowsingContext, logging, LogInspector, until };
|
32 |
|
33 | /**
|
34 | * Typings for lib/error
|
35 | */
|
36 | export namespace error {
|
37 | class IError extends Error {
|
38 | constructor(message?: string);
|
39 | message: string;
|
40 | }
|
41 |
|
42 | /**
|
43 | * The base WebDriver error type. This error type is only used directly when a
|
44 | * more appropriate category is not defined for the offending error.
|
45 | */
|
46 | class WebDriverError extends IError {
|
47 | constructor(message?: string);
|
48 | remoteStacktrace?: string | undefined;
|
49 | }
|
50 |
|
51 | /**
|
52 | * Indicates a { ./webdriver.WebElement#click click command} could
|
53 | * not completed because the click target is obscured by other elements on the
|
54 | * page.
|
55 | */
|
56 | class ElementClickInterceptedError extends WebDriverError {
|
57 | constructor(message?: string);
|
58 | }
|
59 |
|
60 | /**
|
61 | * An attempt was made to select an element that cannot be selected.
|
62 | */
|
63 | class ElementNotSelectableError extends WebDriverError {
|
64 | constructor(message?: string);
|
65 | }
|
66 |
|
67 | /**
|
68 | * Indicates a command could not be completed because the target element is
|
69 | * not pointer or keyboard interactable. This will often occur if an element
|
70 | * is present in the DOM, but not rendered (i.e. its CSS style has
|
71 | * "display: none").
|
72 | */
|
73 |
|
74 | class ElementNotInteractableError extends WebDriverError {
|
75 | constructor(message?: string);
|
76 | }
|
77 |
|
78 | /**
|
79 | * Indicates a navigation event caused the browser to generate a certificate
|
80 | * warning. This is usually caused by an expired or invalid TLS certificate.
|
81 | */
|
82 | class InsecureCertificateError extends WebDriverError {
|
83 | constructor(message?: string);
|
84 | }
|
85 |
|
86 | /**
|
87 | * The arguments passed to a command are either invalid or malformed.
|
88 | */
|
89 | class InvalidArgumentError extends WebDriverError {
|
90 | constructor(message?: string);
|
91 | }
|
92 |
|
93 | /**
|
94 | * An illegal attempt was made to set a cookie under a different domain than
|
95 | * the current page.
|
96 | */
|
97 | class InvalidCookieDomainError extends WebDriverError {
|
98 | constructor(message?: string);
|
99 | }
|
100 |
|
101 | /**
|
102 | * The coordinates provided to an interactions operation are invalid.
|
103 | */
|
104 | class InvalidCoordinatesError extends WebDriverError {
|
105 | constructor(message?: string);
|
106 | }
|
107 |
|
108 | /**
|
109 | * An element command could not be completed because the element is in an
|
110 | * invalid state, e.g. attempting to click an element that is no longer
|
111 | * attached to the document.
|
112 | */
|
113 | class InvalidElementStateError extends WebDriverError {
|
114 | constructor(message?: string);
|
115 | }
|
116 |
|
117 | /**
|
118 | * Argument was an invalid selector.
|
119 | */
|
120 | class InvalidSelectorError extends WebDriverError {
|
121 | constructor(message?: string);
|
122 | }
|
123 |
|
124 | /**
|
125 | * Occurs when a command is directed to a session that does not exist.
|
126 | */
|
127 | class NoSuchSessionError extends WebDriverError {
|
128 | constructor(message?: string);
|
129 | }
|
130 |
|
131 | /**
|
132 | * An error occurred while executing JavaScript supplied by the user.
|
133 | */
|
134 | class JavascriptError extends WebDriverError {
|
135 | constructor(message?: string);
|
136 | }
|
137 |
|
138 | /**
|
139 | * The target for mouse interaction is not in the browser’s viewport and
|
140 | * cannot be brought into that viewport.
|
141 | */
|
142 | class MoveTargetOutOfBoundsError extends WebDriverError {
|
143 | constructor(message?: string);
|
144 | }
|
145 |
|
146 | /**
|
147 | * An attempt was made to operate on a modal dialog when one was not open.
|
148 | */
|
149 | class NoSuchAlertError extends WebDriverError {
|
150 | constructor(message?: string);
|
151 | }
|
152 |
|
153 | /**
|
154 | * Indicates a named cookie could not be found in the cookie jar for the
|
155 | * currently selected document.
|
156 | */
|
157 | class NoSuchCookieError extends WebDriverError {
|
158 | constructor(message?: string);
|
159 | }
|
160 |
|
161 | /**
|
162 | * An element could not be located on the page using the given search
|
163 | * parameters.
|
164 | */
|
165 | class NoSuchElementError extends WebDriverError {
|
166 | constructor(message?: string);
|
167 | }
|
168 |
|
169 | /**
|
170 | * A request to switch to a frame could not be satisfied because the frame
|
171 | * could not be found.
|
172 | */
|
173 | class NoSuchFrameError extends WebDriverError {
|
174 | constructor(message?: string);
|
175 | }
|
176 |
|
177 | /**
|
178 | * A request to switch to a window could not be satisfied because the window
|
179 | * could not be found.
|
180 | */
|
181 | class NoSuchWindowError extends WebDriverError {
|
182 | constructor(message?: string);
|
183 | }
|
184 |
|
185 | /**
|
186 | * A script did not complete before its timeout expired.
|
187 | */
|
188 | class ScriptTimeoutError extends WebDriverError {
|
189 | constructor(message?: string);
|
190 | }
|
191 |
|
192 | /**
|
193 | * A new session could not be created.
|
194 | */
|
195 | class SessionNotCreatedError extends WebDriverError {
|
196 | constructor(message?: string);
|
197 | }
|
198 |
|
199 | /**
|
200 | * An element command failed because the referenced element is no longer
|
201 | * attached to the DOM.
|
202 | */
|
203 | class StaleElementReferenceError extends WebDriverError {
|
204 | constructor(message?: string);
|
205 | }
|
206 |
|
207 | /**
|
208 | * An operation did not completErrorCodee before its timeout expired.
|
209 | */
|
210 | class TimeoutError extends WebDriverError {
|
211 | constructor(message?: string);
|
212 | }
|
213 |
|
214 | /**
|
215 | * A request to set a cookie’s value could not be satisfied.
|
216 | */
|
217 | class UnableToSetCookieError extends WebDriverError {
|
218 | constructor(message?: string);
|
219 | }
|
220 |
|
221 | /**
|
222 | * A screen capture operation was not possible.
|
223 | */
|
224 | class UnableToCaptureScreenError extends WebDriverError {
|
225 | constructor(message?: string);
|
226 | }
|
227 |
|
228 | /**
|
229 | * A modal dialog was open, blocking this operation.
|
230 | */
|
231 | class UnexpectedAlertOpenError extends WebDriverError {
|
232 | constructor(message?: string, openAlertText?: string);
|
233 | /**
|
234 | * @return {(string|undefined)} The text displayed with the unhandled alert,
|
235 | * if available.
|
236 | */
|
237 | getAlertText(): string;
|
238 | }
|
239 |
|
240 | /**
|
241 | * A command could not be executed because the remote end is not aware of it.
|
242 | */
|
243 | class UnknownCommandError extends WebDriverError {
|
244 | constructor(message?: string);
|
245 | }
|
246 |
|
247 | /**
|
248 | * The requested command matched a known URL but did not match an method for
|
249 | * that URL.
|
250 | */
|
251 | class UnknownMethodError extends WebDriverError {
|
252 | constructor(message?: string);
|
253 | }
|
254 |
|
255 | /**
|
256 | * Reports an unsupport operation.
|
257 | */
|
258 | class UnsupportedOperationError extends WebDriverError {
|
259 | constructor(message?: string);
|
260 | }
|
261 |
|
262 | interface Response {
|
263 | error: string | number;
|
264 | message: string;
|
265 | }
|
266 | /**
|
267 | * Checks a response object from a server that adheres to the W3C WebDriver
|
268 | * protocol.
|
269 | */
|
270 | function checkResponse(data: Response): Response;
|
271 |
|
272 | interface MaybeLegacyResponse {
|
273 | status?: number | undefined;
|
274 | value?: { message: string } | undefined;
|
275 | message?: string | undefined;
|
276 | getAlertText?(): string;
|
277 | }
|
278 |
|
279 | /**
|
280 | * Checks a legacy response from the Selenium 2.0 wire protocol for an error.
|
281 | */
|
282 | function checkLegacyResponse(response: MaybeLegacyResponse): MaybeLegacyResponse;
|
283 |
|
284 | interface ErrorData {
|
285 | error: string | number;
|
286 | message: string;
|
287 | [key: string]: string | number;
|
288 | }
|
289 |
|
290 | /**
|
291 | * Throws an error coded from the W3C protocol. A generic error will be thrown
|
292 | * if the provided `data` is not a valid encoded error.
|
293 | */
|
294 | function throwDecodedError(data: ErrorData | string): never;
|
295 |
|
296 | interface ErrorCodeType {
|
297 | [key: string]: number;
|
298 | }
|
299 |
|
300 | const ErrorCode: ErrorCodeType;
|
301 |
|
302 | /**
|
303 | * Lookup the err in table of errors.
|
304 | */
|
305 | function encodeError(err: any): { error: string; message: string };
|
306 | }
|
307 |
|
308 | /**
|
309 | * x,y
|
310 | */
|
311 | export interface ILocation {
|
312 | x: number;
|
313 | y: number;
|
314 | }
|
315 |
|
316 | /**
|
317 | * width, height
|
318 | */
|
319 | export interface ISize {
|
320 | width: number;
|
321 | height: number;
|
322 | }
|
323 |
|
324 | /**
|
325 | * x,y,w,h
|
326 | */
|
327 | export interface IRectangle {
|
328 | x: number;
|
329 | y: number;
|
330 | width: number;
|
331 | height: number;
|
332 | }
|
333 |
|
334 | /**
|
335 | * Class for defining sequences of user touch interactions. Each sequence
|
336 | * will not be executed until {@link #perform} is called.
|
337 | *
|
338 | * Example:
|
339 | *
|
340 | * new TouchSequence(driver).
|
341 | * tapAndHold({x: 0, y: 0}).
|
342 | * move({x: 3, y: 4}).
|
343 | * release({x: 10, y: 10}).
|
344 | * perform();
|
345 | */
|
346 | export class TouchSequence {
|
347 | /*
|
348 | * @param {!WebDriver} driver The driver instance to use.
|
349 | * @constructor
|
350 | */
|
351 | constructor(driver: WebDriver);
|
352 |
|
353 | /**
|
354 | * Executes this action sequence.
|
355 | * @return {!Promise} A promise that will be resolved once
|
356 | * this sequence has completed.
|
357 | */
|
358 | perform(): Promise<void>;
|
359 |
|
360 | /**
|
361 | * Taps an element.
|
362 | *
|
363 | * @param {!WebElement} elem The element to tap.
|
364 | * @return {!TouchSequence} A self reference.
|
365 | */
|
366 | tap(elem: WebElement): TouchSequence;
|
367 |
|
368 | /**
|
369 | * Double taps an element.
|
370 | *
|
371 | * @param {!WebElement} elem The element to double tap.
|
372 | * @return {!TouchSequence} A self reference.
|
373 | */
|
374 | doubleTap(elem: WebElement): TouchSequence;
|
375 |
|
376 | /**
|
377 | * Long press on an element.
|
378 | *
|
379 | * @param {!WebElement} elem The element to long press.
|
380 | * @return {!TouchSequence} A self reference.
|
381 | */
|
382 | longPress(elem: WebElement): TouchSequence;
|
383 |
|
384 | /**
|
385 | * Touch down at the given location.
|
386 | *
|
387 | * @param {{ x: number, y: number }} location The location to touch down at.
|
388 | * @return {!TouchSequence} A self reference.
|
389 | */
|
390 | tapAndHold(location: ILocation): TouchSequence;
|
391 |
|
392 | /**
|
393 | * Move a held {@linkplain #tapAndHold touch} to the specified location.
|
394 | *
|
395 | * @param {{x: number, y: number}} location The location to move to.
|
396 | * @return {!TouchSequence} A self reference.
|
397 | */
|
398 | move(location: ILocation): TouchSequence;
|
399 |
|
400 | /**
|
401 | * Release a held {@linkplain #tapAndHold touch} at the specified location.
|
402 | *
|
403 | * @param {{x: number, y: number}} location The location to release at.
|
404 | * @return {!TouchSequence} A self reference.
|
405 | */
|
406 | release(location: ILocation): TouchSequence;
|
407 |
|
408 | /**
|
409 | * Scrolls the touch screen by the given offset.
|
410 | *
|
411 | * @param {{x: number, y: number}} offset The offset to scroll to.
|
412 | * @return {!TouchSequence} A self reference.
|
413 | */
|
414 | scroll(offset: IOffset): TouchSequence;
|
415 |
|
416 | /**
|
417 | * Scrolls the touch screen, starting on `elem` and moving by the specified
|
418 | * offset.
|
419 | *
|
420 | * @param {!WebElement} elem The element where scroll starts.
|
421 | * @param {{x: number, y: number}} offset The offset to scroll to.
|
422 | * @return {!TouchSequence} A self reference.
|
423 | */
|
424 | scrollFromElement(elem: WebElement, offset: IOffset): TouchSequence;
|
425 |
|
426 | /**
|
427 | * Flick, starting anywhere on the screen, at speed xspeed and yspeed.
|
428 | *
|
429 | * @param {{xspeed: number, yspeed: number}} speed The speed to flick in each
|
430 | * direction, in pixels per second.
|
431 | * @return {!TouchSequence} A self reference.
|
432 | */
|
433 | flick(speed: ISpeed): TouchSequence;
|
434 |
|
435 | /**
|
436 | * Flick starting at elem and moving by x and y at specified speed.
|
437 | *
|
438 | * @param {!WebElement} elem The element where flick starts.
|
439 | * @param {{x: number, y: number}} offset The offset to flick to.
|
440 | * @param {number} speed The speed to flick at in pixels per second.
|
441 | * @return {!TouchSequence} A self reference.
|
442 | */
|
443 | flickElement(elem: WebElement, offset: IOffset, speed: number): TouchSequence;
|
444 | }
|
445 |
|
446 | /**
|
447 | * x.y again
|
448 | */
|
449 | export interface IOffset {
|
450 | x: number;
|
451 | y: number;
|
452 | }
|
453 |
|
454 | /**
|
455 | * delta x,y
|
456 | */
|
457 | export interface ISpeed {
|
458 | xspeed: number;
|
459 | yspeed: number;
|
460 | }
|
461 |
|
462 | /**
|
463 | * ProxyConfig
|
464 | */
|
465 | export interface ProxyConfig {
|
466 | proxyType: string;
|
467 | proxyAutoconfigUrl?: string | undefined;
|
468 | ftpProxy?: string | undefined;
|
469 | httpProxy?: string | undefined;
|
470 | sslProxy?: string | undefined;
|
471 | noProxy?: string | undefined;
|
472 | socksProxy?: string | undefined;
|
473 | socksUsername?: string | undefined;
|
474 | socksPassword?: string | undefined;
|
475 | }
|
476 |
|
477 | /**
|
478 | * Creates new {@link WebDriver WebDriver} instances. The environment
|
479 | * variables listed below may be used to override a builder's configuration,
|
480 | * allowing quick runtime changes.
|
481 | *
|
482 | * - {@code SELENIUM_BROWSER}: defines the target browser in the form
|
483 | * {@code browser[:version][:platform]}.
|
484 | *
|
485 | * - {@code SELENIUM_REMOTE_URL}: defines the remote URL for all builder
|
486 | * instances. This environment variable should be set to a fully qualified
|
487 | * URL for a WebDriver server (e.g. http://localhost:4444/wd/hub). This
|
488 | * option always takes precedence over {@code SELENIUM_SERVER_JAR}.
|
489 | *
|
490 | * - {@code SELENIUM_SERVER_JAR}: defines the path to the
|
491 | * <a href='http://selenium-release.storage.googleapis.com/index.html'>
|
492 | * standalone Selenium server</a> jar to use. The server will be started the
|
493 | * first time a WebDriver instance and be killed when the process exits.
|
494 | *
|
495 | * Suppose you had mytest.js that created WebDriver with
|
496 | *
|
497 | * var driver = new Builder()
|
498 | * .forBrowser('chrome')
|
499 | * .build();
|
500 | *
|
501 | * This test could be made to use Firefox on the local machine by running with
|
502 | * `SELENIUM_BROWSER=firefox node mytest.js`. Rather than change the code to
|
503 | * target Google Chrome on a remote machine, you can simply set the
|
504 | * `SELENIUM_BROWSER` and `SELENIUM_REMOTE_URL` environment variables:
|
505 | *
|
506 | * SELENIUM_BROWSER=chrome:36:LINUX \
|
507 | * SELENIUM_REMOTE_URL=http://www.example.com:4444/wd/hub \
|
508 | * node mytest.js
|
509 | *
|
510 | * You could also use a local copy of the standalone Selenium server:
|
511 | *
|
512 | * SELENIUM_BROWSER=chrome:36:LINUX \
|
513 | * SELENIUM_SERVER_JAR=/path/to/selenium-server-standalone.jar \
|
514 | * node mytest.js
|
515 | */
|
516 | export class Builder {
|
517 | // region Constructors
|
518 |
|
519 | /** */
|
520 | constructor();
|
521 |
|
522 | // endregion
|
523 |
|
524 | // region Methods
|
525 |
|
526 | /**
|
527 | * Configures this builder to ignore any environment variable overrides and to
|
528 | * only use the configuration specified through this instance's API.
|
529 | *
|
530 | * @return {!Builder} A self reference.
|
531 | */
|
532 | disableEnvironmentOverrides(): Builder;
|
533 |
|
534 | /**
|
535 | * Creates a new WebDriver client based on this builder's current
|
536 | * configuration.
|
537 | *
|
538 | * This method will return a {@linkplain ThenableWebDriver} instance, allowing
|
539 | * users to issue commands directly without calling `then()`. The returned
|
540 | * thenable wraps a promise that will resolve to a concrete
|
541 | * {@linkplain webdriver.WebDriver WebDriver} instance. The promise will be
|
542 | * rejected if the remote end fails to create a new session.
|
543 | *
|
544 | * @return {!ThenableWebDriver} A new WebDriver instance.
|
545 | * @throws {Error} If the current configuration is invalid.
|
546 | */
|
547 | build(): ThenableWebDriver;
|
548 |
|
549 | /**
|
550 | * Configures the target browser for clients created by this instance.
|
551 | * Any calls to {@link #withCapabilities} after this function will
|
552 | * overwrite these settings.
|
553 | *
|
554 | * <p>You may also define the target browser using the {@code
|
555 | * SELENIUM_BROWSER} environment variable. If set, this environment variable
|
556 | * should be of the form {@code browser[:[version][:platform]]}.
|
557 | *
|
558 | * @param {(string|Browser)} name The name of the target browser;
|
559 | * common defaults are available on the {@link Browser} enum.
|
560 | * @param {string=} opt_version A desired version; may be omitted if any
|
561 | * version should be used.
|
562 | * @param {string=} opt_platform The desired platform; may be omitted if any
|
563 | * version may be used.
|
564 | * @return {!Builder} A self reference.
|
565 | */
|
566 | forBrowser(name: string, opt_version?: string, opt_platform?: string): Builder;
|
567 |
|
568 | /**
|
569 | * Returns the base set of capabilities this instance is currently configured
|
570 | * to use.
|
571 | * @return {!Capabilities} The current capabilities for this builder.
|
572 | */
|
573 | getCapabilities(): Capabilities;
|
574 |
|
575 | /**
|
576 | * @return {string} The URL of the WebDriver server this instance is
|
577 | * configured to use.
|
578 | */
|
579 | getServerUrl(): string;
|
580 |
|
581 | /**
|
582 | * @return {?string} The URL of the proxy server to use for the WebDriver's
|
583 | * HTTP connections, or `null` if not set.
|
584 | */
|
585 | getWebDriverProxy(): string | null;
|
586 |
|
587 | /**
|
588 | * Sets the default action to take with an unexpected alert before returning
|
589 | * an error.
|
590 | * @param {string} beahvior The desired behavior; should be 'accept',
|
591 | * 'dismiss', or 'ignore'. Defaults to 'dismiss'.
|
592 | * @return {!Builder} A self reference.
|
593 | */
|
594 | setAlertBehavior(behavior?: string): Builder;
|
595 |
|
596 | /**
|
597 | * Sets Chrome-specific options for drivers created by this builder. Any
|
598 | * logging or proxy settings defined on the given options will take precedence
|
599 | * over those set through {@link #setLoggingPrefs} and {@link #setProxy},
|
600 | * respectively.
|
601 | *
|
602 | * @param {!chrome.Options} options The ChromeDriver options to use.
|
603 | * @return {!Builder} A self reference.
|
604 | */
|
605 | setChromeOptions(options: chrome.Options): Builder;
|
606 |
|
607 | /**
|
608 | * @return {chrome.Options} the Chrome specific options currently configured
|
609 | * for this builder.
|
610 | */
|
611 | getChromeOptions(): chrome.Options;
|
612 |
|
613 | /**
|
614 | * Sets the service builder to use for managing the chromedriver child process
|
615 | * when creating new Chrome sessions.
|
616 | *
|
617 | * @param {chrome.ServiceBuilder} service the service to use.
|
618 | * @return {!Builder} A self reference.
|
619 | */
|
620 | setChromeService(service: chrome.ServiceBuilder): Builder;
|
621 |
|
622 | /**
|
623 | * Set {@linkplain edge.Options options} specific to Microsoft's Edge browser
|
624 | * for drivers created by this builder. Any proxy settings defined on the
|
625 | * given options will take precedence over those set through
|
626 | * {@link #setProxy}.
|
627 | *
|
628 | * @param {!edge.Options} options The MicrosoftEdgeDriver options to use.
|
629 | * @return {!Builder} A self reference.
|
630 | */
|
631 | setEdgeOptions(options: edge.Options): Builder;
|
632 |
|
633 | /**
|
634 | * Sets the {@link edge.ServiceBuilder} to use to manage the
|
635 | * MicrosoftEdgeDriver child process when creating sessions locally.
|
636 | *
|
637 | * @param {edge.ServiceBuilder} service the service to use.
|
638 | * @return {!Builder} a self reference.
|
639 | */
|
640 | setEdgeService(service: edge.ServiceBuilder): Builder;
|
641 |
|
642 | /**
|
643 | * Sets Firefox-specific options for drivers created by this builder. Any
|
644 | * logging or proxy settings defined on the given options will take precedence
|
645 | * over those set through {@link #setLoggingPrefs} and {@link #setProxy},
|
646 | * respectively.
|
647 | *
|
648 | * @param {!firefox.Options} options The FirefoxDriver options to use.
|
649 | * @return {!Builder} A self reference.
|
650 | */
|
651 | setFirefoxOptions(options: firefox.Options): Builder;
|
652 |
|
653 | /**
|
654 | * @return {firefox.Options} the Firefox specific options currently configured
|
655 | * for this instance.
|
656 | */
|
657 | getFirefoxOptions(): firefox.Options;
|
658 |
|
659 | /**
|
660 | * Sets the {@link firefox.ServiceBuilder} to use to manage the geckodriver
|
661 | * child process when creating Firefox sessions locally.
|
662 | *
|
663 | * @param {firefox.ServiceBuilder} service the service to use.
|
664 | * @return {!Builder} a self reference.
|
665 | */
|
666 | setFirefoxService(service: firefox.ServiceBuilder): Builder;
|
667 |
|
668 | /**
|
669 | * Set Internet Explorer specific {@linkplain ie.Options options} for drivers
|
670 | * created by this builder. Any proxy settings defined on the given options
|
671 | * will take precedence over those set through {@link #setProxy}.
|
672 | *
|
673 | * @param {!ie.Options} options The IEDriver options to use.
|
674 | * @return {!Builder} A self reference.
|
675 | */
|
676 | setIeOptions(options: ie.Options): Builder;
|
677 |
|
678 | /**
|
679 | * Sets the {@link ie.ServiceBuilder} to use to manage the geckodriver
|
680 | * child process when creating IE sessions locally.
|
681 | *
|
682 | * @param {ie.ServiceBuilder} service the service to use.
|
683 | * @return {!Builder} a self reference.
|
684 | */
|
685 | setIeService(service: ie.ServiceBuilder): Builder;
|
686 |
|
687 | /**
|
688 | * Sets the logging preferences for the created session. Preferences may be
|
689 | * changed by repeated calls, or by calling {@link #withCapabilities}.
|
690 | * @param {!(logging.Preferences|Object.<string, string>)} prefs The
|
691 | * desired logging preferences.
|
692 | * @return {!Builder} A self reference.
|
693 | */
|
694 | setLoggingPrefs(prefs: logging.Preferences | {}): Builder;
|
695 |
|
696 | /**
|
697 | * Sets the proxy configuration to use for WebDriver clients created by this
|
698 | * builder. Any calls to {@link #withCapabilities} after this function will
|
699 | * overwrite these settings.
|
700 | * @param {!capabilities.ProxyConfig} config The configuration to use.
|
701 | * @return {!Builder} A self reference.
|
702 | */
|
703 | setProxy(config: ProxyConfig): Builder;
|
704 |
|
705 | /**
|
706 | * Sets Safari specific {@linkplain safari.Options options} for drivers
|
707 | * created by this builder. Any logging settings defined on the given options
|
708 | * will take precedence over those set through {@link #setLoggingPrefs}.
|
709 | *
|
710 | * @param {!safari.Options} options The Safari options to use.
|
711 | * @return {!Builder} A self reference.
|
712 | */
|
713 | setSafariOptions(options: safari.Options): Builder;
|
714 |
|
715 | /**
|
716 | * @return {safari.Options} the Safari specific options currently configured
|
717 | * for this instance.
|
718 | */
|
719 | getSafariOptions(): safari.Options;
|
720 |
|
721 | /**
|
722 | * Sets the http agent to use for each request.
|
723 | * If this method is not called, the Builder will use http.globalAgent by
|
724 | * default.
|
725 | *
|
726 | * @param {http.Agent} agent The agent to use for each request.
|
727 | * @return {!Builder} A self reference.
|
728 | */
|
729 | usingHttpAgent(agent: any): Builder;
|
730 |
|
731 | /**
|
732 | * @return {http.Agent} The http agent used for each request
|
733 | */
|
734 | getHttpAgent(): any | null;
|
735 |
|
736 | /**
|
737 | * Sets the URL of a remote WebDriver server to use. Once a remote URL has
|
738 | * been specified, the builder direct all new clients to that server. If this
|
739 | * method is never called, the Builder will attempt to create all clients
|
740 | * locally.
|
741 | *
|
742 | * <p>As an alternative to this method, you may also set the
|
743 | * {@code SELENIUM_REMOTE_URL} environment variable.
|
744 | *
|
745 | * @param {string} url The URL of a remote server to use.
|
746 | * @return {!Builder} A self reference.
|
747 | */
|
748 | usingServer(url: string): Builder;
|
749 |
|
750 | /**
|
751 | * Sets the URL of the proxy to use for the WebDriver's HTTP connections.
|
752 | * If this method is never called, the Builder will create a connection
|
753 | * without a proxy.
|
754 | *
|
755 | * @param {string} proxy The URL of a proxy to use.
|
756 | * @return {!Builder} A self reference.
|
757 | */
|
758 | usingWebDriverProxy(proxy: string): Builder;
|
759 |
|
760 | /**
|
761 | * Sets the desired capabilities when requesting a new session. This will
|
762 | * overwrite any previously set capabilities.
|
763 | * @param {!(Object|Capabilities)} capabilities The desired
|
764 | * capabilities for a new session.
|
765 | * @return {!Builder} A self reference.
|
766 | */
|
767 | withCapabilities(capabilities: {} | Capabilities): Builder;
|
768 |
|
769 | // endregion
|
770 | }
|
771 |
|
772 | export type Locator = By | Function | ByHash | RelativeBy;
|
773 |
|
774 | /**
|
775 | * Describes an event listener registered on an {@linkplain EventEmitter}.
|
776 | */
|
777 | export class Listener {
|
778 | /**
|
779 | * @param {!Function} fn The acutal listener function.
|
780 | * @param {(Object|undefined)} scope The object in whose scope to invoke the
|
781 | * listener.
|
782 | * @param {boolean} oneshot Whether this listener should only be used once.
|
783 | */
|
784 | constructor(fn: Function, scope: {}, oneshot: boolean);
|
785 | }
|
786 |
|
787 | /**
|
788 | * Object that can emit events for others to listen for. This is used instead
|
789 | * of Closure's event system because it is much more light weight. The API is
|
790 | * based on Node's EventEmitters.
|
791 | */
|
792 | export class EventEmitter {
|
793 | // region Constructors
|
794 |
|
795 | /** */
|
796 | constructor();
|
797 |
|
798 | // endregion
|
799 |
|
800 | // region Methods
|
801 |
|
802 | /**
|
803 | * Fires an event and calls all listeners.
|
804 | * @param {string} type The type of event to emit.
|
805 | * arguments to pass to each listener.
{...*} var_args Any |
806 | */
|
807 | emit(type: string, ...var_args: any[]): void;
|
808 |
|
809 | /**
|
810 | * Returns a mutable list of listeners for a specific type of event.
|
811 | * @param {string} type The type of event to retrieve the listeners for.
|
812 | * @return {!Set<!Listener>} The registered listeners for the given event
|
813 | * type.
|
814 | */
|
815 | listeners(type: string): any;
|
816 |
|
817 | /**
|
818 | * Registers a listener.
|
819 | * @param {string} type The type of event to listen for.
|
820 | * @param {!Function} fn The function to invoke when the event is fired.
|
821 | * @param {Object=} opt_self The object in whose scope to invoke the listener.
|
822 | * @param {boolean=} opt_oneshot Whether the listener should b (e removed
|
823 | * after
|
824 | * the first event is fired.
|
825 | * @return {!EventEmitter} A self reference.
|
826 | */
|
827 | addListener(type: string, fn: Function, opt_scope?: any, opt_oneshot?: boolean): EventEmitter;
|
828 |
|
829 | /**
|
830 | * Registers a one-time listener which will be called only the first time an
|
831 | * event is emitted, after which it will be removed.
|
832 | * @param {string} type The type of event to listen for.
|
833 | * @param {!Function} fn The function to invoke when the event is fired.
|
834 | * @param {Object=} opt_scope The object in whose scope to invoke the
|
835 | * listener.
|
836 | * @return {!EventEmitter} A self reference.
|
837 | */
|
838 | once(type: string, fn: any, opt_scope?: any): EventEmitter;
|
839 |
|
840 | /**
|
841 | * An alias for {@code #addListener()}.
|
842 | * @param {string} type The type of event to listen for.
|
843 | * @param {!Function} fn The function to invoke when the event is fired.
|
844 | * @param {Object=} opt_scope The object in whose scope to invoke the
|
845 | * listener.
|
846 | * @return {!EventEmitter} A self reference.
|
847 | */
|
848 | on(type: string, fn: Function, opt_scope?: any): EventEmitter;
|
849 |
|
850 | /**
|
851 | * Removes a previously registered event listener.
|
852 | * @param {string} type The type of event to unregister.
|
853 | * @param {!Function} listenerFn The handler function to remove.
|
854 | * @return {!EventEmitter} A self reference.
|
855 | */
|
856 | removeListener(type: string, listenerFn: Function): EventEmitter;
|
857 |
|
858 | /**
|
859 | * Removes all listeners for a specific type of event. If no event is
|
860 | * specified, all listeners across all types will be removed.
|
861 | * @param {string=} opt_type The type of event to remove listeners from.
|
862 | * @return {!EventEmitter} A self reference.
|
863 | */
|
864 | removeAllListeners(opt_type?: string): EventEmitter;
|
865 |
|
866 | // endregion
|
867 | }
|
868 |
|
869 | /**
|
870 | * An interface for managing the current window.
|
871 | */
|
872 | export class Window {
|
873 | // region Constructors
|
874 |
|
875 | /**
|
876 | * @param {!WebDriver} driver The parent driver.
|
877 | */
|
878 | constructor(driver: WebDriver);
|
879 |
|
880 | // endregion
|
881 |
|
882 | // region Methods
|
883 |
|
884 | /**
|
885 | * Retrieves the window's current position, relative to the top left corner of
|
886 | * the screen.
|
887 | * @return {!Promise} A promise that will be resolved with the
|
888 | * window's position in the form of a {x:number, y:number} object literal.
|
889 | */
|
890 | getPosition(): Promise<ILocation>;
|
891 |
|
892 | /**
|
893 | * Repositions the current window.
|
894 | * @param {number} x The desired horizontal position, relative to the left
|
895 | * side of the screen.
|
896 | * @param {number} y The desired vertical position, relative to the top of the
|
897 | * of the screen.
|
898 | * @return {!Promise} A promise that will be resolved when the
|
899 | * command has completed.
|
900 | */
|
901 | setPosition(x: number, y: number): Promise<void>;
|
902 |
|
903 | /**
|
904 | * Retrieves the window's current size.
|
905 | * @return {!Promise} A promise that will be resolved with the
|
906 | * window's size in the form of a {width:number, height:number} object
|
907 | * literal.
|
908 | */
|
909 | getSize(): Promise<ISize>;
|
910 |
|
911 | /**
|
912 | * Resizes the current window.
|
913 | * @param {number} width The desired window width.
|
914 | * @param {number} height The desired window height.
|
915 | * @return {!Promise} A promise that will be resolved when the
|
916 | * command has completed.
|
917 | */
|
918 | setSize(width: number, height: number): Promise<void>;
|
919 |
|
920 | /**
|
921 | * Returns the current top-level window's size and position.
|
922 | */
|
923 | getRect(): Promise<IRectangle>;
|
924 |
|
925 | /**
|
926 | * Sets the current top-level window's size and position. You may update
|
927 | * just the size by omitting `x` & `y`, or just the position by omitting
|
928 | * `width` & `height` options.
|
929 | */
|
930 | setRect({ x, y, width, height }: Partial<IRectangle>): Promise<IRectangle>;
|
931 |
|
932 | /**
|
933 | * Maximizes the current window. The exact behavior of this command is
|
934 | * specific to individual window managers, but typically involves increasing
|
935 | * the window to the maximum available size without going full-screen.
|
936 | * @return {!Promise} A promise that will be resolved when the
|
937 | * command has completed.
|
938 | */
|
939 | maximize(): Promise<void>;
|
940 |
|
941 | /**
|
942 | * Minimizes the current window. The exact behavior of this command is
|
943 | * specific to individual window managers, but typically involves hiding
|
944 | * the window in the system tray.
|
945 | * @return {!Promise} A promise that will be resolved when the
|
946 | * command has completed.
|
947 | */
|
948 | minimize(): Promise<void>;
|
949 |
|
950 | /**
|
951 | * Invokes the "full screen" operation on the current window. The exact
|
952 | * behavior of this command is specific to individual window managers, but
|
953 | * this will typically increase the window size to the size of the physical
|
954 | * display and hide the browser chrome.
|
955 | *
|
956 | * @return {!Promise<void>} A promise that will be resolved when the command
|
957 | * has completed.
|
958 | * @see <https://fullscreen.spec.whatwg.org/#fullscreen-an-element>
|
959 | */
|
960 | fullscreen(): Promise<void>;
|
961 |
|
962 | // endregion
|
963 | }
|
964 |
|
965 | /**
|
966 | * Interface for managing WebDriver log records.
|
967 | */
|
968 | export class Logs {
|
969 | // region Constructors
|
970 |
|
971 | /**
|
972 | * @param {!WebDriver} driver The parent driver.
|
973 | */
|
974 | constructor(driver: WebDriver);
|
975 |
|
976 | // endregion
|
977 |
|
978 | // region
|
979 |
|
980 | /**
|
981 | * Fetches available log entries for the given type.
|
982 | *
|
983 | * <p/>Note that log buffers are reset after each call, meaning that
|
984 | * available log entries correspond to those entries not yet returned for a
|
985 | * given log type. In practice, this means that this call will return the
|
986 | * available log entries since the last call, or from the start of the
|
987 | * session.
|
988 | *
|
989 | * @param {!logging.Type} type The desired log type.
|
990 | * Promise.<!Array.<!logging.Entry>>} A
{! |
991 | * promise that will resolve to a list of log entries for the specified
|
992 | * type.
|
993 | */
|
994 | get(type: string): Promise<logging.Entry[]>;
|
995 |
|
996 | /**
|
997 | * Retrieves the log types available to this driver.
|
998 | * @return {!Promise.<!Array.<!logging.Type>>} A
|
999 | * promise that will resolve to a list of available log types.
|
1000 | */
|
1001 | getAvailableLogTypes(): Promise<string[]>;
|
1002 |
|
1003 | // endregion
|
1004 | }
|
1005 |
|
1006 | export type CreateSessionCapabilities = Capabilities | {
|
1007 | desired?: Capabilities | undefined;
|
1008 | required?: Capabilities | undefined;
|
1009 | };
|
1010 |
|
1011 | /**
|
1012 | * A thenable wrapper around a {@linkplain webdriver.IWebDriver IWebDriver}
|
1013 | * instance that allows commands to be issued directly instead of having to
|
1014 | * repeatedly call `then`:
|
1015 | *
|
1016 | * let driver = new Builder().build();
|
1017 | * driver.then(d => d.get(url)); // You can do this...
|
1018 | * driver.get(url); // ...or this
|
1019 | *
|
1020 | * If the driver instance fails to resolve (e.g. the session cannot be created),
|
1021 | * every issued command will fail.
|
1022 | *
|
1023 | * @interface
|
1024 | */
|
1025 | export interface ThenableWebDriver extends WebDriver, Promise<WebDriver> {}
|
1026 |
|
1027 | export interface IWebElementId {
|
1028 | [ELEMENT: string]: string;
|
1029 | }
|
1030 |
|
1031 | /**
|
1032 | * Represents a DOM element. WebElements can be found by searching from the
|
1033 | * document root using a {@code WebDriver} instance, or by searching
|
1034 | * under another {@code WebElement}:
|
1035 | * <pre><code>
|
1036 | * driver.get('http://www.google.com');
|
1037 | * var searchForm = driver.findElement(By.tagName('form'));
|
1038 | * var searchBox = searchForm.findElement(By.name('q'));
|
1039 | * searchBox.sendKeys('webdriver');
|
1040 | * </code></pre>
|
1041 | *
|
1042 | * The WebElement is implemented as a promise for compatibility with the promise
|
1043 | * API. It will always resolve itself when its internal state has been fully
|
1044 | * resolved and commands may be issued against the element. This can be used to
|
1045 | * catch errors when an element cannot be located on the page:
|
1046 | * <pre><code>
|
1047 | * driver.findElement(By.id('not-there')).then(function(element) {
|
1048 | * alert('Found an element that was not expected to be there!');
|
1049 | * }, function(error) {
|
1050 | * alert('The element was not found, as expected');
|
1051 | * });
|
1052 | * </code></pre>
|
1053 | */
|
1054 | export interface IWebElement {
|
1055 | // region Methods
|
1056 |
|
1057 | /**
|
1058 | * Schedules a command to click on this element.
|
1059 | * @return {!Promise} A promise that will be resolved when
|
1060 | * the click command has completed.
|
1061 | */
|
1062 | click(): Promise<void>;
|
1063 |
|
1064 | /**
|
1065 | * Schedules a command to type a sequence on the DOM element represented by
|
1066 | * this instance.
|
1067 | *
|
1068 | * Modifier keys (SHIFT, CONTROL, ALT, META) are stateful; once a modifier is
|
1069 | * processed in the key sequence, that key state is toggled until one of the
|
1070 | * following occurs:
|
1071 | *
|
1072 | * - The modifier key is encountered again in the sequence. At this point the
|
1073 | * state of the key is toggled (along with the appropriate keyup/down
|
1074 | * events).
|
1075 | * - The {@link input.Key.NULL} key is encountered in the sequence. When
|
1076 | * this key is encountered, all modifier keys current in the down state are
|
1077 | * released (with accompanying keyup events). The NULL key can be used to
|
1078 | * simulate common keyboard shortcuts:
|
1079 | *
|
1080 | * element.sendKeys('text was',
|
1081 | * Key.CONTROL, 'a', Key.NULL,
|
1082 | * 'now text is');
|
1083 | * // Alternatively:
|
1084 | * element.sendKeys('text was',
|
1085 | * Key.chord(Key.CONTROL, 'a'),
|
1086 | * 'now text is');
|
1087 | *
|
1088 | * - The end of the key sequence is encountered. When there are no more keys
|
1089 | * to type, all depressed modifier keys are released (with accompanying
|
1090 | * keyup events).
|
1091 | *
|
1092 | * If this element is a file input ({@code <input type='file'>}), the
|
1093 | * specified key sequence should specify the path to the file to attach to
|
1094 | * the element. This is analogous to the user clicking 'Browse...' and
|
1095 | * entering the path into the file select dialog.
|
1096 | *
|
1097 | * var form = driver.findElement(By.css('form'));
|
1098 | * var element = form.findElement(By.css('input[type=file]'));
|
1099 | * element.sendKeys('/path/to/file.txt');
|
1100 | * form.submit();
|
1101 | *
|
1102 | * For uploads to function correctly, the entered path must reference a file
|
1103 | * on the _browser's_ machine, not the local machine running this script. When
|
1104 | * running against a remote Selenium server, a {@link input.FileDetector}
|
1105 | * may be used to transparently copy files to the remote machine before
|
1106 | * attempting to upload them in the browser.
|
1107 | *
|
1108 | * __Note:__ On browsers where native keyboard events are not supported
|
1109 | * (e.g. Firefox on OS X), key events will be synthesized. Special
|
1110 | * punctuation keys will be synthesized according to a standard QWERTY en-us
|
1111 | * keyboard layout.
|
1112 | *
|
1113 | * @param {...(number|string|!IThenable<(number|string)>)} var_args The
|
1114 | * sequence of keys to type. Number keys may be referenced numerically or
|
1115 | * by string (1 or '1'). All arguments will be joined into a single
|
1116 | * sequence.
|
1117 | * @return {!Promise} A promise that will be resolved when all
|
1118 | * keys have been typed.
|
1119 | */
|
1120 | sendKeys(...var_args: Array<number | string | Promise<string | number>>): Promise<void>;
|
1121 |
|
1122 | /**
|
1123 | * Schedules a command to query for the tag/node name of this element.
|
1124 | * @return {!Promise} A promise that will be resolved with the
|
1125 | * element's tag name.
|
1126 | */
|
1127 | getTagName(): Promise<string>;
|
1128 |
|
1129 | /**
|
1130 | * Schedules a command to query for the computed style of the element
|
1131 | * represented by this instance. If the element inherits the named style from
|
1132 | * its parent, the parent will be queried for its value. Where possible,
|
1133 | * color values will be converted to their hex representation (e.g. #00ff00
|
1134 | * instead of rgb(0, 255, 0)). <p/> <em>Warning:</em> the value returned will
|
1135 | * be as the browser interprets it, so it may be tricky to form a proper
|
1136 | * assertion.
|
1137 | *
|
1138 | * @param {string} cssStyleProperty The name of the CSS style property to look
|
1139 | * up.
|
1140 | * @return {!Promise} A promise that will be resolved with the
|
1141 | * requested CSS value.
|
1142 | */
|
1143 | getCssValue(cssStyleProperty: string): Promise<string>;
|
1144 |
|
1145 | /**
|
1146 | * Schedules a command to query for the value of the given attribute of the
|
1147 | * element. Will return the current value even if it has been modified after
|
1148 | * the page has been loaded. More exactly, this method will return the value
|
1149 | * of the given attribute, unless that attribute is not present, in which case
|
1150 | * the value of the property with the same name is returned. If neither value
|
1151 | * is set, null is returned. The 'style' attribute is converted as best can be
|
1152 | * to a text representation with a trailing semi-colon. The following are
|
1153 | * deemed to be 'boolean' attributes and will be returned as thus:
|
1154 | *
|
1155 | * <p>async, autofocus, autoplay, checked, compact, complete, controls,
|
1156 | * declare, defaultchecked, defaultselected, defer, disabled, draggable,
|
1157 | * ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap,
|
1158 | * itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate,
|
1159 | * nowrap, open, paused, pubdate, readonly, required, reversed, scoped,
|
1160 | * seamless, seeking, selected, spellcheck, truespeed, willvalidate
|
1161 | *
|
1162 | * <p>Finally, the following commonly mis-capitalized attribute/property names
|
1163 | * are evaluated as expected:
|
1164 | * <ul>
|
1165 | * <li>'class'
|
1166 | * <li>'readonly'
|
1167 | * </ul>
|
1168 | * @param {string} attributeName The name of the attribute to query.
|
1169 | * @return {!Promise} A promise that will be resolved with the
|
1170 | * attribute's value.
|
1171 | */
|
1172 | getAttribute(attributeName: string): Promise<string>;
|
1173 |
|
1174 | /**
|
1175 | * Get the visible (i.e. not hidden by CSS) innerText of this element,
|
1176 | * including sub-elements, without any leading or trailing whitespace.
|
1177 | * @return {!Promise} A promise that will be resolved with the
|
1178 | * element's visible text.
|
1179 | */
|
1180 | getText(): Promise<string>;
|
1181 |
|
1182 | /**
|
1183 | * Schedules a command to compute the size of this element's bounding box, in
|
1184 | * pixels.
|
1185 | * @return {!Promise} A promise that will be resolved with the
|
1186 | * element's size as a {@code {width:number, height:number}} object.
|
1187 | */
|
1188 | getSize(): Promise<ISize>;
|
1189 |
|
1190 | /**
|
1191 | * Returns an object describing an element's location, in pixels relative to
|
1192 | * the document element, and the element's size in pixels.
|
1193 | */
|
1194 | getRect(): Promise<IRectangle>;
|
1195 |
|
1196 | /**
|
1197 | * Schedules a command to compute the location of this element in page space.
|
1198 | * @return {!Promise} A promise that will be resolved to the
|
1199 | * element's location as a {@code {x:number, y:number}} object.
|
1200 | */
|
1201 | getLocation(): Promise<ILocation>;
|
1202 |
|
1203 | /**
|
1204 | * Schedules a command to query whether the DOM element represented by this
|
1205 | * instance is enabled, as dicted by the {@code disabled} attribute.
|
1206 | * @return {!Promise} A promise that will be resolved with
|
1207 | * whether this element is currently enabled.
|
1208 | */
|
1209 | isEnabled(): Promise<boolean>;
|
1210 |
|
1211 | /**
|
1212 | * Schedules a command to query whether this element is selected.
|
1213 | * @return {!Promise} A promise that will be resolved with
|
1214 | * whether this element is currently selected.
|
1215 | */
|
1216 | isSelected(): Promise<boolean>;
|
1217 |
|
1218 | /**
|
1219 | * Schedules a command to submit the form containing this element (or this
|
1220 | * element if it is a FORM element). This command is a no-op if the element is
|
1221 | * not contained in a form.
|
1222 | * @return {!Promise} A promise that will be resolved when
|
1223 | * the form has been submitted.
|
1224 | */
|
1225 | submit(): Promise<void>;
|
1226 |
|
1227 | /**
|
1228 | * Schedules a command to clear the {@code value} of this element. This
|
1229 | * command has no effect if the underlying DOM element is neither a text INPUT
|
1230 | * element nor a TEXTAREA element.
|
1231 | * @return {!Promise} A promise that will be resolved when
|
1232 | * the element has been cleared.
|
1233 | */
|
1234 | clear(): Promise<void>;
|
1235 |
|
1236 | /**
|
1237 | * Schedules a command to test whether this element is currently displayed.
|
1238 | * @return {!Promise} A promise that will be resolved with
|
1239 | * whether this element is currently visible on the page.
|
1240 | */
|
1241 | isDisplayed(): Promise<boolean>;
|
1242 |
|
1243 | /**
|
1244 | * @return {!Promise.<WebElement.Id>} A promise
|
1245 | * that resolves to this element's JSON representation as defined by the
|
1246 | * WebDriver wire protocol.
|
1247 | * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol
|
1248 | */
|
1249 | getId(): Promise<IWebElementId>;
|
1250 |
|
1251 | // endregion
|
1252 | }
|
1253 |
|
1254 | export interface IWebElementFinders {
|
1255 | /**
|
1256 | * Schedule a command to find a descendant of this element. If the element
|
1257 | * cannot be found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will
|
1258 | * be returned by the driver. Unlike other commands, this error cannot be
|
1259 | * suppressed. In other words, scheduling a command to find an element doubles
|
1260 | * as an assert that the element is present on the page. To test whether an
|
1261 | * element is present on the page, use {@code #findElements}.
|
1262 | *
|
1263 | * <p>The search criteria for an element may be defined using one of the
|
1264 | * factories in the {@link By} namespace, or as a short-hand
|
1265 | * {@link By.Hash} object. For example, the following two statements
|
1266 | * are equivalent:
|
1267 | * <code><pre>
|
1268 | * var e1 = element.findElement(By.id('foo'));
|
1269 | * var e2 = element.findElement({id:'foo'});
|
1270 | * </pre></code>
|
1271 | *
|
1272 | * <p>You may also provide a custom locator function, which takes as input
|
1273 | * this WebDriver instance and returns a {@link WebElement}, or a
|
1274 | * promise that will resolve to a WebElement. For example, to find the first
|
1275 | * visible link on a page, you could write:
|
1276 | * <code><pre>
|
1277 | * var link = element.findElement(firstVisibleLink);
|
1278 | *
|
1279 | * function firstVisibleLink(element) {
|
1280 | * var links = element.findElements(By.tagName('a'));
|
1281 | * return promise.filter(links, function(link) {
|
1282 | * return links.isDisplayed();
|
1283 | * }).then(function(visibleLinks) {
|
1284 | * return visibleLinks[0];
|
1285 | * });
|
1286 | * }
|
1287 | * </pre></code>
|
1288 | *
|
1289 | * @param {!(Locator|By.Hash|Function)} locator The
|
1290 | * locator strategy to use when searching for the element.
|
1291 | * @return {!WebElement} A WebElement that can be used to issue
|
1292 | * commands against the located element. If the element is not found, the
|
1293 | * element will be invalidated and all scheduled commands aborted.
|
1294 | */
|
1295 | findElement(locator: Locator): WebElementPromise;
|
1296 |
|
1297 | /**
|
1298 | * Schedules a command to find all of the descendants of this element that
|
1299 | * match the given search criteria.
|
1300 | *
|
1301 | * @param {!(Locator|By.Hash|Function)} locator The
|
1302 | * locator strategy to use when searching for the elements.
|
1303 | * @return {!Promise.<!Array.<!WebElement>>} A
|
1304 | * promise that will resolve to an array of WebElements.
|
1305 | */
|
1306 | findElements(locator: Locator): Promise<WebElement[]>;
|
1307 | }
|
1308 |
|
1309 | /**
|
1310 | * Defines an object that can be asynchronously serialized to its WebDriver
|
1311 | * wire representation.
|
1312 | *
|
1313 | * @template T
|
1314 | */
|
1315 | export interface Serializable<T> {
|
1316 | /**
|
1317 | * Returns either this instance's serialized represention, if immediately
|
1318 | * available, or a promise for its serialized representation. This function is
|
1319 | * conceptually equivalent to objects that have a {@code toJSON()} property,
|
1320 | * except the serialize() result may be a promise or an object containing a
|
1321 | * promise (which are not directly JSON friendly).
|
1322 | *
|
1323 | * @return {!(T|IThenable.<!T>)} This instance's serialized wire format.
|
1324 | */
|
1325 | serialize(): T | Promise<T>;
|
1326 | }
|
1327 |
|
1328 | /**
|
1329 | * Represents a DOM element. WebElements can be found by searching from the
|
1330 | * document root using a {@link WebDriver} instance, or by searching
|
1331 | * under another WebElement:
|
1332 | *
|
1333 | * driver.get('http://www.google.com');
|
1334 | * var searchForm = driver.findElement(By.tagName('form'));
|
1335 | * var searchBox = searchForm.findElement(By.name('q'));
|
1336 | * searchBox.sendKeys('webdriver');
|
1337 | *
|
1338 | * The WebElement is implemented as a promise for compatibility with the promise
|
1339 | * API. It will always resolve itself when its internal state has been fully
|
1340 | * resolved and commands may be issued against the element. This can be used to
|
1341 | * catch errors when an element cannot be located on the page:
|
1342 | *
|
1343 | * driver.findElement(By.id('not-there')).then(function(element) {
|
1344 | * alert('Found an element that was not expected to be there!');
|
1345 | * }, function(error) {
|
1346 | * alert('The element was not found, as expected');
|
1347 | * });
|
1348 | */
|
1349 | export class WebElement implements Serializable<IWebElementId> {
|
1350 | /**
|
1351 | * @param {!WebDriver} driver the parent WebDriver instance for this element.
|
1352 | * @param {(!IThenable<string>|string)} id The server-assigned opaque ID for
|
1353 | * the underlying DOM element.
|
1354 | */
|
1355 | constructor(driver: WebDriver, id: Promise<string> | string);
|
1356 |
|
1357 | /**
|
1358 | * @param {string} id The raw ID.
|
1359 | * boolean=} opt_noLegacy Whether to exclude the legacy element key.
{ |
1360 | * @return {!Object} The element ID for use with WebDriver's wire protocol.
|
1361 | */
|
1362 | static buildId(id: string, opt_noLegacy?: boolean): IWebElementId;
|
1363 |
|
1364 | /**
|
1365 | * Extracts the encoded WebElement ID from the object.
|
1366 | *
|
1367 | * @param {?} obj The object to extract the ID from.
|
1368 | * @return {string} the extracted ID.
|
1369 | * @throws {TypeError} if the object is not a valid encoded ID.
|
1370 | */
|
1371 | static extractId(obj: IWebElementId): string;
|
1372 |
|
1373 | /**
|
1374 | * @param {?} obj the object to test.
|
1375 | * @return {boolean} whether the object is a valid encoded WebElement ID.
|
1376 | */
|
1377 | static isId(obj: IWebElementId): boolean;
|
1378 |
|
1379 | /**
|
1380 | * Compares two WebElements for equality.
|
1381 | *
|
1382 | * @param {!WebElement} a A WebElement.
|
1383 | * @param {!WebElement} b A WebElement.
|
1384 | * @return {!Promise<boolean>} A promise that will be
|
1385 | * resolved to whether the two WebElements are equal.
|
1386 | */
|
1387 | static equals(a: WebElement, b: WebElement): Promise<boolean>;
|
1388 |
|
1389 | /**
|
1390 | * @return {!WebDriver} The parent driver for this instance.
|
1391 | */
|
1392 | getDriver(): WebDriver;
|
1393 |
|
1394 | /**
|
1395 | * @return {!Promise<string>} A promise that resolves to
|
1396 | * the server-assigned opaque ID assigned to this element.
|
1397 | */
|
1398 | getId(): Promise<string>;
|
1399 |
|
1400 | /**
|
1401 | * Schedule a command to find a descendant of this element. If the element
|
1402 | * cannot be found, a {@link bot.ErrorCode.NO_SUCH_ELEMENT} result will
|
1403 | * be returned by the driver. Unlike other commands, this error cannot be
|
1404 | * suppressed. In other words, scheduling a command to find an element doubles
|
1405 | * as an assert that the element is present on the page. To test whether an
|
1406 | * element is present on the page, use {@link #findElements}.
|
1407 | *
|
1408 | * The search criteria for an element may be defined using one of the
|
1409 | * factories in the {@link By} namespace, or as a short-hand
|
1410 | * {@link By.Hash} object. For example, the following two statements
|
1411 | * are equivalent:
|
1412 | *
|
1413 | * var e1 = element.findElement(By.id('foo'));
|
1414 | * var e2 = element.findElement({id:'foo'});
|
1415 | *
|
1416 | * You may also provide a custom locator function, which takes as input
|
1417 | * this WebDriver instance and returns a {@link WebElement}, or a
|
1418 | * promise that will resolve to a WebElement. For example, to find the first
|
1419 | * visible link on a page, you could write:
|
1420 | *
|
1421 | * var link = element.findElement(firstVisibleLink);
|
1422 | *
|
1423 | * function firstVisibleLink(element) {
|
1424 | * var links = element.findElements(By.tagName('a'));
|
1425 | * return promise.filter(links, function(link) {
|
1426 | * return links.isDisplayed();
|
1427 | * }).then(function(visibleLinks) {
|
1428 | * return visibleLinks[0];
|
1429 | * });
|
1430 | * }
|
1431 | *
|
1432 | * @param {!(by.By|Function)} locator The locator strategy to use when
|
1433 | * searching for the element.
|
1434 | * @return {!WebElementPromise} A WebElement that can be used to issue
|
1435 | * commands against the located element. If the element is not found, the
|
1436 | * element will be invalidated and all scheduled commands aborted.
|
1437 | */
|
1438 | findElement(locator: Locator): WebElementPromise;
|
1439 |
|
1440 | /**
|
1441 | * Schedules a command to find all of the descendants of this element that
|
1442 | * match the given search criteria.
|
1443 | *
|
1444 | * @param {!(by.By|Function)} locator The locator strategy to use when
|
1445 | * searching for the element.
|
1446 | * @return {!Promise<!Array<!WebElement>>} A
|
1447 | * promise that will resolve to an array of WebElements.
|
1448 | */
|
1449 | findElements(locator: Locator): Promise<WebElement[]>;
|
1450 |
|
1451 | /**
|
1452 | * Schedules a command to click on this element.
|
1453 | * @return {!Promise.<void>} A promise that will be resolved
|
1454 | * when the click command has completed.
|
1455 | */
|
1456 | click(): Promise<void>;
|
1457 |
|
1458 | /**
|
1459 | * Schedules a command to type a sequence on the DOM element represented by
|
1460 | * this promsieinstance.
|
1461 | *
|
1462 | * Modifier keys (SHIFT, CONTROL, ALT, META) are stateful; once a modifier is
|
1463 | * processed in the keysequence, that key state is toggled until one of the
|
1464 | * following occurs:
|
1465 | *
|
1466 | * - The modifier key is encountered again in the sequence. At this point the
|
1467 | * state of the key is toggled (along with the appropriate keyup/down
|
1468 | * events).
|
1469 | * - The {@link Key.NULL} key is encountered in the sequence. When
|
1470 | * this key is encountered, all modifier keys current in the down state are
|
1471 | * released (with accompanying keyup events). The NULL key can be used to
|
1472 | * simulate common keyboard shortcuts:
|
1473 | *
|
1474 | * element.sendKeys('text was',
|
1475 | * Key.CONTROL, 'a', Key.NULL,
|
1476 | * 'now text is');
|
1477 | * // Alternatively:
|
1478 | * element.sendKeys('text was',
|
1479 | * Key.chord(Key.CONTROL, 'a'),
|
1480 | * 'now text is');
|
1481 | *
|
1482 | * - The end of the keysequence is encountered. When there are no more keys
|
1483 | * to type, all depressed modifier keys are released (with accompanying
|
1484 | * keyup events).
|
1485 | *
|
1486 | * If this element is a file input ({@code <input type='file'>}), the
|
1487 | * specified key sequence should specify the path to the file to attach to
|
1488 | * the element. This is analgous to the user clicking 'Browse...' and entering
|
1489 | * the path into the file select dialog.
|
1490 | *
|
1491 | * var form = driver.findElement(By.css('form'));
|
1492 | * var element = form.findElement(By.css('input[type=file]'));
|
1493 | * element.sendKeys('/path/to/file.txt');
|
1494 | * form.submit();
|
1495 | *
|
1496 | * For uploads to function correctly, the entered path must reference a file
|
1497 | * on the _browser's_ machine, not the local machine running this script. When
|
1498 | * running against a remote Selenium server, a {@link FileDetector}
|
1499 | * may be used to transparently copy files to the remote machine before
|
1500 | * attempting to upload them in the browser.
|
1501 | *
|
1502 | * __Note:__ On browsers where native keyboard events are not supported
|
1503 | * (e.g. Firefox on OS X), key events will be synthesized. Special
|
1504 | * punctionation keys will be synthesized according to a standard QWERTY en-us
|
1505 | * keyboard layout.
|
1506 | *
|
1507 | * @param {...(string|!Promise<string>)} var_args The sequence
|
1508 | * of keys to type. All arguments will be joined into a single sequence.
|
1509 | * @return {!Promise.<void>} A promise that will be resolved
|
1510 | * when all keys have been typed.
|
1511 | */
|
1512 | sendKeys(...var_args: Array<string | number | Promise<string | number>>): Promise<void>;
|
1513 |
|
1514 | /**
|
1515 | * Schedules a command to query for the tag/node name of this element.
|
1516 | * @return {!Promise.<string>} A promise that will be
|
1517 | * resolved with the element's tag name.
|
1518 | */
|
1519 | getTagName(): Promise<string>;
|
1520 |
|
1521 | /**
|
1522 | * Schedules a command to query for the computed style of the element
|
1523 | * represented by this instance. If the element inherits the named style from
|
1524 | * its parent, the parent will be queried for its value. Where possible,
|
1525 | * color values will be converted to their hex representation (e.g. #00ff00
|
1526 | * instead of rgb(0, 255, 0)).
|
1527 | *
|
1528 | * _Warning:_ the value returned will be as the browser interprets it, so
|
1529 | * it may be tricky to form a proper assertion.
|
1530 | *
|
1531 | * @param {string} cssStyleProperty The name of the CSS style property to look
|
1532 | * up.
|
1533 | * @return {!Promise<string>} A promise that will be
|
1534 | * resolved with the requested CSS value.
|
1535 | */
|
1536 | getCssValue(cssStyleProperty: string): Promise<string>;
|
1537 |
|
1538 | /**
|
1539 | * Schedules a command to query for the value of the given attribute of the
|
1540 | * element. Will return the current value, even if it has been modified after
|
1541 | * the page has been loaded. More exactly, this method will return the value
|
1542 | * of the given attribute, unless that attribute is not present, in which case
|
1543 | * the value of the property with the same name is returned. If neither value
|
1544 | * is set, null is returned (for example, the 'value' property of a textarea
|
1545 | * element). The 'style' attribute is converted as best can be to a
|
1546 | * text representation with a trailing semi-colon. The following are deemed to
|
1547 | * be 'boolean' attributes and will return either 'true' or null:
|
1548 | *
|
1549 | * async, autofocus, autoplay, checked, compact, complete, controls, declare,
|
1550 | * defaultchecked, defaultselected, defer, disabled, draggable, ended,
|
1551 | * formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope,
|
1552 | * loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open,
|
1553 | * paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
|
1554 | * selected, spellcheck, truespeed, willvalidate
|
1555 | *
|
1556 | * Finally, the following commonly mis-capitalized attribute/property names
|
1557 | * are evaluated as expected:
|
1558 | *
|
1559 | * - 'class'
|
1560 | * - 'readonly'
|
1561 | *
|
1562 | * @param {string} attributeName The name of the attribute to query.
|
1563 | * @return {!Promise.<?string>} A promise that will be
|
1564 | * resolved with the attribute's value. The returned value will always be
|
1565 | * either a string or null.
|
1566 | */
|
1567 | getAttribute(attributeName: string): Promise<string>;
|
1568 |
|
1569 | /**
|
1570 | * Get the visible (i.e. not hidden by CSS) innerText of this element,
|
1571 | * including sub-elements, without any leading or trailing whitespace.
|
1572 | * @return {!Promise.<string>} A promise that will be
|
1573 | * resolved with the element's visible text.
|
1574 | */
|
1575 | getText(): Promise<string>;
|
1576 |
|
1577 | /**
|
1578 | * DEPRECATED 3.0
|
1579 | * Schedules a command to compute the size of this element's bounding box, in
|
1580 | * pixels.
|
1581 | * @return {!Promise.<{width: number, height: number}>} A
|
1582 | * promise that will be resolved with the element's size as a
|
1583 | * {@code {width:number, height:number}} object.
|
1584 | */
|
1585 | getSize(): Promise<ISize>;
|
1586 |
|
1587 | /**
|
1588 | * Returns an object describing an element's location, in pixels relative to
|
1589 | * the document element, and the element's size in pixels.
|
1590 | */
|
1591 | getRect(): Promise<IRectangle>;
|
1592 |
|
1593 | /**
|
1594 | * DEPRECATED 3.0
|
1595 | * Schedules a command to compute the location of this element in page space.
|
1596 | * @return {!Promise.<{x: number, y: number}>} A promise that
|
1597 | * will be resolved to the element's location as a
|
1598 | * {@code {x:number, y:number}} object.
|
1599 | */
|
1600 | getLocation(): Promise<ILocation>;
|
1601 |
|
1602 | /**
|
1603 | * Schedules a command to query whether the DOM element represented by this
|
1604 | * instance is enabled, as dicted by the {@code disabled} attribute.
|
1605 | * @return {!Promise.<boolean>} A promise that will be
|
1606 | * resolved with whether this element is currently enabled.
|
1607 | */
|
1608 | isEnabled(): Promise<boolean>;
|
1609 |
|
1610 | /**
|
1611 | * Schedules a command to query whether this element is selected.
|
1612 | * @return {!Promise.<boolean>} A promise that will be
|
1613 | * resolved with whether this element is currently selected.
|
1614 | */
|
1615 | isSelected(): Promise<boolean>;
|
1616 |
|
1617 | /**
|
1618 | * Schedules a command to submit the form containing this element (or this
|
1619 | * element if it is a FORM element). This command is a no-op if the element is
|
1620 | * not contained in a form.
|
1621 | * @return {!Promise.<void>} A promise that will be resolved
|
1622 | * when the form has been submitted.
|
1623 | */
|
1624 | submit(): Promise<void>;
|
1625 |
|
1626 | /**
|
1627 | * Schedules a command to clear the `value` of this element. This command has
|
1628 | * no effect if the underlying DOM element is neither a text INPUT element
|
1629 | * nor a TEXTAREA element.
|
1630 | * @return {!Promise<void>} A promise that will be resolved
|
1631 | * when the element has been cleared.
|
1632 | */
|
1633 | clear(): Promise<void>;
|
1634 |
|
1635 | /**
|
1636 | * Schedules a command to test whether this element is currently displayed.
|
1637 | * @return {!Promise.<boolean>} A promise that will be
|
1638 | * resolved with whether this element is currently visible on the page.
|
1639 | */
|
1640 | isDisplayed(): Promise<boolean>;
|
1641 |
|
1642 | /**
|
1643 | * Take a screenshot of the visible region encompassed by this element's
|
1644 | * bounding rectangle.
|
1645 | *
|
1646 | * @param {boolean=} opt_scroll Optional argument that indicates whether the
|
1647 | * element should be scrolled into view before taking a screenshot.
|
1648 | * Defaults to false.
|
1649 | * @return {!Promise<string>} A promise that will be
|
1650 | * resolved to the screenshot as a base-64 encoded PNG.
|
1651 | */
|
1652 | takeScreenshot(opt_scroll?: boolean): Promise<string>;
|
1653 |
|
1654 | /**
|
1655 | * Get the shadow root of the current web element.
|
1656 | * @returns {!Promise<ShadowRoot>} A promise that will be
|
1657 | * resolved with the elements shadow root or rejected
|
1658 | * with {@link NoSuchShadowRootError}
|
1659 | */
|
1660 | getShadowRoot(): ShadowRootPromise;
|
1661 |
|
1662 | /** @override */
|
1663 | serialize(): Promise<IWebElementId>;
|
1664 | }
|
1665 |
|
1666 | /**
|
1667 | * WebElementPromise is a promise that will be fulfilled with a WebElement.
|
1668 | * This serves as a forward proxy on WebElement, allowing calls to be
|
1669 | * scheduled without directly on this instance before the underlying
|
1670 | * WebElement has been fulfilled. In other words, the following two statements
|
1671 | * are equivalent:
|
1672 | * <pre><code>
|
1673 | * driver.findElement({id: 'my-button'}).click();
|
1674 | * driver.findElement({id: 'my-button'}).then(function(el) {
|
1675 | * return el.click();
|
1676 | * });
|
1677 | * </code></pre>
|
1678 | *
|
1679 | * @param {!WebDriver} driver The parent WebDriver instance for this
|
1680 | * element.
|
1681 | * @param {!Promise.<!WebElement>} el A promise
|
1682 | * that will resolve to the promised element.
|
1683 | * @final
|
1684 | */
|
1685 | export interface WebElementPromise extends Promise<WebElement> {}
|
1686 |
|
1687 | /**
|
1688 | * Implement WebElementPromise
|
1689 | */
|
1690 | export class WebElementPromise extends WebElement {
|
1691 | /**
|
1692 | * @param {!WebDriver} driver The parent WebDriver instance for this
|
1693 | * element.
|
1694 | * @param {!Promise<!WebElement>} el A promise
|
1695 | * that will resolve to the promised element.
|
1696 | */
|
1697 | constructor(driver: WebDriver, el: Promise<WebElement>);
|
1698 | }
|
1699 |
|
1700 | /**
|
1701 | * Contains information about a WebDriver session.
|
1702 | */
|
1703 | export class Session {
|
1704 | // region Constructors
|
1705 |
|
1706 | /**
|
1707 | * @param {string} id The session ID.
|
1708 | * @param {!(Object|Capabilities)} capabilities The session
|
1709 | * capabilities.
|
1710 | */
|
1711 | constructor(id: string, capabilities: Capabilities | {});
|
1712 |
|
1713 | // endregion
|
1714 |
|
1715 | // region Methods
|
1716 |
|
1717 | /**
|
1718 | * @return {string} This session's ID.
|
1719 | */
|
1720 | getId(): string;
|
1721 |
|
1722 | /**
|
1723 | * @return {!Capabilities} This session's capabilities.
|
1724 | */
|
1725 | getCapabilities(): Capabilities;
|
1726 |
|
1727 | /**
|
1728 | * Retrieves the value of a specific capability.
|
1729 | * @param {string} key The capability to retrieve.
|
1730 | * @return {*} The capability value.
|
1731 | */
|
1732 | getCapability(key: string): any;
|
1733 |
|
1734 | /**
|
1735 | * Returns the JSON representation of this object, which is just the string
|
1736 | * session ID.
|
1737 | * @return {string} The JSON representation of this Session.
|
1738 | */
|
1739 | toJSON(): string;
|
1740 |
|
1741 | // endregion
|
1742 | }
|