UNPKG

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