1 | // Type definitions for nightwatch 2.3
|
2 | // Project: http://nightwatchjs.org
|
3 | // Definitions by: Rahul Kavalapara <https://github.com/rkavalap>
|
4 | // Connor Schlesiger <https://github.com/schlesiger>
|
5 | // Clayton Astrom <https://github.com/ClaytonAstrom>
|
6 | // Lukas Beranek <https://github.com/lloiser>
|
7 | // Vaibhav Singh <https://github.com/vaibhavsingh97>
|
8 | // Andrei Rusu <https://github.com/beatfactor>
|
9 | // David Burns <https://github.com/AutomatedTester>
|
10 | // Ravi Sawlani <https://github.com/gravityvi>
|
11 | // Binayak Ghosh <https://github.com/swrdfish>
|
12 | // Harshit Agrawal <https://github.com/harshit-bs>
|
13 | // David Mello <https://github.com/literallyMello>
|
14 | // Luke Bickell <https://github.com/lukebickell>
|
15 | // Priyansh Garg <https://github.com/garg3133>
|
16 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
17 | // TypeScript Version: 4.5
|
18 | // Nightwatch Version: 2.3.0
|
19 |
|
20 | import { WebElement, By, RelativeBy, Actions } from 'selenium-webdriver';
|
21 | import { Protocol } from 'devtools-protocol';
|
22 | import { Expect } from './expect';
|
23 |
|
24 | export * from './globals';
|
25 | export * from './expect';
|
26 |
|
27 | export const ELEMENT_KEY = 'element-6066-11e4-a52e-4f735466cecf';
|
28 |
|
29 | export interface ElementResult { [ELEMENT_KEY]: string; }
|
30 |
|
31 | export interface JSON_WEB_OBJECT extends ElementResult {
|
32 | getId: () => string;
|
33 | }
|
34 |
|
35 | export type Definition = string | ElementProperties | Element | RelativeBy;
|
36 |
|
37 | export type Awaitable<T, V> = Omit<T, "then"> & PromiseLike<V>;
|
38 |
|
39 | export interface ChromePerfLoggingPrefs {
|
40 | /**
|
41 | * Default: true. Whether or not to collect events from Network domain.
|
42 | */
|
43 | enableNetwork?: boolean | undefined;
|
44 | /**
|
45 | * Default: true. Whether or not to collect events from Page domain.
|
46 | */
|
47 | enablePage?: boolean | undefined;
|
48 | /**
|
49 | * A comma-separated string of Chrome tracing categories for which trace events should be collected.
|
50 | * An unspecified or empty string disables tracing.
|
51 | */
|
52 | traceCategories?: string | undefined;
|
53 | /**
|
54 | * Default: 1000. The requested number of milliseconds between DevTools trace buffer usage events. For example, if 1000,
|
55 | * then once per second, DevTools will report how full the trace buffer is. If a report indicates the buffer usage is 100%,
|
56 | * a warning will be issued.
|
57 | */
|
58 | bufferUsageReportingInterval?: number | undefined;
|
59 | }
|
60 |
|
61 | export interface ChromeOptions {
|
62 | /**
|
63 | * List of command-line arguments to use when starting Chrome. Arguments with an associated value should be separated by a '=' sign
|
64 | * (e.g., ['start-maximized', 'user-data-dir=/tmp/temp_profile']).
|
65 | */
|
66 | args?: string[] | undefined;
|
67 | /**
|
68 | * Path to the Chrome executable to use (on Mac OS X, this should be the actual binary, not just the app. e.g.,
|
69 | * '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')
|
70 | */
|
71 | binary?: string | undefined;
|
72 | /**
|
73 | * A list of Chrome extensions to install on startup. Each item in the list should be a base-64 encoded packed Chrome extension (.crx)
|
74 | */
|
75 | extensions?: string[] | undefined;
|
76 | /**
|
77 | * A dictionary with each entry consisting of the name of the preference and its value. These preferences are applied
|
78 | * to the Local State file in the user data folder.
|
79 | */
|
80 | localState?: Record<string, string> | undefined;
|
81 | /**
|
82 | * A dictionary with each entry consisting of the name of the preference and its value. These preferences are only applied
|
83 | * to the user profile in use.
|
84 | */
|
85 | prefs?: Record<string, string> | undefined;
|
86 | /**
|
87 | * Default: false. If false, Chrome will be quit when ChromeDriver is killed, regardless of whether the session is quit.
|
88 | * If true, Chrome will only be quit if the session is quit (or closed). Note, if true, and the session is not quit,
|
89 | * ChromeDriver cannot clean up the temporary user data directory that the running Chrome instance is using.
|
90 | */
|
91 | detach?: boolean | undefined;
|
92 | /**
|
93 | * An address of a Chrome debugger server to connect to, in the form of <hostname/ip:port>, e.g. '127.0.0.1:38947'
|
94 | */
|
95 | debuggerAddress?: string | undefined;
|
96 | /**
|
97 | * List of Chrome command line switches to exclude that ChromeDriver by default passes when starting Chrome.
|
98 | * Do not prefix switches with --.
|
99 | */
|
100 | excludeSwitches?: string[] | undefined;
|
101 | /**
|
102 | * Directory to store Chrome minidumps . (Supported only on Linux.)
|
103 | */
|
104 | minidumpPath?: string | undefined;
|
105 | /**
|
106 | * A dictionary with either a value for “deviceName,” or values for “deviceMetrics” and “userAgent.” Refer to Mobile Emulation for more information.
|
107 | */
|
108 | mobileEmulation?: Record<string, string> | undefined;
|
109 | /**
|
110 | * An optional dictionary that specifies performance logging preferences. See below for more information.
|
111 | */
|
112 | perfLoggingPrefs?: ChromePerfLoggingPrefs | undefined;
|
113 | /**
|
114 | * A list of window types that will appear in the list of window handles. For access to <webview> elements, include "webview" in this list.
|
115 | */
|
116 | windowTypes?: string[] | undefined;
|
117 | }
|
118 |
|
119 | // TODO: visit later
|
120 | export interface NightwatchDesiredCapabilities {
|
121 | /**
|
122 | * The name of the browser being used; examples: {chrome|firefox|safari|edge|internet explorer|android|iPhone|iPad|opera|brave}.
|
123 | */
|
124 | browserName?: string | null;
|
125 |
|
126 | /**
|
127 | * The browser version, or the empty string if unknown.
|
128 | */
|
129 | version?: string | undefined;
|
130 |
|
131 | /**
|
132 | * A key specifying which platform the browser should be running on. This value should be one of {WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANDROID}.
|
133 | * When requesting a new session, the client may specify ANY to indicate any available platform may be used.
|
134 | * For more information see [GridPlatforms (https://code.google.com/p/selenium/wiki/GridPlatforms)]
|
135 | */
|
136 | platform?: string | undefined;
|
137 |
|
138 | /**
|
139 | * Whether the session supports taking screenshots of the current page.
|
140 | */
|
141 | takesScreenShot?: boolean | undefined;
|
142 |
|
143 | /**
|
144 | * Whether the session can interact with modal popups, such as window.alert and window.confirm.
|
145 | */
|
146 | handlesAlerts?: boolean | undefined;
|
147 |
|
148 | /**
|
149 | * Whether the session supports CSS selectors when searching for elements.
|
150 | */
|
151 | cssSelectorsEnabled?: boolean | undefined;
|
152 |
|
153 | /**
|
154 | * Whether the session supports executing user supplied JavaScript in the context of the current page (only on HTMLUnitDriver).
|
155 | */
|
156 | javascriptEnabled?: boolean | undefined;
|
157 |
|
158 | /**
|
159 | * Whether the session can interact with database storage.
|
160 | */
|
161 | databaseEnabled?: boolean | undefined;
|
162 |
|
163 | /**
|
164 | * Whether the session can set and query the browser's location context.
|
165 | */
|
166 | locationContextEnabled?: boolean | undefined;
|
167 |
|
168 | /**
|
169 | * Whether the session can interact with the application cache.
|
170 | */
|
171 | applicationCacheEnabled?: boolean | undefined;
|
172 |
|
173 | /**
|
174 | * Whether the session can query for the browser's connectivity and disable it if desired.
|
175 | */
|
176 | browserConnectionEnabled?: boolean | undefined;
|
177 |
|
178 | /**
|
179 | * Whether the session supports interactions with storage objects (http://www.w3.org/TR/2009/WD-webstorage-20091029/).
|
180 | */
|
181 | webStorageEnabled?: boolean | undefined;
|
182 |
|
183 | /**
|
184 | * Whether the session should accept all SSL certs by default.
|
185 | */
|
186 | acceptSslCerts?: boolean | undefined;
|
187 |
|
188 | /**
|
189 | * Whether the session can rotate the current page's current layout between portrait and landscape orientations (only applies to mobile platforms).
|
190 | */
|
191 | rotatable?: boolean | undefined;
|
192 |
|
193 | /**
|
194 | * Whether the session is capable of generating native events when simulating user input.
|
195 | */
|
196 | nativeEvents?: boolean | undefined;
|
197 |
|
198 | /**
|
199 | * What the browser should do with an unhandled alert before throwing out the UnhandledAlertException. Possible values are "accept", "dismiss" and "ignore"
|
200 | */
|
201 | unexpectedAlertBehaviour?: string | undefined;
|
202 |
|
203 | /**
|
204 | * Allows the user to specify whether elements are scrolled into the viewport for interaction to align with the top (0) or bottom (1) of the viewport.
|
205 | * The default value is to align with the top of the viewport. Supported in IE and Firefox (since 2.36)
|
206 | */
|
207 | elementScrollBehaviour?: number | undefined;
|
208 |
|
209 | /**
|
210 | * A JSON object describing the logging level of different components in the browser, the driver, or any intermediary WebDriver servers.
|
211 | * Available values for most loggers are "OFF", "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST", "ALL".
|
212 | * This produces a JSON object looking something like: {"loggingPrefs": {"driver": "INFO", "server": "OFF", "browser": "FINE"}}.
|
213 | */
|
214 | loggingPrefs?:
|
215 | | {
|
216 | browser?: string | undefined;
|
217 | driver?: string | undefined;
|
218 | server?: string | undefined;
|
219 | }
|
220 | | undefined;
|
221 | /**
|
222 | * This is a list of all the Chrome-specific desired capabilities.
|
223 | */
|
224 | chromeOptions?: ChromeOptions | undefined;
|
225 | }
|
226 |
|
227 | export interface NightwatchScreenshotOptions {
|
228 | enabled?: boolean | undefined;
|
229 | filename_format: ({
|
230 | testSuite,
|
231 | testCase,
|
232 | isError,
|
233 | dateObject,
|
234 | }?: {
|
235 | testSuite?: string;
|
236 | testCase?: string;
|
237 | isError?: boolean;
|
238 | dateObject?: Date;
|
239 | }) => string;
|
240 | on_failure?: boolean | undefined;
|
241 | on_error?: boolean | undefined;
|
242 | path?: string | undefined;
|
243 | }
|
244 |
|
245 | export interface NightwatchTestRunner {
|
246 | type?: string | undefined;
|
247 | options?:
|
248 | | {
|
249 | ui?: string | undefined;
|
250 | feature_path?: string | undefined;
|
251 | auto_start_session?: boolean | undefined;
|
252 | parallel?: number | undefined;
|
253 | reporter?: string | undefined;
|
254 | reporterOptions?: { [key: string]: any };
|
255 | }
|
256 | | undefined;
|
257 | }
|
258 |
|
259 | export interface NightwatchTestWorker {
|
260 | enabled: boolean;
|
261 | workers: string | number;
|
262 | node_options?: string | string[] | undefined;
|
263 | }
|
264 |
|
265 | export interface TimeoutOptions {
|
266 | /**
|
267 | * @default 60000
|
268 | */
|
269 | timeout: number;
|
270 | /**
|
271 | * @default 0
|
272 | */
|
273 | retry_attempts: number;
|
274 | }
|
275 |
|
276 | export interface NightwatchOptions {
|
277 | /**
|
278 | * Location(s) where custom commands will be loaded from.
|
279 | */
|
280 | custom_commands_path?: string | string[] | undefined;
|
281 |
|
282 | /**
|
283 | * Location(s) where custom assertions will be loaded from.
|
284 | */
|
285 | custom_assertions_path?: string | string[] | undefined;
|
286 |
|
287 | /**
|
288 | * Location(s) where page object files will be loaded from.
|
289 | */
|
290 | page_objects_path?: string | string[] | undefined;
|
291 |
|
292 | // An array specifying a list of Nightwatch plugin names that should be used;
|
293 | // e.g.: plugins: ['vite-plugin-nightwatch']
|
294 | plugins: string[];
|
295 |
|
296 | /**
|
297 | * Location of an external globals module which will be loaded and made available to the test as a property globals on the main client instance.
|
298 | * Globals can also be defined/overwritten inside a test_settings environment.
|
299 | */
|
300 | globals_path?: string | undefined;
|
301 |
|
302 | /**
|
303 | * An object which will be made available on the main test api, throughout the test execution.
|
304 | */
|
305 | globals?: NightwatchGlobals;
|
306 |
|
307 | /**
|
308 | * configuration settings for the dotenv module - a zero-dependency module that loads environment variables from a .env file into process.env. More details on https://www.npmjs.com/package/dotenv
|
309 | */
|
310 | dotenv?: any;
|
311 |
|
312 | /**
|
313 | * persist the same globals object between runs or have a (deep) copy of it per each test;
|
314 | * this can be useful when persisting data between test suites is needed, such as a cookie or session information.
|
315 | * @default false
|
316 | */
|
317 | persist_globals?: boolean | undefined;
|
318 |
|
319 | /**
|
320 | * The location where the JUnit XML report files will be saved. Set this to false if you want to disable XML reporting.
|
321 | */
|
322 | output_folder?: string | undefined;
|
323 |
|
324 | /**
|
325 | * An array of folders (excluding subfolders) where the tests are located.
|
326 | */
|
327 | src_folders: string | string[];
|
328 |
|
329 | /**
|
330 | * Used when running in parallel to determine if the output should be collected and displayed at the end.
|
331 | */
|
332 | live_output?: boolean | undefined;
|
333 |
|
334 | /**
|
335 | * disable support of loading of typescript files for backwards compatibility with test suites.
|
336 | */
|
337 | disable_typescript: boolean | undefined;
|
338 |
|
339 | /**
|
340 | * Controls whether or not to disable coloring of the cli output globally.
|
341 | */
|
342 | disable_colors?: boolean | undefined;
|
343 |
|
344 | /**
|
345 | * Used when running in parallel to specify the delay (in milliseconds) between starting the child processes
|
346 | */
|
347 | parallel_process_delay?: number | undefined;
|
348 |
|
349 | /**
|
350 | * An object containing Selenium Server related configuration options. See below for details.
|
351 | */
|
352 | selenium?: NightwatchSeleniumOptions | undefined;
|
353 |
|
354 | /**
|
355 | * Whether or not to automatically start the Selenium/WebDriver session. If running unit tests, this should be set tot false.
|
356 | * @default true
|
357 | */
|
358 | start_process?: boolean | undefined;
|
359 |
|
360 | /**
|
361 | * End the session automatically when the test is being terminated, usually after a failed assertion.
|
362 | * @default true
|
363 | */
|
364 | end_session_on_fail?: boolean | undefined;
|
365 |
|
366 | /**
|
367 | * Skip the remaining test cases from the current test suite, when one test case fails.
|
368 | */
|
369 | skip_testcases_on_fail?: boolean | undefined;
|
370 |
|
371 | /**
|
372 | * Whether or not to run individual test files in parallel. If set to true, runs the tests in parallel and determines the number of workers automatically.
|
373 | * If set to an object, can specify specify the number of workers as "auto" or a number. Example: "test_workers" : {"enabled" : true, "workers" : "auto"}
|
374 | * @default false
|
375 | */
|
376 | test_workers?: boolean | NightwatchTestWorker | undefined;
|
377 |
|
378 | /**
|
379 | * This object contains all the test related options. See below for details.
|
380 | */
|
381 | test_settings: NightwatchTestSettings;
|
382 |
|
383 | /**
|
384 | * Specifies which test runner to use when running the tests. Values can be either default (built in nightwatch runner) or mocha.
|
385 | * Example: "test_runner" : {"type" : "mocha", "options" : {"ui" : "tdd"}}
|
386 | * @default 'default'
|
387 | */
|
388 | test_runner?: string | NightwatchTestRunner | undefined;
|
389 |
|
390 | /**
|
391 | * Allows for webdriver config (mostly the same as selenium)
|
392 | */
|
393 | webdriver?:
|
394 | | {
|
395 | /**
|
396 | * When this is enabled, the Webdriver server is run in background in a child process and started/stopped automatically.
|
397 | * Nightwatch includes support for managing Chromedriver, Geckodriver (Firefox), Safaridriver, and Selenium Server. Please refer to the Install Webdriver section for details.
|
398 | * @default false
|
399 | */
|
400 | start_process: boolean;
|
401 |
|
402 | /**
|
403 | * Only useful if start_process is enabled.
|
404 | * @default none
|
405 | */
|
406 | server_path: string;
|
407 |
|
408 | /**
|
409 | * Only needed when the Webdriver service is running on a different machine.
|
410 | */
|
411 | host: string;
|
412 |
|
413 | /**
|
414 | * The port number on which the Webdriver service will listen and/or on which Nightwatch will attempt to connect.
|
415 | */
|
416 | port: number;
|
417 |
|
418 | /**
|
419 | * Should be set to true if connecting to a remote (cloud) service via HTTPS. Also don't forget to set port to 443.
|
420 | */
|
421 | ssl: boolean;
|
422 |
|
423 | /**
|
424 | * The location where the Webdriver service log file output.log file will be placed. Defaults to current directory.
|
425 | * To disable Webdriver logging, set this to false.
|
426 | * @default none
|
427 | */
|
428 | log_path: string | boolean;
|
429 |
|
430 | /**
|
431 | * List of cli arguments to be passed to the Webdriver process. This varies for each Webdriver implementation.
|
432 | *
|
433 | * @default none
|
434 | */
|
435 | cli_args: any;
|
436 |
|
437 | /**
|
438 | * Some Webdriver implementations (Safari, Edge) support both the W3C Webdriver API as well as the legacy JSON Wire (Selenium) API.
|
439 | *
|
440 | * @default false
|
441 | */
|
442 | use_legacy_jsonwire: boolean;
|
443 |
|
444 | /**
|
445 | * Time to wait (in ms) before starting to check the Webdriver server is up and running.
|
446 | *
|
447 | * @default 100
|
448 | */
|
449 | check_process_delay: number;
|
450 |
|
451 | /**
|
452 | * Maximum number of ping status check attempts when checking if the Webdriver server is up and running before returning a timeout error.
|
453 | *
|
454 | * @default 5
|
455 | */
|
456 | max_status_poll_tries: number;
|
457 |
|
458 | /**
|
459 | * Interval (in ms) to use between status ping checks when checking if the Webdriver server is up and running.
|
460 | *
|
461 | * @default 100
|
462 | */
|
463 | status_poll_interval: number;
|
464 |
|
465 | /**
|
466 | * The entire time (in ms) to wait for the Node.js process to be created and running (default is 2 min), including spawning the child process and checking the status.
|
467 | *
|
468 | * @default 120000
|
469 | */
|
470 | process_create_timeout: number;
|
471 |
|
472 | /**
|
473 | * Proxy requests to the Webdriver (or Selenium) service. http, https, socks(v5), socks5, sock4, and pac are accepted. Uses node-proxy-agent.
|
474 | *
|
475 | * @example http://user:pass@host:port
|
476 | * @default none
|
477 | */
|
478 | proxy: string;
|
479 |
|
480 | /**
|
481 | * Requests to the Webdriver service will timeout in timeout miliseconds; a retry will happen retry_attempts number of times.
|
482 | *
|
483 | * @example {timeout: 15000, retry_attempts: 5}
|
484 | */
|
485 | timeout_options: TimeoutOptions;
|
486 |
|
487 | /**
|
488 | * Needed sometimes when using a Selenium Server. The prefix to be added to to all requests (e.g. /wd/hub).
|
489 | */
|
490 | default_path_prefix: string;
|
491 |
|
492 | /**
|
493 | * Usually only needed for cloud testing Selenium services. In case the server requires credentials this username will be used to compute the Authorization header.
|
494 | *
|
495 | * The value can be also an environment variable, in which case it will look like this:
|
496 | * "username" : "${SAUCE_USERNAME}"
|
497 | *
|
498 | * @default none
|
499 | */
|
500 | username: string;
|
501 |
|
502 | /**
|
503 | * This field will be used together with username to compute the Authorization header.
|
504 | *
|
505 | * Like username, the value can be also an environment variable:
|
506 | * "access_key" : "${SAUCE_ACCESS_KEY}"
|
507 | *
|
508 | * @default none
|
509 | */
|
510 | access_key: string;
|
511 |
|
512 | /**
|
513 | * Sets the path to the Chrome binary to use.
|
514 | * On Mac OS X, this path should reference the actual Chrome executable,
|
515 | * not just the application binary (e.g. "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome").
|
516 | */
|
517 | chrome_binary?: '';
|
518 |
|
519 | /**
|
520 | * Sets the path to Chrome's log file. This path should exist on the machine that will launch Chrome.
|
521 | */
|
522 | chrome_log_file?: '';
|
523 |
|
524 | /**
|
525 | * Configures the ChromeDriver to launch Chrome on Android via adb.
|
526 | */
|
527 | android_chrome?: false;
|
528 |
|
529 | /**
|
530 | * Sets the path to the Edge binary to use. This path should exist on the machine that will launch Edge.
|
531 | */
|
532 | edge_binary?: '';
|
533 |
|
534 | /**
|
535 | * Sets the path to the Edge binary to use.
|
536 | */
|
537 | edge_log_file?: '';
|
538 |
|
539 | /**
|
540 | * Sets the binary to use. The binary may be specified as the path to a Firefox executable or a desired release Channel. This path should exist on the machine that will launch Firefox.
|
541 | */
|
542 | firefox_binary?: '';
|
543 |
|
544 | /**
|
545 | * Sets the path to an existing profile to use as a template for new browser sessions.
|
546 | * This profile will be copied for each new session - changes will not be applied to the profile itself.
|
547 | */
|
548 | firefox_profile?: '';
|
549 | }
|
550 | | undefined;
|
551 |
|
552 | /**
|
553 | * An array of folders or file patterns to be skipped (relative to the main source folder).
|
554 | * @example
|
555 | * "exclude" : ["excluded-folder"]
|
556 | * or:
|
557 | * "exclude" : ["test-folder/*-smoke.js"]
|
558 | */
|
559 | exclude?: string[];
|
560 |
|
561 | /**
|
562 | * Folder or file pattern to be used when loading the tests. Files that don't match this pattern will be ignored
|
563 | * @example
|
564 | * "filter" : "tests/*-smoke.js"
|
565 | */
|
566 | filter?: string;
|
567 |
|
568 | /**
|
569 | * Skip a group of tests (a subfolder); can be a list of comma-separated values (no space).
|
570 | */
|
571 | skipgroup?: string;
|
572 |
|
573 | /**
|
574 | * A name property will be added to the desiredCapabilities containing the test suite name when this is enabled. It is useful when using cloud testing services.
|
575 | */
|
576 | sync_test_names?: boolean;
|
577 |
|
578 | /**
|
579 | * Skip tests by tag name; can be a list of comma-separated values (no space).
|
580 | */
|
581 | skiptags?: string;
|
582 |
|
583 | /**
|
584 | * Use xpath as the default locator strategy.
|
585 | */
|
586 | use_xpath?: boolean;
|
587 |
|
588 | parallel_mode?: boolean;
|
589 |
|
590 | report_prefix?: string;
|
591 |
|
592 | unit_testing_mode?: boolean;
|
593 |
|
594 | /**
|
595 | * @default junit
|
596 | */
|
597 | default_reporter?: string;
|
598 |
|
599 | /**
|
600 | * Set this to true to use the v1.x response format for commands when using ES6 async/await
|
601 | * @default false
|
602 | */
|
603 | backwards_compatibility_mode?: boolean;
|
604 |
|
605 | /**
|
606 | * Set this to true to disable the global objects such as element(), browser, by(), expect()
|
607 | */
|
608 | disable_global_apis?: boolean;
|
609 |
|
610 | /**
|
611 | * Ignore network errors (e.g. ECONNRESET errors)
|
612 | */
|
613 | report_network_errors?: boolean;
|
614 |
|
615 | /**
|
616 | * Interactive element commands such as "click" or "setValue" can be retried
|
617 | * if an error occurred (such as an "element not interactable" error)
|
618 | */
|
619 | element_command_retries?: number;
|
620 |
|
621 | /**
|
622 | * Sets the initial window size: {height: number, width: number}
|
623 | */
|
624 | window_size?: WindowSize;
|
625 | }
|
626 |
|
627 | export interface NightwatchGlobals {
|
628 | [key: string]: any;
|
629 | /**
|
630 | * this controls whether to abort the test execution when an assertion failed and skip the rest
|
631 | * it's being used in waitFor commands and expect assertions
|
632 | * @default true
|
633 | */
|
634 | abortOnAssertionFailure?: boolean | undefined;
|
635 |
|
636 | /**
|
637 | * this controls whether to abort the test execution when an assertion failed and skip the rest
|
638 | * it's being used in waitFor commands and expect assertions
|
639 | * @default false
|
640 | */
|
641 | abortOnElementLocateError?: boolean | undefined;
|
642 |
|
643 | /**
|
644 | * this will overwrite the default polling interval (currently 500ms) for waitFor commands
|
645 | * and expect assertions that use retry
|
646 | * @default 500
|
647 | */
|
648 | waitForConditionPollInterval?: number | undefined;
|
649 |
|
650 | /**
|
651 | * default timeout value in milliseconds for waitFor commands and implicit waitFor value for
|
652 | * expect assertions
|
653 | * @default 5000
|
654 | */
|
655 | waitForConditionTimeout?: number | undefined;
|
656 |
|
657 | /**
|
658 | * this will cause waitFor commands on elements to throw an error if multiple
|
659 | * elements are found using the given locate strategy and selector
|
660 | * @default false
|
661 | */
|
662 | throwOnMultipleElementsReturned?: boolean | undefined;
|
663 |
|
664 | /**
|
665 | * By default a warning is printed if multiple elements are found using the given locate strategy
|
666 | * and selector; set this to true to suppress those warnings
|
667 | * @default false
|
668 | */
|
669 | suppressWarningsOnMultipleElementsReturned: boolean | undefined;
|
670 |
|
671 | /**
|
672 | * controls the timeout time for async hooks. Expects the done() callback to be invoked within this time
|
673 | * or an error is thrown
|
674 | * @default 20000
|
675 | */
|
676 | asyncHookTimeout?: number | undefined;
|
677 |
|
678 | /**
|
679 | * controls the timeout value for when running async unit tests. Expects the done() callback to be invoked within this time
|
680 | * or an error is thrown
|
681 | * @default 2000
|
682 | */
|
683 | unitTestsTimeout?: number | undefined;
|
684 |
|
685 | /**
|
686 | * controls the timeout value for when executing the global async reporter. Expects the done() callback to be invoked within this time
|
687 | * or an error is thrown
|
688 | * @default 20000
|
689 | */
|
690 | customReporterCallbackTimeout?: number | undefined;
|
691 |
|
692 | /**
|
693 | * Automatically retrying failed assertions - You can tell Nightwatch to automatically retry failed assertions until a given timeout is reached, before the test runner gives up and fails the test.
|
694 | */
|
695 | retryAssertionTimeout?: number | undefined;
|
696 |
|
697 | reporter: (results: any, cb: any) => void;
|
698 | beforeTestSuite(browser: any): Promise<void>;
|
699 | afterTestSuite(browser: any): Promise<void>;
|
700 | beforeTestCase(browser: any): Promise<void>;
|
701 | afterTestCase(browser: any): Promise<void>;
|
702 | onBrowserNavigate(browser: any): Promise<void>;
|
703 | onBrowserQuit(browser: any): Promise<void>;
|
704 | }
|
705 |
|
706 | export interface NightwatchSeleniumOptions {
|
707 | /**
|
708 | * Whether or not to manage the selenium process automatically.
|
709 | * @default false
|
710 | */
|
711 | start_process: boolean;
|
712 |
|
713 | /**
|
714 | * Whether or not to automatically start the Selenium session.
|
715 | */
|
716 | start_session: boolean;
|
717 |
|
718 | /**
|
719 | * The location of the selenium jar file. This needs to be specified if start_process is enabled.E.g.: lib/selenium-server-standalone-2.43.0.jar
|
720 | */
|
721 | server_path: string;
|
722 |
|
723 | /**
|
724 | * The location where the selenium Selenium-debug.log file will be placed. Defaults to current directory. To disable Selenium logging, set this to false
|
725 | */
|
726 | log_path: string | boolean;
|
727 |
|
728 | /**
|
729 | * Usually not required and only used if start_process is true. Specify the IP address you wish Selenium to listen on.
|
730 | */
|
731 | host: string;
|
732 |
|
733 | /**
|
734 | * The port number Selenium will listen on.
|
735 | */
|
736 | port: number | undefined;
|
737 |
|
738 | /**
|
739 | * List of cli arguments to be passed to the Selenium process. Here you can set various options for browser drivers, such as:
|
740 | *
|
741 | * webdriver.firefox.profile: Selenium will be default create a new Firefox profile for each session.
|
742 | * If you wish to use an existing Firefox profile you can specify its name here.
|
743 | * Complete list of Firefox Driver arguments available https://code.google.com/p/selenium/wiki/FirefoxDriver.
|
744 | *
|
745 | * webdriver.chrome.driver: Nightwatch can run the tests using Chrome browser also. To enable this you have to download the ChromeDriver binary
|
746 | * (http://chromedriver.storage.googleapis.com/index.html) and specify it's location here. Also don't forget to specify chrome as the browser name in the
|
747 | * desiredCapabilities object.
|
748 | * More information can be found on the ChromeDriver website (https://sites.google.com/a/chromium.org/chromedriver/).
|
749 | *
|
750 | * webdriver.ie.driver: Nightwatch has support for Internet Explorer also. To enable this you have to download the IE Driver binary
|
751 | * (https://code.google.com/p/selenium/wiki/InternetExplorerDriver) and specify it's location here. Also don't forget to specify "internet explorer" as the browser
|
752 | * name in the desiredCapabilities object.
|
753 | */
|
754 | cli_args: {};
|
755 |
|
756 | /**
|
757 | * Time to wait (in ms) before starting to check the Webdriver server is up and running
|
758 | * @default 500
|
759 | */
|
760 | check_process_delay: number;
|
761 |
|
762 | /**
|
763 | * Maximum number of ping status check attempts before returning a timeout error
|
764 | * @default 15
|
765 | */
|
766 | max_status_poll_tries: number;
|
767 |
|
768 | /**
|
769 | * Interval (in ms) to use between status ping checks when checking if the Webdriver server is up and running
|
770 | * @default 200
|
771 | */
|
772 | status_poll_interval: number;
|
773 | }
|
774 |
|
775 | // TODO: Remove duplicates from NightwatchOptions
|
776 | export interface NightwatchTestSettingGeneric {
|
777 | /**
|
778 | * A url which can be used later in the tests as the main url to load. Can be useful if your tests will run on different environments, each one with a different url.
|
779 | */
|
780 | launch_url?: string | undefined;
|
781 |
|
782 | /**
|
783 | * The hostname/IP on which the selenium server is accepting connections.
|
784 | */
|
785 | selenium_host?: string | undefined;
|
786 |
|
787 | /**
|
788 | * The port number on which the selenium server is accepting connections.
|
789 | */
|
790 | selenium_port?: number | undefined;
|
791 |
|
792 | /**
|
793 | * Whether to show extended Selenium command logs.
|
794 | */
|
795 | silent?: boolean | undefined;
|
796 |
|
797 | /**
|
798 | * Use to disable terminal output completely.
|
799 | */
|
800 | output?: boolean | undefined;
|
801 |
|
802 | /**
|
803 | * Use to disable colored output in the terminal.
|
804 | */
|
805 | disable_colors?: boolean | undefined;
|
806 |
|
807 | /**
|
808 | * In case the selenium server requires credentials this username will be used to compute the Authorization header.
|
809 | * The value can be also an environment variable, in which case it will look like this: "username" : "${SAUCE_USERNAME}"
|
810 | */
|
811 | username?: string | undefined;
|
812 |
|
813 | /**
|
814 | * This field will be used together with username to compute the Authorization header.
|
815 | * Like username, the value can be also an environment variable: "access_key" : "${SAUCE_ACCESS_KEY}"
|
816 | */
|
817 | access_key?: string | undefined;
|
818 |
|
819 | /**
|
820 | * Proxy requests to the selenium server. http, https, socks(v5), socks5, sock4, and pac are accepted. Uses node-proxy-agent. Example: http://user:pass@host:port
|
821 | */
|
822 | proxy?: string | undefined;
|
823 |
|
824 | /**
|
825 | * An object which will be passed to the Selenium WebDriver when a new session will be created. You can specify browser name for instance along with other capabilities.
|
826 | * Example:
|
827 | * "desiredCapabilities" : {
|
828 | * "browserName" : "firefox",
|
829 | * "acceptSslCerts" : true
|
830 | * }
|
831 | * You can view the complete list of capabilities https://code.google.com/p/selenium/wiki/DesiredCapabilities.
|
832 | */
|
833 | desiredCapabilities?: NightwatchDesiredCapabilities | undefined;
|
834 |
|
835 | /**
|
836 | * An object which will be made available within the test and can be overwritten per environment. Example:"globals" : { "myGlobal" : "some_global" }
|
837 | */
|
838 | globals?: NightwatchTestHooks | undefined;
|
839 |
|
840 | /**
|
841 | * An array of folders or file patterns to be skipped (relative to the main source folder).
|
842 | * Example: "exclude" : ["excluded-folder"] or: "exclude" : ["test-folder/*-smoke.js"]
|
843 | */
|
844 | exclude?: string[] | undefined;
|
845 |
|
846 | /**
|
847 | * Folder or file pattern to be used when loading the tests. Files that don't match this patter will be ignored.
|
848 | * Example: "filter" : "tests/*-smoke.js"
|
849 | */
|
850 | filter?: string | undefined;
|
851 |
|
852 | /**
|
853 | * Do not show the Base64 image data in the (verbose) log when taking screenshots.
|
854 | */
|
855 | log_screenshot_data?: boolean | undefined;
|
856 |
|
857 | /**
|
858 | * Use xpath as the default locator strategy
|
859 | */
|
860 | use_xpath?: boolean | undefined;
|
861 |
|
862 | /**
|
863 | * Same as Selenium settings cli_args. You can override the global cli_args on a per-environment basis.
|
864 | */
|
865 | cli_args?: any;
|
866 |
|
867 | /**
|
868 | * End the session automatically when the test is being terminated, usually after a failed assertion.
|
869 | */
|
870 | end_session_on_fail?: boolean | undefined;
|
871 |
|
872 | /**
|
873 | * Skip the rest of testcases (if any) when one testcase fails..
|
874 | */
|
875 | skip_testcases_on_fail?: boolean | undefined;
|
876 | }
|
877 |
|
878 | export interface NightwatchTestSettingScreenshots extends NightwatchTestSettingGeneric {
|
879 | /**
|
880 | * Selenium generates screenshots when command errors occur. With on_failure set to true, also generates screenshots for failing or erroring tests. These are saved on the disk.
|
881 | * Since v0.7.5 you can disable screenshots for command errors by setting "on_error" to false.
|
882 | * Example:
|
883 | * "screenshots" : {
|
884 | * "enabled" : true,
|
885 | * "on_failure" : true,
|
886 | * "on_error" : false,
|
887 | * "path" : ""
|
888 | * }
|
889 | */
|
890 | screenshots: NightwatchScreenshotOptions;
|
891 | }
|
892 |
|
893 | export interface NightwatchTestOptions extends NightwatchTestSettingGeneric {
|
894 | screenshots: boolean;
|
895 | screenshotsPath: string;
|
896 | }
|
897 |
|
898 | export interface NightwatchTestSettings {
|
899 | [key: string]: NightwatchTestSettingScreenshots;
|
900 | }
|
901 |
|
902 | export interface NightwatchTestSuite {
|
903 | name: string;
|
904 | module: string;
|
905 | group: string;
|
906 | results: any;
|
907 | }
|
908 |
|
909 | export interface NightwatchAssertionsError {
|
910 | name: string;
|
911 | message: string;
|
912 | showDiff: boolean;
|
913 | stack: string;
|
914 | }
|
915 |
|
916 | export interface NightwatchEnsureResult {
|
917 | value: null;
|
918 | returned: 1;
|
919 | }
|
920 |
|
921 | export interface Ensure {
|
922 | /**
|
923 | * Ensures that the Nightwatch WebDriver client is able to switch to the designated frame.
|
924 | */
|
925 | ableToSwitchToFrame(frame: number | WebElement | By): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
926 |
|
927 | /**
|
928 | * Creates a condition that waits for an alert to be opened.
|
929 | */
|
930 | alertIsPresent(): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
931 |
|
932 | /**
|
933 | * Creates a condition that will wait for the given element to be disabled.
|
934 | */
|
935 | elementIsDisabled(element: WebElement | Element | string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
936 |
|
937 | /**
|
938 | * Creates a condition that will wait for the given element to be enabled.
|
939 | */
|
940 | elementIsEnabled(element: WebElement): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
941 |
|
942 | /**
|
943 | * Creates a condition that will wait for the given element to be deselected.
|
944 | */
|
945 | elementIsNotSelected(element: WebElement | Element | string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
946 |
|
947 | /**
|
948 | * Creates a condition that will wait for the given element to be in the DOM, yet not displayed to the user.
|
949 | */
|
950 | elementIsNotVisible(element: WebElement | Element | string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
951 |
|
952 | /**
|
953 | * Creates a condition that will wait for the given element to be selected.
|
954 | */
|
955 | elementIsSelected(element: WebElement | Element | string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
956 |
|
957 | /**
|
958 | * Creates a condition that will wait for the given element to be displayed.
|
959 | */
|
960 | elementIsVisible(element: WebElement | Element | string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
961 |
|
962 | /**
|
963 | * Creates a condition that will loop until an element is found with the given locator.
|
964 | */
|
965 | elementLocated(locator: By): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
966 |
|
967 | /**
|
968 | * Creates a condition that will wait for the given element's text to contain the given substring.
|
969 | */
|
970 | elementTextContains(element: WebElement | Element | string, substr: string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
971 |
|
972 | /**
|
973 | * Creates a condition that will wait for the given element's text to equal the given text.
|
974 | */
|
975 | elementTextIs(element: WebElement | Element | string, text: string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
976 |
|
977 | /**
|
978 | * Creates a condition that will wait for the given element's text to match a given regular expression.
|
979 | */
|
980 | elementTextMatches(element: WebElement | Element | string, regex: RegExp): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
981 |
|
982 | /**
|
983 | * Creates a condition that will loop until at least one element is found with the given locator.
|
984 | */
|
985 | elementsLocated(locator: By): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
986 |
|
987 | /**
|
988 | * Creates a condition that will wait for the given element to become stale.
|
989 | * An element is considered stale once it is removed from the DOM, or a new page has loaded.
|
990 | */
|
991 | stalenessOf(element: WebElement | Element | string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
992 |
|
993 | /**
|
994 | * Creates a condition that will wait for the current page's title to contain the given substring.
|
995 | */
|
996 | titleContains(substr: string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
997 |
|
998 | /**
|
999 | * Creates a condition that will wait for the current page's title to match the given value.
|
1000 | */
|
1001 | titleIs(title: string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
1002 |
|
1003 | /**
|
1004 | * Creates a condition that will wait for the current page's title to match the given regular expression.
|
1005 | */
|
1006 | titleMatches(regex: RegExp): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
1007 |
|
1008 | /**
|
1009 | * Creates a condition that will wait for the current page's url to contain the given substring.
|
1010 | */
|
1011 | urlContains(substrUrl: string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
1012 |
|
1013 | /**
|
1014 | * Creates a condition that will wait for the current page's url to match the given value.
|
1015 | */
|
1016 | urlIs(url: string): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
1017 |
|
1018 | /**
|
1019 | * Creates a condition that will wait for the current page's url to match the given regular expression.
|
1020 | */
|
1021 | urlMatches(regex: RegExp): Awaitable<NightwatchAPI, NightwatchEnsureResult>;
|
1022 | }
|
1023 |
|
1024 | export interface Assert extends NightwatchAssertions, NightwatchNodeAssertions {}
|
1025 |
|
1026 | export interface NightwatchAssertions extends NightwatchCommonAssertions, NightwatchCustomAssertions {
|
1027 | /**
|
1028 | * Negates any of assertions following in the chain.
|
1029 | */
|
1030 | not: Omit<NightwatchAssertions, "not">;
|
1031 | }
|
1032 |
|
1033 | export interface NightwatchAssertionsResult<T> {
|
1034 | value: T;
|
1035 | status: 0;
|
1036 | returned: 1;
|
1037 | passed: true;
|
1038 | }
|
1039 |
|
1040 | export interface NightwatchCommonAssertions {
|
1041 | /**
|
1042 | * Checks if the given attribute of an element contains the expected value.
|
1043 | *
|
1044 | * ```
|
1045 | * this.demoTest = function (client) {
|
1046 | * browser.assert.attributeContains('#someElement', 'href', 'google.com');
|
1047 | * };
|
1048 | * ```
|
1049 | */
|
1050 | attributeContains(
|
1051 | selector: Definition, attribute: string, expected: string, message?: string
|
1052 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1053 |
|
1054 | /**
|
1055 | * Checks if the given attribute of an element has the expected value.
|
1056 | *
|
1057 | * ```
|
1058 | * this.demoTest = function (client) {
|
1059 | * browser.assert.attributeEquals('body', 'data-attr', 'some value');
|
1060 | * };
|
1061 | * ```
|
1062 | */
|
1063 | attributeEquals(
|
1064 | selector: Definition, attribute: string, expected: string, message?: string
|
1065 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1066 |
|
1067 | /**
|
1068 | * Check if an element's attribute value matches a regular expression.
|
1069 | *
|
1070 | * @example
|
1071 | *
|
1072 | * ```
|
1073 | * this.demoTest = function (browser) {
|
1074 | * browser.assert.attributeMatches('body', 'data-attr', '(value)');
|
1075 | * };
|
1076 | * ```
|
1077 | *
|
1078 | */
|
1079 | attributeMatches(
|
1080 | selector: Definition,
|
1081 | attribute: string,
|
1082 | regex: string | RegExp,
|
1083 | msg?: string,
|
1084 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1085 |
|
1086 | /**
|
1087 | * Checks if the specified css property of a given element has the expected value.
|
1088 | *
|
1089 | * ```
|
1090 | * this.demoTest = function (client) {
|
1091 | * browser.assert.cssProperty('#main', 'display', 'block');
|
1092 | * };
|
1093 | * ```
|
1094 | */
|
1095 | cssProperty(
|
1096 | selector: Definition, cssProperty: string, expected: string | number, msg?: string
|
1097 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string | number>>;
|
1098 |
|
1099 | /**
|
1100 | * Checks if the specified DOM property of a given element has the expected value.
|
1101 | * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
|
1102 | * Several properties can be specified (either as an array or command-separated list). Nightwatch will check each one for presence.
|
1103 | */
|
1104 | domPropertyContains(
|
1105 | selector: Definition,
|
1106 | domProperty: string,
|
1107 | expected: string | number,
|
1108 | msg?: string,
|
1109 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<any>>;
|
1110 |
|
1111 | /**
|
1112 | * Checks if the specified DOM property of a given element has the expected value.
|
1113 | * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
|
1114 | * If the result value is JSON object or array, a deep equality comparison will be performed.
|
1115 | */
|
1116 | domPropertyEquals(
|
1117 | selector: Definition,
|
1118 | domProperty: string,
|
1119 | expected: string | number,
|
1120 | msg?: string,
|
1121 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<any>>;
|
1122 |
|
1123 | /**
|
1124 | * Check if specified DOM property value of a given element matches a regex.
|
1125 | * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
|
1126 | */
|
1127 | domPropertyMatches(
|
1128 | selector: Definition,
|
1129 | domProperty: string,
|
1130 | expected: string | RegExp,
|
1131 | msg?: string,
|
1132 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<any>>;
|
1133 |
|
1134 | /**
|
1135 | * Checks if the number of elements specified by a selector is equal to a given value.
|
1136 | *
|
1137 | * @example
|
1138 | *
|
1139 | * this.demoTest = function (browser) {
|
1140 | * browser.assert.elementsCount('div', 10);
|
1141 | * browser.assert.not.elementsCount('div', 10);
|
1142 | * }
|
1143 | *
|
1144 | */
|
1145 | elementsCount(
|
1146 | selector: Definition, count: number, msg?: string
|
1147 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<JSON_WEB_OBJECT[]> & {WebdriverElementId: string}>;
|
1148 |
|
1149 | /**
|
1150 | * Checks if the given element exists in the DOM.
|
1151 | *
|
1152 | * ```
|
1153 | * this.demoTest = function (client) {
|
1154 | * browser.assert.elementPresent("#main");
|
1155 | * };
|
1156 | * ```
|
1157 | */
|
1158 | elementPresent(
|
1159 | selector: Definition, msg?: string
|
1160 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<Array<Omit<JSON_WEB_OBJECT, "getId">>>>;
|
1161 |
|
1162 | /**
|
1163 | * Checks if the given element does not exists in the DOM.
|
1164 | *
|
1165 | * @example
|
1166 | * ```
|
1167 | * this.demoTest = function (browser) {
|
1168 | * browser.assert.elementNotPresent(".should_not_exist");
|
1169 | * };
|
1170 | * ```
|
1171 | *
|
1172 | * @deprecated In favour of `assert.not.elementPresent()`.
|
1173 | */
|
1174 | elementNotPresent(
|
1175 | selector: Definition, msg?: string
|
1176 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<Array<Omit<JSON_WEB_OBJECT, "getId">>>>;
|
1177 |
|
1178 | /**
|
1179 | * Checks if the given element does not have the specified CSS class.
|
1180 | *
|
1181 | * ```
|
1182 | * this.demoTest = function (browser) {
|
1183 | * browser.assert.cssClassNotPresent('#main', 'container');
|
1184 | * };
|
1185 | * ```
|
1186 | *
|
1187 | * @deprecated In favour of `assert.not.hasClass()`.
|
1188 | */
|
1189 | cssClassNotPresent(selector: Definition, className: string, msg?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1190 |
|
1191 | /**
|
1192 | * Checks if the given element has the specified CSS class.
|
1193 | *
|
1194 | * ```
|
1195 | * this.demoTest = function (client) {
|
1196 | * browser.assert.cssClassPresent('#main', 'container');
|
1197 | * };
|
1198 | * ```
|
1199 | *
|
1200 | * @deprecated In favour of `assert.hasClass()`.
|
1201 | */
|
1202 | cssClassPresent(selector: Definition, className: string, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1203 |
|
1204 | /**
|
1205 | * Checks if the given element has the specified CSS class.
|
1206 | *
|
1207 | * @example
|
1208 | *
|
1209 | *
|
1210 | * ```
|
1211 | * this.demoTest = function (browser) {
|
1212 | * browser.assert.hasClass('#main', 'container');
|
1213 | * browser.assert.hasClass('#main', ['visible', 'container']);
|
1214 | * browser.assert.hasClass('#main', 'visible container');
|
1215 | * };
|
1216 | * ```
|
1217 | *
|
1218 | */
|
1219 | hasClass(
|
1220 | selector: Definition, className: string | string[], msg?: string
|
1221 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1222 |
|
1223 | /**
|
1224 | * Checks if the given element contains the specified DOM attribute.
|
1225 | *
|
1226 | * Equivalent of: https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute
|
1227 | *
|
1228 | * @example
|
1229 | *
|
1230 | * ```
|
1231 | * this.demoTest = function (browser) {
|
1232 | * browser.assert.hasAttribute('#main', 'data-track');
|
1233 | * };
|
1234 | * ```
|
1235 | *
|
1236 | */
|
1237 | hasAttribute(
|
1238 | selector: Definition, expectedAttribute: string, msg?: string
|
1239 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string[]>>;
|
1240 |
|
1241 | /**
|
1242 | * Checks if the given element is enabled (as indicated by the 'disabled' attribute).
|
1243 | *
|
1244 | * @example
|
1245 | * this.demoTest = function (browser) {
|
1246 | * browser.assert.enabled('.should_be_enabled');
|
1247 | * browser.assert.enabled({selector: '.should_be_enabled'});
|
1248 | * browser.assert.enabled({selector: '.should_be_enabled', suppressNotFoundErrors: true});
|
1249 | * };
|
1250 | */
|
1251 | enabled(selector: Definition, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<boolean>>;
|
1252 |
|
1253 | /**
|
1254 | * Checks if the given element is selected.
|
1255 | *
|
1256 | * @example
|
1257 | * this.demoTest = function (browser) {
|
1258 | * browser.assert.selected('.should_be_selected');
|
1259 | * browser.assert.selected({selector: '.should_be_selected'});
|
1260 | * browser.assert.selected({selector: '.should_be_selected', suppressNotFoundErrors: true});
|
1261 | * };
|
1262 | */
|
1263 | selected(selector: Definition, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<boolean>>;
|
1264 |
|
1265 | /**
|
1266 | * Checks if the given element contains the specified text.
|
1267 | *
|
1268 | * ```
|
1269 | * this.demoTest = function (client) {
|
1270 | * browser.assert.containsText('#main', 'The Night Watch');
|
1271 | * };
|
1272 | * ```
|
1273 | *
|
1274 | * @deprecated In favour of `assert.textContains()`.
|
1275 | */
|
1276 | containsText(
|
1277 | selector: Definition, expectedText: string, message?: string
|
1278 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1279 |
|
1280 | /**
|
1281 | * Checks if the given element contains the specified text.
|
1282 | *
|
1283 | * @example
|
1284 | * ```
|
1285 | * this.demoTest = function (browser) {
|
1286 | * browser.assert.textContains('#main', 'The Night Watch');
|
1287 | * };
|
1288 | * ```
|
1289 | *
|
1290 | */
|
1291 | textContains(
|
1292 | selector: Definition, expectedText: string, msg?: string
|
1293 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1294 |
|
1295 | /**
|
1296 | * Check if an element's inner text equals the expected text.
|
1297 | *
|
1298 | * @example
|
1299 | *
|
1300 | * ```
|
1301 | * this.demoTest = function (browser) {
|
1302 | * browser.assert.textEquals('#main', 'The Night Watch');
|
1303 | * };
|
1304 | * ```
|
1305 | *
|
1306 | */
|
1307 | textEquals(
|
1308 | selector: Definition, expectedText: string, msg?: string
|
1309 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1310 |
|
1311 | /**
|
1312 | * Check if an elements inner text matches a regular expression.
|
1313 | *
|
1314 | * @example
|
1315 | *
|
1316 | * ```
|
1317 | * this.demoTest = function (browser) {
|
1318 | * browser.assert.textMatches('#main', '^Nightwatch');
|
1319 | * };
|
1320 | * ```
|
1321 | *
|
1322 | */
|
1323 | textMatches(
|
1324 | selector: Definition, regex: string | RegExp, msg?: string
|
1325 | ): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1326 |
|
1327 | /**
|
1328 | * Checks if the page title equals the given value.
|
1329 | *
|
1330 | * ```
|
1331 | * this.demoTest = function (client) {
|
1332 | * browser.assert.title("Nightwatch.js");
|
1333 | * };
|
1334 | * ```
|
1335 | *
|
1336 | * @deprecated In favour of `titleEquals()`.
|
1337 | */
|
1338 | title(expected: string, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1339 |
|
1340 | /**
|
1341 | * Checks if the page title equals the given value.
|
1342 | *
|
1343 | * ```
|
1344 | * this.demoTest = function (client) {
|
1345 | * browser.assert.title("Nightwatch.js");
|
1346 | * };
|
1347 | * ```
|
1348 | */
|
1349 | titleContains(expected: string, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1350 |
|
1351 | /**
|
1352 | * Checks if the page title equals the given value.
|
1353 | * @since 2.0
|
1354 | * ```
|
1355 | * this.demoTest = function (client) {
|
1356 | * browser.assert.titleEquals("Nightwatch.js");
|
1357 | * };
|
1358 | * ```
|
1359 | */
|
1360 | titleEquals(expected: string, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1361 |
|
1362 | /**
|
1363 | * Checks if the current title matches a regular expression.
|
1364 | *
|
1365 | * @example
|
1366 | *
|
1367 | * ```
|
1368 | * this.demoTest = function (client) {
|
1369 | * browser.assert.titleMatches('^Nightwatch');
|
1370 | * };
|
1371 | * ```
|
1372 | *
|
1373 | */
|
1374 | titleMatches(regex: string | RegExp, msg?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1375 |
|
1376 | /**
|
1377 | * Checks if the current URL contains the given value.
|
1378 | *
|
1379 | * ```
|
1380 | * this.demoTest = function (client) {
|
1381 | * browser.assert.urlContains('google');
|
1382 | * };
|
1383 | * ```
|
1384 | */
|
1385 | urlContains(expectedText: string, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1386 |
|
1387 | /**
|
1388 | * Checks if the current url equals the given value.
|
1389 | *
|
1390 | * ```
|
1391 | * this.demoTest = function (client) {
|
1392 | * browser.assert.urlEquals('https://www.google.com');
|
1393 | * };
|
1394 | * ```
|
1395 | */
|
1396 | urlEquals(expected: string, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1397 |
|
1398 | /**
|
1399 | * Checks if the current url matches a regular expression.
|
1400 | *
|
1401 | * @example
|
1402 | * ```
|
1403 | * this.demoTest = function (client) {
|
1404 | * browser.assert.urlMatches('^https');
|
1405 | * };
|
1406 | * ```
|
1407 | *
|
1408 | */
|
1409 | urlMatches(regex: string | RegExp, msg?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1410 |
|
1411 | /**
|
1412 | * Checks if the given form element's value equals the expected value.
|
1413 | *
|
1414 | * ```
|
1415 | * this.demoTest = function (client) {
|
1416 | * browser.assert.value("form.login input[type=text]", "username");
|
1417 | * };
|
1418 | * ```
|
1419 | *
|
1420 | * @deprecated In favour of `assert.valueEquals()`.
|
1421 | */
|
1422 | value(selector: Definition, expectedText: string, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1423 |
|
1424 | /**
|
1425 | * Checks if the given form element's value contains the expected value.
|
1426 | *
|
1427 | * ```
|
1428 | * this.demoTest = function (client) {
|
1429 | * browser.assert.valueContains("form.login input[type=text]", "username");
|
1430 | * };
|
1431 | * ```
|
1432 | */
|
1433 | valueContains(selector: Definition, expectedText: string, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1434 |
|
1435 | /**
|
1436 | * Checks if the given form element's value equals the expected value.
|
1437 | *
|
1438 | * The existing .assert.value() command.
|
1439 | *
|
1440 | * @example
|
1441 | * ```
|
1442 | * this.demoTest = function (browser) {
|
1443 | * browser.assert.valueEquals("form.login input[type=text]", "username");
|
1444 | * };
|
1445 | * ```
|
1446 | *
|
1447 | */
|
1448 | valueEquals(selector: Definition, expected: string, msg?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<string>>;
|
1449 |
|
1450 | /**
|
1451 | * Checks if the given element is not visible on the page.
|
1452 | *
|
1453 | * @example
|
1454 | * ```
|
1455 | * this.demoTest = function (browser) {
|
1456 | * browser.assert.hidden('.should_not_be_visible');
|
1457 | * };
|
1458 | * ```
|
1459 | *
|
1460 | * @deprecated In favour of `assert.not.visible()`.
|
1461 | */
|
1462 | hidden(selector: Definition, msg?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<boolean>>;
|
1463 |
|
1464 | /**
|
1465 | * Checks if the given element is visible on the page.
|
1466 | *
|
1467 | * ```
|
1468 | * this.demoTest = function (client) {
|
1469 | * browser.assert.visible(".should_be_visible");
|
1470 | * };
|
1471 | * ```
|
1472 | */
|
1473 | visible(selector: Definition, message?: string): Awaitable<NightwatchAPI, NightwatchAssertionsResult<boolean>>;
|
1474 |
|
1475 | NightwatchAssertionsError: NightwatchAssertionsError;
|
1476 | }
|
1477 |
|
1478 | export interface NightwatchNodeAssertionsResult {
|
1479 | value: null;
|
1480 | returned: 1;
|
1481 | }
|
1482 |
|
1483 | export interface NightwatchNodeAssertions {
|
1484 | // The following definitions are taken from @types/assert
|
1485 |
|
1486 | fail(message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1487 | fail(actual: any, expected: any, message?: string | Error, operator?: string): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1488 |
|
1489 | ok(value: any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1490 |
|
1491 | equal(actual: any, expected: any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1492 | notEqual(actual: any, expected: any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1493 |
|
1494 | deepEqual(actual: any, expected: any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1495 | notDeepEqual(actual: any, expected: any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1496 |
|
1497 | strictEqual(actual: any, expected: any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1498 | notStrictEqual(actual: any, expected: any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1499 |
|
1500 | deepStrictEqual(actual: any, expected: any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1501 | notDeepStrictEqual(actual: any, expected: any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1502 |
|
1503 | throws(block: () => any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1504 | doesNotThrow(block: () => any, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1505 |
|
1506 | ifError(value: any): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1507 |
|
1508 | rejects(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1509 | doesNotReject(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1510 |
|
1511 | match(value: string, regExp: RegExp, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1512 | doesNotMatch(value: string, regExp: RegExp, message?: string | Error): Awaitable<NightwatchAPI, NightwatchNodeAssertionsResult | Error>;
|
1513 | }
|
1514 |
|
1515 | export interface ElementProperties {
|
1516 | /**
|
1517 | * the element selector name
|
1518 | *
|
1519 | * @example
|
1520 | * '@searchBar'
|
1521 | */
|
1522 | selector: string;
|
1523 |
|
1524 | /**
|
1525 | * locator strategy can be one of
|
1526 | * - css selector
|
1527 | * - link text
|
1528 | * - partial link text
|
1529 | * - tag name
|
1530 | * - xpath
|
1531 | *
|
1532 | * @example
|
1533 | * 'css selector'
|
1534 | */
|
1535 | locateStrategy?: LocateStrategy;
|
1536 |
|
1537 | /**
|
1538 | * used to target a specific element in a query that results in multiple elements returned. Normally,
|
1539 | * only the first element is used (index = 0) but using the index property, you can specify any element within the result.
|
1540 | */
|
1541 | index?: number;
|
1542 |
|
1543 | /**
|
1544 | * used to overwrite this setting when using waitForElement* commands.
|
1545 | */
|
1546 | abortOnFailure?: boolean;
|
1547 |
|
1548 | /**
|
1549 | * used to overwrite the default timeout for when using waitForElement* commands or assertions.
|
1550 | */
|
1551 | timeout?: number;
|
1552 |
|
1553 | /**
|
1554 | * used to overwrite the default retry interval for when using waitForElement* commands or assertions.
|
1555 | */
|
1556 | retryInterval?: number;
|
1557 |
|
1558 | /**
|
1559 | * Some element commands like .click() or .getText() will throw a NoSuchElement error if the element cannot be located, causing the test to fail.
|
1560 | * If this option is set to true then this error is ignored.
|
1561 | */
|
1562 | suppressNotFoundErrors?: boolean;
|
1563 | }
|
1564 |
|
1565 | export interface NightwatchTypedCallbackResult<T> {
|
1566 | status: 0;
|
1567 | value: T;
|
1568 | error: Error;
|
1569 | }
|
1570 | export interface NightwatchCallbackResultError {
|
1571 | status: 1; // we cannot use `number` so giving it a "symbolic" value allows to disjoint the union
|
1572 | value: {
|
1573 | message: string;
|
1574 | screen: string;
|
1575 | class: string;
|
1576 | stackTrace: Array<{
|
1577 | fileName: string;
|
1578 | lineNumber: number;
|
1579 | className: string;
|
1580 | methodName: string;
|
1581 | }>;
|
1582 | };
|
1583 | state: Error | string;
|
1584 | }
|
1585 |
|
1586 | export type NightwatchCallbackResult<T> = NightwatchTypedCallbackResult<T> | NightwatchCallbackResultError;
|
1587 |
|
1588 | export interface NightwatchLogEntry {
|
1589 | /**
|
1590 | * The log entry message.
|
1591 | */
|
1592 | message: string;
|
1593 |
|
1594 | /**
|
1595 | * The time stamp of log entry in seconds.
|
1596 | */
|
1597 | opt_timestamp: number;
|
1598 |
|
1599 | /**
|
1600 | * The log type, if known.
|
1601 | */
|
1602 | opt_type?: string;
|
1603 |
|
1604 | /**
|
1605 | * Severity level
|
1606 | */
|
1607 | level: 'ALL' | 'DEBUG' | 'FINE' | 'FINER' | 'FINEST' | 'INFO' | 'OFF' | 'SEVERE' | 'WARNING' | Level | number;
|
1608 | }
|
1609 |
|
1610 | export interface Level {
|
1611 | /**
|
1612 | * the level's name.
|
1613 | */
|
1614 | name: string;
|
1615 |
|
1616 | /**
|
1617 | * the level's numeric value.
|
1618 | */
|
1619 | level: number;
|
1620 | }
|
1621 |
|
1622 | export interface NightwatchKeys {
|
1623 | /** Releases all held modifier keys. */
|
1624 | NULL: string;
|
1625 | /** OS-specific keystroke sequence that performs a cancel action. */
|
1626 | CANCEL: string;
|
1627 | /** The help key. This key only appears on older Apple keyboards in place of the Insert key. */
|
1628 | HELP: string;
|
1629 | /** The backspace key. */
|
1630 | BACK_SPACE: string;
|
1631 | /** The tab key. */
|
1632 | TAB: string;
|
1633 | /** The clear key. This key only appears on full-size Apple keyboards in place of Num Lock key. */
|
1634 | CLEAR: string;
|
1635 | /** The return key. */
|
1636 | RETURN: string;
|
1637 | /** The enter (numpad) key. */
|
1638 | ENTER: string;
|
1639 | /** The shift key. */
|
1640 | SHIFT: string;
|
1641 | /** The control key. */
|
1642 | CONTROL: string;
|
1643 | /** The alt key. */
|
1644 | ALT: string;
|
1645 | /** The pause key. */
|
1646 | PAUSE: string;
|
1647 | /** The escape key. */
|
1648 | ESCAPE: string;
|
1649 |
|
1650 | /** The space bar. */
|
1651 | SPACE: string;
|
1652 | /** The page up key. */
|
1653 | PAGEUP: string;
|
1654 | /** The page down key. */
|
1655 | PAGEDOWN: string;
|
1656 | /** The end key. */
|
1657 | END: string;
|
1658 | /** The home key. */
|
1659 | HOME: string;
|
1660 | /** The left arrow. */
|
1661 | ARROW_LEFT: string;
|
1662 | LEFT_ARROW: string;
|
1663 | /** The up arrow. */
|
1664 | ARROW_UP: string;
|
1665 | UP_ARROW: string;
|
1666 | /** The right arrow. */
|
1667 | ARROW_RIGHT: string;
|
1668 | RIGHT_ARROW: string;
|
1669 | /** The down arrow. */
|
1670 | ARROW_DOWN: string;
|
1671 | DOWN_ARROW: string;
|
1672 | /** The insert key. */
|
1673 | INSERT: string;
|
1674 | /** The delete key. */
|
1675 | DELETE: string;
|
1676 | /** The semicolon key. */
|
1677 | SEMICOLON: string;
|
1678 | /** The equals key. */
|
1679 | EQUALS: string;
|
1680 |
|
1681 | /** The numpad zero key. */
|
1682 | NUMPAD0: string;
|
1683 | /** The numpad one key. */
|
1684 | NUMPAD1: string;
|
1685 | /** The numpad two key. */
|
1686 | NUMPAD2: string;
|
1687 | /** The numpad three key. */
|
1688 | NUMPAD3: string;
|
1689 | /** The numpad four key. */
|
1690 | NUMPAD4: string;
|
1691 | /** The numpad five key. */
|
1692 | NUMPAD5: string;
|
1693 | /** The numpad six key. */
|
1694 | NUMPAD6: string;
|
1695 | /** The numpad seven key. */
|
1696 | NUMPAD7: string;
|
1697 | /** The numpad eight key. */
|
1698 | NUMPAD8: string;
|
1699 | /** The numpad nine key. */
|
1700 | NUMPAD9: string;
|
1701 |
|
1702 | /** The numpad multiply (*) key. */
|
1703 | MULTIPLY: string;
|
1704 | /** The numpad add (+) key. */
|
1705 | ADD: string;
|
1706 | /** The numpad separator (=) key. */
|
1707 | SEPARATOR: string;
|
1708 | /** The numpad subtract (-) key. */
|
1709 | SUBTRACT: string;
|
1710 | /** The numpad decimal (.) key. */
|
1711 | DECIMAL: string;
|
1712 | /** The numpad divide (/) key. */
|
1713 | DIVIDE: string;
|
1714 |
|
1715 | /** The F1 key. */
|
1716 | F1: string;
|
1717 | /** The F2 key. */
|
1718 | F2: string;
|
1719 | /** The F3 key. */
|
1720 | F3: string;
|
1721 | /** The F4 key. */
|
1722 | F4: string;
|
1723 | /** The F5 key. */
|
1724 | F5: string;
|
1725 | /** The F6 key. */
|
1726 | F6: string;
|
1727 | /** The F7 key. */
|
1728 | F7: string;
|
1729 | /** The F8 key. */
|
1730 | F8: string;
|
1731 | /** The F9 key. */
|
1732 | F9: string;
|
1733 | /** The F10 key. */
|
1734 | F10: string;
|
1735 | /** The F11 key. */
|
1736 | F11: string;
|
1737 | /** The F12 key. */
|
1738 | F12: string;
|
1739 | /** The meta (Windows) key. */
|
1740 | META: string;
|
1741 | /** The command (⌘) key. */
|
1742 | COMMAND: string;
|
1743 | }
|
1744 |
|
1745 | export type NightwatchPage = {
|
1746 | [name: string]: () => EnhancedPageObject<any, any, any>;
|
1747 | } & {
|
1748 | [name: string]: NightwatchPage;
|
1749 | };
|
1750 |
|
1751 | export interface NightwatchApiCommands {
|
1752 | readonly WEBDRIVER_ELEMENT_ID: string;
|
1753 | readonly browserName: string;
|
1754 | readonly platformName: string;
|
1755 | __isBrowserName(browser: string, alternateName: string): boolean;
|
1756 | __isPlatformName(platform: string): boolean;
|
1757 | isIOS(): boolean;
|
1758 | isAndroid(): boolean;
|
1759 | isMobile(): boolean;
|
1760 | isSafari(): boolean;
|
1761 | isChrome(): boolean;
|
1762 | isFirefox(): boolean;
|
1763 | isEdge(): boolean;
|
1764 | isInternetExplorer(): boolean;
|
1765 | isOpera(): boolean;
|
1766 | }
|
1767 |
|
1768 | export interface NightwatchAPI
|
1769 | extends SharedCommands,
|
1770 | WebDriverProtocol,
|
1771 | NightwatchCustomCommands,
|
1772 | NightwatchApiCommands {
|
1773 | baseUrl: string;
|
1774 | assert: Assert;
|
1775 | actions(options?: { async?: boolean; bridge?: boolean }): Actions;
|
1776 | expect: Expect;
|
1777 | ensure: Ensure;
|
1778 | verify: Assert;
|
1779 |
|
1780 | page: NightwatchPage & NightwatchCustomPageObjects;
|
1781 |
|
1782 | /**
|
1783 | * SessionId of the session used by the Nightwatch api.
|
1784 | */
|
1785 | sessionId: string;
|
1786 |
|
1787 | /**
|
1788 | * Override the sessionId used by Nightwatch client with another session id.
|
1789 | */
|
1790 | setSessionId(sessionId: string): this;
|
1791 |
|
1792 | options: NightwatchTestOptions;
|
1793 |
|
1794 | Keys: NightwatchKeys;
|
1795 |
|
1796 | currentTest: NightwatchTestSuite;
|
1797 |
|
1798 | globals: NightwatchGlobals;
|
1799 |
|
1800 | launchUrl: string;
|
1801 | launch_url: string;
|
1802 | }
|
1803 |
|
1804 | // tslint:disable-next-line:no-empty-interface
|
1805 | export interface NightwatchCustomCommands {}
|
1806 |
|
1807 | // tslint:disable-next-line:no-empty-interface
|
1808 | export interface NightwatchCustomAssertions {}
|
1809 |
|
1810 | // tslint:disable-next-line:no-empty-interface
|
1811 | export interface NightwatchCustomPageObjects {}
|
1812 |
|
1813 | export interface NightwatchBrowser
|
1814 | extends NightwatchAPI,
|
1815 | NightwatchComponentTestingCommands,
|
1816 | NightwatchCustomCommands {}
|
1817 |
|
1818 | export interface NightwatchComponentTestingCommands {
|
1819 | importScript(scriptPath: string, options: { scriptType: string; componentTyp: string }, callback: () => void): this;
|
1820 | mountReactComponent(componentPath: string, props?: string | (() => void), callback?: () => void): Element;
|
1821 | mountComponent(componentPath: string, props?: string | (() => void), callback?: () => void): Element;
|
1822 | mountVueComponent(componentPath: string, options?: any, callback?: () => void): Element;
|
1823 | launchComponentRenderer(): this;
|
1824 | }
|
1825 |
|
1826 | // tslint:disable-next-line
|
1827 | export interface NightwatchElement extends WebElement {}
|
1828 |
|
1829 | export type NightwatchTest = (browser?: NightwatchBrowser) => void;
|
1830 | export interface NightwatchTestFunctions {
|
1831 | before?: NightwatchTestHook | undefined;
|
1832 | after?: NightwatchTestHook | undefined;
|
1833 | beforeEach?: NightwatchTestHook | undefined;
|
1834 | afterEach?: NightwatchTestHook | undefined;
|
1835 | '@tags'?: string | string[] | undefined;
|
1836 | '@disabled'?: boolean | undefined;
|
1837 | [key: string]: any;
|
1838 | }
|
1839 |
|
1840 | export type NightwatchTestHook = GlobalNightwatchTestHookEach | GlobalNightwatchTestHook;
|
1841 |
|
1842 | export type GlobalNightwatchTestHookEach = (browser: NightwatchBrowser, done: (err?: any) => void) => void;
|
1843 |
|
1844 | export type GlobalNightwatchTestHook = (done: (err?: any) => void) => void;
|
1845 |
|
1846 | export interface NightwatchTestHooks extends NightwatchGlobals {
|
1847 | before?: GlobalNightwatchTestHook | undefined;
|
1848 | after?: GlobalNightwatchTestHook | undefined;
|
1849 | beforeEach?: GlobalNightwatchTestHookEach | undefined;
|
1850 | afterEach?: GlobalNightwatchTestHookEach | undefined;
|
1851 | }
|
1852 |
|
1853 | export class Element {
|
1854 | name: string;
|
1855 | webElement: WebElement;
|
1856 | index: number;
|
1857 | selector: string;
|
1858 | locateStrategy: string;
|
1859 | pseudoSelector: null;
|
1860 | parent: any;
|
1861 | resolvedElement: any;
|
1862 | abortOnFailure: boolean;
|
1863 | suppressNotFoundErrors: boolean;
|
1864 | retryInterval: number;
|
1865 | message: string;
|
1866 | timeout: number;
|
1867 | getId: () => string;
|
1868 | findElement: ElementCommands['findElement'] & {(): Awaitable<NightwatchAPI, WebElement>};
|
1869 | element: typeof globalElement;
|
1870 | find: (selector: Definition | WebElement | By) => any;
|
1871 | get: (selector: Definition | WebElement | By) => any;
|
1872 | findElements: ElementCommands['findElements'];
|
1873 | findAll: (selector: Definition) => any;
|
1874 | click: ElementCommands['click'];
|
1875 | sendKeys: ElementCommands['sendKeys'];
|
1876 | getTagName: ElementCommands['getTagName'];
|
1877 | tagName: (selector: Definition) => string;
|
1878 | getCssValue: ElementCommands['getCssProperty'];
|
1879 | css: (selector: Definition) => string;
|
1880 | getAttribute: ElementCommands['getAttribute'];
|
1881 | attr: (selector: Definition) => string;
|
1882 | attribute: (selector: Definition) => string;
|
1883 | getProperty: ElementCommands['getElementProperty'];
|
1884 | property: (selector: Definition) => any;
|
1885 | prop: (selector: Definition) => any;
|
1886 | getText: ElementCommands['getText'];
|
1887 | text: (selector: Definition) => string;
|
1888 | getAriaRole: ElementCommands['getAriaRole'];
|
1889 | arialRole: (selector: Definition) => string;
|
1890 | getAccessibleName: ElementCommands['getAccessibleName'];
|
1891 | accessibleName: (selector: Definition) => string;
|
1892 | getRect: ClientCommands['getWindowRect'];
|
1893 | rect: () => { x: number; y: number; width: number; height: number };
|
1894 | isEnabled: ElementCommands['isEnabled'];
|
1895 | isSelected: ElementCommands['isSelected'];
|
1896 | submit: WebDriverProtocolElementInteraction['submit'];
|
1897 | clear: ElementCommands['clearValue'];
|
1898 | isDisplayed: WebDriverProtocolElementState['elementIdDisplayed'];
|
1899 | takeScreenshot: ElementCommands['takeElementScreenshot'];
|
1900 | screenshot: (selector: Definition) => 'string';
|
1901 | getWebElement: () => Promise<WebElement>;
|
1902 | isComponent: () => boolean;
|
1903 | }
|
1904 |
|
1905 | export function globalElement(locator: Definition | By | WebElement, options?: any): Element;
|
1906 |
|
1907 | export type NightwatchTests = NightwatchTestFunctions | NightwatchTestHooks;
|
1908 |
|
1909 | export class DescribeInstance {
|
1910 | '[instance]': any;
|
1911 | '[attributes]': {};
|
1912 | '[client]': NightwatchClient;
|
1913 |
|
1914 | /**
|
1915 | * Title of the describe suite.
|
1916 | */
|
1917 | get name(): string;
|
1918 |
|
1919 | /**
|
1920 | * Get or set tags for the test suite.
|
1921 | *
|
1922 | * @see https://nightwatchjs.org/guide/running-tests/filtering-by-test-tags.html
|
1923 | */
|
1924 | get tags(): string | string[];
|
1925 | set tags(value: string | string[]);
|
1926 |
|
1927 | /**
|
1928 | * Enable if the current test is a unit/integration test
|
1929 | * (no webdriver session is required).
|
1930 | */
|
1931 | get unitTest(): boolean;
|
1932 | set unitTest(value: boolean);
|
1933 |
|
1934 | /**
|
1935 | * Set to false if you'd like the browser window to be kept open
|
1936 | * in case of a failure or error (useful for debugging).
|
1937 | */
|
1938 | get endSessionOnFail(): boolean;
|
1939 | set endSessionOnFail(value: boolean);
|
1940 |
|
1941 | /**
|
1942 | * Set to false if you'd like the rest of the test cases/test steps
|
1943 | * to be executed in the event of an assertion failure/error.
|
1944 | */
|
1945 | get skipTestcasesOnFail(): boolean;
|
1946 | set skipTestcasesOnFail(value: boolean);
|
1947 |
|
1948 | /**
|
1949 | * Set to true if you'd like this test suite to be skipped by the
|
1950 | * test runner.
|
1951 | */
|
1952 | get disabled(): boolean;
|
1953 | set disabled(value: boolean);
|
1954 |
|
1955 | /**
|
1956 | * Get or set testsuite specific capabilities.
|
1957 | */
|
1958 | get desiredCapabilities(): NightwatchDesiredCapabilities;
|
1959 | set desiredCapabilities(value: NightwatchDesiredCapabilities);
|
1960 |
|
1961 | /**
|
1962 | * Get available page objects.
|
1963 | */
|
1964 | get page(): NightwatchAPI['page'];
|
1965 |
|
1966 | /**
|
1967 | * Get all current globals.
|
1968 | */
|
1969 | get globals(): NightwatchGlobals;
|
1970 |
|
1971 | /**
|
1972 | * Get all current settings.
|
1973 | */
|
1974 | get settings(): NightwatchOptions;
|
1975 |
|
1976 | /**
|
1977 | * Get all current cli arguments.
|
1978 | */
|
1979 | get argv(): {[key: string]: any};
|
1980 |
|
1981 | /**
|
1982 | * Get all current mocha options.
|
1983 | */
|
1984 | get mochaOptions(): {[key: string]: any} | undefined;
|
1985 |
|
1986 | /**
|
1987 | * Control the unit test timeout.
|
1988 | *
|
1989 | * Control the assertion and element commands timeout until when
|
1990 | * an element should be located or assertion passed.
|
1991 | *
|
1992 | * @param value Timeout in `ms`
|
1993 | */
|
1994 | timeout(value: number): void;
|
1995 |
|
1996 | /**
|
1997 | * Get the assertion and element commands timeout until when
|
1998 | * an element would be located or assertion passed.
|
1999 | *
|
2000 | * @returns Timeout in `ms`
|
2001 | */
|
2002 | waitForTimeout(): number;
|
2003 |
|
2004 | /**
|
2005 | * Control the assertion and element commands timeout until when
|
2006 | * an element should be located or assertion passed.
|
2007 | *
|
2008 | * @param value Timeout in `ms`
|
2009 | */
|
2010 | waitForTimeout(value: number): void;
|
2011 |
|
2012 | /**
|
2013 | * Get the polling interval between re-tries for assertions
|
2014 | * or element commands.
|
2015 | *
|
2016 | * @returns Time interval in `ms`
|
2017 | */
|
2018 | waitForRetryInterval(): number;
|
2019 |
|
2020 | /**
|
2021 | * Control the polling interval between re-tries for assertions
|
2022 | * or element commands.
|
2023 | *
|
2024 | * @param value Time interval in `ms`
|
2025 | */
|
2026 | waitForRetryInterval(value: number): void;
|
2027 |
|
2028 | /**
|
2029 | * Control the polling interval between re-tries for assertions
|
2030 | * or element commands.
|
2031 | *
|
2032 | * @param value Time interval in `ms`
|
2033 | */
|
2034 | retryInterval(value: number): void;
|
2035 |
|
2036 | /**
|
2037 | * How many time to retry a failed testcase inside this test suite
|
2038 | */
|
2039 | retries(n: number): void;
|
2040 |
|
2041 | /**
|
2042 | * How many times to retry the current test suite in case of an
|
2043 | * assertion failure or error
|
2044 | */
|
2045 | suiteRetries(n: number): void;
|
2046 | }
|
2047 |
|
2048 | export type ExtendDescribeThis<T> = DescribeInstance & {[P in keyof T]?: T[P]};
|
2049 |
|
2050 | interface SuiteFunction {
|
2051 | (title: string, fn?: (this: DescribeInstance) => void): this;
|
2052 | only: ExclusiveSuiteFunction;
|
2053 | skip: PendingSuiteFunction;
|
2054 | }
|
2055 |
|
2056 | interface ExclusiveSuiteFunction {
|
2057 | (title: string, fn?: (this: DescribeInstance) => void): this;
|
2058 | }
|
2059 |
|
2060 | interface PendingSuiteFunction {
|
2061 | (title: string, fn?: (this: DescribeInstance) => void): this | void;
|
2062 | }
|
2063 |
|
2064 | interface ExclusiveTestFunction {
|
2065 | (fn: NormalFunc | AsyncFunc): this;
|
2066 | (title: string, fn: NormalFunc | AsyncFunc): this;
|
2067 | }
|
2068 |
|
2069 | interface PendingTestFunction {
|
2070 | (fn: NormalFunc | AsyncFunc): this;
|
2071 | (title: string, fn: NormalFunc | AsyncFunc): this;
|
2072 | }
|
2073 |
|
2074 | type NormalFunc = (this: DescribeInstance, browser: NightwatchBrowser) => void;
|
2075 | type AsyncFunc = (this: DescribeInstance, browser: NightwatchBrowser) => PromiseLike<any>;
|
2076 | interface TestFunction {
|
2077 | (fn: NormalFunc | AsyncFunc): this;
|
2078 | (title: string, fn: NormalFunc | AsyncFunc): this;
|
2079 | only: ExclusiveTestFunction;
|
2080 | skip: PendingTestFunction;
|
2081 | retries(n: number): void;
|
2082 | }
|
2083 |
|
2084 | type NightwatchBddTestHookCallback = (this: DescribeInstance, browser: NightwatchBrowser, done: (err?: any) => void) => void;
|
2085 |
|
2086 | type NightwatchBddTestHook = (callback: NightwatchBddTestHookCallback) => void;
|
2087 |
|
2088 | declare global {
|
2089 | const describe: SuiteFunction;
|
2090 | const xdescribe: PendingSuiteFunction;
|
2091 | const context: SuiteFunction;
|
2092 | const xcontext: PendingSuiteFunction;
|
2093 | const test: TestFunction;
|
2094 | const it: TestFunction;
|
2095 | const xit: PendingTestFunction;
|
2096 | const specify: TestFunction;
|
2097 | const xspecify: PendingTestFunction;
|
2098 | const before: NightwatchBddTestHook;
|
2099 | const after: NightwatchBddTestHook;
|
2100 | const beforeEach: NightwatchBddTestHook;
|
2101 | const afterEach: NightwatchBddTestHook;
|
2102 | }
|
2103 |
|
2104 | /**
|
2105 | * Performs an assertion
|
2106 | *
|
2107 | */
|
2108 | export type NightwatchAssert = (
|
2109 | passed: boolean,
|
2110 | receivedValue?: any,
|
2111 | expectedValue?: any,
|
2112 | message?: string,
|
2113 | abortOnFailure?: boolean,
|
2114 | originalStackTrace?: string,
|
2115 | ) => void;
|
2116 |
|
2117 | /**
|
2118 | * Abstract assertion class that will subclass all defined assertions
|
2119 | *
|
2120 | * All assertions must implement the following api:
|
2121 | *
|
2122 | * - @param {T|function} expected
|
2123 | * - @param {string} message
|
2124 | * - @param {function} pass
|
2125 | * - @param {function} value
|
2126 | * - @param {function} command
|
2127 | * - @param {function} - Optional failure
|
2128 | */
|
2129 | export interface NightwatchAssertion<T, U = any> {
|
2130 | expected: (() => T) | T;
|
2131 | message: string;
|
2132 | pass(value: T): any;
|
2133 | value(result: U): T;
|
2134 | command(callback: (result: U) => void): this;
|
2135 | failure?(result: U): boolean;
|
2136 | api: NightwatchAPI;
|
2137 | client: NightwatchClient;
|
2138 | }
|
2139 |
|
2140 | export interface NightwatchClient extends Nightwatch {
|
2141 | api: NightwatchAPI;
|
2142 | locateStrategy: LocateStrategy;
|
2143 | options: NightwatchOptions;
|
2144 | // TODO: Add reporter
|
2145 | // reporter: reporte
|
2146 | sessionID: string;
|
2147 | settings: NightwatchOptions;
|
2148 | }
|
2149 |
|
2150 | export interface CreateClientParams {
|
2151 | browserName: string | null;
|
2152 | headless?: boolean;
|
2153 | silent?: boolean;
|
2154 | output?: boolean;
|
2155 | useAsync?: boolean;
|
2156 | env?: string;
|
2157 | timeout?: number;
|
2158 | parallel?: boolean;
|
2159 | reporter?: null;
|
2160 | globals?: any;
|
2161 | devtools?: boolean;
|
2162 | debug?: boolean;
|
2163 | enable_global_apis?: boolean;
|
2164 | config?: string;
|
2165 | }
|
2166 |
|
2167 | export interface Nightwatch {
|
2168 | cli(callback: any): this;
|
2169 | client(settings: NightwatchOptions, reporter?: any, argv?: {}): this;
|
2170 | createClient({
|
2171 | headless,
|
2172 | silent,
|
2173 | output,
|
2174 | useAsync,
|
2175 | env,
|
2176 | timeout,
|
2177 | parallel,
|
2178 | reporter,
|
2179 | browserName,
|
2180 | globals,
|
2181 | devtools,
|
2182 | debug,
|
2183 | enable_global_apis,
|
2184 | config,
|
2185 | }: CreateClientParams): this;
|
2186 | cliRunner(argv?: {}): this;
|
2187 | initClient(opts: any): this;
|
2188 | runner(argv?: {}, done?: () => void, settings?: {}): this;
|
2189 | runTests(testSource: string | string[], settings?: any, ...args: any[]): any;
|
2190 | api: NightwatchAPI;
|
2191 | assert: Assert;
|
2192 | expect: Expect;
|
2193 | verify: Assert;
|
2194 | updateCapabilities(...args: any): this;
|
2195 | launchBrowser(): NightwatchAPI | Promise<NightwatchAPI>;
|
2196 | }
|
2197 |
|
2198 | export type LocateStrategy =
|
2199 | | 'class name'
|
2200 | | 'css selector'
|
2201 | | 'id'
|
2202 | | 'name'
|
2203 | | 'link text'
|
2204 | | 'partial link text'
|
2205 | | 'tag name'
|
2206 | | 'xpath';
|
2207 |
|
2208 | /**
|
2209 | * #### [Enhanced Element Instances](https://github.com/nightwatchjs/nightwatch/wiki/Page-Object-API#enhanced-element-instances)
|
2210 | * Element instances encapsulate the definition used to handle element selectors.
|
2211 | * Generally you won't need to access them directly,
|
2212 | * instead referring to them using their `@`-prefixed names for selector arguments,
|
2213 | * but they are available through a page object or section's elements property.
|
2214 | */
|
2215 | export interface EnhancedElementInstance<T> {
|
2216 | /**
|
2217 | * The name of the element as defined by its key in the parent section or the page object's `elements` definition.
|
2218 | * This is the same name used with the `@` prefix in selector arguments for page object commands that refer to the element.
|
2219 | */
|
2220 | name: string;
|
2221 |
|
2222 | /**
|
2223 | * The locate strategy to be used with `selector` when finding the element within the DOM.
|
2224 | */
|
2225 | locateStrategy: LocateStrategy;
|
2226 |
|
2227 | /**
|
2228 | * A reference to the parent object instance.
|
2229 | * This is the parent section or the page object that contained the definition for this object.
|
2230 | */
|
2231 | parent: T;
|
2232 |
|
2233 | /**
|
2234 | * The selector string used to find the element in the DOM.
|
2235 | */
|
2236 | selector: string;
|
2237 | }
|
2238 |
|
2239 | export type EnhancedSectionInstance<
|
2240 | Commands = {},
|
2241 | Elements = {},
|
2242 | Sections extends EnhancedPageObjectSections = {},
|
2243 | > = EnhancedPageObject<Commands, Elements, Sections>;
|
2244 |
|
2245 | export interface EnhancedPageObjectSections {
|
2246 | [name: string]: EnhancedSectionInstance<any, any, any>;
|
2247 | }
|
2248 |
|
2249 | /**
|
2250 | * #### [Enhanced Page Object Instances](https://github.com/nightwatchjs/nightwatch/wiki/Page-Object-API#enhanced-page-object-instances)
|
2251 | * Page object module definitions are used to define page object instances when their respective factory functions within the page reference of the standard command API is called.
|
2252 | * ```
|
2253 | * var myPageObject = browser.page.MyPage(); // defined in MyPage.js module
|
2254 | * ```
|
2255 | * Every time a factory function like MyPage above is called, a new instance of the page object is instantiated.
|
2256 | */
|
2257 | export type EnhancedPageObject<
|
2258 | Commands = {},
|
2259 | Elements = {},
|
2260 | Sections extends EnhancedPageObjectSections = {},
|
2261 | > = Nightwatch &
|
2262 | SharedCommands &
|
2263 | NightwatchCustomCommands &
|
2264 | Commands & {
|
2265 | /**
|
2266 | * A map of Element objects (see [Enhanced Element Instances](https://github.com/nightwatchjs/nightwatch/wiki/Page-Object-API#enhanced-element-instances)) used by element selectors.
|
2267 | */
|
2268 | elements: {
|
2269 | [name: string]: EnhancedElementInstance<EnhancedPageObject<Commands, Elements, Sections>>;
|
2270 | };
|
2271 |
|
2272 | section: Sections;
|
2273 |
|
2274 | /**
|
2275 | * The name of the page object as defined by its module name (not including the extension).
|
2276 | * This is the same name used to access the `page` object factory from the page reference in the command API.
|
2277 | */
|
2278 | name: string;
|
2279 |
|
2280 | /**
|
2281 | * This command is an alias to url and also a convenience method because when called without any arguments
|
2282 | * it performs a call to .url() with passing the value of `url` property on the page object.
|
2283 | * Uses `url` protocol command.
|
2284 | */
|
2285 | navigate(url?: string, callback?: () => void): EnhancedPageObject<Commands, Elements, Sections>;
|
2286 | };
|
2287 |
|
2288 | export interface Cookie {
|
2289 | name: string;
|
2290 | value: string;
|
2291 | path?: string;
|
2292 | domain?: string;
|
2293 | secure?: boolean;
|
2294 | expiry?: Date | number;
|
2295 | httpOnly?: boolean;
|
2296 | }
|
2297 |
|
2298 | export interface SharedCommands extends ClientCommands, ElementCommands {}
|
2299 |
|
2300 | export interface WindowPosition { x: number; y: number; }
|
2301 |
|
2302 | // tslint:disable-next-line
|
2303 | export interface NightwatchPosition extends WindowPosition {}
|
2304 |
|
2305 | export interface WindowSize { height: number; width: number; }
|
2306 |
|
2307 | // tslint:disable-next-line
|
2308 | export interface NightwatchSize extends WindowSize {}
|
2309 |
|
2310 | export type WindowSizeAndPosition = WindowPosition & WindowSize;
|
2311 |
|
2312 | export type NightwatchSizeAndPosition = WindowSizeAndPosition;
|
2313 |
|
2314 | export type WindowType = 'tab' | 'window';
|
2315 |
|
2316 | export interface ChromiumClientCommands {
|
2317 | /**
|
2318 | * Mock the geolocation of the browser.
|
2319 | *
|
2320 | * Call without any arguments to reset the geolocation.
|
2321 | *
|
2322 | * @example
|
2323 | * describe('mock geolocation', function() {
|
2324 | * it('sets the geolocation to Tokyo, Japan and then resets it', () => {
|
2325 | * browser
|
2326 | * .setGeolocation({
|
2327 | * latitude: 35.689487,
|
2328 | * longitude: 139.691706,
|
2329 | * accuracy: 100
|
2330 | * }) // sets the geolocation to Tokyo, Japan
|
2331 | * .navigateTo('https://www.gps-coordinates.net/my-location')
|
2332 | * .pause(3000)
|
2333 | * .setGeolocation() // resets the geolocation
|
2334 | * .navigateTo('https://www.gps-coordinates.net/my-location')
|
2335 | * .pause(3000);
|
2336 | * });
|
2337 | * });
|
2338 | *
|
2339 | * @see https://nightwatchjs.org/guide/network-requests/mock-geolocation.html
|
2340 | */
|
2341 | setGeolocation(
|
2342 | coordinates?: { latitude: number; longitude: number; accuracy?: number },
|
2343 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2344 | ): Awaitable<this, null>;
|
2345 |
|
2346 | /**
|
2347 | * Capture outgoing network calls from the browser.
|
2348 | *
|
2349 | * @example
|
2350 | * describe('capture network requests', function() {
|
2351 | * it('captures and logs network requests as they occur', function(this: ExtendDescribeThis<{requestCount: number}>) {
|
2352 | * this.requestCount = 1;
|
2353 | * browser
|
2354 | * .captureNetworkRequests((requestParams) => {
|
2355 | * console.log('Request Number:', this.requestCount!++);
|
2356 | * console.log('Request URL:', requestParams.request.url);
|
2357 | * console.log('Request method:', requestParams.request.method);
|
2358 | * console.log('Request headers:', requestParams.request.headers);
|
2359 | * })
|
2360 | * .navigateTo('https://www.google.com');
|
2361 | * });
|
2362 | * });
|
2363 | *
|
2364 | * @see https://nightwatchjs.org/guide/network-requests/capture-network-calls.html
|
2365 | */
|
2366 | captureNetworkRequests(
|
2367 | onRequestCallback: (requestParams: Protocol.Network.RequestWillBeSentEvent) => void,
|
2368 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2369 | ): Awaitable<this, null>;
|
2370 |
|
2371 | /**
|
2372 | * Intercept the request made on a particular URL and mock the response.
|
2373 | *
|
2374 | * @example
|
2375 | * describe('mock network response', function() {
|
2376 | * it('intercepts the request made to Google search and mocks its response', function() {
|
2377 | * browser
|
2378 | * .mockNetworkResponse('https://www.google.com/', {
|
2379 | * status: 200,
|
2380 | * headers: {
|
2381 | * 'Content-Type': 'UTF-8'
|
2382 | * },
|
2383 | * body: 'Hello there!'
|
2384 | * })
|
2385 | * .navigateTo('https://www.google.com/')
|
2386 | * .pause(2000);
|
2387 | * });
|
2388 | * });
|
2389 | *
|
2390 | * @see https://nightwatchjs.org/guide/network-requests/mock-network-response.html
|
2391 | */
|
2392 | mockNetworkResponse(
|
2393 | urlToIntercept: string,
|
2394 | response?: {
|
2395 | status?: Protocol.Fetch.FulfillRequestRequest['responseCode'];
|
2396 | headers?: { [name: string]: string };
|
2397 | body?: Protocol.Fetch.FulfillRequestRequest['body'];
|
2398 | },
|
2399 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2400 | ): Awaitable<this, null>;
|
2401 |
|
2402 | /**
|
2403 | * Override device mode/dimensions.
|
2404 | *
|
2405 | * @example
|
2406 | * describe('modify device dimensions', function() {
|
2407 | * it('modifies the device dimensions and then resets it', function() {
|
2408 | * browser
|
2409 | * .setDeviceDimensions({
|
2410 | * width: 400,
|
2411 | * height: 600,
|
2412 | * deviceScaleFactor: 50,
|
2413 | * mobile: true
|
2414 | * })
|
2415 | * .navigateTo('https://www.google.com')
|
2416 | * .pause(1000)
|
2417 | * .setDeviceDimensions() // resets the device dimensions
|
2418 | * .navigateTo('https://www.google.com')
|
2419 | * .pause(1000);
|
2420 | * });
|
2421 | * });
|
2422 | *
|
2423 | * @see https://nightwatchjs.org/guide/mobile-web-testing/override-device-dimensions.html
|
2424 | */
|
2425 | setDeviceDimensions(
|
2426 | metrics?: {
|
2427 | width?: number;
|
2428 | height?: number;
|
2429 | deviceScaleFactor?: number;
|
2430 | mobile?: boolean
|
2431 | },
|
2432 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2433 | ): Awaitable<this, null>;
|
2434 |
|
2435 | /**
|
2436 | * Get the performance metrics from the browser. Metrics collection
|
2437 | * only begin after `enablePerformanceMetrics()` command is called.
|
2438 | *
|
2439 | * @returns A promise that contains metrics collected between the
|
2440 | * last call to `enablePerformanceMetrics()` command and this command.
|
2441 | *
|
2442 | * @example
|
2443 | * describe('collect performance metrics', function() {
|
2444 | * it('enables the metrics collection, does some stuff and collects the metrics', function() {
|
2445 | * browser
|
2446 | * .enablePerformanceMetrics()
|
2447 | * .navigateTo('https://www.google.com')
|
2448 | * .getPerformanceMetrics((result) => {
|
2449 | * if (result.status === 0) {
|
2450 | * const metrics = result.value;
|
2451 | * console.log(metrics);
|
2452 | * }
|
2453 | * });
|
2454 | * });
|
2455 | * });
|
2456 | *
|
2457 | * @see https://web.dev/metrics/
|
2458 | * @see https://pptr.dev/api/puppeteer.page.metrics/
|
2459 | */
|
2460 | getPerformanceMetrics(
|
2461 | callback?: (
|
2462 | this: NightwatchAPI,
|
2463 | result: NightwatchCallbackResult<{[metricName: string]: number}>,
|
2464 | ) => void,
|
2465 | ): Awaitable<this, {[metricName: string]: number}>;
|
2466 |
|
2467 | /**
|
2468 | * Enable/disable the collection of performance metrics in the browser. Metrics
|
2469 | * collection only begin after this command is called.
|
2470 | *
|
2471 | * @example
|
2472 | * describe('collect performance metrics', function() {
|
2473 | * it('enables the metrics collection, does some stuff and collects the metrics', function() {
|
2474 | * browser
|
2475 | * .enablePerformanceMetrics()
|
2476 | * .navigateTo('https://www.google.com')
|
2477 | * .getPerformanceMetrics((result) => {
|
2478 | * if (result.status === 0) {
|
2479 | * const metrics = result.value;
|
2480 | * console.log(metrics);
|
2481 | * }
|
2482 | * });
|
2483 | * });
|
2484 | * });
|
2485 | *
|
2486 | * @see https://web.dev/metrics/
|
2487 | * @see https://pptr.dev/api/puppeteer.page.metrics/
|
2488 | */
|
2489 | enablePerformanceMetrics(
|
2490 | enable?: boolean,
|
2491 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2492 | ): Awaitable<this, null>;
|
2493 |
|
2494 | /**
|
2495 | * Take heap snapshot and save it as a `.heapsnapshot` file.
|
2496 | * The saved snapshot file can then be loaded into Chrome
|
2497 | * DevTools' Memory tab for inspection.
|
2498 | *
|
2499 | * The contents of the heap snapshot are also available in the `value`
|
2500 | * property of the `result` argument passed to the callback, in
|
2501 | * string-serialized JSON format.
|
2502 | *
|
2503 | * @returns A promise that contains heap snapshot in string-serialized
|
2504 | * JSON format.
|
2505 | *
|
2506 | * @example
|
2507 | * describe('take heap snapshot', function() {
|
2508 | * it('takes heap snapshot and saves it as snap.heapsnapshot file', function() {
|
2509 | * browser
|
2510 | * .navigateTo('https://www.google.com')
|
2511 | * .takeHeapSnapshot('./snap.heapsnapshot');
|
2512 | * });
|
2513 | * });
|
2514 | *
|
2515 | * @see https://nightwatchjs.org/guide/running-tests/take-heap-snapshot.html
|
2516 | */
|
2517 | takeHeapSnapshot(
|
2518 | heapSnapshotLocation?: string,
|
2519 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
2520 | ): Awaitable<this, string>;
|
2521 |
|
2522 | /**
|
2523 | * Listen to the `console` events (ex. `console.log` event) and
|
2524 | * register callback to process the same.
|
2525 | *
|
2526 | * @example
|
2527 | * describe('capture console events', function() {
|
2528 | * it('captures and logs console.log event', function() {
|
2529 | * browser
|
2530 | * .captureBrowserConsoleLogs((event) => {
|
2531 | * console.log(event.type, event.timestamp, event.args[0].value);
|
2532 | * })
|
2533 | * .navigateTo('https://www.google.com')
|
2534 | * .executeScript(function() {
|
2535 | * console.log('here');
|
2536 | * }, []);
|
2537 | * });
|
2538 | * });
|
2539 | *
|
2540 | * @see https://nightwatchjs.org/guide/running-tests/capture-console-messages.html
|
2541 | */
|
2542 | captureBrowserConsoleLogs(
|
2543 | onEventCallback: (
|
2544 | event: Pick<
|
2545 | Protocol.Runtime.ConsoleAPICalledEvent,
|
2546 | "type" | "timestamp" | "args"
|
2547 | >
|
2548 | ) => void,
|
2549 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2550 | ): Awaitable<this, null>;
|
2551 |
|
2552 | /**
|
2553 | * Catch the JavaScript exceptions thrown in the browser.
|
2554 | *
|
2555 | * @example
|
2556 | * describe('catch browser exceptions', function() {
|
2557 | * it('captures the js exceptions thrown in the browser', async function() {
|
2558 | * await browser.captureBrowserExceptions((event) => {
|
2559 | * console.log('>>> Exception:', event);
|
2560 | * });
|
2561 | *
|
2562 | * await browser.navigateTo('https://duckduckgo.com/');
|
2563 | *
|
2564 | * const searchBoxElement = await browser.findElement('input[name=q]');
|
2565 | * await browser.executeScript(function(_searchBoxElement) {
|
2566 | * _searchBoxElement.setAttribute('onclick', 'throw new Error("Hello world!")');
|
2567 | * }, [searchBoxElement]);
|
2568 | *
|
2569 | * await browser.elementIdClick(searchBoxElement.getId());
|
2570 | * });
|
2571 | * });
|
2572 | *
|
2573 | * @see https://nightwatchjs.org/guide/running-tests/catch-js-exceptions.html
|
2574 | */
|
2575 | captureBrowserExceptions(
|
2576 | onExceptionCallback: (event: Protocol.Runtime.ExceptionThrownEvent) => void,
|
2577 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2578 | ): Awaitable<this, null>;
|
2579 | }
|
2580 |
|
2581 | export interface ClientCommands extends ChromiumClientCommands {
|
2582 | /**
|
2583 | * Close the current window. This can be useful when you're working with multiple windows open (e.g. an OAuth login).
|
2584 | * Uses `window` protocol command.
|
2585 | *
|
2586 | * @example
|
2587 | * describe('closeWindow command demo' , function (result) {
|
2588 | * test('demo test', function () {
|
2589 | * browser.closeWindow();
|
2590 | * });
|
2591 | * });
|
2592 | * @see https://nightwatchjs.org/api/closeWindow.html
|
2593 | */
|
2594 | closeWindow(
|
2595 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2596 | ): Awaitable<this, null>;
|
2597 |
|
2598 | /**
|
2599 | * Sets the current window state to fullscreen.
|
2600 | *
|
2601 | * @example
|
2602 | * module.exports = {
|
2603 | * 'demo Test': function(browser) {
|
2604 | * browser.fullscreenWindow(function(result) {
|
2605 | * console.log(result);
|
2606 | * });
|
2607 | * },
|
2608 | *
|
2609 | * 'ES6 async demo Test': async function(browser) {
|
2610 | * const result = await browser.fullscreenWindow();
|
2611 | * console.log('result value is:', result.value);
|
2612 | * }
|
2613 | * }
|
2614 | * @see https://nightwatchjs.org/api/fullscreenWindow.html
|
2615 | */
|
2616 | fullscreenWindow(
|
2617 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
2618 | ): Awaitable<this, null>;
|
2619 |
|
2620 | /**
|
2621 | * Hides the window in the system tray. If the window happens to be in fullscreen mode,
|
2622 | * it is restored the normal state then it will be "iconified" - minimize or hide the window from the visible screen.
|
2623 | *
|
2624 | * @example
|
2625 | * module.exports = {
|
2626 | * 'demo Test': function(browser) {
|
2627 | * browser.minimizeWindow(function(result) {
|
2628 | * console.log(result);
|
2629 | * });
|
2630 | * },
|
2631 | *
|
2632 | * 'ES6 async demo Test': async function(browser) {
|
2633 | * const result = await browser.minimizeWindow();
|
2634 | * console.log('result value is:', result.value);
|
2635 | * }
|
2636 | * }
|
2637 | * @see https://nightwatchjs.org/api/minimizeWindow.html
|
2638 | */
|
2639 | minimizeWindow(
|
2640 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
2641 | ): Awaitable<this, null>;
|
2642 |
|
2643 | /**
|
2644 | * Opens a new top-level browser window, which can be either a tab (default) or a separate new window.
|
2645 | *
|
2646 | * This command is only available for W3C Webdriver compatible browsers.
|
2647 | *
|
2648 | * @example
|
2649 | * module.exports = {
|
2650 | * 'demo Test': function(browser) {
|
2651 | * // open a new window tab (default)
|
2652 | * browser.openNewWindow(function(result) {
|
2653 | * console.log(result);
|
2654 | * });
|
2655 | *
|
2656 | * // open a new window
|
2657 | * browser.openNewWindow('window', function(result) {
|
2658 | * console.log(result);
|
2659 | * });
|
2660 | * },
|
2661 | *
|
2662 | * 'ES6 async demo Test': async function(browser) {
|
2663 | * const result = await browser.openNewWindow();
|
2664 | * console.log('result value is:', result.value);
|
2665 | * }
|
2666 | * }
|
2667 | * @see https://nightwatchjs.org/api/openNewWindow.html
|
2668 | */
|
2669 | openNewWindow(
|
2670 | type?: WindowType,
|
2671 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2672 | ): Awaitable<this, null>;
|
2673 |
|
2674 | /**
|
2675 | * Delete the cookie with the given name. This command is a no-op if there is no such cookie visible to the current page.
|
2676 | *
|
2677 | * @example
|
2678 | * this.demoTest = function() {
|
2679 | * browser.deleteCookie("test_cookie", function() {
|
2680 | * // do something more in here
|
2681 | * });
|
2682 | * }
|
2683 | *
|
2684 | * @see https://nightwatchjs.org/api/deleteCookie.html
|
2685 | */
|
2686 | deleteCookie(
|
2687 | cookieName: string,
|
2688 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2689 | ): Awaitable<this, null>;
|
2690 |
|
2691 | /**
|
2692 | * Delete all cookies visible to the current page.
|
2693 | *
|
2694 | * @example
|
2695 | * this.demoTest = function() {
|
2696 | * browser.deleteCookies(function() {
|
2697 | * // do something more in here
|
2698 | * });
|
2699 | * }
|
2700 | *
|
2701 | * @see https://nightwatchjs.org/api/deleteCookies.html
|
2702 | */
|
2703 | deleteCookies(
|
2704 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
2705 | ): Awaitable<this, null>;
|
2706 |
|
2707 | /**
|
2708 | * Ends the session. Uses session protocol command.
|
2709 | *
|
2710 | * @example
|
2711 | * this.demoTest = function () {
|
2712 | * browser.end();
|
2713 | * };
|
2714 | *
|
2715 | * @see https://nightwatchjs.org/api/end.html
|
2716 | */
|
2717 | end(
|
2718 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
2719 | ): Awaitable<this, null>;
|
2720 |
|
2721 | /**
|
2722 | * Retrieve a single cookie visible to the current page. The cookie is returned as a cookie JSON object,
|
2723 | * as defined [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).
|
2724 | *
|
2725 | * Uses `cookie` protocol command.
|
2726 | *
|
2727 | * @example
|
2728 | * this.demoTest = function() {
|
2729 | * browser.getCookie(name, function callback(result) {
|
2730 | * this.assert.equal(result.value, '123456');
|
2731 | * this.assert.equals(result.name, 'test_cookie');
|
2732 | * });
|
2733 | * }
|
2734 | *
|
2735 | * @see https://nightwatchjs.org/api/getCookie.html
|
2736 | */
|
2737 | getCookie(
|
2738 | name: string,
|
2739 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Cookie>) => void
|
2740 | ): Awaitable<this, Cookie>;
|
2741 |
|
2742 | /**
|
2743 | * Retrieve all cookies visible to the current page. The cookies are returned as an array of cookie JSON object,
|
2744 | * as defined [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).
|
2745 | *
|
2746 | * Uses `cookie` protocol command.
|
2747 | *
|
2748 | * @example
|
2749 | * this.demoTest = function() {
|
2750 | * browser.getCookies(function callback(result) {
|
2751 | * this.assert.equal(result.value.length, 1);
|
2752 | * this.assert.equals(result.value[0].name, 'test_cookie');
|
2753 | * });
|
2754 | * }
|
2755 | *
|
2756 | * @see https://nightwatchjs.org/api/getCookies.html
|
2757 | */
|
2758 | getCookies(
|
2759 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Cookie[]>) => void
|
2760 | ): Awaitable<this, Cookie[]>;
|
2761 |
|
2762 | /**
|
2763 | * Gets a log from Selenium.
|
2764 | *
|
2765 | * @example
|
2766 | * this.demoTest = function() {
|
2767 | * this.getLog('browser', function(logEntriesArray) {
|
2768 | * console.log('Log length: ' + logEntriesArray.length);
|
2769 | * logEntriesArray.forEach(function(log) {
|
2770 | * console.log('[' + log.level + '] ' + log.timestamp + ' : ' + log.message);
|
2771 | * });
|
2772 | * });
|
2773 | * };
|
2774 | *
|
2775 | * @see https://nightwatchjs.org/api/getLog.html
|
2776 | */
|
2777 | getLog(
|
2778 | typestring: string, callback?: (this: NightwatchAPI, log: NightwatchLogEntry[]) => void
|
2779 | ): Awaitable<this, NightwatchLogEntry[]>;
|
2780 |
|
2781 | /**
|
2782 | * Gets the available log types. More info about log types in WebDriver can be found here: https://github.com/SeleniumHQ/selenium/wiki/Logging
|
2783 | *
|
2784 | * @example
|
2785 | * this.demoTest = function() {
|
2786 | * this.getLogTypes(function(typesArray) {
|
2787 | * console.log(typesArray);
|
2788 | * });
|
2789 | * };
|
2790 | *
|
2791 | * @see https://nightwatchjs.org/api/getLogTypes.html
|
2792 | */
|
2793 | getLogTypes(
|
2794 | callback?: (
|
2795 | this: NightwatchAPI,
|
2796 | result: Array<'client' | 'driver' | 'browser' | 'server' | 'performance'>,
|
2797 | ) => void,
|
2798 | ): Awaitable<this, Array<'client' | 'driver' | 'browser' | 'server' | 'performance'>>;
|
2799 |
|
2800 | /**
|
2801 | * Retrieve the URL of the current page.
|
2802 | *
|
2803 | * @example
|
2804 | * describe('Navigation commands demo', function() {
|
2805 | * test('demoTest', function(browser) {
|
2806 | * // navigate to new url:
|
2807 | * browser.navigateTo('https://nightwatchjs.org');
|
2808 | *
|
2809 | * // Retrieve to url with callback:
|
2810 | * browser.getCurrentUrl(function(result) {
|
2811 | * console.log(result.value);
|
2812 | * });
|
2813 | * });
|
2814 | *
|
2815 | * test('demoTestAsync', async function(browser) {
|
2816 | * const currentUrl = await browser.navigateTo('https://nightwatchjs.org').getCurrentUrl();
|
2817 | * console.log('currentUrl:', currentUrl); // will print 'https://nightwatchjs.org'
|
2818 | * });
|
2819 | *
|
2820 | * });
|
2821 | *
|
2822 | * @see https://nightwatchjs.org/api/getCurrentUrl.html
|
2823 | */
|
2824 | getCurrentUrl(
|
2825 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void
|
2826 | ): Awaitable<this, string>;
|
2827 |
|
2828 | /**
|
2829 | * Returns the title of the current page. Uses title protocol command.
|
2830 | *
|
2831 | * @example
|
2832 | * this.demoTest = function () {
|
2833 | * browser.getTitle(function(title) {
|
2834 | * this.assert.equal(typeof title, 'string');
|
2835 | * this.assert.equal(title, 'Nightwatch.js');
|
2836 | * });
|
2837 | * };
|
2838 | *
|
2839 | * @see https://nightwatchjs.org/api/getTitle.html
|
2840 | */
|
2841 | getTitle(
|
2842 | callback?: (this: NightwatchAPI, result: string) => void
|
2843 | ): Awaitable<this, string>;
|
2844 |
|
2845 | /**
|
2846 | * Navigate to a new URL. This method will also call the `onBrowserNavigate()` test global,
|
2847 | * right after the page is loaded.
|
2848 | *
|
2849 | * @example
|
2850 | * describe('Navigation commands demo', function() {
|
2851 | * test('demoTest', function(browser) {
|
2852 | * // navigate to new url:
|
2853 | * browser.navigateTo('https://nightwatchjs.org');
|
2854 | *
|
2855 | * // Retrieve to url with callback:
|
2856 | * browser.getCurrentUrl(function(result) {
|
2857 | * console.log(result.value);
|
2858 | * });
|
2859 | * });
|
2860 | *
|
2861 | * test('demoTestAsync', async function(browser) {
|
2862 | * const currentUrl = await browser.navigateTo('https://nightwatchjs.org').getCurrentUrl();
|
2863 | * console.log('currentUrl:', currentUrl); // will print 'https://nightwatchjs.org'
|
2864 | * });
|
2865 | * });
|
2866 | *
|
2867 | * @see https://nightwatchjs.org/api/navigateTo.html
|
2868 | */
|
2869 | navigateTo(
|
2870 | url: string,
|
2871 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2872 | ): Awaitable<this, null>;
|
2873 |
|
2874 | /**
|
2875 | * Ends the session and closes down the test WebDriver server, if one is running.
|
2876 | * This is similar to calling the .end() command, but the former doesn't quit the WebDriver session.
|
2877 | *
|
2878 | * This command will also execute the `onBrowserQuit()` global, if one is defined.
|
2879 | *
|
2880 | * @example
|
2881 | * this.demoTest = function (browser) {
|
2882 | * browser.quit(function(result) {
|
2883 | * console.log(result.value);
|
2884 | * });
|
2885 | * }
|
2886 | *
|
2887 | * @see https://nightwatchjs.org/api/quit.html
|
2888 | */
|
2889 | quit(
|
2890 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
2891 | ): Awaitable<this, null>;
|
2892 |
|
2893 | /**
|
2894 | * This command is an alias to url and also a convenience method when called without any arguments in the sense
|
2895 | * that it performs a call to .url() with passing the value of `launch_url` field from the settings file.
|
2896 | * Uses `url` protocol command.
|
2897 | *
|
2898 | * @example
|
2899 | * this.demoTest = function () {
|
2900 | * browser.init();
|
2901 | * };
|
2902 | *
|
2903 | * @see https://nightwatchjs.org/api/init.html
|
2904 | */
|
2905 | init(
|
2906 | url?: string,
|
2907 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
2908 | ): Awaitable<this, null>;
|
2909 |
|
2910 | /**
|
2911 | * Utility command to load an external script into the page specified by url.
|
2912 | *
|
2913 | * @example
|
2914 | * this.demoTest = function() {
|
2915 | * this.injectScript("{script-url}", function() {
|
2916 | * // we're all done here.
|
2917 | * });
|
2918 | * };
|
2919 | *
|
2920 | * @see https://nightwatchjs.org/api/injectScript.html
|
2921 | */
|
2922 | injectScript(
|
2923 | scriptUrl: string,
|
2924 | id?: string,
|
2925 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<HTMLScriptElement>) => void,
|
2926 | ): Awaitable<this, HTMLScriptElement>;
|
2927 |
|
2928 | /**
|
2929 | * Utility command to test if the log type is available.
|
2930 | *
|
2931 | * @example
|
2932 | * this.demoTest = function() {
|
2933 | * browser.isLogAvailable('browser', function(isAvailable) {
|
2934 | * // do something more in here
|
2935 | * });
|
2936 | * }
|
2937 | *
|
2938 | * @see https://nightwatchjs.org/api/isLogAvailable.html
|
2939 | */
|
2940 | isLogAvailable(
|
2941 | typeString: string, callback?: (this: NightwatchAPI, result: boolean) => void
|
2942 | ): Awaitable<this, boolean>;
|
2943 |
|
2944 | /**
|
2945 | * Maximizes the current window.
|
2946 | *
|
2947 | * @example
|
2948 | * this.demoTest = function () {
|
2949 | * browser.maximizeWindow();
|
2950 | * };
|
2951 | *
|
2952 | * @see https://nightwatchjs.org/api/maximizeWindow.html
|
2953 | */
|
2954 | maximizeWindow(
|
2955 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
2956 | ): Awaitable<this, null>;
|
2957 |
|
2958 | /**
|
2959 | * Suspends the test for the given time in milliseconds. If the milliseconds argument is missing it will suspend the test indefinitely
|
2960 | *
|
2961 | * @example
|
2962 | * this.demoTest = function () {
|
2963 | * browser.pause(1000);
|
2964 | * // or suspend indefinitely
|
2965 | * browser.pause();
|
2966 | * };
|
2967 | *
|
2968 | * @see https://nightwatchjs.org/api/pause.html
|
2969 | */
|
2970 | pause(ms?: number, callback?: (this: NightwatchAPI) => void): Awaitable<this, undefined>;
|
2971 |
|
2972 | /**
|
2973 | * This command halts the test execution and provides users with a REPL interface where they can type
|
2974 | * any of the available Nightwatch commands and the command will be executed in the running browser
|
2975 | * in real-time.
|
2976 | *
|
2977 | * This can be used to debug why a certain command in not working as expected, find the correct
|
2978 | * locators for your assertions or just play around with the available Nightwatch commands.
|
2979 | *
|
2980 | * @example
|
2981 | * // async function is required while using the debug
|
2982 | * // command to get the correct result as output.
|
2983 | * this.demoTest = async function (browser) {
|
2984 | * browser.debug();
|
2985 | *
|
2986 | * // with no auto-complete
|
2987 | * browser.debug({preview: false});
|
2988 | *
|
2989 | * // with a timeout of 6000 ms (time for which the interface
|
2990 | * // would wait for a result).
|
2991 | * browser.debug({timeout: 6000})
|
2992 | * };
|
2993 | *
|
2994 | * @see https://nightwatchjs.org/api/debug.html
|
2995 | */
|
2996 | debug(
|
2997 | config?: { useGlobal?: boolean; preview?: boolean; timeout?: number },
|
2998 | callback?: (this: NightwatchAPI) => void
|
2999 | ): Awaitable<this, undefined>;
|
3000 |
|
3001 | /**
|
3002 | * A simple perform command which allows access to the Nightwatch API in a callback. Can be useful if you want to read variables set by other commands.
|
3003 | *
|
3004 | * The callback signature can have up to two parameters.
|
3005 | * - no parameters: callback runs and perform completes immediately at the end of the execution of the callback.
|
3006 | * - one parameter: allows for asynchronous execution within the callback providing a done callback function for completion as the first argument.
|
3007 | * - two parameters: allows for asynchronous execution with the Nightwatch `api` object passed in as the first argument, followed by the done callback.
|
3008 | *
|
3009 | * @example
|
3010 | * this.demoTest = function () {
|
3011 | * var elementValue;
|
3012 | * browser
|
3013 | * .getValue('.some-element', function(result) {
|
3014 | * elementValue = result.value;
|
3015 | * })
|
3016 | * // other stuff going on ...
|
3017 | * //
|
3018 | * // self-completing callback
|
3019 | * .perform(function() {
|
3020 | * console.log('elementValue', elementValue);
|
3021 | * // without any defined parameters, perform
|
3022 | * // completes immediately (synchronously)
|
3023 | * })
|
3024 | * //
|
3025 | * // asynchronous completion
|
3026 | * .perform(function(done) {
|
3027 | * console.log('elementValue', elementValue);
|
3028 | * // potentially other async stuff going on
|
3029 | * // on finished, call the done callback
|
3030 | * done();
|
3031 | * })
|
3032 | * //
|
3033 | * // asynchronous completion including api (client)
|
3034 | * .perform(function(done) {
|
3035 | * console.log('elementValue', elementValue);
|
3036 | * // similar to before, but now with client
|
3037 | * // potentially other async stuff going on
|
3038 | * // on finished, call the done callback
|
3039 | * done();
|
3040 | * });
|
3041 | * };
|
3042 | */
|
3043 | perform(
|
3044 | callback:
|
3045 | | (() => undefined | Promise<any>)
|
3046 | | ((done: () => void) => void)
|
3047 | | ((client: NightwatchAPI, done: () => void) => void),
|
3048 | ): Awaitable<this, undefined | Error>;
|
3049 |
|
3050 | /**
|
3051 | * Waits for a condition to evaluate to a "truthy" value. The condition may be specified by any function which
|
3052 | * returns the value to be evaluated or a Promise to wait for.
|
3053 | *
|
3054 | * An optional wait time can be specified, otherwise the global waitForConditionTimeout value will be used.
|
3055 | *
|
3056 | * @example
|
3057 | * describe('waitUntil Example', function() {
|
3058 | * it('demo Test', function(browser) {
|
3059 | * browser
|
3060 | * .url('https://nightwatchjs.org)
|
3061 | * .waitUntil(async function() {
|
3062 | * const title = await this.execute(function() {
|
3063 | * return document.title;
|
3064 | * });
|
3065 | *
|
3066 | * return title === 'Nightwatch.js';
|
3067 | * }, 1000);
|
3068 | * });
|
3069 | * }
|
3070 | *
|
3071 | */
|
3072 | waitUntil(
|
3073 | conditionFn:
|
3074 | | ((this: NightwatchAPI) => undefined | Promise<any>)
|
3075 | | ((this: NightwatchAPI, done: () => void) => void)
|
3076 | | ((this: NightwatchAPI, client: NightwatchAPI, done: () => void) => void),
|
3077 | waitTimeMs?: number,
|
3078 | retryInterval?: number,
|
3079 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
3080 | ): Awaitable<this, null>;
|
3081 |
|
3082 | /**
|
3083 | * Resizes the current window.
|
3084 | *
|
3085 | * @example
|
3086 | * this.demoTest = function () {
|
3087 | * browser.resizeWindow(1000, 800);
|
3088 | * };
|
3089 | *
|
3090 | * @see https://nightwatchjs.org/api/resizeWindow.html
|
3091 | */
|
3092 | resizeWindow(
|
3093 | width: number,
|
3094 | height: number,
|
3095 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
3096 | ): Awaitable<this, null>;
|
3097 |
|
3098 | /**
|
3099 | * Take a screenshot of the current page and saves it as the given filename.
|
3100 | *
|
3101 | * @example
|
3102 | * this.demoTest = function ( ) {
|
3103 | * browser.saveScreenshot('/path/to/fileName.png');
|
3104 | * };
|
3105 | *
|
3106 | * @see https://nightwatchjs.org/api/saveScreenshot.html
|
3107 | */
|
3108 | saveScreenshot(
|
3109 | fileName: string,
|
3110 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3111 | ): Awaitable<this, string>;
|
3112 |
|
3113 | /**
|
3114 | * Set a cookie, specified as a cookie JSON object, as defined [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).
|
3115 | *
|
3116 | * Uses `cookie` protocol command.
|
3117 | *
|
3118 | * @example
|
3119 | * this.demoTest = function() {
|
3120 | * browser.setCookie({
|
3121 | * name : "test_cookie",
|
3122 | * value : "test_value",
|
3123 | * path : "/", (Optional)
|
3124 | * domain : "example.org", (Optional)
|
3125 | * secure : false, (Optional)
|
3126 | * httpOnly : false, // (Optional)
|
3127 | * expiry : 1395002765 // (Optional) time in seconds since midnight, January 1, 1970 UTC
|
3128 | * });
|
3129 | * }
|
3130 | *
|
3131 | * @see https://nightwatchjs.org/api/setCookie.html
|
3132 | */
|
3133 | setCookie(
|
3134 | cookie: Cookie, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
3135 | ): Awaitable<this, null>;
|
3136 |
|
3137 | /**
|
3138 | * Sets the current window position.
|
3139 | *
|
3140 | * @example
|
3141 | * this.demoTest = function () {
|
3142 | * browser.setWindowPosition(0, 0);
|
3143 | * };
|
3144 | *
|
3145 | * @see https://nightwatchjs.org/api/setWindowPosition.html
|
3146 | */
|
3147 | setWindowPosition(
|
3148 | offsetX: number,
|
3149 | offsetY: number,
|
3150 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
3151 | ): Awaitable<this, null>;
|
3152 |
|
3153 | /**
|
3154 | * Change the [window rect](https://w3c.github.io/webdriver/#dfn-window-rect). This is defined as a dictionary of the `screenX`, `screenY`, `outerWidth` and `outerHeight` attributes of the window.
|
3155 | *
|
3156 | * Its JSON representation is the following:
|
3157 | * - `x` - window's screenX attribute;
|
3158 | * - `y` - window's screenY attribute;
|
3159 | * - `width` - outerWidth attribute;
|
3160 | * - `height` - outerHeight attribute.
|
3161 | *
|
3162 | * All attributes are in in CSS pixels. To change the window react, you can either specify `width` and `height`, `x` and `y` or all properties together.
|
3163 | *
|
3164 | * @example
|
3165 | * module.exports = {
|
3166 | * 'demo test .setWindowRect()': function() {
|
3167 | *
|
3168 | * // Change the screenX and screenY attributes of the window rect.
|
3169 | * browser.setWindowRect({x: 500, y: 500});
|
3170 | *
|
3171 | * // Change the width and height attributes of the window rect.
|
3172 | * browser.setWindowRect({width: 600, height: 300});
|
3173 | *
|
3174 | * // Retrieve the attributes
|
3175 | * browser.setWindowRect(function(result) {
|
3176 | * console.log(result.value);
|
3177 | * });
|
3178 | * },
|
3179 | *
|
3180 | * 'setWindowRect ES6 demo test': async function() {
|
3181 | * await browser.setWindowRect({
|
3182 | * width: 600,
|
3183 | * height: 300,
|
3184 | * x: 100,
|
3185 | * y: 100
|
3186 | * });
|
3187 | * }
|
3188 | * }
|
3189 | *
|
3190 | * @see https://nightwatchjs.org/api/setWindowRect.html
|
3191 | */
|
3192 | setWindowRect(
|
3193 | options: WindowSizeAndPosition,
|
3194 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
3195 | ): Awaitable<this, null>;
|
3196 |
|
3197 | /**
|
3198 | * Sets the current window position.
|
3199 | *
|
3200 | * @example
|
3201 | * this.demoTest = function () {
|
3202 | * browser.setWindowPosition(0, 0);
|
3203 | * };
|
3204 | *
|
3205 | * @see https://nightwatchjs.org/api/setWindowSize.html
|
3206 | *
|
3207 | */
|
3208 | setWindowSize(
|
3209 | width: number,
|
3210 | height: number,
|
3211 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
3212 | ): Awaitable<this, null>;
|
3213 |
|
3214 | /**
|
3215 | * Change focus to another window. The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute.
|
3216 | *
|
3217 | * To find out the window handle use `windowHandles` command
|
3218 | *
|
3219 | * @example
|
3220 | * this.demoTest = function () {
|
3221 | * browser.windowHandles(function(result) {
|
3222 | * const handle = result.value[0];
|
3223 | * browser.switchWindow(handle);
|
3224 | * });
|
3225 | * };
|
3226 | *
|
3227 | * this.demoTestAsync = async function () {
|
3228 | * const result = await browser.windowHandles();
|
3229 | * const handle = result.value[0];
|
3230 | * browser.switchWindow(handle);
|
3231 | * };
|
3232 | *
|
3233 | * @alias switchToWindow
|
3234 | *
|
3235 | * @see https://nightwatchjs.org/api/switchWindow.html
|
3236 | */
|
3237 | switchWindow(
|
3238 | handleOrName: string,
|
3239 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
3240 | ): Awaitable<this, null>;
|
3241 |
|
3242 | /**
|
3243 | * Change focus to another window. The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute.
|
3244 | *
|
3245 | * To find out the window handle use `windowHandles` command
|
3246 | *
|
3247 | * @example
|
3248 | * this.demoTest = function () {
|
3249 | * browser.windowHandles(function(result) {
|
3250 | * const handle = result.value[0];
|
3251 | * browser.switchToWindow(handle);
|
3252 | * });
|
3253 | * };
|
3254 | *
|
3255 | * this.demoTestAsync = async function () {
|
3256 | * const result = await browser.windowHandles();
|
3257 | * const handle = result.value[0];
|
3258 | * browser.switchToWindow(handle);
|
3259 | * };
|
3260 | *
|
3261 | * @see https://nightwatchjs.org/api/switchToWindow.html
|
3262 | */
|
3263 | switchToWindow(
|
3264 | handleOrName: string,
|
3265 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
3266 | ): Awaitable<this, null>;
|
3267 |
|
3268 | /**
|
3269 | * Change or get the [window rect](https://w3c.github.io/webdriver/#dfn-window-rect).
|
3270 | * This is defined as a dictionary of the `screenX`, `screenY`, `outerWidth` and `outerHeight` attributes of the window.
|
3271 | *
|
3272 | * Its JSON representation is the following:
|
3273 | * - `x` - window's screenX attribute;
|
3274 | * - `y` - window's screenY attribute;
|
3275 | * - `width` - outerWidth attribute;
|
3276 | * - `height` - outerHeight attribute.
|
3277 | *
|
3278 | * All attributes are in in CSS pixels. To change the window react, you can either specify `width` and `height`, `x` and `y` or all properties together.
|
3279 | *
|
3280 | * @example
|
3281 | * module.exports = {
|
3282 | * 'demo test .getWindowRect()': function() {
|
3283 | * // Retrieve the attributes
|
3284 | * browser.getWindowRect(function(value) {
|
3285 | * console.log(value);
|
3286 | * });
|
3287 | * },
|
3288 | *
|
3289 | * 'getWindowRect ES6 demo test': async function() {
|
3290 | * const resultValue = await browser.getWindowRect();
|
3291 | * console.log('result value', resultValue);
|
3292 | * }
|
3293 | * }
|
3294 | *
|
3295 | * @see https://nightwatchjs.org/api/getWindowRect.html
|
3296 | */
|
3297 | getWindowRect(
|
3298 | callback?: (
|
3299 | this: NightwatchAPI,
|
3300 | result: NightwatchCallbackResult<WindowSizeAndPosition>,
|
3301 | ) => void,
|
3302 | ): Awaitable<this, WindowSizeAndPosition>;
|
3303 |
|
3304 | /**
|
3305 | * Retrieves the current window size.
|
3306 | *
|
3307 | * For clients which are compatible with the [W3C Webdriver API](https://w3c.github.io/webdriver/), `getWindowSize` is an alias of `getWindowRect`.
|
3308 | *
|
3309 | * The `getWindowRect` command returns both dimensions and position of the window, using the `windowRect` protocol command.
|
3310 | *
|
3311 | * @example
|
3312 | * module.exports = {
|
3313 | * 'demo test .getWindowSize()': function() {
|
3314 | * // Retrieve the attributes
|
3315 | * browser.getWindowSize(function(value) {
|
3316 | * console.log(value);
|
3317 | * });
|
3318 | * },
|
3319 | *
|
3320 | * 'getWindowSize ES6 demo test': async function(browser) {
|
3321 | * const value = await browser.getWindowSize();
|
3322 | * console.log('value', value);
|
3323 | * }
|
3324 | * }
|
3325 | *
|
3326 | * @see https://nightwatchjs.org/api/getWindowSize.html
|
3327 | */
|
3328 | getWindowSize(
|
3329 | callback?: (
|
3330 | this: NightwatchAPI,
|
3331 | result: NightwatchCallbackResult<WindowSizeAndPosition>,
|
3332 | ) => void,
|
3333 | ): Awaitable<this, WindowSizeAndPosition>;
|
3334 |
|
3335 | /**
|
3336 | * Retrieves the current window position.
|
3337 | *
|
3338 | * For clients which are compatible with the [W3C Webdriver API](https://w3c.github.io/webdriver/), `getWindowPosition` is an alias of `getWindowRect`.
|
3339 | *
|
3340 | * The `getWindowRect` command returns both dimensions and position of the window, using the `windowRect` protocol command.
|
3341 | *
|
3342 | * @example
|
3343 | * module.exports = {
|
3344 | * 'demo test .getWindowPosition()': function(browser) {
|
3345 | * // Retrieve the attributes
|
3346 | * browser.getWindowPosition(function(value) {
|
3347 | * console.log(value);
|
3348 | * });
|
3349 | * },
|
3350 | *
|
3351 | * 'getWindowPosition ES6 demo test': async function(browser) {
|
3352 | * const value = await browser.getWindowPosition();
|
3353 | * console.log('value', value);
|
3354 | * }
|
3355 | * }
|
3356 | *
|
3357 | * @see https://nightwatchjs.org/api/getWindowPosition.html
|
3358 | */
|
3359 | getWindowPosition(
|
3360 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<WindowPosition>) => void,
|
3361 | ): Awaitable<this, WindowPosition>;
|
3362 |
|
3363 | /**
|
3364 | * Returns the page source. Uses pageSource protocol command.
|
3365 | *
|
3366 | * @example
|
3367 | * this.demoTest = function (browser) {
|
3368 | * browser.pageSource(function(pageSource) {
|
3369 | * console.log(pageSource);
|
3370 | * });
|
3371 | * };
|
3372 | *
|
3373 | * @see https://nightwatchjs.org/api/pageSource.html
|
3374 | */
|
3375 | pageSource(
|
3376 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void
|
3377 | ): Awaitable<this, string>;
|
3378 |
|
3379 | /**
|
3380 | * Convenience command that adds the specified hash (i.e. url fragment) to the current value of the `launch_url` as set in `nightwatch.json`.
|
3381 | *
|
3382 | * @example
|
3383 | * this.demoTest = function () {
|
3384 | * browser.urlHash('#hashvalue');
|
3385 | * // or
|
3386 | * browser.urlHash('hashvalue');
|
3387 | * };
|
3388 | *
|
3389 | * @see https://nightwatchjs.org/api/urlHash.html
|
3390 | */
|
3391 | urlHash(
|
3392 | hash: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
3393 | ): Awaitable<this, null>;
|
3394 |
|
3395 | /**
|
3396 | * Sets the locate strategy for selectors to `css selector`, therefore every following selector needs to be specified as css.
|
3397 | *
|
3398 | * @example
|
3399 | * this.demoTest = function () {
|
3400 | * browser
|
3401 | * .useCss() // we're back to CSS now
|
3402 | * .setValue('input[type=text]', 'nightwatch');
|
3403 | * };
|
3404 | *
|
3405 | * @see https://nightwatchjs.org/api/useCss.html
|
3406 | */
|
3407 | useCss(callback?: (this: NightwatchAPI) => void): Awaitable<this, undefined>;
|
3408 |
|
3409 | /**
|
3410 | * Sets the locate strategy for selectors to xpath, therefore every following selector needs to be specified as xpath.
|
3411 | *
|
3412 | * @example
|
3413 | * this.demoTest = function () {
|
3414 | * browser
|
3415 | * .useXpath() // every selector now must be xpath
|
3416 | * .click("//tr[@data-recordid]/span[text()='Search Text']");
|
3417 | * };
|
3418 | *
|
3419 | * @see https://nightwatchjs.org/api/useXpath.html
|
3420 | */
|
3421 | useXpath(callback?: (this: NightwatchAPI) => void): Awaitable<this, undefined>;
|
3422 |
|
3423 | /**
|
3424 | * Injects the axe-core js library into the current page (using the .executeScript() command) to be paired
|
3425 | * with axeRun to evaluate the axe-core accessibility rules.
|
3426 | *
|
3427 | * @example
|
3428 | * this.demoTest = function () {
|
3429 | * browser
|
3430 | * .url('https://nightwatchjs.org')
|
3431 | * .axeInject()
|
3432 | * .axeRun();
|
3433 | * };
|
3434 | *
|
3435 | * @see https://nightwatchjs.org/api/axeInject.html
|
3436 | */
|
3437 | axeInject(): Awaitable<this, null>;
|
3438 |
|
3439 | /**
|
3440 | * Analyzes the current page against applied axe rules.
|
3441 | *
|
3442 | * @example
|
3443 | * this.demoTest = function () {
|
3444 | * browser
|
3445 | * .url('https://nightwatchjs.org')
|
3446 | * .axeInject()
|
3447 | * .axeRun(
|
3448 | * 'body',
|
3449 | * { runOnly: ['color-contrast', 'image-alt'] }
|
3450 | * );
|
3451 | * };
|
3452 | *
|
3453 | * @example
|
3454 | * this.demoTest = function () {
|
3455 | * browser
|
3456 | * .url('https://nightwatchjs.org')
|
3457 | * .axeInject()
|
3458 | * .axeRun(
|
3459 | * 'body',
|
3460 | * {
|
3461 | * 'color-contrast': {
|
3462 | * enabled: false
|
3463 | * }
|
3464 | * },
|
3465 | * }
|
3466 | * );
|
3467 | * };
|
3468 | *
|
3469 | * @param selector - CSS selector to scope rule analysis against, will cascade to child elements
|
3470 | * @param options - Allows configuration of what rules will be run (accessibility standard or rules to enable/disable)
|
3471 | * @see {@link https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter}
|
3472 | *
|
3473 | * @see {@link https://nightwatchjs.org/api/axeRun.html}
|
3474 | */
|
3475 | axeRun(
|
3476 | selector?: string,
|
3477 | options?: { [key: string]: any },
|
3478 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
3479 | ): Awaitable<this, null>;
|
3480 | }
|
3481 |
|
3482 | export interface ElementCommands {
|
3483 | /**
|
3484 | * Clear a textarea or a text input element's value.
|
3485 | * Starting with v1.1 `clearValue()` will wait for the element to be present (until the specified timeout).
|
3486 | *
|
3487 | * If the element is not found, an error is thrown which will cause the test to fail.
|
3488 | * Starting with `v1.2` you can suppress element not found errors by specifying the `suppressNotFoundErrors` flag.
|
3489 | *
|
3490 | * @example
|
3491 | * describe('clearValue Command demo', function() {
|
3492 | * test('demo test', function() {
|
3493 | * browser.clearValue('#login input[type=text]');
|
3494 | *
|
3495 | * browser.clearValue('#login input[type=text]', function(result) {
|
3496 | * console.log('clearValue result', result);
|
3497 | * });
|
3498 | *
|
3499 | * // with explicit locate strategy
|
3500 | * browser.clearValue('css selector', '#login input[type=text]');
|
3501 | *
|
3502 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3503 | * browser.clearValue({
|
3504 | * selector: '#login input[type=text]',
|
3505 | * index: 1,
|
3506 | * suppressNotFoundErrors: true
|
3507 | * });
|
3508 | *
|
3509 | * browser.clearValue({
|
3510 | * selector: '#login input[type=text]',
|
3511 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
3512 | * });
|
3513 | *
|
3514 | * });
|
3515 | *
|
3516 | * });
|
3517 | *
|
3518 | * @see https://nightwatchjs.org/api/clearValue.html
|
3519 | */
|
3520 | clearValue(
|
3521 | selector: Definition,
|
3522 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
3523 | ): Awaitable<this, null>;
|
3524 | clearValue(
|
3525 | using: LocateStrategy,
|
3526 | selector: Definition,
|
3527 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
|
3528 | ): Awaitable<this, null>;
|
3529 |
|
3530 | /**
|
3531 | * Simulates a click event on the given DOM element.
|
3532 | * The element is scrolled into view if it is not already pointer-interactable.
|
3533 | * See the WebDriver specification for <a href="https://www.w3.org/TR/webdriver/#element-interactability" target="_blank">element interactability</a>.
|
3534 | *
|
3535 | * @example
|
3536 | * module.exports = {
|
3537 | * demoTest() {
|
3538 | * browser.click('#main ul li a.first');
|
3539 | *
|
3540 | * browser.click('#main ul li a.first', function(result) {
|
3541 | * console.log('Click result', result);
|
3542 | * });
|
3543 | *
|
3544 | * // with explicit locate strategy
|
3545 | * browser.click('css selector', '#main ul li a.first');
|
3546 | *
|
3547 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3548 | * browser.click({
|
3549 | * selector: '#main ul li a',
|
3550 | * index: 1,
|
3551 | * suppressNotFoundErrors: true
|
3552 | * });
|
3553 | *
|
3554 | * browser.click({
|
3555 | * selector: '#main ul li a.first',
|
3556 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
3557 | * });
|
3558 | * },
|
3559 | *
|
3560 | * demoTestAsync: async function(browser) {
|
3561 | * const result = await browser.click('#main ul li a.first');
|
3562 | * console.log('Click result', result);
|
3563 | * }
|
3564 | * }
|
3565 | *
|
3566 | *
|
3567 | * @see https://nightwatchjs.org/api/click.html
|
3568 | */
|
3569 | click(selector: Definition, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void): Awaitable<this, null>;
|
3570 | click(
|
3571 | using: LocateStrategy,
|
3572 | selector: Definition,
|
3573 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
3574 | ): Awaitable<this, null>;
|
3575 |
|
3576 | /**
|
3577 | * Retrieve the value of an attribute for a given DOM element.
|
3578 | *
|
3579 | * @example
|
3580 | * module.exports = {
|
3581 | * demoTest() {
|
3582 | * browser.getAttribute('#main ul li a.first', 'href', function(result) {
|
3583 | * console.log('result', result);
|
3584 | * });
|
3585 | *
|
3586 | * // with explicit locate strategy
|
3587 | * browser.getAttribute('css selector', '#main ul li a.first', 'href', function(result) {
|
3588 | * console.log('result', result);
|
3589 | * });
|
3590 | *
|
3591 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3592 | * browser.getAttribute({
|
3593 | * selector: '#main ul li a.first',
|
3594 | * index: 1,
|
3595 | * suppressNotFoundErrors: true
|
3596 | * }, 'href', function(result) {
|
3597 | * console.log('result', result);
|
3598 | * });
|
3599 | * },
|
3600 | *
|
3601 | * demoTestAsync: async function(browser) {
|
3602 | * const result = await browser.getAttribute('#main ul li a.first', 'href');
|
3603 | * console.log('attribute', result);
|
3604 | * }
|
3605 | * }
|
3606 | *
|
3607 | * @see https://nightwatchjs.org/api/getAttribute.html
|
3608 | */
|
3609 | getAttribute(
|
3610 | selector: Definition,
|
3611 | attribute: string,
|
3612 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string | null>) => void,
|
3613 | ): Awaitable<this, string | null>;
|
3614 | getAttribute(
|
3615 | using: LocateStrategy,
|
3616 | selector: Definition,
|
3617 | attribute: string,
|
3618 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string | null>) => void,
|
3619 | ): Awaitable<this, string | null>;
|
3620 |
|
3621 | /**
|
3622 | * Retrieve the value of a css property for a given DOM element.
|
3623 | *
|
3624 | * @example
|
3625 | * module.exports = {
|
3626 | * demoTest() {
|
3627 | * browser.getCssProperty('#main ul li a.first', 'display', function(result) {
|
3628 | * console.log('result', result);
|
3629 | * });
|
3630 | *
|
3631 | * // with explicit locate strategy
|
3632 | * browser.getCssProperty('css selector', '#main ul li a.first', 'display', function(result) {
|
3633 | * console.log('result', result);
|
3634 | * });
|
3635 | *
|
3636 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3637 | * browser.getCssProperty({
|
3638 | * selector: '#main ul li a.first',
|
3639 | * index: 1,
|
3640 | * suppressNotFoundErrors: true
|
3641 | * }, 'display', function(result) {
|
3642 | * console.log('result', result);
|
3643 | * });
|
3644 | * },
|
3645 | *
|
3646 | * demoTestAsync: async function(browser) {
|
3647 | * const result = await browser.getCssProperty('#main ul li a.first', 'display');
|
3648 | * console.log('display', result);
|
3649 | * }
|
3650 | * }
|
3651 | *
|
3652 | * @see https://nightwatchjs.org/api/getCssProperty.html
|
3653 | */
|
3654 | getCssProperty(
|
3655 | selector: Definition,
|
3656 | cssProperty: string,
|
3657 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3658 | ): Awaitable<this, string>;
|
3659 | getCssProperty(
|
3660 | using: LocateStrategy,
|
3661 | selector: Definition,
|
3662 | cssProperty: string,
|
3663 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3664 | ): Awaitable<this, string>;
|
3665 |
|
3666 | /**
|
3667 | * Determine an element's size in pixels. For W3C Webdriver compatible clients (such as GeckoDriver), this command is equivalent to `getLocation` and both return
|
3668 | * the dimensions and coordinates of the given element:
|
3669 | * - x: X axis position of the top-left corner of the element, in CSS pixels
|
3670 | * - y: Y axis position of the top-left corner of the element, in CSS pixels
|
3671 | * - height: Height of the element’s bounding rectangle in CSS pixels;
|
3672 | * - width: Width of the web element’s bounding rectangle in CSS pixels.
|
3673 | *
|
3674 | * @example
|
3675 | * module.exports = {
|
3676 | * demoTest() {
|
3677 | * browser.getElementSize('#login', function(result) {
|
3678 | * console.log('result', result);
|
3679 | * });
|
3680 | *
|
3681 | * // with explicit locate strategy
|
3682 | * browser.getElementSize('css selector', '#login', function(result) {
|
3683 | * console.log('result', result);
|
3684 | * });
|
3685 | *
|
3686 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3687 | * browser.getElementSize({
|
3688 | * selector: '#login',
|
3689 | * index: 1,
|
3690 | * suppressNotFoundErrors: true
|
3691 | * }, function(result) {
|
3692 | * console.log('result', result);
|
3693 | * });
|
3694 | * },
|
3695 | *
|
3696 | * demoTestAsync: async function(browser) {
|
3697 | * const result = await browser.getElementSize('#login');
|
3698 | * console.log('classList', result);
|
3699 | * }
|
3700 | * }
|
3701 | *
|
3702 | * @see https://nightwatchjs.org/api/getElementSize.html
|
3703 | */
|
3704 | getElementSize(
|
3705 | selector: Definition,
|
3706 | callback?: (
|
3707 | this: NightwatchAPI,
|
3708 | result: NightwatchCallbackResult<NightwatchSizeAndPosition>,
|
3709 | ) => void,
|
3710 | ): Awaitable<this, NightwatchSizeAndPosition>;
|
3711 | getElementSize(
|
3712 | using: LocateStrategy,
|
3713 | selector: Definition,
|
3714 | callback?: (
|
3715 | this: NightwatchAPI,
|
3716 | result: NightwatchCallbackResult<NightwatchSizeAndPosition>,
|
3717 | ) => void,
|
3718 | ): Awaitable<this, NightwatchSizeAndPosition>;
|
3719 |
|
3720 | /**
|
3721 | * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. The element's coordinates are returned as a JSON object with x and y properties.
|
3722 | *
|
3723 | * For W3C Webdriver compatible clients (such as GeckoDriver), this command is equivalent to `getElementSize` and both return
|
3724 | * the dimensions and coordinates of the given element:
|
3725 | * - x: X axis position of the top-left corner of the element, in CSS pixels
|
3726 | * - y: Y axis position of the top-left corner of the element, in CSS pixels
|
3727 | * - height: Height of the element’s bounding rectangle in CSS pixels;
|
3728 | * - width: Width of the web element’s bounding rectangle in CSS pixels.
|
3729 | *
|
3730 | * @example
|
3731 | * module.exports = {
|
3732 | * demoTest() {
|
3733 | * browser.getLocation('#login', function(result) {
|
3734 | * console.log('result', result);
|
3735 | * });
|
3736 | *
|
3737 | * // with explicit locate strategy
|
3738 | * browser.getLocation('css selector', '#login', function(result) {
|
3739 | * console.log('result', result);
|
3740 | * });
|
3741 | *
|
3742 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3743 | * browser.getLocation({
|
3744 | * selector: '#login',
|
3745 | * index: 1,
|
3746 | * suppressNotFoundErrors: true
|
3747 | * }, function(result) {
|
3748 | * console.log('result', result);
|
3749 | * });
|
3750 | * },
|
3751 | *
|
3752 | * demoTestAsync: async function(browser) {
|
3753 | * const result = await browser.getLocation('#login');
|
3754 | * console.log('location', result);
|
3755 | * }
|
3756 | * }
|
3757 | *
|
3758 | * @see https://nightwatchjs.org/api/getLocation.html
|
3759 | */
|
3760 | getLocation(
|
3761 | selector: Definition,
|
3762 | callback?: (
|
3763 | this: NightwatchAPI,
|
3764 | result: NightwatchCallbackResult<NightwatchSizeAndPosition>,
|
3765 | ) => void,
|
3766 | ): Awaitable<this, NightwatchSizeAndPosition>;
|
3767 | getLocation(
|
3768 | using: LocateStrategy,
|
3769 | selector: Definition,
|
3770 | callback?: (
|
3771 | this: NightwatchAPI,
|
3772 | result: NightwatchCallbackResult<NightwatchSizeAndPosition>,
|
3773 | ) => void,
|
3774 | ): Awaitable<this, NightwatchSizeAndPosition>;
|
3775 |
|
3776 | /**
|
3777 | * Determine an element's location on the screen once it has been scrolled into view. Uses `elementIdLocationInView` protocol command.
|
3778 | *
|
3779 | * @example
|
3780 | * this.demoTest = function () {
|
3781 | * browser.getLocationInView("#main ul li a.first", function(result) {
|
3782 | * this.assert.equal(typeof result, "object");
|
3783 | * this.assert.equal(result.status, 0);
|
3784 | * this.assert.equal(result.value.x, 200);
|
3785 | * this.assert.equal(result.value.y, 200);
|
3786 | * });
|
3787 | * };
|
3788 | *
|
3789 | * @see https://nightwatchjs.org/api/getLocationInView.html
|
3790 | */
|
3791 | getLocationInView(
|
3792 | selector: Definition,
|
3793 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<NightwatchPosition>) => void,
|
3794 | ): Awaitable<this, NightwatchPosition>;
|
3795 | getLocationInView(
|
3796 | using: LocateStrategy,
|
3797 | selector: Definition,
|
3798 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<NightwatchPosition>) => void,
|
3799 | ): Awaitable<this, NightwatchPosition>;
|
3800 |
|
3801 | /**
|
3802 | * Query for an element's tag name.
|
3803 | *
|
3804 | * @example
|
3805 | * module.exports = {
|
3806 | * demoTest() {
|
3807 | * browser.getTagName('#login', function(result) {
|
3808 | * console.log('result', result);
|
3809 | * });
|
3810 | *
|
3811 | * // with explicit locate strategy
|
3812 | * browser.getTagName('css selector', '#login', function(result) {
|
3813 | * console.log('result', result);
|
3814 | * });
|
3815 | *
|
3816 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3817 | * browser.getTagName({
|
3818 | * selector: '#login',
|
3819 | * index: 1,
|
3820 | * suppressNotFoundErrors: true
|
3821 | * }, function(result) {
|
3822 | * console.log('result', result);
|
3823 | * });
|
3824 | * },
|
3825 | *
|
3826 | * demoTestAsync: async function(browser) {
|
3827 | * const result = await browser.getTagName('#login');
|
3828 | * console.log('tagName', result);
|
3829 | * }
|
3830 | * }
|
3831 | *
|
3832 | * @see https://nightwatchjs.org/api/getTagName.html
|
3833 | */
|
3834 | getTagName(
|
3835 | selector: Definition,
|
3836 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3837 | ): Awaitable<this, string>;
|
3838 | getTagName(
|
3839 | using: LocateStrategy,
|
3840 | selector: Definition,
|
3841 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3842 | ): Awaitable<this, string>;
|
3843 |
|
3844 | /**
|
3845 | * Returns the visible text for the element.
|
3846 | *
|
3847 | * @example
|
3848 | * module.exports = {
|
3849 | * demoTest() {
|
3850 | * browser.getText('#main ul li a.first', function(result) {
|
3851 | * this.assert.equal(typeof result, 'object);
|
3852 | * this.assert.strictEqual(result.status, 0); // only when using Selenium / JSONWire
|
3853 | * this.assert.equal(result.value, 'nightwatchjs.org');
|
3854 | * });
|
3855 | *
|
3856 | * // with explicit locate strategy
|
3857 | * browser.getText('css selector', '#main ul li a.first', function(result) {
|
3858 | * console.log('getText result', result.value);
|
3859 | * });
|
3860 | *
|
3861 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3862 | * browser.getText({
|
3863 | * selector: '#main ul li a',
|
3864 | * index: 1
|
3865 | * }, function(result) {
|
3866 | * console.log('getText result', result.value);
|
3867 | * });
|
3868 | *
|
3869 | * browser.getText({
|
3870 | * selector: '#main ul li a.first',
|
3871 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
3872 | * }, function(result) {
|
3873 | * console.log('getText result', result.value);
|
3874 | * });
|
3875 | * },
|
3876 | *
|
3877 | * demoTestAsync: async function() {
|
3878 | * const result = await browser.getText('#main ul li a.first');
|
3879 | * console.log('getText result', result);
|
3880 | * }
|
3881 | * }
|
3882 | *
|
3883 | * @see https://nightwatchjs.org/api/getText.html
|
3884 | */
|
3885 | getText(
|
3886 | selector: Definition,
|
3887 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3888 | ): Awaitable<this, string>;
|
3889 | getText(
|
3890 | using: LocateStrategy,
|
3891 | selector: Definition,
|
3892 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3893 | ): Awaitable<this, string>;
|
3894 |
|
3895 | /**
|
3896 | * Returns a form element current value.
|
3897 | *
|
3898 | * @example
|
3899 | * module.exports = {
|
3900 | * demoTest() {
|
3901 | * browser.getValue('#login input[type=text]', function(result) {
|
3902 | * console.log('result', result);
|
3903 | * });
|
3904 | *
|
3905 | * // with explicit locate strategy
|
3906 | * browser.getValue('css selector', '#login input[type=text]', function(result) {
|
3907 | * console.log('result', result);
|
3908 | * });
|
3909 | *
|
3910 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3911 | * browser.getValue({
|
3912 | * selector: '#login input[type=text]',
|
3913 | * index: 1,
|
3914 | * suppressNotFoundErrors: true
|
3915 | * }, function(result) {
|
3916 | * console.log('result', result);
|
3917 | * });
|
3918 | * },
|
3919 | *
|
3920 | * demoTestAsync: async function() {
|
3921 | * const result = await browser.getValue('#login input[type=text]');
|
3922 | * console.log('Value', result);
|
3923 | * }
|
3924 | * }
|
3925 | *
|
3926 | * @see https://nightwatchjs.org/api/getValue.html
|
3927 | */
|
3928 | getValue(
|
3929 | selector: Definition,
|
3930 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3931 | ): Awaitable<this, string>;
|
3932 | getValue(
|
3933 | using: LocateStrategy,
|
3934 | selector: Definition,
|
3935 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3936 | ): Awaitable<this, string>;
|
3937 |
|
3938 | /**
|
3939 | * Determine if an element is currently displayed.
|
3940 | *
|
3941 | * @example
|
3942 | * module.exports = {
|
3943 | * demoTest() {
|
3944 | * browser.isVisible('#main ul li a.first', function(result) {
|
3945 | * this.assert.equal(typeof result, "object");
|
3946 | * this.assert.equal(result.status, 0);
|
3947 | * this.assert.equal(result.value, true);
|
3948 | * });
|
3949 | *
|
3950 | * // with explicit locate strategy
|
3951 | * browser.isVisible('css selector', '#main ul li a.first');
|
3952 | *
|
3953 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3954 | * browser.isVisible({
|
3955 | * selector: '#main ul li a',
|
3956 | * index: 1,
|
3957 | * suppressNotFoundErrors: true
|
3958 | * });
|
3959 | *
|
3960 | * browser.isVisible({
|
3961 | * selector: '#main ul li a.first',
|
3962 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
3963 | * });
|
3964 | * },
|
3965 | *
|
3966 | * demoTestAsync: async function() {
|
3967 | * const result = await browser.isVisible('#main ul li a.first');
|
3968 | * console.log('isVisible result', result);
|
3969 | * }
|
3970 | * }
|
3971 | *
|
3972 | * @see https://nightwatchjs.org/api/isVisible.html
|
3973 | */
|
3974 | isVisible(
|
3975 | selector: Definition,
|
3976 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
3977 | ): Awaitable<this, boolean>;
|
3978 | isVisible(
|
3979 | using: LocateStrategy,
|
3980 | selector: Definition,
|
3981 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
3982 | ): Awaitable<this, boolean>;
|
3983 |
|
3984 | /**
|
3985 | * Determines if an element is present in the DOM.
|
3986 | *
|
3987 | * @example
|
3988 | * module.exports = {
|
3989 | * demoTest(browser) {
|
3990 | * browser.isPresent('#main ul li a.first', function(result) {
|
3991 | * this.assert.equal(typeof result, "object");
|
3992 | * this.assert.equal(result.status, 0);
|
3993 | * this.assert.equal(result.value, true);
|
3994 | * });
|
3995 | *
|
3996 | * // with explicit locate strategy
|
3997 | * browser.isPresent('css selector', '#main ul li a.first');
|
3998 | *
|
3999 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
4000 | * browser.isPresent({
|
4001 | * selector: '#main ul li a',
|
4002 | * index: 1,
|
4003 | * });
|
4004 | *
|
4005 | * browser.isPresent({
|
4006 | * selector: '#main ul li a.first',
|
4007 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
4008 | * });
|
4009 | * },
|
4010 | *
|
4011 | * demoTestAsync: async function(browser) {
|
4012 | * const result = await browser.isPresent('#main ul li a.first');
|
4013 | * console.log('isPresent result', result);
|
4014 | * }
|
4015 | * }
|
4016 | *
|
4017 | * @see https://nightwatchjs.org/api/isPresent.html
|
4018 | */
|
4019 | isPresent(
|
4020 | selector: Definition,
|
4021 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4022 | ): Awaitable<this, boolean>;
|
4023 | isPresent(
|
4024 | using: LocateStrategy,
|
4025 | selector: Definition,
|
4026 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4027 | ): Awaitable<this, boolean>;
|
4028 |
|
4029 | /**
|
4030 | * Move the mouse by an offset of the specified element. If an element is provided but no offset, the mouse will be moved to the center of the element.
|
4031 | * If the element is not visible, it will be scrolled into view.
|
4032 | *
|
4033 | * @example
|
4034 | * this.demoTest = function () {
|
4035 | * browser.moveToElement('#main', 10, 10);
|
4036 | * };
|
4037 | *
|
4038 | * @see https://nightwatchjs.org/api/moveToElement.html
|
4039 | */
|
4040 | moveToElement(
|
4041 | selector: Definition,
|
4042 | xoffset: number,
|
4043 | yoffset: number,
|
4044 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4045 | ): Awaitable<this, null>;
|
4046 | moveToElement(
|
4047 | using: LocateStrategy,
|
4048 | selector: Definition,
|
4049 | xoffset: number,
|
4050 | yoffset: number,
|
4051 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4052 | ): Awaitable<this, null>;
|
4053 |
|
4054 | /**
|
4055 | * Sends some text to an element. Can be used to set the value of a form element or to send a sequence of key strokes to an element. Any UTF-8 character may be specified.
|
4056 | *
|
4057 | * From Nightwatch v2, **setValue** also clears the existing value of the element by calling the **clearValue()** beforehand.
|
4058 | *
|
4059 | * An object map with available keys and their respective UTF-8 characters, as defined on [W3C WebDriver draft spec](https://www.w3.org/TR/webdriver/#character-types),
|
4060 | * is loaded onto the main Nightwatch instance as `browser.Keys`.
|
4061 | *
|
4062 | * @example
|
4063 | * // send some simple text to an input
|
4064 | * this.demoTest = function () {
|
4065 | * browser.setValue('input[type=text]', 'nightwatch');
|
4066 | * };
|
4067 | * //
|
4068 | * // send some text to an input and hit enter.
|
4069 | * this.demoTest = function () {
|
4070 | * browser.setValue('input[type=text]', ['nightwatch', browser.Keys.ENTER]);
|
4071 | * };
|
4072 | *
|
4073 | * @see https://nightwatchjs.org/api/setValue.html
|
4074 | */
|
4075 | setValue(
|
4076 | selector: Definition,
|
4077 | inputValue: string | string[],
|
4078 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4079 | ): Awaitable<this, null>;
|
4080 | setValue(
|
4081 | using: LocateStrategy,
|
4082 | selector: Definition,
|
4083 | inputValue: string | string[],
|
4084 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4085 | ): Awaitable<this, null>;
|
4086 |
|
4087 | /**
|
4088 | * Types a key sequence on the DOM element. Can be used to send a sequence of key strokes to an element.
|
4089 | * Any UTF-8 character may be specified.
|
4090 | *
|
4091 | * **sendKeys** does not clear the existing value of the element. To do so, use **setValue()** instead.
|
4092 | *
|
4093 | * An object map with available keys and their respective UTF-8 characters,
|
4094 | * as defined on [W3C WebDriver draft spec](https://www.w3.org/TR/webdriver/#character-types),
|
4095 | * is loaded onto the main Nightwatch instance as `browser.Keys`.
|
4096 | *
|
4097 | * @example
|
4098 | * // send some simple text to an input
|
4099 | * this.demoTest = function () {
|
4100 | * browser.sendKeys('input[type=text]', 'nightwatch');
|
4101 | * };
|
4102 | * //
|
4103 | * // send some text to an input and hit enter.
|
4104 | * this.demoTest = function () {
|
4105 | * browser.sendKeys('input[type=text]', ['nightwatch', browser.Keys.ENTER]);
|
4106 | * };
|
4107 | *
|
4108 | * @see https://nightwatchjs.org/api/sendKeys.html
|
4109 | */
|
4110 | sendKeys(
|
4111 | selector: Definition,
|
4112 | inputValue: string | string[],
|
4113 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4114 | ): Awaitable<this, null>;
|
4115 | sendKeys(
|
4116 | using: LocateStrategy,
|
4117 | selector: Definition,
|
4118 | inputValue: string | string[],
|
4119 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4120 | ): Awaitable<this, null>;
|
4121 |
|
4122 | /**
|
4123 | * Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element. Uses `submit` protocol command.
|
4124 | *
|
4125 | * @example
|
4126 | * this.demoTest = function () {
|
4127 | * browser.submitForm('form.login');
|
4128 | * };
|
4129 | *
|
4130 | * @see https://nightwatchjs.org/api/submitForm.html
|
4131 | */
|
4132 | submitForm(
|
4133 | selector: Definition,
|
4134 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4135 | ): Awaitable<this, null>;
|
4136 | submitForm(
|
4137 | using: LocateStrategy,
|
4138 | selector: Definition,
|
4139 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4140 | ): Awaitable<this, null>;
|
4141 |
|
4142 | /**
|
4143 | * Opposite of `waitForElementPresent`. Waits a given time in milliseconds (default 5000ms)
|
4144 | * for an element to be not present (i.e. removed) in the page before performing
|
4145 | * any other commands or assertions.
|
4146 | * If the element is still present after the specified amount of time, the test fails.
|
4147 | *
|
4148 | * You can change the polling interval by defining a `waitForConditionPollInterval` property (in milliseconds) in as a global property in your `nightwatch.json` or in your external globals file.
|
4149 | * Similarly, a default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
4150 | *
|
4151 | * @example
|
4152 | * module.exports = {
|
4153 | * 'demo Test': function() {
|
4154 | * // with default implicit timeout of 5000ms (can be overwritten in settings under 'globals.waitForConditionTimeout')
|
4155 | * browser.waitForElementNotPresent('#dialog');
|
4156 | *
|
4157 | * // specify the locate strategy (css selector/xpath) as the first argument
|
4158 | * browser.waitForElementNotPresent('css selector', '#dialog');
|
4159 | *
|
4160 | * // with explicit timeout (in milliseconds)
|
4161 | * browser.waitForElementNotPresent('#dialog', 1000);
|
4162 | *
|
4163 | * // continue if failed
|
4164 | * browser.waitForElementNotPresent('#dialog', 1000, false);
|
4165 | *
|
4166 | * // with callback
|
4167 | * browser.waitForElementNotPresent('#dialog', 1000, function() {
|
4168 | * // do something while we're here
|
4169 | * });
|
4170 | *
|
4171 | * // with custom output message - the locate strategy is required
|
4172 | * browser.waitForElementNotPresent('css selector', '#dialog', 'The dialog container is removed.');
|
4173 | *
|
4174 | * // with custom Spanish message
|
4175 | * browser.waitForElementNotPresent('#dialog', 1000, 'elemento %s no era presente en %d ms');
|
4176 | *
|
4177 | * // many combinations possible - the message is always the last argument
|
4178 | * browser.waitForElementNotPresent('#dialog', 1000, false, function() {}, 'elemento %s no era presente en %d ms');
|
4179 | * },
|
4180 | *
|
4181 | * 'demo Test with selector objects': function() {
|
4182 | * browser.waitForElementNotPresent({
|
4183 | * selector: '#dialog',
|
4184 | * timeout: 1000
|
4185 | * });
|
4186 | *
|
4187 | * browser.waitForElementNotPresent({
|
4188 | * selector: '#dialog',
|
4189 | * locateStrategy: 'css selector'
|
4190 | * }, 'Custom output message');
|
4191 | *
|
4192 | * browser.waitForElementNotPresent({
|
4193 | * selector: '.container',
|
4194 | * index: 2,
|
4195 | * retryInterval: 100,
|
4196 | * abortOnFailure: true
|
4197 | * });
|
4198 | * }
|
4199 | *
|
4200 | * 'page object demo Test': function () {
|
4201 | * var nightwatch = browser.page.nightwatch();
|
4202 | * nightwatch
|
4203 | * .navigate()
|
4204 | * .assert.titleContains('Nightwatch.js');
|
4205 | *
|
4206 | * nightwatch.api.waitForElementNotPresent('@dialogContainer', function(result) {
|
4207 | * console.log(result);
|
4208 | * });
|
4209 | * }
|
4210 | * }
|
4211 | *
|
4212 | * @see https://nightwatchjs.org/api/waitForElementNotPresent.html
|
4213 | * @since v0.4.0
|
4214 | */
|
4215 | waitForElementNotPresent(
|
4216 | selector: Definition,
|
4217 | time?: number,
|
4218 | poll?: number,
|
4219 | abortOnFailure?: boolean,
|
4220 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<ElementResult[]>) => void,
|
4221 | message?: string,
|
4222 | ): Awaitable<this, ElementResult[]>;
|
4223 | waitForElementNotPresent(
|
4224 | using: LocateStrategy,
|
4225 | selector: Definition,
|
4226 | time?: number,
|
4227 | poll?: number,
|
4228 | abortOnFailure?: boolean,
|
4229 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<ElementResult[]>) => void,
|
4230 | message?: string,
|
4231 | ): Awaitable<this, ElementResult[]>;
|
4232 |
|
4233 | /**
|
4234 | * Opposite of `waitForElementVisible`. Waits a given time in milliseconds (default 5000ms)
|
4235 | * for an element to be not visible (i.e. hidden but existing) in the page before
|
4236 | * performing any other commands or assertions.
|
4237 | * If the element fails to be hidden in the specified amount of time, the test fails.
|
4238 | *
|
4239 | * You can change the polling interval by defining a `waitForConditionPollInterval` property (in milliseconds) in as a global property in your `nightwatch.json` or in your external globals file.
|
4240 | * Similarly, a default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
4241 | *
|
4242 | * @example
|
4243 | * module.exports = {
|
4244 | * 'demo Test': function() {
|
4245 | * // with default implicit timeout of 5000ms (can be overwritten in settings under 'globals.waitForConditionTimeout')
|
4246 | * browser.waitForElementNotVisible('#dialog');
|
4247 | *
|
4248 | * // specify the locate strategy (css selector/xpath) as the first argument
|
4249 | * browser.waitForElementNotVisible('css selector', '#dialog');
|
4250 | *
|
4251 | * // with explicit timeout (in milliseconds)
|
4252 | * browser.waitForElementNotVisible('#dialog', 1000);
|
4253 | *
|
4254 | * // continue if failed
|
4255 | * browser.waitForElementNotVisible('#dialog', 1000, false);
|
4256 | *
|
4257 | * // with callback
|
4258 | * browser.waitForElementNotVisible('#dialog', 1000, function() {
|
4259 | * // do something while we're here
|
4260 | * });
|
4261 | *
|
4262 | * // with custom output message - the locate strategy is required
|
4263 | * browser.waitForElementNotVisible('css selector', '#dialog', 'The dialog container is not visible.');
|
4264 | *
|
4265 | * // with custom Spanish message
|
4266 | * browser.waitForElementNotVisible('#dialog', 1000, 'elemento %s no era visible en %d ms');
|
4267 | *
|
4268 | * // many combinations possible - the message is always the last argument
|
4269 | * browser.waitForElementNotVisible('#dialog', 1000, false, function() {}, 'elemento %s no era visible en %d ms');
|
4270 | * },
|
4271 | *
|
4272 | * 'demo Test with selector objects': function() {
|
4273 | * browser.waitForElementNotVisible({
|
4274 | * selector: '#dialog',
|
4275 | * timeout: 1000
|
4276 | * });
|
4277 | *
|
4278 | * browser.waitForElementNotVisible({
|
4279 | * selector: '#dialog',
|
4280 | * locateStrategy: 'css selector'
|
4281 | * }, 'Custom output message');
|
4282 | *
|
4283 | * browser.waitForElementNotVisible({
|
4284 | * selector: '.container',
|
4285 | * index: 2,
|
4286 | * retryInterval: 100,
|
4287 | * abortOnFailure: true
|
4288 | * });
|
4289 | * }
|
4290 | *
|
4291 | * 'page object demo Test': function () {
|
4292 | * var nightwatch = browser.page.nightwatch();
|
4293 | * nightwatch
|
4294 | * .navigate()
|
4295 | * .assert.titleContains('Nightwatch.js');
|
4296 | *
|
4297 | * nightwatch.api.waitForElementNotVisible('@mainDialog', function(result) {
|
4298 | * console.log(result);
|
4299 | * });
|
4300 | * }
|
4301 | * }
|
4302 | *
|
4303 | * @since v0.4.0
|
4304 | * @see https://nightwatchjs.org/api/waitForElementNotVisible.html
|
4305 | */
|
4306 | waitForElementNotVisible(
|
4307 | selector: Definition,
|
4308 | time?: number,
|
4309 | poll?: number,
|
4310 | abortOnFailure?: boolean,
|
4311 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4312 | message?: string,
|
4313 | ): Awaitable<this, boolean>;
|
4314 | waitForElementNotVisible(
|
4315 | using: LocateStrategy,
|
4316 | selector: Definition,
|
4317 | time?: number,
|
4318 | poll?: number,
|
4319 | abortOnFailure?: boolean,
|
4320 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4321 | message?: string,
|
4322 | ): Awaitable<this, boolean>;
|
4323 |
|
4324 | /**
|
4325 | * Waits a given time in milliseconds (default 5000ms) for an element to be present in the page before performing any other commands or assertions.
|
4326 | * If the element fails to be present in the specified amount of time, the test fails. You can change this by setting `abortOnFailure` to `false`.
|
4327 | *
|
4328 | * You can change the polling interval by defining a `waitForConditionPollInterval` property (in milliseconds) in as a global property in your `nightwatch.json` or in your external globals file.
|
4329 | * Similarly, the default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
4330 | *
|
4331 | * @example
|
4332 | * module.exports = {
|
4333 | * 'demo Test': function() {
|
4334 | * // with default implicit timeout of 5000ms (can be overwritten in settings under 'globals.waitForConditionTimeout')
|
4335 | * browser.waitForElementPresent('#index-container');
|
4336 | *
|
4337 | * // specify the locate strategy (css selector/xpath) as the first argument
|
4338 | * browser.waitForElementPresent('css selector', '#index-container');
|
4339 | *
|
4340 | * // with explicit timeout (in milliseconds)
|
4341 | * browser.waitForElementPresent('#index-container', 1000);
|
4342 | *
|
4343 | * // continue if failed
|
4344 | * browser.waitForElementPresent('#index-container', 1000, false);
|
4345 | *
|
4346 | * // with callback
|
4347 | * browser.waitForElementPresent('#index-container', 1000, function() {
|
4348 | * // do something while we're here
|
4349 | * });
|
4350 | *
|
4351 | * // with custom output message - the locate strategy is required
|
4352 | * browser.waitForElementPresent('css selector', '#index-container', 'The index container is found.');
|
4353 | *
|
4354 | * // with custom Spanish message
|
4355 | * browser.waitForElementPresent('#index-container', 1000, 'elemento %s no era presente en %d ms');
|
4356 | *
|
4357 | * // many combinations possible - the message is always the last argument
|
4358 | * browser.waitForElementPresent('#index-container', 1000, false, function() {}, 'elemento %s no era presente en %d ms');
|
4359 | * },
|
4360 | *
|
4361 | * 'demo Test with selector objects': function() {
|
4362 | * browser.waitForElementPresent({
|
4363 | * selector: '#index-container',
|
4364 | * timeout: 1000
|
4365 | * });
|
4366 | *
|
4367 | * browser.waitForElementPresent({
|
4368 | * selector: '#index-container',
|
4369 | * locateStrategy: 'css selector'
|
4370 | * }, 'Custom output message');
|
4371 | *
|
4372 | * browser.waitForElementPresent({
|
4373 | * selector: '.container',
|
4374 | * index: 2,
|
4375 | * retryInterval: 100,
|
4376 | * abortOnFailure: true
|
4377 | * });
|
4378 | * }
|
4379 | *
|
4380 | * 'page object demo Test': function () {
|
4381 | * var nightwatch = browser.page.nightwatch();
|
4382 | * nightwatch
|
4383 | * .navigate()
|
4384 | * .assert.titleContains('Nightwatch.js');
|
4385 | *
|
4386 | * nightwatch.api.waitForElementPresent('@featuresList', function(result) {
|
4387 | * console.log(result);
|
4388 | * });
|
4389 | * }
|
4390 | * }
|
4391 | *
|
4392 | * @see https://nightwatchjs.org/api/waitForElementPresent.html
|
4393 | */
|
4394 | waitForElementPresent(
|
4395 | selector: Definition,
|
4396 | time?: number,
|
4397 | poll?: number,
|
4398 | abortOnFailure?: boolean,
|
4399 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<ElementResult[]>) => void,
|
4400 | message?: string,
|
4401 | ): Awaitable<this, ElementResult[]>;
|
4402 | waitForElementPresent(
|
4403 | using: LocateStrategy,
|
4404 | selector: Definition,
|
4405 | time?: number,
|
4406 | poll?: number,
|
4407 | abortOnFailure?: boolean,
|
4408 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<ElementResult[]>) => void,
|
4409 | message?: string,
|
4410 | ): Awaitable<this, ElementResult[]>;
|
4411 |
|
4412 | /**
|
4413 | * Waits a given time in milliseconds for an element to be visible in the page before performing any other commands or assertions.
|
4414 | *
|
4415 | * If the element fails to be present and visible in the specified amount of time, the test fails. You can change this by setting `abortOnFailure` to `false`.
|
4416 | *
|
4417 | * You can change the polling interval by defining a `waitForConditionPollInterval` property (in milliseconds) in as a global property in your `nightwatch.json` or in your external globals file.
|
4418 | *
|
4419 | * Similarly, a default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
4420 | *
|
4421 | * @example
|
4422 | * this.demoTest = function (browser) {
|
4423 | * browser.waitForElementVisible('body', 1000);
|
4424 | * // continue if failed
|
4425 | * browser.waitForElementVisible('body', 1000, false);
|
4426 | * // with callback
|
4427 | * browser.waitForElementVisible('body', 1000, function() {
|
4428 | * // do something while we're here
|
4429 | * });
|
4430 | * // custom Spanish message
|
4431 | * browser.waitForElementVisible('body', 1000, 'elemento %s no era visible en %d ms');
|
4432 | * // many combinations possible - the message is always the last argument
|
4433 | * browser.waitForElementVisible('body', 1000, false, function() {}, 'elemento %s no era visible en %d ms');
|
4434 | * };
|
4435 | *
|
4436 | * @see https://nightwatchjs.org/api/waitForElementVisible.html
|
4437 | */
|
4438 | waitForElementVisible(
|
4439 | selector: Definition,
|
4440 | time?: number,
|
4441 | poll?: number,
|
4442 | abortOnFailure?: boolean,
|
4443 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4444 | message?: string,
|
4445 | ): Awaitable<this, boolean>;
|
4446 |
|
4447 | waitForElementVisible(
|
4448 | using: LocateStrategy,
|
4449 | selector: Definition,
|
4450 | time?: number,
|
4451 | poll?: number,
|
4452 | abortOnFailure?: boolean,
|
4453 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4454 | message?: string,
|
4455 | ): Awaitable<this, boolean>;
|
4456 |
|
4457 | /**
|
4458 | * Returns the computed WAI-ARIA label of an element.
|
4459 | *
|
4460 | * @example
|
4461 | * module.exports = {
|
4462 | * demoTest() {
|
4463 | * browser.getAccessibleName('*[name="search"]', function(result) {
|
4464 | * this.assert.equal(typeof result, 'object);
|
4465 | * this.assert.equal(result.value, 'search input');
|
4466 | * });
|
4467 | *
|
4468 | * // with explicit locate strategy
|
4469 | * browser.getAccessibleName('css selector', '*[name="search"]', function(result) {
|
4470 | * console.log('getAccessibleName result', result.value);
|
4471 | * });
|
4472 | *
|
4473 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
4474 | * browser.getAccessibleName({
|
4475 | * selector: '*[name="search"]',
|
4476 | * index: 1
|
4477 | * }, function(result) {
|
4478 | * console.log('getAccessibleName result', result.value);
|
4479 | * });
|
4480 | *
|
4481 | * browser.getAccessibleName({
|
4482 | * selector: '*[name="search"]',
|
4483 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
4484 | * }, function(result) {
|
4485 | * console.log('getAccessibleName result', result.value);
|
4486 | * });
|
4487 | * },
|
4488 | *
|
4489 | * demoTestAsync: async function() {
|
4490 | * const result = await browser.getAccessibleName('*[name="search"]');
|
4491 | * console.log('getAccessibleName result', result);
|
4492 | * }
|
4493 | * }
|
4494 | *
|
4495 | * @see https://nightwatchjs.org/api/getAccessibleName.html
|
4496 | */
|
4497 | getAccessibleName(
|
4498 | selector: Definition,
|
4499 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
4500 | ): Awaitable<this, string>;
|
4501 | getAccessibleName(
|
4502 | using: LocateStrategy,
|
4503 | selector: Definition,
|
4504 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
4505 | ): Awaitable<this, string>;
|
4506 |
|
4507 | /**
|
4508 | * Returns the computed WAI-ARIA role of an element.
|
4509 | *
|
4510 | * @example
|
4511 | * module.exports = {
|
4512 | * demoTest(browser) {
|
4513 | * browser.getAriaRole('*[name="search"]', function(result) {
|
4514 | * this.assert.equal(typeof result, 'object');
|
4515 | * this.assert.equal(result.value, 'combobox');
|
4516 | * });
|
4517 | *
|
4518 | * // with explicit locate strategy
|
4519 | * browser.getAriaRole('css selector', '*[name="search"]', function(result) {
|
4520 | * console.log('getAriaRole result', result.value);
|
4521 | * });
|
4522 | *
|
4523 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
4524 | * browser.getAriaRole({
|
4525 | * selector: '*[name="search"]',
|
4526 | * index: 1
|
4527 | * }, function(result) {
|
4528 | * console.log('getAriaRole result', result.value);
|
4529 | * });
|
4530 | *
|
4531 | * browser.getAriaRole({
|
4532 | * selector: '*[name="search"]',
|
4533 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
4534 | * }, function(result) {
|
4535 | * console.log('getAriaRole result', result.value);
|
4536 | * });
|
4537 | * },
|
4538 | *
|
4539 | * demoTestAsync: async function(browser) {
|
4540 | * const result = await browser.getAriaRole('*[name="search"]');
|
4541 | * console.log('getAriaRole result', result);
|
4542 | * }
|
4543 | * }
|
4544 | *
|
4545 | * @see https://nightwatchjs.org/api/getAriaRole.html
|
4546 | */
|
4547 | getAriaRole(
|
4548 | selector: Definition,
|
4549 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
4550 | ): Awaitable<this, string>;
|
4551 | getAriaRole(
|
4552 | using: LocateStrategy,
|
4553 | selector: Definition,
|
4554 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
4555 | ): Awaitable<this, string>;
|
4556 |
|
4557 | /**
|
4558 | * Determine an element's size in pixels. For W3C Webdriver compatible clients (such as GeckoDriver), this command is equivalent to `getLocation` and both return
|
4559 | * the dimensions and coordinates of the given element:
|
4560 | * - x: X axis position of the top-left corner of the element, in CSS pixels
|
4561 | * - y: Y axis position of the top-left corner of the element, in CSS pixels
|
4562 | * - height: Height of the element’s bounding rectangle in CSS pixels;
|
4563 | * - width: Width of the web element’s bounding rectangle in CSS pixels.
|
4564 | *
|
4565 | * @example
|
4566 | * module.exports = {
|
4567 | * demoTest() {
|
4568 | * browser.getElementSize('#login', function(result) {
|
4569 | * console.log('result', result);
|
4570 | * });
|
4571 | *
|
4572 | * // with explicit locate strategy
|
4573 | * browser.getElementSize('css selector', '#login', function(result) {
|
4574 | * console.log('result', result);
|
4575 | * });
|
4576 | *
|
4577 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
4578 | * browser.getElementSize({
|
4579 | * selector: '#login',
|
4580 | * index: 1,
|
4581 | * suppressNotFoundErrors: true
|
4582 | * }, function(result) {
|
4583 | * console.log('result', result);
|
4584 | * });
|
4585 | * },
|
4586 | *
|
4587 | * demoTestAsync: async function() {
|
4588 | * const result = await browser.getElementSize('#login');
|
4589 | * console.log('classList', result);
|
4590 | * }
|
4591 | * }
|
4592 | *
|
4593 | * @see https://nightwatchjs.org/api/getElementRect.html
|
4594 | */
|
4595 | getElementRect(
|
4596 | selector: Definition,
|
4597 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<NightwatchSizeAndPosition>) => void,
|
4598 | ): Awaitable<this, NightwatchSizeAndPosition>;
|
4599 | getElementRect(
|
4600 | using: LocateStrategy,
|
4601 | selector: Definition,
|
4602 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<NightwatchSizeAndPosition>) => void,
|
4603 | ): Awaitable<this, NightwatchSizeAndPosition>;
|
4604 |
|
4605 | /**
|
4606 | *
|
4607 | * Uploads file to an element using absolute file path.
|
4608 | *
|
4609 | *
|
4610 | * @example
|
4611 | * // send a file to for upload to a field.
|
4612 | * this.demoTest = function (browser) {
|
4613 | * browser.uploadFile('#myFile', '/path/file.pdf');
|
4614 | * };
|
4615 | *
|
4616 | *
|
4617 | * @see https://nightwatchjs.org/api/uploadFile.html
|
4618 | */
|
4619 | uploadFile(
|
4620 | selector: Definition,
|
4621 | filePath: string,
|
4622 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4623 | ): Awaitable<this, null>;
|
4624 | uploadFile(
|
4625 | using: LocateStrategy,
|
4626 | selector: Definition,
|
4627 | filePath: string,
|
4628 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4629 | ): Awaitable<this, null>;
|
4630 |
|
4631 | /**
|
4632 | * Sends some text to an element. Can be used to set the value of a form element or
|
4633 | * to send a sequence of key strokes to an element. Any UTF-8 character may be specified.
|
4634 | *
|
4635 | * <div class="alert alert-warning"><strong>updateValue</strong> is equivalent
|
4636 | * with <strong>setValue</strong> and <strong>sendKeys</strong> with the exception
|
4637 | * that it clears the value beforehand.</div>
|
4638 | *
|
4639 | * An object map with available keys and their respective UTF-8 characters,
|
4640 | * as defined on [W3C WebDriver draft spec](https://www.w3.org/TR/webdriver/#character-types),
|
4641 | * is loaded onto the main Nightwatch instance as `browser.Keys`.
|
4642 | *
|
4643 | * @example
|
4644 | * // send some simple text to an input
|
4645 | * this.demoTest = function (browser) {
|
4646 | * browser.updateValue('input[type=text]', 'nightwatch');
|
4647 | * };
|
4648 | *
|
4649 | * // send some text to an input and hit enter.
|
4650 | * this.demoTest = function (browser) {
|
4651 | * browser.updateValue('input[type=text]', ['nightwatch', browser.Keys.ENTER]);
|
4652 | * };
|
4653 | *
|
4654 | * @see https://nightwatchjs.org/api/updateValue.html
|
4655 | */
|
4656 | updateValue(
|
4657 | selector: Definition,
|
4658 | inputValue: string | string[],
|
4659 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4660 | ): Awaitable<this, null>;
|
4661 | updateValue(
|
4662 | using: LocateStrategy,
|
4663 | selector: Definition,
|
4664 | inputValue: string | string[],
|
4665 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4666 | ): Awaitable<this, null>;
|
4667 | /**
|
4668 | * Drag an element to the given position or destination element.
|
4669 | *
|
4670 | * @example
|
4671 | * module.exports = {
|
4672 | * demoTest(browser) {
|
4673 | * browser.dragAndDrop('#main', {x: 100, y:100}):
|
4674 | *
|
4675 | *
|
4676 | *
|
4677 | * //using webElement as a destination
|
4678 | * demoTestAsync: async function(browser) {
|
4679 | * const destination = await browser.findElement('#upload');
|
4680 | * browser.dragAndDrop('#main', destination.getId());
|
4681 | * }
|
4682 | * }
|
4683 | *
|
4684 | * @see https://nightwatchjs.org/api/dragAndDrop.html
|
4685 | */
|
4686 | dragAndDrop(
|
4687 | selector: Definition,
|
4688 | destination: NightwatchElement | NightwatchPosition,
|
4689 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4690 | ): Awaitable<this, null>;
|
4691 | dragAndDrop(
|
4692 | using: LocateStrategy,
|
4693 | selector: Definition,
|
4694 | destination: NightwatchElement | NightwatchPosition,
|
4695 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
4696 | ): Awaitable<this, null>;
|
4697 |
|
4698 | /**
|
4699 | * Returns an element's first child. The child element will be returned as web
|
4700 | * element JSON object (with an added .getId() convenience method).
|
4701 | *
|
4702 | *
|
4703 | * @example
|
4704 | * module.exports = {
|
4705 | * 'demo Test': function(browser) {
|
4706 | * const resultElement = await browser.getFirstElementChild('.features-container');
|
4707 | *
|
4708 | * console.log('last child element Id:', resultElement.getId());
|
4709 | * },
|
4710 | *
|
4711 | * @see https://nightwatchjs.org/api/getFirstElementChild.html
|
4712 | */
|
4713 | getFirstElementChild(
|
4714 | selector: Definition,
|
4715 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT>) => void,
|
4716 | ): Awaitable<this, JSON_WEB_OBJECT>;
|
4717 | getFirstElementChild(
|
4718 | using: LocateStrategy,
|
4719 | selector: Definition,
|
4720 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT>) => void,
|
4721 | ): Awaitable<this, JSON_WEB_OBJECT>;
|
4722 |
|
4723 | /**
|
4724 | * Returns an element's last child. The child element will be returned
|
4725 | * as web element JSON object (with an added .getId() convenience method).
|
4726 | *
|
4727 | *
|
4728 | * @example
|
4729 | * module.exports = {
|
4730 | * 'demo Test': function(browser) {
|
4731 | * const resultElement = await browser.getLastElementChild('.features-container');
|
4732 | *
|
4733 | * console.log('last child element Id:', resultElement.getId());
|
4734 | * },
|
4735 | *
|
4736 | * @see https://nightwatchjs.org/api/getLastElementChild.html
|
4737 | */
|
4738 | getLastElementChild(
|
4739 | selector: Definition,
|
4740 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT>) => void,
|
4741 | ): Awaitable<this, JSON_WEB_OBJECT>;
|
4742 | getLastElementChild(
|
4743 | using: LocateStrategy,
|
4744 | selector: Definition,
|
4745 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT>) => void,
|
4746 | ): Awaitable<this, JSON_WEB_OBJECT>;
|
4747 |
|
4748 | /**
|
4749 | * Returns the element immediately following the specified one in their parent's childNodes.
|
4750 | * The element will be returned as web element JSON object (with an added .getId() convenience method).
|
4751 | *
|
4752 | *
|
4753 | * @example
|
4754 | * module.exports = {
|
4755 | * 'demo Test': function(browser) {
|
4756 | * const resultElement = await browser.getNextSibling('.features-container li:first-child');
|
4757 | *
|
4758 | * console.log('next sibling element Id:', resultElement.getId());
|
4759 | * },
|
4760 | *
|
4761 | * @see https://nightwatchjs.org/api/getNextSibling.html
|
4762 | */
|
4763 | getNextSibling(
|
4764 | selector: Definition,
|
4765 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT>) => void,
|
4766 | ): Awaitable<this, JSON_WEB_OBJECT>;
|
4767 | getNextSibling(
|
4768 | using: LocateStrategy,
|
4769 | selector: Definition,
|
4770 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT>) => void,
|
4771 | ): Awaitable<this, JSON_WEB_OBJECT>;
|
4772 |
|
4773 | /**
|
4774 | * Returns the element immediately preceding the specified one in its parent's child elements list.
|
4775 | * The element will be returned as web element JSON object (with an added `.getId()` convenience method).
|
4776 | *
|
4777 | *
|
4778 | * @example
|
4779 | * module.exports = {
|
4780 | * 'demo Test': function(browser) {
|
4781 | * const resultElement = await browser.getPreviousSibling('.features-container li:second-child');
|
4782 | *
|
4783 | * console.log('previous sibling element Id:', resultElement.getId());
|
4784 | * },
|
4785 | *
|
4786 | * browser.getPreviousSibling('#web-button', function(result) {
|
4787 | *
|
4788 | * console.log(result.value)
|
4789 | * }})
|
4790 | * await browser.getPreviousSibling('#web-button')
|
4791 | * await browser.getPreviousSibling({selector: '#web-button', locateStrategy: 'css selector'})
|
4792 | *
|
4793 | * // with global element():
|
4794 | * const formEl = element('form');
|
4795 | * const result = await browser.getPreviousSibling(formEl)
|
4796 | *
|
4797 | * // with Selenium By() locators
|
4798 | * // https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_By.html
|
4799 | * const locator = by.tagName('form');
|
4800 | * const result = await browser.getPreviousSibling(locator)
|
4801 | *
|
4802 | * // with browser.findElement()
|
4803 | * const formEl = await browser.findElement('form');
|
4804 | * const result = await browser.getPreviousSibling(formEl)
|
4805 | *
|
4806 | * @see https://nightwatchjs.org/api/getPreviousSibling.html
|
4807 | */
|
4808 | getPreviousSibling(
|
4809 | selector: Definition,
|
4810 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT>) => void,
|
4811 | ): Awaitable<this, JSON_WEB_OBJECT>;
|
4812 | getPreviousSibling(
|
4813 | using: LocateStrategy,
|
4814 | selector: Definition,
|
4815 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT>) => void,
|
4816 | ): Awaitable<this, JSON_WEB_OBJECT>;
|
4817 |
|
4818 | /**
|
4819 | * Returns true or false based on whether the DOM has any child nodes
|
4820 | *
|
4821 | * @example
|
4822 | * module.exports = {
|
4823 | * 'demo Test': function(browser) {
|
4824 | * const result = await browser.hasDescendants('.features-container');
|
4825 | *
|
4826 | * console.log('true or false:', result);
|
4827 | * },
|
4828 | *
|
4829 | * @see https://nightwatchjs.org/api/hasDescendants.html
|
4830 | */
|
4831 | hasDescendants(
|
4832 | selector: Definition,
|
4833 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4834 | ): Awaitable<this, boolean>;
|
4835 | hasDescendants(
|
4836 | using: LocateStrategy,
|
4837 | selector: Definition,
|
4838 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4839 | ): Awaitable<this, boolean>;
|
4840 |
|
4841 | /**
|
4842 | * Returns the `shadowRoot` read-only property which represents the shadow root hosted by the element.
|
4843 | * This can further be used to retrieve elements part of the shadow root element.
|
4844 | *
|
4845 | * @example
|
4846 | * describe('Shadow Root example test', function() {
|
4847 | * it('retrieve the shadowRoot', async function(browser) {
|
4848 | * await browser
|
4849 | * .navigateTo('https://mdn.github.io/web-components-examples/popup-info-box-web-component/')
|
4850 | * .waitForElementVisible('form');
|
4851 | *
|
4852 | * const shadowRootEl = await browser.getShadowRoot('popup-info');
|
4853 | * const infoElement = await shadowRootEl.find('.info');
|
4854 | *
|
4855 | * await expect(infoElement.property('innerHTML')).to.include('card validation code');
|
4856 | * const iconElement = await shadowRootEl.find('.icon');
|
4857 | * const firstElement = await browser.getFirstElementChild(iconElement);
|
4858 | *
|
4859 | * await expect.element(firstElement).to.be.an('img');
|
4860 | * });
|
4861 | * });
|
4862 | *
|
4863 | * @see https://nightwatchjs.org/api/getShadowRoot.html
|
4864 | */
|
4865 | getShadowRoot(
|
4866 | selector: Definition | WebElement | By,
|
4867 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Element | null>) => void,
|
4868 | ): Awaitable<this, Element | null>;
|
4869 | getShadowRoot(
|
4870 | using: LocateStrategy,
|
4871 | selector: Definition | WebElement | By,
|
4872 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Element | null>) => void,
|
4873 | ): Awaitable<this, Element | null>;
|
4874 |
|
4875 | /**
|
4876 | * Search for an elements on the page, starting from the document root. The located element will be returned as web element JSON object (with an added .getId() convenience method).
|
4877 | * First argument is the element selector, either specified as a string or as an object (with 'selector' and 'locateStrategy' properties).
|
4878 | *
|
4879 | * @example
|
4880 | * module.exports = {
|
4881 | * 'demo Test': function(browser) {
|
4882 | * const resultElement = await browser.findElement('.features-container li:first-child');
|
4883 | *
|
4884 | * console.log('Element Id:', resultElement.getId());
|
4885 | * }
|
4886 | * }
|
4887 | *
|
4888 | * @see https://nightwatchjs.org/api/findElement.html
|
4889 | */
|
4890 | findElement(
|
4891 | selector: Definition,
|
4892 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT>) => void,
|
4893 | ): Awaitable<this, JSON_WEB_OBJECT>;
|
4894 | findElement(
|
4895 | using: LocateStrategy,
|
4896 | selector: Definition,
|
4897 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT>) => void,
|
4898 | ): Awaitable<this, JSON_WEB_OBJECT>;
|
4899 |
|
4900 | /**
|
4901 | * Search for multiple elements on the page, starting from the document root. The located elements will be returned as web element JSON objects (with an added .getId() convenience method).
|
4902 | * First argument is the element selector, either specified as a string or as an object (with 'selector' and 'locateStrategy' properties).
|
4903 | *
|
4904 | *
|
4905 | * @example
|
4906 | * module.exports = {
|
4907 | * 'demo Test': function(browser) {
|
4908 | * const resultElements = await browser.findElements('.features-container li');
|
4909 | *
|
4910 | * resultElements.forEach(item => console.log('Element Id:', item.getId()));
|
4911 | * },
|
4912 | *
|
4913 | * @see https://nightwatchjs.org/api/findElements.html
|
4914 | */
|
4915 | findElements(
|
4916 | selector: Definition,
|
4917 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT[]>) => void,
|
4918 | ): Awaitable<this, JSON_WEB_OBJECT[]>;
|
4919 | findElements(
|
4920 | using: LocateStrategy,
|
4921 | selector: Definition,
|
4922 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<JSON_WEB_OBJECT[]>) => void,
|
4923 | ): Awaitable<this, JSON_WEB_OBJECT[]>;
|
4924 |
|
4925 | /**
|
4926 | * Retrieve the value of a specified DOM property for the given element.
|
4927 | * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
|
4928 | *
|
4929 | * @example
|
4930 | * module.exports = {
|
4931 | * demoTest(browser) {
|
4932 | * browser.getElementProperty('#login input[type=text]', 'classList', function(result) {
|
4933 | * console.log('result', result);
|
4934 | * });
|
4935 | *
|
4936 | * // with explicit locate strategy
|
4937 | * browser.getElementProperty('css selector', '#login input[type=text]', 'classList', function(result) {
|
4938 | * console.log('result', result);
|
4939 | * });
|
4940 | *
|
4941 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
4942 | * browser.getElementProperty({
|
4943 | * selector: '#login input[type=text]',
|
4944 | * index: 1,
|
4945 | * suppressNotFoundErrors: true
|
4946 | * }, 'classList', function(result) {
|
4947 | * console.log('result', result);
|
4948 | * });
|
4949 | * },
|
4950 | *
|
4951 | * demoTestAsync: async function(browser) {
|
4952 | * const result = await browser.getElementProperty('#login input[type=text]', 'classList');
|
4953 | * console.log('classList', result);
|
4954 | * }
|
4955 | * }
|
4956 | *
|
4957 | * @see https://nightwatchjs.org/api/getElementProperty.html
|
4958 | */
|
4959 | getElementProperty(
|
4960 | selector: Definition,
|
4961 | property: string,
|
4962 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void,
|
4963 | ): Awaitable<this, any>;
|
4964 | getElementProperty(
|
4965 | using: LocateStrategy,
|
4966 | selector: Definition,
|
4967 | property: string,
|
4968 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void,
|
4969 | ): Awaitable<this, any>;
|
4970 |
|
4971 | /**
|
4972 | *
|
4973 | * Determines if an element is enabled, as indicated by the 'disabled' attribute.
|
4974 | *
|
4975 | * @example
|
4976 | * module.exports = {
|
4977 | * demoTest(browser) {
|
4978 | * browser.isEnabled('#main select option.first', function(result) {
|
4979 | * this.assert.equal(typeof result, "object");
|
4980 | * this.assert.equal(result.status, 0);
|
4981 | * this.assert.equal(result.value, true);
|
4982 | * });
|
4983 | *
|
4984 | * // with explicit locate strategy
|
4985 | * browser.isEnabled('css selector', '#main select option.first');
|
4986 | *
|
4987 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
4988 | * browser.isEnabled({
|
4989 | * selector: '#main ul li a',
|
4990 | * index: 1,
|
4991 | * suppressNotFoundErrors: true
|
4992 | * });
|
4993 | *
|
4994 | * browser.isEnabled({
|
4995 | * selector: '#main select option.first',
|
4996 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
4997 | * });
|
4998 | * },
|
4999 | *
|
5000 | * demoTestAsync: async function(browser) {
|
5001 | * const result = await browser.isEnabled('#main select option.first');
|
5002 | * console.log('isVisible result', result);
|
5003 | * }
|
5004 | * }
|
5005 | * @see https://nightwatchjs.org/api/isEnabled.html
|
5006 | */
|
5007 | isEnabled(
|
5008 | selector: Definition,
|
5009 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
5010 | ): Awaitable<this, boolean>;
|
5011 | isEnabled(
|
5012 | using: LocateStrategy,
|
5013 | selector: Definition,
|
5014 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
5015 | ): Awaitable<this, boolean>;
|
5016 |
|
5017 | /**
|
5018 | *
|
5019 | * Determines if an element is selected.
|
5020 | *
|
5021 | * @example
|
5022 | * module.exports = {
|
5023 | * demoTest(browser) {
|
5024 | * browser.isSelected('#main select option.first', function(result) {
|
5025 | * this.assert.equal(typeof result, "object");
|
5026 | * this.assert.equal(result.status, 0);
|
5027 | * this.assert.equal(result.value, true);
|
5028 | * });
|
5029 | *
|
5030 | * // with explicit locate strategy
|
5031 | * browser.isSelected('css selector', '#main select option.first');
|
5032 | *
|
5033 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
5034 | * browser.isSelected({
|
5035 | * selector: '#main ul li a',
|
5036 | * index: 1,
|
5037 | * suppressNotFoundErrors: true
|
5038 | * });
|
5039 | *
|
5040 | * browser.isSelected({
|
5041 | * selector: '#main select option.first',
|
5042 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
5043 | * });
|
5044 | * },
|
5045 | *
|
5046 | * demoTestAsync: async function(browser) {
|
5047 | * const result = await browser.isSelected('#main select option.first');
|
5048 | * console.log('isVisible result', result);
|
5049 | * }
|
5050 | * }
|
5051 | * @see https://nightwatchjs.org/api/isSelected.html
|
5052 | */
|
5053 | isSelected(
|
5054 | selector: Definition,
|
5055 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
5056 | ): Awaitable<this, boolean>;
|
5057 | isSelected(
|
5058 | using: LocateStrategy,
|
5059 | selector: Definition,
|
5060 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
5061 | ): Awaitable<this, boolean>;
|
5062 |
|
5063 | /**
|
5064 | *
|
5065 | * Set the value of a specified DOM attribute for the given element.
|
5066 | * For all the available DOM attributes, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
|
5067 | *
|
5068 | * @example
|
5069 | * module.exports = {
|
5070 | * demoTest(browser) {
|
5071 | * browser.setAttribute('#login input[type=text]', 'disabled', 'true', function(result) {
|
5072 | * console.log('result', result);
|
5073 | * });
|
5074 | *
|
5075 | * // with explicit locate strategy
|
5076 | * browser.setAttribute('css selector', '#login input[type=text]', 'disabled', 'true', function(result) {
|
5077 | * console.log('result', result);
|
5078 | * });
|
5079 | *
|
5080 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
5081 | * browser.setAttribute({
|
5082 | * selector: '#login input[type=text]',
|
5083 | * index: 1,
|
5084 | * suppressNotFoundErrors: true
|
5085 | * }, 'disabled', 'true', function(result) {
|
5086 | * console.log('result', result);
|
5087 | * });
|
5088 | * },
|
5089 | *
|
5090 | * demoTestAsync: async function(browser) {
|
5091 | * await browser.setAttribute('#login input[type=text]', 'disabled', 'true');
|
5092 | * }
|
5093 | * }
|
5094 | * @see https://nightwatchjs.org/api/setAttribute.html
|
5095 | */
|
5096 | setAttribute(
|
5097 | selector: Definition,
|
5098 | attribute: string,
|
5099 | value: string,
|
5100 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
5101 | ): Awaitable<this, boolean>;
|
5102 | setAttribute(
|
5103 | using: LocateStrategy,
|
5104 | selector: Definition,
|
5105 | attribute: string,
|
5106 | value: string,
|
5107 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
5108 | ): Awaitable<this, boolean>;
|
5109 |
|
5110 | /**
|
5111 | *
|
5112 | * An alias of "setValue" command, but hides the content from the nightwatch logs.
|
5113 | *
|
5114 | * <div class="alert alert-warning"><strong>setValue/setPassword</strong> do not clear
|
5115 | * the existing value of the element. To do so, use the <strong>clearValue()</strong> command.</div>
|
5116 | *
|
5117 | * An object map with available keys and their respective UTF-8 characters,
|
5118 | * as defined on [W3C WebDriver draft spec](https://www.w3.org/TR/webdriver/#character-types), is loaded onto the main Nightwatch instance as `browser.Keys`.
|
5119 | *
|
5120 | * @example
|
5121 | * // send some simple text to an input
|
5122 | * this.demoTest = function (browser) {
|
5123 | * browser.setPassword('input[type=text]', 'nightwatch');
|
5124 | * };
|
5125 | * //
|
5126 | * // send some text to an input and hit enter.
|
5127 | * this.demoTest = function (browser) {
|
5128 | * browser.setPassword('input[type=text]', ['nightwatch', browser.Keys.ENTER]);
|
5129 | * };
|
5130 | *
|
5131 | */
|
5132 | setPassword(
|
5133 | selector: Definition,
|
5134 | inputValue: string | string[],
|
5135 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
5136 | ): Awaitable<this, null>;
|
5137 | setPassword(
|
5138 | using: LocateStrategy,
|
5139 | selector: Definition,
|
5140 | inputValue: string | string[],
|
5141 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
5142 | ): Awaitable<this, null>;
|
5143 |
|
5144 | /**
|
5145 | *
|
5146 | * Take a screenshot of the visible region encompassed by this element's bounding rectangle.
|
5147 | *
|
5148 | * @example
|
5149 | * module.exports = {
|
5150 | * demoTest(browser) {
|
5151 | * browser.takeElementScreenshot('#main', function (imageData, err) {
|
5152 | * require('fs').writeFile('out.png', imageData.value, 'base64', function (err) {
|
5153 | * console.log(err);
|
5154 | * });
|
5155 | * });
|
5156 | *
|
5157 | * // with explicit locate strategy
|
5158 | * browser.takeElementScreenshot('css selector', '#main', function(imageData, err) {
|
5159 | * require('fs').writeFile('out.png', imageData.value, 'base64', function (err) {
|
5160 | * console.log(err);
|
5161 | * });
|
5162 | * });
|
5163 | *
|
5164 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
5165 | * browser.takeElementScreenshot({
|
5166 | * selector: '#main ul li a',
|
5167 | * index: 1
|
5168 | * }, function(imageData, err) {
|
5169 | * require('fs').writeFile('out.png', imageData.value, 'base64', function (err) {
|
5170 | * console.log(err);
|
5171 | * });
|
5172 | * });
|
5173 | * },
|
5174 | *
|
5175 | * demoTestAsync: async function(browser) {
|
5176 | * const data = await browser.takeElementScreenshot('#main');
|
5177 | * require('fs').writeFile('out.png', data, 'base64');
|
5178 | * }
|
5179 | * }
|
5180 | *
|
5181 | * @see https://nightwatchjs.org/api/takeElementScreenshot.html
|
5182 | */
|
5183 | takeElementScreenshot(
|
5184 | selector: Definition,
|
5185 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
5186 | ): Awaitable<this, string>;
|
5187 | takeElementScreenshot(
|
5188 | using: LocateStrategy,
|
5189 | selector: Definition,
|
5190 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
5191 | ): Awaitable<this, string>;
|
5192 | }
|
5193 |
|
5194 | export interface WebDriverProtocol
|
5195 | extends WebDriverProtocolSessions,
|
5196 | WebDriverProtocolNavigation,
|
5197 | WebDriverProtocolCommandContexts,
|
5198 | WebDriverProtocolElements,
|
5199 | WebDriverProtocolElementState,
|
5200 | WebDriverProtocolElementInteraction,
|
5201 | WebDriverProtocolElementLocation,
|
5202 | WebDriverProtocolDocumentHandling,
|
5203 | WebDriverProtocolCookies,
|
5204 | WebDriverProtocolUserActions,
|
5205 | WebDriverProtocolUserPrompts,
|
5206 | WebDriverProtocolScreenCapture,
|
5207 | WebDriverProtocolMobileRelated {}
|
5208 |
|
5209 | export interface WebDriverProtocolSessions {
|
5210 | /**
|
5211 | * Get info about, delete or create a new session. Defaults to the current session.
|
5212 | *
|
5213 | * @example
|
5214 | * this.demoTest = function (browser) {
|
5215 | * browser.session(function(result) {
|
5216 | * console.log(result.value);
|
5217 | * });
|
5218 | * //
|
5219 | * browser.session('delete', function(result) {
|
5220 | * console.log(result.value);
|
5221 | * });
|
5222 | * //
|
5223 | * browser.session('delete', '12345-abc', function(result) {
|
5224 | * console.log(result.value);
|
5225 | * });
|
5226 | * }
|
5227 | */
|
5228 | session(
|
5229 | action?: string,
|
5230 | sessionId?: string,
|
5231 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Record<string, any>>) => void,
|
5232 | ): this;
|
5233 |
|
5234 | /**
|
5235 | * Returns a list of the currently active sessions.
|
5236 | *
|
5237 | * @example
|
5238 | * this.demoTest = function (browser) {
|
5239 | * browser.sessions(function(result) {
|
5240 | * console.log(result.value);
|
5241 | * });
|
5242 | * }
|
5243 | */
|
5244 | sessions(
|
5245 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Array<Record<string, any>>>) => void,
|
5246 | ): this;
|
5247 |
|
5248 | /**
|
5249 | * Configure the amount of time that a particular type of operation can execute for before they are aborted and a |Timeout| error is returned to the client.
|
5250 | *
|
5251 | * @example
|
5252 | * this.demoTest = function (browser) {
|
5253 | * browser.timeouts('script', 10000, function(result) {
|
5254 | * console.log(result);
|
5255 | * });
|
5256 | * }
|
5257 | */
|
5258 | timeouts(
|
5259 | typeOfOperation: string,
|
5260 | ms: number,
|
5261 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5262 | ): this;
|
5263 | timeouts(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
5264 |
|
5265 | /**
|
5266 | * Set the amount of time, in milliseconds, that asynchronous scripts executed by `.executeAsync` are permitted to run before they are aborted and a |Timeout| error is returned to the client.
|
5267 | *
|
5268 | * @example
|
5269 | * this.demoTest = function (browser) {
|
5270 | * browser.timeoutsAsyncScript(10000, function(result) {
|
5271 | * console.log(result);
|
5272 | * });
|
5273 | * }
|
5274 | */
|
5275 | timeoutsAsyncScript(
|
5276 | ms: number,
|
5277 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5278 | ): this;
|
5279 |
|
5280 | /**
|
5281 | * Set the amount of time the driver should wait when searching for elements. If this command is never sent, the driver will default to an implicit wait of 0ms.
|
5282 | *
|
5283 | * @example
|
5284 | * this.demoTest = function (browser) {
|
5285 | * browser.timeoutsImplicitWait(10000, function(result) {
|
5286 | * console.log(result);
|
5287 | * });
|
5288 | * }
|
5289 | */
|
5290 | timeoutsImplicitWait(
|
5291 | ms: number,
|
5292 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5293 | ): this;
|
5294 |
|
5295 | /**
|
5296 | * Query the server's current status.
|
5297 | */
|
5298 | status(
|
5299 | callback?: (
|
5300 | this: NightwatchAPI,
|
5301 | result: NightwatchCallbackResult<{
|
5302 | build: { version: string; revision: string; time: string };
|
5303 | status: { arch: string; name: string; version: string };
|
5304 | }>,
|
5305 | ) => void,
|
5306 | ): this;
|
5307 |
|
5308 | /**
|
5309 | * Gets the text of the log type specified. To find out the available log types, use `.getLogTypes()`.
|
5310 | *
|
5311 | * Returns a [log entry JSON object](https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#log-entry-json-object).
|
5312 | *
|
5313 | * @example
|
5314 | * this.demoTest = function (browser) {
|
5315 | * browser.sessionLog('client', function(result) {
|
5316 | * console.log(result.value);
|
5317 | * });
|
5318 | * }
|
5319 | */
|
5320 | sessionLog(typeString: string, callback?: (this: NightwatchAPI, log: NightwatchLogEntry[]) => void): this;
|
5321 |
|
5322 | /**
|
5323 | * Gets an array of strings for which log types are available. This methods returns the entire WebDriver response, if you are only interested in the logs array, use `.getLogTypes()` instead.
|
5324 | *
|
5325 | * @example
|
5326 | * this.demoTest = function (browser) {
|
5327 | * browser.sessionLogTypes(function(result) {
|
5328 | * console.log(result.value);
|
5329 | * });
|
5330 | * }
|
5331 | */
|
5332 | sessionLogTypes(
|
5333 | callback?: (
|
5334 | this: NightwatchAPI,
|
5335 | result: NightwatchCallbackResult<Array<'client' | 'driver' | 'browser' | 'server'>>,
|
5336 | ) => void,
|
5337 | ): this;
|
5338 |
|
5339 | /**
|
5340 | * Command to set Chrome network emulation settings.
|
5341 | *
|
5342 | * @example
|
5343 | * this.demoTest = function() {
|
5344 | * browser.setNetworkConditions({
|
5345 | * offline: false,
|
5346 | * latency: 50000,
|
5347 | * download_throughput: 450 * 1024,
|
5348 | * upload_throughput: 150 * 1024
|
5349 | * });
|
5350 | * };
|
5351 | */
|
5352 | setNetworkConditions(
|
5353 | spec: {
|
5354 | [key: string]: any;
|
5355 | },
|
5356 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
5357 | ): this;
|
5358 | }
|
5359 |
|
5360 | export interface WebDriverProtocolNavigation {
|
5361 | /**
|
5362 | * Retrieve the URL of the current page or navigate to a new URL.
|
5363 | *
|
5364 | * @example
|
5365 | * module.exports = {
|
5366 | * 'demo Test' : function(browser) {
|
5367 | * browser.url(function(result) {
|
5368 | * // return the current url
|
5369 | * console.log(result);
|
5370 | * });
|
5371 | * //
|
5372 | * // navigate to new url:
|
5373 | * browser.url('{URL}');
|
5374 | * //
|
5375 | * //
|
5376 | * // navigate to new url:
|
5377 | * browser.url('{URL}', function(result) {
|
5378 | * console.log(result);
|
5379 | * });
|
5380 | * }
|
5381 | * }
|
5382 | */
|
5383 | url(url?: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
5384 | url(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
5385 |
|
5386 | /**
|
5387 | * Navigate backwards in the browser history, if possible.
|
5388 | */
|
5389 | back(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
5390 |
|
5391 | /**
|
5392 | * Navigate forwards in the browser history, if possible.
|
5393 | */
|
5394 | forward(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
5395 |
|
5396 | /**
|
5397 | * Refresh the current page.
|
5398 | */
|
5399 | refresh(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
5400 |
|
5401 | /**
|
5402 | * Get the current page title.
|
5403 | *
|
5404 | * @example
|
5405 | * this.demoTest = function (browser) {
|
5406 | * browser.title(function(result) {
|
5407 | * console.log(result.value);
|
5408 | * });
|
5409 | * }
|
5410 | */
|
5411 | title(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
5412 | }
|
5413 |
|
5414 | export interface WebDriverProtocolCommandContexts {
|
5415 | /**
|
5416 | * Change focus to another window or close the current window. Shouldn't normally be used directly, instead `.switchWindow()` and `.closeWindow()` should be used.
|
5417 | */
|
5418 | window(
|
5419 | method: string,
|
5420 | handleOrName?: string,
|
5421 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5422 | ): this;
|
5423 |
|
5424 | /**
|
5425 | * Retrieve the current window handle.
|
5426 | *
|
5427 | * @example
|
5428 | * this.demoTest = function (browser) {
|
5429 | * browser.windowHandle(function(result) {
|
5430 | * console.log(result.value);
|
5431 | * });
|
5432 | * }
|
5433 | */
|
5434 | windowHandle(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): Awaitable<this, string>;
|
5435 |
|
5436 | /**
|
5437 | * Retrieve the list of all window handles available to the session.
|
5438 | *
|
5439 | * @example
|
5440 | * this.demoTest = function (browser) {
|
5441 | * browser.windowHandles(function(result) {
|
5442 | * // An array of window handles.
|
5443 | * console.log(result.value);
|
5444 | * });
|
5445 | * }
|
5446 | */
|
5447 | windowHandles(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string[]>) => void): Awaitable<this, string[]>;
|
5448 |
|
5449 | /**
|
5450 | * Increases the window to the maximum available size without going full-screen.
|
5451 | *
|
5452 | * @example
|
5453 | * this.demoTest = function (browser) {
|
5454 | * browser.windowMaximize('current', function(result) {
|
5455 | * console.log(result);
|
5456 | * });
|
5457 | * }
|
5458 | */
|
5459 | windowMaximize(
|
5460 | handleOrName?: string,
|
5461 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5462 | ): this;
|
5463 |
|
5464 | /**
|
5465 | * Change or get the position of the specified window. If the second argument is a function it will be used as a callback and
|
5466 | * the call will perform a get request to retrieve the existing window position.
|
5467 | *
|
5468 | * @example
|
5469 | * this.demoTest = function (browser) {
|
5470 | *
|
5471 | * // Change the position of the specified window.
|
5472 | * // If the :windowHandle URL parameter is "current", the currently active window will be moved.
|
5473 | * browser.windowPosition('current', 0, 0, function(result) {
|
5474 | * console.log(result);
|
5475 | * });
|
5476 | *
|
5477 | * // Get the position of the specified window.
|
5478 | * // If the :windowHandle URL parameter is "current", the position of the currently active window will be returned.
|
5479 | * browser.windowPosition('current', function(result) {
|
5480 | * console.log(result.value);
|
5481 | * });
|
5482 | * }
|
5483 | */
|
5484 | windowPosition(
|
5485 | windowHandle: string,
|
5486 | offsetX: number,
|
5487 | offsetY: number,
|
5488 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<NightwatchPosition>) => void,
|
5489 | ): this;
|
5490 | windowPosition(
|
5491 | windowHandle: string,
|
5492 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<NightwatchPosition>) => void,
|
5493 | ): this;
|
5494 |
|
5495 | /**
|
5496 | * Change or get the size of the specified window. If the second argument is a function it will be used as a callback and the call will perform a get request to retrieve the existing window size.
|
5497 | *
|
5498 | * @example
|
5499 | * this.demoTest = function (browser) {
|
5500 | *
|
5501 | * // Return the size of the specified window. If the :windowHandle URL parameter is "current", the size of the currently active window will be returned.
|
5502 | * browser.windowSize('current', function(result) {
|
5503 | * console.log(result.value);
|
5504 | * });
|
5505 | *
|
5506 | * // Change the size of the specified window.
|
5507 | * // If the :windowHandle URL parameter is "current", the currently active window will be resized.
|
5508 | * browser.windowSize('current', 300, 300, function(result) {
|
5509 | * console.log(result.value);
|
5510 | * });
|
5511 | * }
|
5512 | */
|
5513 | windowSize(
|
5514 | windowHandle: string,
|
5515 | width: number,
|
5516 | height: number,
|
5517 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5518 | ): this;
|
5519 | windowSize(
|
5520 | windowHandle: string,
|
5521 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ width: number; height: number }>) => void,
|
5522 | ): this;
|
5523 |
|
5524 | /**
|
5525 | *
|
5526 | * Change or get the [window rect](https://w3c.github.io/webdriver/#dfn-window-rect).
|
5527 | * This is defined as a dictionary of the `screenX`, `screenY`, `outerWidth` and `outerHeight` attributes of the window.
|
5528 | *
|
5529 | * Its JSON representation is the following:
|
5530 | * - `x` - window's screenX attribute;
|
5531 | * - `y` - window's screenY attribute;
|
5532 | * - `width` - outerWidth attribute;
|
5533 | * - `height` - outerHeight attribute.
|
5534 | *
|
5535 | * All attributes are in in CSS pixels. To change the window react, you can either specify `width` and `height`, `x` and `y` or all properties together.
|
5536 | *
|
5537 | * @example
|
5538 | * module.exports = {
|
5539 | * 'demo test .windowRect()': function(browser) {
|
5540 | *
|
5541 | * // Change the screenX and screenY attributes of the window rect.
|
5542 | * browser.windowRect({x: 500, y: 500});
|
5543 | *
|
5544 | * // Change the width and height attributes of the window rect.
|
5545 | * browser.windowRect({width: 600, height: 300});
|
5546 | *
|
5547 | * // Retrieve the attributes
|
5548 | * browser.windowRect(function(result) {
|
5549 | * console.log(result.value);
|
5550 | * });
|
5551 | * },
|
5552 | *
|
5553 | * 'windowRect ES6 demo test': async function(browser) {
|
5554 | * const resultValue = await browser.windowRect();
|
5555 | * console.log('result value', resultValue);
|
5556 | * }
|
5557 | * }
|
5558 | */
|
5559 | windowRect(
|
5560 | options: { width?: number; height?: number; x?: number; y?: number },
|
5561 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5562 | ): this;
|
5563 |
|
5564 | /**
|
5565 | * Change focus to another frame on the page. If the frame id is missing or null, the server should switch to the page's default content.
|
5566 | *
|
5567 | * @example
|
5568 | * this.demoTest = function (browser) {
|
5569 | * browser.frame('<ID>', function(result) {
|
5570 | * console.log(result);
|
5571 | * });
|
5572 | * }
|
5573 | */
|
5574 | frame(
|
5575 | frameId?: WebElement | string | number | null,
|
5576 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5577 | ): this;
|
5578 |
|
5579 | /**
|
5580 | * Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged.
|
5581 | *
|
5582 | * @example
|
5583 | * this.demoTest = function (browser) {
|
5584 | * browser.frameParent(function(result) {
|
5585 | * console.log(result);
|
5586 | * });
|
5587 | * }
|
5588 | *
|
5589 | * @since v0.4.8
|
5590 | */
|
5591 | frameParent(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
5592 | }
|
5593 |
|
5594 | export interface WebDriverProtocolElements {
|
5595 | /**
|
5596 | * Search for an element on the page, starting from the document root. The located element will be returned as a web element JSON object.
|
5597 | * First argument to be passed is the locator strategy, which is detailed on the [WebDriver docs](https://www.w3.org/TR/webdriver/#locator-strategies).
|
5598 | *
|
5599 | * The locator stragy can be one of:
|
5600 | * - `css selector`
|
5601 | * - `link text`
|
5602 | * - `partial link text`
|
5603 | * - `tag name`
|
5604 | * - `xpath`
|
5605 | *
|
5606 | * @example
|
5607 | * module.exports = {
|
5608 | * 'demo Test' : function(browser) {
|
5609 | * browser.element('css selector', 'body', function(result) {
|
5610 | * console.log(result.value)
|
5611 | * });
|
5612 | * },
|
5613 | *
|
5614 | * 'es6 async demo Test': async function(browser) {
|
5615 | * const result = await browser.element('css selector', 'body');
|
5616 | * console.log('result value is:', result);
|
5617 | * },
|
5618 | *
|
5619 | * 'demo Test with page object': function(browser) {
|
5620 | * const loginPage = browser.page.login();
|
5621 | * loginPage.api.element('@resultContainer', function(result) {
|
5622 | * console.log(result.value)
|
5623 | * });
|
5624 | * }
|
5625 | * }
|
5626 | */
|
5627 | element(
|
5628 | using: LocateStrategy,
|
5629 | value: string,
|
5630 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ [ELEMENT_KEY]: string }>) => void,
|
5631 | ): Awaitable<this, { [ELEMENT_KEY]: string }>;
|
5632 |
|
5633 | /**
|
5634 | * Search for multiple elements on the page, starting from the document root. The located elements will be returned as web element JSON objects.
|
5635 | * First argument to be passed is the locator strategy, which is detailed on the [WebDriver docs](https://www.w3.org/TR/webdriver/#locator-strategies).
|
5636 | *
|
5637 | * * The locator strategy can be one of:
|
5638 | * - `css selector`
|
5639 | * - `link text`
|
5640 | * - `partial link text`
|
5641 | * - `tag name`
|
5642 | * - `xpath`
|
5643 | *
|
5644 | * @example
|
5645 | * module.exports = {
|
5646 | * 'demo Test' : function(browser) {
|
5647 | * browser.elements('css selector', 'ul li', function(result) {
|
5648 | * console.log(result.value)
|
5649 | * });
|
5650 | * },
|
5651 | *
|
5652 | * 'es6 async demo Test': async function(browser) {
|
5653 | * const result = await browser.elements('css selector', 'ul li');
|
5654 | * console.log('result value is:', result);
|
5655 | * },
|
5656 | *
|
5657 | * 'page object demo Test': function (browser) {
|
5658 | * var nightwatch = browser.page.nightwatch();
|
5659 | * nightwatch
|
5660 | * .navigate()
|
5661 | * .assert.titleContains('Nightwatch.js');
|
5662 | *
|
5663 | * nightwatch.api.elements('@featuresList', function(result) {
|
5664 | * console.log(result);
|
5665 | * });
|
5666 | *
|
5667 | * browser.end();
|
5668 | * }
|
5669 | * }
|
5670 | */
|
5671 | elements(
|
5672 | using: LocateStrategy,
|
5673 | value: string,
|
5674 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Array<{ [ELEMENT_KEY]: string }>>) => void,
|
5675 | ): Awaitable<this, Array<{ [ELEMENT_KEY]: string }>>;
|
5676 |
|
5677 | /**
|
5678 | * Search for an element on the page, starting from the identified element. The located element will be returned as a Web Element JSON object.
|
5679 | *
|
5680 | * This command operates on a protocol level and requires a [Web Element ID](https://www.w3.org/TR/webdriver1/#dfn-web-elements).
|
5681 | * Read more on [Element retrieval](https://www.w3.org/TR/webdriver1/#element-retrieval) on the W3C WebDriver spec page.
|
5682 | *
|
5683 | * @example
|
5684 | * module.exports = {
|
5685 | * 'demo Test' : function(browser) {
|
5686 | * browser.elementIdElement('<WebElementId>', 'css selector', '.new-element', function(result) {
|
5687 | * console.log(result.value)
|
5688 | * });
|
5689 | * },
|
5690 | *
|
5691 | * 'es6 async demo Test': async function(browser) {
|
5692 | * const result = await browser.elementIdElement('<WebElementId>', 'css selector', '.new-element');
|
5693 | * console.log(result.value);
|
5694 | * }
|
5695 | * }
|
5696 | */
|
5697 | elementIdElement(
|
5698 | id: string,
|
5699 | using: LocateStrategy,
|
5700 | value: string,
|
5701 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ [ELEMENT_KEY]: string }>) => void,
|
5702 | ): this;
|
5703 |
|
5704 | /**
|
5705 | * Search for multiple elements on the page, starting from the identified element. The located element will be returned as a web element JSON objects.
|
5706 | *
|
5707 | * @example
|
5708 | * module.exports = {
|
5709 | * 'demo Test' : function(browser) {
|
5710 | * browser.elementIdElements('<WebElementId>', 'css selector', 'ul li', function(result) {
|
5711 | * console.log(result.value)
|
5712 | * });
|
5713 | * },
|
5714 | *
|
5715 | * 'es6 async demo Test': async function(browser) {
|
5716 | * const result = await browser.elementIdElements('<WebElementId>', 'css selector', 'ul li');
|
5717 | * console.log(result.value);
|
5718 | * }
|
5719 | * }
|
5720 | */
|
5721 | elementIdElements(
|
5722 | id: string,
|
5723 | using: LocateStrategy,
|
5724 | value: string,
|
5725 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Array<{ [ELEMENT_KEY]: string }>>) => void,
|
5726 | ): this;
|
5727 |
|
5728 | /**
|
5729 | * Move to the element and performs a double-click in the middle of the given element if
|
5730 | * element is given else double-clicks at the current mouse coordinates (set by `.moveTo()`).
|
5731 | *
|
5732 | */
|
5733 | elementIdDoubleClick(
|
5734 | webElementId: string,
|
5735 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5736 | ): this;
|
5737 |
|
5738 | /**
|
5739 | *
|
5740 | * Retrieve the value of a specified DOM property for the given element.
|
5741 | * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
|
5742 | */
|
5743 | elementIdProperty(
|
5744 | webElementId: string,
|
5745 | DOMPropertyName: string,
|
5746 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
5747 | ): this;
|
5748 |
|
5749 | /**
|
5750 | * Test if two web element IDs refer to the same DOM element.
|
5751 | *
|
5752 | * This command is __deprecated__ and is only available on the [JSON Wire protocol](https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidelementidequalsother)
|
5753 | *
|
5754 | * @example
|
5755 | * module.exports = {
|
5756 | * 'demo Test' : function(browser) {
|
5757 | * browser.elementIdEquals('<ID-1>', '<ID-2>', function(result) {
|
5758 | * console.log(result.value)
|
5759 | * });
|
5760 | * }
|
5761 | * }
|
5762 | */
|
5763 | elementIdEquals(
|
5764 | id: string,
|
5765 | otherId: string,
|
5766 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
5767 | ): this;
|
5768 |
|
5769 | /**
|
5770 | * Get the element on the page that currently has focus. The element will be returned as a [Web Element](https://www.w3.org/TR/webdriver1/#dfn-web-elements) JSON object.
|
5771 | *
|
5772 | * @example
|
5773 | * module.exports = {
|
5774 | * 'demo Test' : function(browser) {
|
5775 | * browser.elementActive(function(result) {
|
5776 | * console.log(result.value)
|
5777 | * });
|
5778 | * }
|
5779 | * }
|
5780 | */
|
5781 | elementActive(
|
5782 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ [ELEMENT_KEY]: string }>) => void,
|
5783 | ): this;
|
5784 | }
|
5785 |
|
5786 | export interface WebDriverProtocolElementState {
|
5787 | /**
|
5788 | * Get the value of an element's attribute.
|
5789 | */
|
5790 | elementIdAttribute(
|
5791 | id: string,
|
5792 | attributeName: string,
|
5793 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string | null>) => void,
|
5794 | ): this;
|
5795 |
|
5796 | /**
|
5797 | * Retrieve the computed value of the given CSS property of the given element.
|
5798 | *
|
5799 | * The CSS property to query should be specified using the CSS property name, not the JavaScript property name (e.g. background-color instead of backgroundColor).
|
5800 | */
|
5801 | elementIdCssProperty(
|
5802 | id: string,
|
5803 | cssPropertyName: string,
|
5804 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
5805 | ): this;
|
5806 |
|
5807 | /**
|
5808 | * Determine if an element is currently displayed.
|
5809 | */
|
5810 | elementIdDisplayed(
|
5811 | id: string,
|
5812 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
5813 | ): this;
|
5814 |
|
5815 | /**
|
5816 | * Determine if an element is currently enabled.
|
5817 | */
|
5818 | elementIdEnabled(
|
5819 | id: string,
|
5820 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
5821 | ): this;
|
5822 |
|
5823 | /**
|
5824 | * Retrieve the qualified tag name of the given element.
|
5825 | */
|
5826 | elementIdName(id: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
5827 |
|
5828 | /**
|
5829 | * Determine if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected.
|
5830 | */
|
5831 | elementIdSelected(
|
5832 | id: string,
|
5833 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
5834 | ): this;
|
5835 |
|
5836 | /**
|
5837 | * Determine an element's size in pixels. The size will be returned as a JSON object with width and height properties.
|
5838 | */
|
5839 | elementIdSize(
|
5840 | id: string,
|
5841 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ width: number; height: number }>) => void,
|
5842 | ): this;
|
5843 |
|
5844 | /**
|
5845 | * Returns the visible text for the element.
|
5846 | */
|
5847 | elementIdText(id: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
5848 | }
|
5849 |
|
5850 | export interface WebDriverProtocolElementInteraction {
|
5851 | /**
|
5852 | * Scrolls into view a submittable element excluding buttons or editable element, and then attempts to clear its value, reset the checked state, or text content.
|
5853 | *
|
5854 | * @example
|
5855 | * browser.elementIdClear(elementId);
|
5856 | */
|
5857 | elementIdClear(id: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
5858 |
|
5859 | /**
|
5860 | * Scrolls into view the element and clicks the in-view center point.
|
5861 | * If the element is not pointer-interactable,
|
5862 | * an <code>element not interactable</code> error is returned.
|
5863 | *
|
5864 | * @example
|
5865 | * browser.elementIdClick(elementId);
|
5866 | */
|
5867 | elementIdClick(
|
5868 | id: string,
|
5869 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
5870 | ): Awaitable<this, null>;
|
5871 |
|
5872 | /**
|
5873 | * Scrolls into view the form control element and then sends the provided keys to the element, or returns the current value of the element.
|
5874 | * In case the element is not keyboard interactable, an <code>element not interactable error</code> is returned.
|
5875 | */
|
5876 | elementIdValue(
|
5877 | id: string,
|
5878 | value?: string,
|
5879 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5880 | ): this;
|
5881 | elementIdValue(
|
5882 | id: string,
|
5883 | value: string,
|
5884 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5885 | ): this;
|
5886 |
|
5887 | /**
|
5888 | * Send a sequence of key strokes to the active element. The sequence is defined in the same format as the `sendKeys` command.
|
5889 | * An object map with available keys and their respective UTF-8 characters, as defined on [W3C WebDriver draft spec](https://www.w3.org/TR/webdriver/#character-types),
|
5890 | * is loaded onto the main Nightwatch instance as `client.Keys`.
|
5891 | *
|
5892 | * Rather than the `setValue`, the modifiers are not released at the end of the call. The state of the modifier keys is kept between calls,
|
5893 | * so mouse interactions can be performed while modifier keys are depressed.
|
5894 | *
|
5895 | * @example
|
5896 | * browser
|
5897 | * .keys(browser.Keys.CONTROL) // hold down CONTROL key
|
5898 | * .click('#element')
|
5899 | * .keys(browser.Keys.NULL) // release all keys
|
5900 | */
|
5901 | keys(
|
5902 | keysToSend: string | string[],
|
5903 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
5904 | ): this;
|
5905 |
|
5906 | /**
|
5907 | * Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element.
|
5908 | *
|
5909 | * @example
|
5910 | * browser.submit(elementID);
|
5911 | */
|
5912 | submit(id: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
5913 | }
|
5914 |
|
5915 | export interface WebDriverProtocolElementLocation {
|
5916 | /**
|
5917 | * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page.
|
5918 | *
|
5919 | * The element's coordinates are returned as a JSON object with x and y properties.
|
5920 | *
|
5921 | * @deprecated
|
5922 | */
|
5923 | elementIdLocation(
|
5924 | id: string,
|
5925 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<NightwatchPosition>) => void,
|
5926 | ): this;
|
5927 |
|
5928 | /**
|
5929 | * Determine an element's location on the screen once it has been scrolled into view.
|
5930 | *
|
5931 | * @deprecated
|
5932 | */
|
5933 | elementIdLocationInView(
|
5934 | id: string,
|
5935 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<NightwatchPosition>) => void,
|
5936 | ): this;
|
5937 | }
|
5938 |
|
5939 | export interface WebDriverProtocolDocumentHandling {
|
5940 | /**
|
5941 | * Returns a string serialisation of the DOM of the current page.
|
5942 | *
|
5943 | * @example
|
5944 | * browser.source();
|
5945 | */
|
5946 | source(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
5947 |
|
5948 | /**
|
5949 | * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be synchronous.
|
5950 | * The script argument defines the script to execute in the form of a function body. The value returned by that function will be returned to the client.
|
5951 | *
|
5952 | * The function will be invoked with the provided args array and the values may be accessed via the arguments object in the order specified.
|
5953 | *
|
5954 | * Under the hood, if the `body` param is a function it is converted to a string with `<function>.toString()`. Any references to your current scope are ignored.
|
5955 | *
|
5956 | * To ensure cross-browser compatibility, the specified function should not be in ES6 format (i.e. `() => {}`).
|
5957 | * If the execution of the function fails, the first argument of the callback contains error information.
|
5958 | *
|
5959 | * @example
|
5960 | * this.demoTest = function (browser) {
|
5961 | * browser.execute(function(imageData) {
|
5962 | * // resize operation
|
5963 | * return true;
|
5964 | * }, [imageData], function(result) {
|
5965 | * // result.value === true
|
5966 | * });
|
5967 | * }
|
5968 | */
|
5969 | execute<T = null>(
|
5970 | body: ((this: undefined, ...data: any[]) => T) | string,
|
5971 | args?: any[],
|
5972 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<T>) => void,
|
5973 | ): Awaitable<this, T>;
|
5974 | executeScript<T = null>(
|
5975 | body: ((this: undefined, ...data: any[]) => T) | string,
|
5976 | args?: any[],
|
5977 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<T>) => void,
|
5978 | ): Awaitable<this, T>;
|
5979 |
|
5980 | /**
|
5981 | *
|
5982 | * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
|
5983 | * The executed script is assumed to be asynchronous.
|
5984 | *
|
5985 | * The function to be injected receives the `done` callback as argument which needs to be called
|
5986 | * when the asynchronous operation finishes. The value passed to the `done` callback is returned to the client.
|
5987 | * Additional arguments for the injected function may be passed as a non-empty array which
|
5988 | * will be passed before the `done` callback.
|
5989 | *
|
5990 | * Asynchronous script commands may not span page loads. If an unload event is fired
|
5991 | * while waiting for the script result, an error will be returned.
|
5992 | *
|
5993 | * @example
|
5994 | * this.demoTest = function (browser) {
|
5995 | * browser.executeAsyncScript(function(done) {
|
5996 | * setTimeout(function() {
|
5997 | * done(true);
|
5998 | * }, 500);
|
5999 | * }, function(result) {
|
6000 | * // result.value === true
|
6001 | * });
|
6002 | *
|
6003 | * browser.executeAsyncScript(function(arg1, arg2, done) {
|
6004 | * setTimeout(function() {
|
6005 | * done(true);
|
6006 | * }, 500);
|
6007 | * }, [arg1, arg2], function(result) {
|
6008 | * // result.value === true
|
6009 | * });
|
6010 | * }
|
6011 | */
|
6012 | executeAsyncScript<T>(
|
6013 | script: string | ((this: undefined, ...data: any[]) => T) | string,
|
6014 | args: any[],
|
6015 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<T>) => void,
|
6016 | ): this;
|
6017 |
|
6018 | /**
|
6019 | * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be asynchronous.
|
6020 | *
|
6021 | * The function to be injected receives the `done` callback as argument which needs to be called when the asynchronous operation finishes.
|
6022 | * The value passed to the `done` callback is returned to the client.
|
6023 | * Additional arguments for the injected function may be passed as a non-empty array which will be passed before the `done` callback.
|
6024 | *
|
6025 | * Asynchronous script commands may not span page loads. If an unload event is fired while waiting for the script result, an error will be returned.
|
6026 | *
|
6027 | * @example
|
6028 | * this.demoTest = function (browser) {
|
6029 | * browser.executeAsync(function(done) {
|
6030 | * setTimeout(function() {
|
6031 | * done(true);
|
6032 | * }, 500);
|
6033 | * }, function(result) {
|
6034 | * // result.value === true
|
6035 | * });
|
6036 | *
|
6037 | * browser.executeAsync(function(arg1, arg2, done) {
|
6038 | * setTimeout(function() {
|
6039 | * done(true);
|
6040 | * }, 500);
|
6041 | * }, [arg1, arg2], function(result) {
|
6042 | * // result.value === true
|
6043 | * });
|
6044 | * }
|
6045 | */
|
6046 | executeAsync(
|
6047 | script: ((this: undefined, ...data: any[]) => any) | string,
|
6048 | args?: any[],
|
6049 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void,
|
6050 | ): this;
|
6051 | }
|
6052 |
|
6053 | export interface WebDriverProtocolCookies {
|
6054 | /**
|
6055 | * Retrieve or delete all cookies visible to the current page or set a cookie. Normally this shouldn't be used directly, instead the cookie convenience methods should be used:
|
6056 | * <code>getCookie</code>, <code>getCookies</code>, <code>setCookie</code>, <code>deleteCookie</code>, <code>deleteCookies</code>.
|
6057 | *
|
6058 | * @see getCookies
|
6059 | * @see getCookie
|
6060 | * @see setCookie
|
6061 | * @see deleteCookie
|
6062 | * @see deleteCookies
|
6063 | */
|
6064 | cookie(method: string, callbackOrCookie?: () => void): this;
|
6065 | }
|
6066 |
|
6067 | export interface WebDriverProtocolUserActions {
|
6068 | /**
|
6069 | * Move to the element and peforms a double-click in the middle of the element.
|
6070 | *
|
6071 | * @example
|
6072 | * module.exports = {
|
6073 | * demoTest() {
|
6074 | * browser.doubleClick('#main ul li a.first');
|
6075 | *
|
6076 | * browser.doubleClick('#main ul li a.first', function(result) {
|
6077 | * console.log('double click result', result);
|
6078 | * });
|
6079 | *
|
6080 | * // with explicit locate strategy
|
6081 | * browser.doubleClick('css selector', '#main ul li a.first');
|
6082 | *
|
6083 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
6084 | * browser.doubleClick({
|
6085 | * selector: '#main ul li a',
|
6086 | * index: 1,
|
6087 | * suppressNotFoundErrors: true
|
6088 | * });
|
6089 | *
|
6090 | * browser.doubleClick({
|
6091 | * selector: '#main ul li a.first',
|
6092 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
6093 | * });
|
6094 | * },
|
6095 | *
|
6096 | * demoTestAsync: async function() {
|
6097 | * const result = await browser.doubleClick('#main ul li a.first');
|
6098 | * console.log('double click result', result);
|
6099 | * }
|
6100 | * }
|
6101 | */
|
6102 | doubleClick(
|
6103 | selector: string,
|
6104 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
6105 | ): this;
|
6106 | doubleClick(
|
6107 | using: LocateStrategy,
|
6108 | selector: string,
|
6109 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
6110 | ): this;
|
6111 |
|
6112 | /**
|
6113 | * Move to the element and click (without releasing) in the middle of the given element.
|
6114 | *
|
6115 | * @example
|
6116 | * module.exports = {
|
6117 | * demoTest() {
|
6118 | * browser.clickAndHold('#main ul li a.first');
|
6119 | *
|
6120 | * browser.clickAndHold('#main ul li a.first', function(result) {
|
6121 | * console.log('Click result', result);
|
6122 | * });
|
6123 | *
|
6124 | * // with explicit locate strategy
|
6125 | * browser.clickAndHold('css selector', '#main ul li a.first');
|
6126 | *
|
6127 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
6128 | * browser.clickAndHold({
|
6129 | * selector: '#main ul li a',
|
6130 | * index: 1,
|
6131 | * suppressNotFoundErrors: true
|
6132 | * });
|
6133 | *
|
6134 | * browser.clickAndHold({
|
6135 | * selector: '#main ul li a.first',
|
6136 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
6137 | * });
|
6138 | * },
|
6139 | *
|
6140 | * demoTestAsync: async function() {
|
6141 | * const result = await browser.clickAndHold('#main ul li a.first');
|
6142 | * console.log('Right click result', result);
|
6143 | * }
|
6144 | * }
|
6145 | *
|
6146 | */
|
6147 | clickAndHold(
|
6148 | selector: string,
|
6149 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
6150 | ): this;
|
6151 | clickAndHold(
|
6152 | using: LocateStrategy,
|
6153 | selector: string,
|
6154 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
6155 | ): this;
|
6156 |
|
6157 | /**
|
6158 | * Release the depressed left mouse button at the current mouse coordinates (set by `.moveTo()`).
|
6159 | *
|
6160 | */
|
6161 | releaseMouseButton(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
6162 |
|
6163 | /**
|
6164 | * Click at the current mouse coordinates (set by `.moveTo()`).
|
6165 | *
|
6166 | * The button can be (0, 1, 2) or ('left', 'middle', 'right'). It defaults to left mouse button.
|
6167 | *
|
6168 | * @deprecated
|
6169 | */
|
6170 | mouseButtonClick(
|
6171 | button: 0 | 1 | 2 | 'left' | 'middle' | 'right',
|
6172 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
6173 | ): this;
|
6174 |
|
6175 | /**
|
6176 | * Click and hold the left mouse button (at the coordinates set by the last `moveTo` command). Note that the next mouse-related command that should follow is `mouseButtonUp` .
|
6177 | * Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour.
|
6178 | *
|
6179 | * Can be used for implementing drag-and-drop. The button can be (0, 1, 2) or ('left', 'middle', 'right'). It defaults to left mouse button,
|
6180 | * and if you don't pass in a button but do pass in a callback, it will handle it correctly.
|
6181 | *
|
6182 | * **Since v2.0, this command is deprecated.** It is only available on older JSONWire-based drivers.
|
6183 | * Please use the new [User Actions API](/api/useractions/).
|
6184 | *
|
6185 | * @deprecated
|
6186 | */
|
6187 | mouseButtonDown(
|
6188 | button: 0 | 1 | 2 | 'left' | 'middle' | 'right',
|
6189 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
6190 | ): this;
|
6191 |
|
6192 | /**
|
6193 | * Releases the mouse button previously held (where the mouse is currently at). Must be called once for every `mouseButtonDown` command issued.
|
6194 | *
|
6195 | * Can be used for implementing drag-and-drop. The button can be (0, 1, 2) or ('left', 'middle', 'right'). It defaults to left mouse button,
|
6196 | * and if you don't pass in a button but do pass in a callback, it will handle it correctly.
|
6197 | *
|
6198 | * **Since v2.0, this command is deprecated.** It is only available on older JSONWire-based drivers.
|
6199 | * Please use the new [User Actions API](/api/useractions/).
|
6200 | *
|
6201 | * @deprecated
|
6202 | */
|
6203 | mouseButtonUp(
|
6204 | button: 0 | 1 | 2 | 'left' | 'middle' | 'right',
|
6205 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
6206 | ): this;
|
6207 |
|
6208 | /**
|
6209 | * Move the mouse by an offset of the specified [Web Element ID](https://www.w3.org/TR/webdriver1/#dfn-web-elements) or relative to the current mouse cursor, if no element is specified.
|
6210 | * If an element is provided but no offset, the mouse will be moved to the center of the element.
|
6211 | *
|
6212 | * If an element is provided but no offset, the mouse will be moved to the center of the element. If the element is not visible, it will be scrolled into view.
|
6213 | *
|
6214 | * @example
|
6215 | * this.demoTest = function (browser) {
|
6216 | * browser.moveTo(null, 110, 100);
|
6217 | * };
|
6218 | */
|
6219 | moveTo(
|
6220 | element: string | null,
|
6221 | xoffset: number,
|
6222 | yoffset: number,
|
6223 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
6224 | ): this;
|
6225 |
|
6226 | /**
|
6227 | * Simulates a context-click(right click) event on the given DOM element.
|
6228 | * The element is scrolled into view if it is not already pointer-interactable.
|
6229 | * See the WebDriver specification for element [interactability](https://www.w3.org/TR/webdriver/#element-interactability).
|
6230 | *
|
6231 | * @example
|
6232 | * module.exports = {
|
6233 | * demoTest() {
|
6234 | * browser.rightClick('#main ul li a.first');
|
6235 | *
|
6236 | * browser.rightClick('#main ul li a.first', function(result) {
|
6237 | * console.log('Click result', result);
|
6238 | * });
|
6239 | *
|
6240 | * // with explicit locate strategy
|
6241 | * browser.rightClick('css selector', '#main ul li a.first');
|
6242 | *
|
6243 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
6244 | * browser.rightClick({
|
6245 | * selector: '#main ul li a',
|
6246 | * index: 1,
|
6247 | * suppressNotFoundErrors: true
|
6248 | * });
|
6249 | *
|
6250 | * browser.rightClick({
|
6251 | * selector: '#main ul li a.first',
|
6252 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
6253 | * });
|
6254 | * },
|
6255 | *
|
6256 | * demoTestAsync: async function() {
|
6257 | * const result = await browser.rightClick('#main ul li a.first');
|
6258 | * console.log('Right click result', result);
|
6259 | * }
|
6260 | * }
|
6261 | *
|
6262 | */
|
6263 | rightClick(
|
6264 | selector: Definition,
|
6265 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
6266 | ): this;
|
6267 | rightClick(
|
6268 | using: LocateStrategy,
|
6269 | selector: Definition,
|
6270 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
6271 | ): this;
|
6272 | }
|
6273 |
|
6274 | export interface WebDriverProtocolUserPrompts {
|
6275 | /**
|
6276 | * Accepts the currently displayed alert dialog. Usually, this is equivalent to clicking on the 'OK' button in the dialog.
|
6277 | *
|
6278 | * @example
|
6279 | * browser.acceptAlert()
|
6280 | */
|
6281 | acceptAlert(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
6282 |
|
6283 | /**
|
6284 | * Dismisses the currently displayed alert dialog. For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button.
|
6285 | *
|
6286 | * For alert() dialogs, this is equivalent to clicking the 'OK' button.
|
6287 | *
|
6288 | * @example
|
6289 | * browser.dismissAlert();
|
6290 | */
|
6291 | dismissAlert(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
6292 |
|
6293 | /**
|
6294 | * Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog.
|
6295 | *
|
6296 | * @example
|
6297 | * browser.getAlertText();
|
6298 | */
|
6299 | getAlertText(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
6300 |
|
6301 | /**
|
6302 | * Sends keystrokes to a JavaScript prompt() dialog.
|
6303 | *
|
6304 | * @example
|
6305 | * browser.setAlertText('randomalert');
|
6306 | */
|
6307 | setAlertText(value: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
6308 |
|
6309 | /**
|
6310 | * Automate the input of basic auth credentials whenever they arise.
|
6311 | *
|
6312 | * @example
|
6313 | * this.demoTest = function (browser) {
|
6314 | * browser
|
6315 | * .registerBasicAuth('test-username', 'test-password')
|
6316 | * .navigateTo('http://browserspy.dk/password-ok.php');
|
6317 | * };
|
6318 | *
|
6319 | */
|
6320 | registerBasicAuth(
|
6321 | username: string,
|
6322 | password: string,
|
6323 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
6324 | ): this;
|
6325 | }
|
6326 |
|
6327 | export interface WebDriverProtocolScreenCapture {
|
6328 | /**
|
6329 | * Take a screenshot of the current page.
|
6330 | *
|
6331 | * @example
|
6332 | * browser.screenshot(true);
|
6333 | */
|
6334 | screenshot(log_screenshot_data: boolean, callback?: (screenshotEncoded: string) => void): this;
|
6335 | }
|
6336 |
|
6337 | export interface WebDriverProtocolMobileRelated {
|
6338 | /**
|
6339 | * Get the current browser orientation.
|
6340 | *
|
6341 | * @example
|
6342 | * browser.getOrientation()
|
6343 | */
|
6344 | getOrientation(
|
6345 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<'LANDSCAPE' | 'PORTRAIT'>) => void,
|
6346 | ): this;
|
6347 |
|
6348 | /**
|
6349 | * Sets the browser orientation.
|
6350 | *
|
6351 | * @example
|
6352 | * browser.setOrientation(orientation)
|
6353 | */
|
6354 | setOrientation(
|
6355 | orientation: 'LANDSCAPE' | 'PORTRAIT',
|
6356 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
6357 | ): this;
|
6358 |
|
6359 | /**
|
6360 | * Get a list of the available contexts.
|
6361 | *
|
6362 | * @example
|
6363 | * browser.contexts();
|
6364 | *
|
6365 | * Used by Appium when testing hybrid mobile web apps. More info here: https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/hybrid.md.
|
6366 | */
|
6367 | contexts(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void): this;
|
6368 |
|
6369 | /**
|
6370 | * Get current context.
|
6371 | *
|
6372 | * @example
|
6373 | * browser.currentContext();
|
6374 | */
|
6375 | currentContext(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void): this;
|
6376 |
|
6377 | /**
|
6378 | * Sets the context.
|
6379 | *
|
6380 | * @example
|
6381 | * browser.setContext(context);
|
6382 | */
|
6383 | setContext(context: string, callback?: () => void): this;
|
6384 | }
|
6385 |
|
6386 | /**
|
6387 | * Map of DOM element locators as shorthand string selectors based on
|
6388 | * global selector setting or ElementLocator
|
6389 | *
|
6390 | * @example
|
6391 | * const elements: PageElements {
|
6392 | * header: "h1",
|
6393 | * banner: {
|
6394 | * locateStrategy: "css selector",
|
6395 | * selector: "#bannerId"
|
6396 | * }
|
6397 | * }
|
6398 | */
|
6399 | export interface PageElements {
|
6400 | [key: string]: Definition;
|
6401 | }
|
6402 |
|
6403 | /**
|
6404 | * Type for defining page object models allowing for optional type-safe
|
6405 | * inclusion of url, elements, sections, commands, and props properties.
|
6406 | */
|
6407 | export interface PageObjectModel {
|
6408 | url?: string | ((...args: any) => string);
|
6409 | elements?: PageElements;
|
6410 | sections?: EnhancedPageObjectSections;
|
6411 | commands?: any;
|
6412 | props?: any;
|
6413 | }
|
6414 |
|
6415 | declare const _default: Nightwatch;
|
6416 | export default _default;
|
6417 |
|
\ | No newline at end of file |