1 | import { logging, ProxyConfig } from "../";
|
2 | import Symbols from "./symbols";
|
3 |
|
4 | /**
|
5 | * Recognized browser names.
|
6 | */
|
7 | export interface IBrowser {
|
8 | CHROME: "chrome";
|
9 | EDGE: "MicrosoftEdge";
|
10 | FIREFOX: "firefox";
|
11 | INTERNET_EXPLORER: "internet explorer";
|
12 | SAFARI: "safari";
|
13 | }
|
14 |
|
15 | /**
|
16 | * Instace of
|
17 | */
|
18 | export const Browser: IBrowser;
|
19 |
|
20 | /**
|
21 | * Common platform names. These platforms are not explicitly defined by the
|
22 | * WebDriver spec, however, their use is encouraged for interoperability.
|
23 | *
|
24 | * @see <https://w3c.github.io/webdriver/webdriver-spec.html>
|
25 | */
|
26 | export interface IPlatform {
|
27 | LINUX: string;
|
28 | MAC: string;
|
29 | WINDOWS: string;
|
30 | }
|
31 |
|
32 | export const Platform: IPlatform;
|
33 |
|
34 | /**
|
35 | * Strategies for waiting for [document readiness] after a navigation event.
|
36 | *
|
37 | * [document readiness]: https://html.spec.whatwg.org/#current-document-readiness
|
38 | */
|
39 | export interface IPageLoadStrategy {
|
40 | /**
|
41 | * Indicates WebDriver should not wait on the document readiness state after a
|
42 | * navigation event.
|
43 | */
|
44 | NONE: string;
|
45 |
|
46 | /**
|
47 | * Indicates WebDriver should wait for the document readiness state to
|
48 | * become "interactive" after navigation.
|
49 | */
|
50 | EAGER: string;
|
51 |
|
52 | /**
|
53 | * Indicates WebDriver should wait for the document readiness state to
|
54 | * be "complete" after navigation. This is the default page loading strategy.
|
55 | */
|
56 | NORMAL: string;
|
57 | }
|
58 |
|
59 | export const PageLoadStrategy: IPageLoadStrategy;
|
60 |
|
61 | /**
|
62 | * The possible default actions a WebDriver session can take to respond to
|
63 | * unhandled user prompts (`window.alert()`, `window.confirm()`, and
|
64 | * `window.prompt()`).
|
65 | */
|
66 | export interface IUserPromptHandler {
|
67 | /** All prompts should be silently accepted. */
|
68 | ACCEPT: string;
|
69 | /** All prompts should be silently dismissed. */
|
70 | DISMISS: string;
|
71 | /**
|
72 | * All prompts should be automatically accepted, but an error should be
|
73 | * returned to the next (or currently executing) WebDriver command.
|
74 | */
|
75 | ACCEPT_AND_NOTIFY: string;
|
76 | /**
|
77 | * All prompts should be automatically dismissed, but an error should be
|
78 | * returned to the next (or currently executing) WebDriver command.
|
79 | */
|
80 | DISMISS_AND_NOTIFY: string;
|
81 | /** All prompts should be left unhandled. */
|
82 | IGNORE: string;
|
83 | }
|
84 |
|
85 | export const UserPromptHandler: IUserPromptHandler;
|
86 |
|
87 | /**
|
88 | * Common webdriver capability keys.
|
89 | */
|
90 | export interface ICapability {
|
91 | /**
|
92 | * Indicates whether a WebDriver session implicitly trusts otherwise untrusted
|
93 | * and self-signed TLS certificates during navigation.
|
94 | */
|
95 | ACCEPT_INSECURE_TLS_CERTS: string;
|
96 |
|
97 | /**
|
98 | * The browser name. Common browser names are defined in the
|
99 | * {@link ./capabilities.Browser Browser} enum.
|
100 | */
|
101 | BROWSER_NAME: string;
|
102 |
|
103 | /** Identifies the browser version. */
|
104 | BROWSER_VERSION: string;
|
105 |
|
106 | /**
|
107 | * Key for the logging driver logging preferences.
|
108 | */
|
109 | LOGGING_PREFS: string;
|
110 |
|
111 | /**
|
112 | * Defines the session's
|
113 | * {@linkplain ./capabilities.PageLoadStrategy page loading strategy}.
|
114 | */
|
115 | PAGE_LOAD_STRATEGY: string;
|
116 |
|
117 | /**
|
118 | * Identifies the operating system of the endpoint node. Common values
|
119 | * recognized by the most WebDriver server implementations are predefined in
|
120 | * the {@link ./capabilities.Platform Platform} enum.
|
121 | */
|
122 | PLATFORM_NAME: string;
|
123 |
|
124 | /**
|
125 | * Describes the proxy configuration to use for a new WebDriver session.
|
126 | */
|
127 | PROXY: string;
|
128 |
|
129 | /**
|
130 | * Indicates whether the remote end supports all of the window resizing and
|
131 | * positioning commands:
|
132 | *
|
133 | * - {@linkplain ./webdriver.Window#getRect Window.getRect()}
|
134 | * - {@linkplain ./webdriver.Window#setRect Window.setRect()}
|
135 | * - {@linkplain ./webdriver.Window#maximize Window.maximize()}
|
136 | * - {@linkplain ./webdriver.Window#minimize Window.minimize()}
|
137 | * - {@linkplain ./webdriver.Window#fullscreen Window.fullscreen()}
|
138 | */
|
139 | SET_WINDOW_RECT: string;
|
140 |
|
141 | /**
|
142 | * Describes the {@linkplain ./capabilities.Timeouts timeouts} imposed on
|
143 | * certain session operations.
|
144 | */
|
145 | TIMEOUTS: string;
|
146 |
|
147 | /**
|
148 | * Defines how a WebDriver session should
|
149 | * {@linkplain ./capabilities.UserPromptHandler respond} to unhandled user
|
150 | * prompts.
|
151 | */
|
152 | UNHANDLED_PROMPT_BEHAVIOR: string;
|
153 | }
|
154 |
|
155 | /**
|
156 | * The standard WebDriver capability keys.
|
157 | */
|
158 | export const Capability: ICapability;
|
159 |
|
160 | /**
|
161 | * Describes a set of capabilities for a WebDriver session.
|
162 | */
|
163 | export class Capabilities {
|
164 | // region Constructors
|
165 |
|
166 | /**
|
167 | * @param {(Capabilities|Map<string, ?>|Object)=} other Another set of
|
168 | * capabilities to initialize this instance from.
|
169 | */
|
170 | constructor(other?: Capabilities | Map<string, any> | {});
|
171 |
|
172 | // endregion
|
173 |
|
174 | // region Static Methods
|
175 |
|
176 | /**
|
177 | * @return {!Capabilities} A basic set of capabilities for Chrome.
|
178 | */
|
179 | static chrome(): Capabilities;
|
180 |
|
181 | /**
|
182 | * @return {!Capabilities} A basic set of capabilities for Microsoft Edge.
|
183 | */
|
184 | static edge(): Capabilities;
|
185 |
|
186 | /**
|
187 | * @return {!Capabilities} A basic set of capabilities for Firefox.
|
188 | */
|
189 | static firefox(): Capabilities;
|
190 |
|
191 | /**
|
192 | * @return {!Capabilities} A basic set of capabilities for
|
193 | * Internet Explorer.
|
194 | */
|
195 | static ie(): Capabilities;
|
196 |
|
197 | /**
|
198 | * @return {!Capabilities} A basic set of capabilities for Safari.
|
199 | */
|
200 | static safari(): Capabilities;
|
201 |
|
202 | // endregion
|
203 |
|
204 | // region Methods
|
205 |
|
206 | /**
|
207 | * @return {!Object<string, ?>} The JSON representation of this instance.
|
208 | * Note, the returned object may contain nested promised values.
|
209 | * @suppress {checkTypes} Suppress [] access on a struct (state inherited from
|
210 | * Map).
|
211 | */
|
212 | [Symbols.serialize](): {};
|
213 |
|
214 | /**
|
215 | * @param {string} key The capability to return.
|
216 | * @return {*} The capability with the given key, or {@code null} if it has
|
217 | * not been set.
|
218 | */
|
219 | get(key: string): any;
|
220 |
|
221 | /**
|
222 | * @param {string} key The capability to check.
|
223 | * @return {boolean} Whether the specified capability is set.
|
224 | */
|
225 | has(key: string): boolean;
|
226 |
|
227 | /**
|
228 | * @return {!Iterator<string>} an iterator of the keys set.
|
229 | */
|
230 | keys(): IterableIterator<string>;
|
231 |
|
232 | /**
|
233 | * Merges another set of capabilities into this instance.
|
234 | * @param {!(Capabilities|Map<String, ?>|Object<string, ?>)} other The other
|
235 | * set of capabilities to merge.
|
236 | * @return {!Capabilities} A self reference.
|
237 | */
|
238 | merge(other: Capabilities | Map<string, any> | {}): Capabilities;
|
239 |
|
240 | /**
|
241 | * Deletes an entry from this set of capabilities.
|
242 | *
|
243 | * @param {string} key the capability key to delete.
|
244 | */
|
245 | delete(key: string): boolean;
|
246 |
|
247 | /**
|
248 | * @param {string} key The capability key.
|
249 | * @param {*} value The capability value.
|
250 | * @return {!Capabilities} A self reference.
|
251 | * @throws {TypeError} If the `key` is not a string.
|
252 | */
|
253 | set(key: string, value: any): Capabilities;
|
254 |
|
255 | /**
|
256 | * Sets whether a WebDriver session should implicitly accept self-signed, or
|
257 | * other untrusted TLS certificates on navigation.
|
258 | *
|
259 | * @param {boolean} accept whether to accept insecure certs.
|
260 | * @return {!Capabilities} a self reference.
|
261 | */
|
262 | setAcceptInsecureCerts(accept: boolean): Capabilities;
|
263 |
|
264 | /**
|
265 | * @return {boolean} whether the session is configured to accept insecure
|
266 | * TLS certificates.
|
267 | */
|
268 | getAcceptInsecureCerts(): boolean;
|
269 |
|
270 | /**
|
271 | * Sets the name of the target browser.
|
272 | *
|
273 | * @param {(Browser|string)} name the browser name.
|
274 | * @return {!Capabilities} a self reference.
|
275 | */
|
276 | setBrowserName(name: string): Capabilities;
|
277 |
|
278 | /**
|
279 | * @return {(string|undefined)} the configured browser name, or undefined if
|
280 | * not set.
|
281 | */
|
282 | getBrowserName(): string | undefined;
|
283 |
|
284 | /**
|
285 | * Sets the desired version of the target browser.
|
286 | *
|
287 | * @param {string} version the desired version.
|
288 | * @return {!Capabilities} a self reference.
|
289 | */
|
290 | setBrowserVersion(version: string): Capabilities;
|
291 |
|
292 | /**
|
293 | * @return {(string|undefined)} the configured browser version, or undefined
|
294 | * if not set.
|
295 | */
|
296 | getBrowserVersion(): string | undefined;
|
297 |
|
298 | /**
|
299 | * Sets the desired page loading strategy for a new WebDriver session.
|
300 | *
|
301 | * @param {PageLoadStrategy} strategy the desired strategy.
|
302 | * @return {!Capabilities} a self reference.
|
303 | */
|
304 | setPageLoadStrategy(strategy: string): Capabilities;
|
305 |
|
306 | /**
|
307 | * Returns the configured page load strategy.
|
308 | *
|
309 | * @return {(string|undefined)} the page load strategy.
|
310 | */
|
311 | getPageLoadStrategy(): string | undefined;
|
312 |
|
313 | /**
|
314 | * Sets the target platform.
|
315 | *
|
316 | * @param {(Platform|string)} platform the target platform.
|
317 | * @return {!Capabilities} a self reference.
|
318 | */
|
319 | setPlatform(platform: string): Capabilities;
|
320 |
|
321 | /**
|
322 | * @return {(string|undefined)} the configured platform or undefined if not
|
323 | * set.
|
324 | */
|
325 | getPlatform(): string | undefined;
|
326 |
|
327 | /**
|
328 | * Sets the logging preferences. Preferences may be specified as a
|
329 | * {@link ./logging.Preferences} instance, or as a map of log-type to
|
330 | * log-level.
|
331 | * @param {!(./logging.Preferences|Object<string>)} prefs The logging
|
332 | * preferences.
|
333 | * @return {!Capabilities} A self reference.
|
334 | */
|
335 | setLoggingPrefs(prefs: logging.Preferences | {}): Capabilities;
|
336 |
|
337 | /**
|
338 | * Sets the proxy configuration for this instance.
|
339 | * @param {proxy.Config} proxy The desired proxy configuration.
|
340 | * @return {!Capabilities} A self reference.
|
341 | */
|
342 | setProxy(proxy: ProxyConfig): Capabilities;
|
343 |
|
344 | /**
|
345 | * @return {(proxy.Config|undefined)} the configured proxy settings, or
|
346 | * undefined if not set.
|
347 | */
|
348 | getProxy(): ProxyConfig | undefined;
|
349 |
|
350 | /**
|
351 | * Sets the default action to take with an unexpected alert before returning
|
352 | * an error. If unspecified, WebDriver will default to
|
353 | * {@link UserPromptHandler.DISMISS_AND_NOTIFY}.
|
354 | *
|
355 | * @param {?UserPromptHandler} behavior The way WebDriver should respond to
|
356 | * unhandled user prompts.
|
357 | * @return {!Capabilities} A self reference.
|
358 | */
|
359 | setAlertBehavior(behavior: string): Capabilities;
|
360 |
|
361 | /**
|
362 | * @return {(UserPromptHandler|undefined)} the behavior pattern for responding
|
363 | * to unhandled user prompts, or undefined if not set.
|
364 | */
|
365 | getAlertBehavior(): string | undefined;
|
366 |
|
367 | // endregion
|
368 | }
|
369 |
|
370 | export interface ITimeouts {
|
371 | /**
|
372 | * Defines when, in milliseconds, to interrupt a script that is being
|
373 | * {@linkplain ./webdriver.IWebDriver#executeScript evaluated}.
|
374 | */
|
375 | script?: number | undefined;
|
376 |
|
377 | /**
|
378 | * The timeout, in milliseconds, to apply to navigation events along with the
|
379 | * {@link PageLoadStrategy}.
|
380 | */
|
381 | pageLoad?: number | undefined;
|
382 |
|
383 | /**
|
384 | * The maximum amount of time, in milliseconds, to spend attempting to
|
385 | * {@linkplain ./webdriver.IWebDriver#findElement locate} an element on the
|
386 | * current page.
|
387 | */
|
388 | implicit?: number | undefined;
|
389 | }
|