UNPKG

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