1 | // Type definitions for nightwatch 2.0
|
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 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
16 | // TypeScript Version: 4.5
|
17 |
|
18 | import { WebElement, WebElementPromise, By } from 'selenium-webdriver';
|
19 |
|
20 | export * from './globals';
|
21 |
|
22 | export interface ChromePerfLoggingPrefs {
|
23 | /**
|
24 | * Default: true. Whether or not to collect events from Network domain.
|
25 | */
|
26 | enableNetwork?: boolean | undefined;
|
27 | /**
|
28 | * Default: true. Whether or not to collect events from Page domain.
|
29 | */
|
30 | enablePage?: boolean | undefined;
|
31 | /**
|
32 | * A comma-separated string of Chrome tracing categories for which trace events should be collected.
|
33 | * An unspecified or empty string disables tracing.
|
34 | */
|
35 | traceCategories?: string | undefined;
|
36 | /**
|
37 | * Default: 1000. The requested number of milliseconds between DevTools trace buffer usage events. For example, if 1000,
|
38 | * then once per second, DevTools will report how full the trace buffer is. If a report indicates the buffer usage is 100%,
|
39 | * a warning will be issued.
|
40 | */
|
41 | bufferUsageReportingInterval?: number | undefined;
|
42 | }
|
43 |
|
44 | export interface ChromeOptions {
|
45 | /**
|
46 | * List of command-line arguments to use when starting Chrome. Arguments with an associated value should be separated by a '=' sign
|
47 | * (e.g., ['start-maximized', 'user-data-dir=/tmp/temp_profile']).
|
48 | */
|
49 | args?: string[] | undefined;
|
50 | /**
|
51 | * Path to the Chrome executable to use (on Mac OS X, this should be the actual binary, not just the app. e.g.,
|
52 | * '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')
|
53 | */
|
54 | binary?: string | undefined;
|
55 | /**
|
56 | * A list of Chrome extensions to install on startup. Each item in the list should be a base-64 encoded packed Chrome extension (.crx)
|
57 | */
|
58 | extensions?: string[] | undefined;
|
59 | /**
|
60 | * A dictionary with each entry consisting of the name of the preference and its value. These preferences are applied
|
61 | * to the Local State file in the user data folder.
|
62 | */
|
63 | localState?: Record<string, string> | undefined;
|
64 | /**
|
65 | * A dictionary with each entry consisting of the name of the preference and its value. These preferences are only applied
|
66 | * to the user profile in use.
|
67 | */
|
68 | prefs?: Record<string, string> | undefined;
|
69 | /**
|
70 | * Default: false. If false, Chrome will be quit when ChromeDriver is killed, regardless of whether the session is quit.
|
71 | * If true, Chrome will only be quit if the session is quit (or closed). Note, if true, and the session is not quit,
|
72 | * ChromeDriver cannot clean up the temporary user data directory that the running Chrome instance is using.
|
73 | */
|
74 | detach?: boolean | undefined;
|
75 | /**
|
76 | * An address of a Chrome debugger server to connect to, in the form of <hostname/ip:port>, e.g. '127.0.0.1:38947'
|
77 | */
|
78 | debuggerAddress?: string | undefined;
|
79 | /**
|
80 | * List of Chrome command line switches to exclude that ChromeDriver by default passes when starting Chrome.
|
81 | * Do not prefix switches with --.
|
82 | */
|
83 | excludeSwitches?: string[] | undefined;
|
84 | /**
|
85 | * Directory to store Chrome minidumps . (Supported only on Linux.)
|
86 | */
|
87 | minidumpPath?: string | undefined;
|
88 | /**
|
89 | * A dictionary with either a value for “deviceName,” or values for “deviceMetrics” and “userAgent.” Refer to Mobile Emulation for more information.
|
90 | */
|
91 | mobileEmulation?: Record<string, string> | undefined;
|
92 | /**
|
93 | * An optional dictionary that specifies performance logging preferences. See below for more information.
|
94 | */
|
95 | perfLoggingPrefs?: ChromePerfLoggingPrefs | undefined;
|
96 | /**
|
97 | * A list of window types that will appear in the list of window handles. For access to <webview> elements, include "webview" in this list.
|
98 | */
|
99 | windowTypes?: string[] | undefined;
|
100 | }
|
101 |
|
102 | // TODO: visit later
|
103 | export interface NightwatchDesiredCapabilities {
|
104 | /**
|
105 | * The name of the browser being used; should be one of {android|chrome|firefox|htmlunit|internet explorer|iPhone|iPad|opera|safari}.
|
106 | */
|
107 | browserName?: string | undefined;
|
108 |
|
109 | /**
|
110 | * The browser version, or the empty string if unknown.
|
111 | */
|
112 | version?: string | undefined;
|
113 |
|
114 | /**
|
115 | * A key specifying which platform the browser should be running on. This value should be one of {WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANDROID}.
|
116 | * When requesting a new session, the client may specify ANY to indicate any available platform may be used.
|
117 | * For more information see [GridPlatforms (https://code.google.com/p/selenium/wiki/GridPlatforms)]
|
118 | */
|
119 | platform?: string | undefined;
|
120 |
|
121 | /**
|
122 | * Whether the session supports taking screenshots of the current page.
|
123 | */
|
124 | takesScreenShot?: boolean | undefined;
|
125 |
|
126 | /**
|
127 | * Whether the session can interact with modal popups, such as window.alert and window.confirm.
|
128 | */
|
129 | handlesAlerts?: boolean | undefined;
|
130 |
|
131 | /**
|
132 | * Whether the session supports CSS selectors when searching for elements.
|
133 | */
|
134 | cssSelectorsEnabled?: boolean | undefined;
|
135 |
|
136 | /**
|
137 | * Whether the session supports executing user supplied JavaScript in the context of the current page (only on HTMLUnitDriver).
|
138 | */
|
139 | javascriptEnabled?: boolean | undefined;
|
140 |
|
141 | /**
|
142 | * Whether the session can interact with database storage.
|
143 | */
|
144 | databaseEnabled?: boolean | undefined;
|
145 |
|
146 | /**
|
147 | * Whether the session can set and query the browser's location context.
|
148 | */
|
149 | locationContextEnabled?: boolean | undefined;
|
150 |
|
151 | /**
|
152 | * Whether the session can interact with the application cache.
|
153 | */
|
154 | applicationCacheEnabled?: boolean | undefined;
|
155 |
|
156 | /**
|
157 | * Whether the session can query for the browser's connectivity and disable it if desired.
|
158 | */
|
159 | browserConnectionEnabled?: boolean | undefined;
|
160 |
|
161 | /**
|
162 | * Whether the session supports interactions with storage objects (http://www.w3.org/TR/2009/WD-webstorage-20091029/).
|
163 | */
|
164 | webStorageEnabled?: boolean | undefined;
|
165 |
|
166 | /**
|
167 | * Whether the session should accept all SSL certs by default.
|
168 | */
|
169 | acceptSslCerts?: boolean | undefined;
|
170 |
|
171 | /**
|
172 | * Whether the session can rotate the current page's current layout between portrait and landscape orientations (only applies to mobile platforms).
|
173 | */
|
174 | rotatable?: boolean | undefined;
|
175 |
|
176 | /**
|
177 | * Whether the session is capable of generating native events when simulating user input.
|
178 | */
|
179 | nativeEvents?: boolean | undefined;
|
180 |
|
181 | /**
|
182 | * What the browser should do with an unhandled alert before throwing out the UnhandledAlertException. Possible values are "accept", "dismiss" and "ignore"
|
183 | */
|
184 | unexpectedAlertBehaviour?: string | undefined;
|
185 |
|
186 | /**
|
187 | * 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.
|
188 | * The default value is to align with the top of the viewport. Supported in IE and Firefox (since 2.36)
|
189 | */
|
190 | elementScrollBehaviour?: number | undefined;
|
191 |
|
192 | /**
|
193 | * A JSON object describing the logging level of different components in the browser, the driver, or any intermediary WebDriver servers.
|
194 | * Available values for most loggers are "OFF", "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST", "ALL".
|
195 | * This produces a JSON object looking something like: {"loggingPrefs": {"driver": "INFO", "server": "OFF", "browser": "FINE"}}.
|
196 | */
|
197 | loggingPrefs?:
|
198 | | {
|
199 | browser?: string | undefined;
|
200 | driver?: string | undefined;
|
201 | server?: string | undefined;
|
202 | }
|
203 | | undefined;
|
204 | /**
|
205 | * This is a list of all the Chrome-specific desired capabilities.
|
206 | */
|
207 | chromeOptions?: ChromeOptions | undefined;
|
208 | }
|
209 |
|
210 | export interface NightwatchScreenshotOptions {
|
211 | enabled?: boolean | undefined;
|
212 | filename_format: ({
|
213 | testSuite,
|
214 | testCase,
|
215 | isError,
|
216 | dateObject,
|
217 | }?: {
|
218 | testSuite?: string;
|
219 | testCase?: string;
|
220 | isError?: boolean;
|
221 | dateObject?: Date;
|
222 | }) => string;
|
223 | on_failure?: boolean | undefined;
|
224 | on_error?: boolean | undefined;
|
225 | path?: string | undefined;
|
226 | }
|
227 |
|
228 | export interface NightwatchTestRunner {
|
229 | type?: string | undefined;
|
230 | options?:
|
231 | | {
|
232 | ui?: string | undefined;
|
233 | }
|
234 | | undefined;
|
235 | }
|
236 |
|
237 | export interface NightwatchTestWorker {
|
238 | enabled: boolean;
|
239 | workers: string | number;
|
240 | node_options?: string | string[] | undefined;
|
241 | }
|
242 |
|
243 | export interface TimeoutOptions {
|
244 | /**
|
245 | * @default 60000
|
246 | */
|
247 | timeout: number;
|
248 | /**
|
249 | * @default 0
|
250 | */
|
251 | retry_attempts: number;
|
252 | }
|
253 |
|
254 | export interface NightwatchOptions {
|
255 | /**
|
256 | * Location(s) where custom commands will be loaded from.
|
257 | */
|
258 | custom_commands_path?: string | string[] | undefined;
|
259 |
|
260 | /**
|
261 | * Location(s) where custom assertions will be loaded from.
|
262 | */
|
263 | custom_assertions_path?: string | string[] | undefined;
|
264 |
|
265 | /**
|
266 | * Location(s) where page object files will be loaded from.
|
267 | */
|
268 | page_objects_path?: string | string[] | undefined;
|
269 |
|
270 | // An array specifying a list of Nightwatch plugin names that should be used;
|
271 | // e.g.: plugins: ['vite-plugin-nightwatch']
|
272 | plugins: string[];
|
273 |
|
274 | /**
|
275 | * 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.
|
276 | * Globals can also be defined/overwritten inside a test_settings environment.
|
277 | */
|
278 | globals_path?: string | undefined;
|
279 |
|
280 | /**
|
281 | * An object which will be made available on the main test api, throughout the test execution.
|
282 | */
|
283 | globals?: NightwatchGlobals;
|
284 |
|
285 | /**
|
286 | * 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
|
287 | */
|
288 | dotenv?: any;
|
289 |
|
290 | /**
|
291 | * persist the same globals object between runs or have a (deep) copy of it per each test;
|
292 | * this can be useful when persisting data between test suites is needed, such as a cookie or session information.
|
293 | * @default false
|
294 | */
|
295 | persist_globals?: boolean | undefined;
|
296 |
|
297 | /**
|
298 | * The location where the JUnit XML report files will be saved. Set this to false if you want to disable XML reporting.
|
299 | */
|
300 | output_folder?: string | undefined;
|
301 |
|
302 | /**
|
303 | * An array of folders (excluding subfolders) where the tests are located.
|
304 | */
|
305 | src_folders: string | string[];
|
306 |
|
307 | /**
|
308 | * Used when running in parallel to determine if the output should be collected and displayed at the end.
|
309 | */
|
310 | live_output?: boolean | undefined;
|
311 |
|
312 | /**
|
313 | * disable support of loading of typescript files for backwards compatibility with test suites.
|
314 | */
|
315 | disable_typescript: boolean | undefined;
|
316 |
|
317 | /**
|
318 | * Controls whether or not to disable coloring of the cli output globally.
|
319 | */
|
320 | disable_colors?: boolean | undefined;
|
321 |
|
322 | /**
|
323 | * Used when running in parallel to specify the delay (in milliseconds) between starting the child processes
|
324 | */
|
325 | parallel_process_delay?: number | undefined;
|
326 |
|
327 | /**
|
328 | * An object containing Selenium Server related configuration options. See below for details.
|
329 | */
|
330 | selenium?: NightwatchSeleniumOptions | undefined;
|
331 |
|
332 | /**
|
333 | * Whether or not to automatically start the Selenium/WebDriver session. If running unit tests, this should be set tot false.
|
334 | * @default true
|
335 | */
|
336 | start_process?: boolean | undefined;
|
337 |
|
338 | /**
|
339 | * End the session automatically when the test is being terminated, usually after a failed assertion.
|
340 | * @default true
|
341 | */
|
342 | end_session_on_fail?: boolean | undefined;
|
343 |
|
344 | /**
|
345 | * Skip the remaining test cases from the current test suite, when one test case fails.
|
346 | */
|
347 | skip_testcases_on_fail?: boolean | undefined;
|
348 |
|
349 | /**
|
350 | * 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.
|
351 | * If set to an object, can specify specify the number of workers as "auto" or a number. Example: "test_workers" : {"enabled" : true, "workers" : "auto"}
|
352 | * @default false
|
353 | */
|
354 | test_workers?: boolean | NightwatchTestWorker | undefined;
|
355 |
|
356 | /**
|
357 | * This object contains all the test related options. See below for details.
|
358 | */
|
359 | test_settings: NightwatchTestSettings;
|
360 |
|
361 | /**
|
362 | * Specifies which test runner to use when running the tests. Values can be either default (built in nightwatch runner) or mocha.
|
363 | * Example: "test_runner" : {"type" : "mocha", "options" : {"ui" : "tdd"}}
|
364 | * @default 'default'
|
365 | */
|
366 | test_runner?: string | NightwatchTestRunner | undefined;
|
367 |
|
368 | /**
|
369 | * Allows for webdriver config (mostly the same as selenium)
|
370 | */
|
371 | webdriver?:
|
372 | | {
|
373 | /**
|
374 | * When this is enabled, the Webdriver server is run in background in a child process and started/stopped automatically.
|
375 | * Nightwatch includes support for managing Chromedriver, Geckodriver (Firefox), Safaridriver, and Selenium Server. Please refer to the Install Webdriver section for details.
|
376 | * @default false
|
377 | */
|
378 | start_process: boolean;
|
379 |
|
380 | /**
|
381 | * Only useful if start_process is enabled.
|
382 | * @default none
|
383 | */
|
384 | server_path: string;
|
385 |
|
386 | /**
|
387 | * Only needed when the Webdriver service is running on a different machine.
|
388 | */
|
389 | host: string;
|
390 |
|
391 | /**
|
392 | * The port number on which the Webdriver service will listen and/or on which Nightwatch will attempt to connect.
|
393 | */
|
394 | port: number;
|
395 |
|
396 | /**
|
397 | * Should be set to true if connecting to a remote (cloud) service via HTTPS. Also don't forget to set port to 443.
|
398 | */
|
399 | ssl: boolean;
|
400 |
|
401 | /**
|
402 | * The location where the Webdriver service log file output.log file will be placed. Defaults to current directory.
|
403 | * To disable Webdriver logging, set this to false.
|
404 | * @default none
|
405 | */
|
406 | log_path: string | boolean;
|
407 |
|
408 | /**
|
409 | * List of cli arguments to be passed to the Webdriver process. This varies for each Webdriver implementation.
|
410 | *
|
411 | * @default none
|
412 | */
|
413 | cli_args: any;
|
414 |
|
415 | /**
|
416 | * Some Webdriver implementations (Safari, Edge) support both the W3C Webdriver API as well as the legacy JSON Wire (Selenium) API.
|
417 | *
|
418 | * @default false
|
419 | */
|
420 | use_legacy_jsonwire: boolean;
|
421 |
|
422 | /**
|
423 | * Time to wait (in ms) before starting to check the Webdriver server is up and running.
|
424 | *
|
425 | * @default 100
|
426 | */
|
427 | check_process_delay: number;
|
428 |
|
429 | /**
|
430 | * Maximum number of ping status check attempts when checking if the Webdriver server is up and running before returning a timeout error.
|
431 | *
|
432 | * @default 5
|
433 | */
|
434 | max_status_poll_tries: number;
|
435 |
|
436 | /**
|
437 | * Interval (in ms) to use between status ping checks when checking if the Webdriver server is up and running.
|
438 | *
|
439 | * @default 100
|
440 | */
|
441 | status_poll_interval: number;
|
442 |
|
443 | /**
|
444 | * 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.
|
445 | *
|
446 | * @default 120000
|
447 | */
|
448 | process_create_timeout: number;
|
449 |
|
450 | /**
|
451 | * Proxy requests to the Webdriver (or Selenium) service. http, https, socks(v5), socks5, sock4, and pac are accepted. Uses node-proxy-agent.
|
452 | *
|
453 | * @example http://user:pass@host:port
|
454 | * @default none
|
455 | */
|
456 | proxy: string;
|
457 |
|
458 | /**
|
459 | * Requests to the Webdriver service will timeout in timeout miliseconds; a retry will happen retry_attempts number of times.
|
460 | *
|
461 | * @example {timeout: 15000, retry_attempts: 5}
|
462 | */
|
463 | timeout_options: TimeoutOptions;
|
464 |
|
465 | /**
|
466 | * Needed sometimes when using a Selenium Server. The prefix to be added to to all requests (e.g. /wd/hub).
|
467 | */
|
468 | default_path_prefix: string;
|
469 |
|
470 | /**
|
471 | * Usually only needed for cloud testing Selenium services. In case the server requires credentials this username will be used to compute the Authorization header.
|
472 | *
|
473 | * The value can be also an environment variable, in which case it will look like this:
|
474 | * "username" : "${SAUCE_USERNAME}"
|
475 | *
|
476 | * @default none
|
477 | */
|
478 | username: string;
|
479 |
|
480 | /**
|
481 | * This field will be used together with username to compute the Authorization header.
|
482 | *
|
483 | * Like username, the value can be also an environment variable:
|
484 | * "access_key" : "${SAUCE_ACCESS_KEY}"
|
485 | *
|
486 | * @default none
|
487 | */
|
488 | access_key: string;
|
489 | }
|
490 | | undefined;
|
491 |
|
492 | /**
|
493 | * An array of folders or file patterns to be skipped (relative to the main source folder).
|
494 | * @example
|
495 | * "exclude" : ["excluded-folder"]
|
496 | * or:
|
497 | * "exclude" : ["test-folder/*-smoke.js"]
|
498 | */
|
499 | exclude?: string[];
|
500 |
|
501 | /**
|
502 | * Folder or file pattern to be used when loading the tests. Files that don't match this pattern will be ignored
|
503 | * @example
|
504 | * "filter" : "tests/*-smoke.js"
|
505 | */
|
506 | filter?: string;
|
507 |
|
508 | /**
|
509 | * Skip a group of tests (a subfolder); can be a list of comma-separated values (no space).
|
510 | */
|
511 | skipgroup?: string;
|
512 |
|
513 | /**
|
514 | * 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.
|
515 | */
|
516 | sync_test_names?: boolean;
|
517 |
|
518 | /**
|
519 | * Skip tests by tag name; can be a list of comma-separated values (no space).
|
520 | */
|
521 | skiptags?: string;
|
522 |
|
523 | /**
|
524 | * Use xpath as the default locator strategy.
|
525 | */
|
526 | use_xpath?: boolean;
|
527 |
|
528 | parallel_mode?: boolean;
|
529 |
|
530 | report_prefix?: string;
|
531 |
|
532 | unit_testing_mode?: boolean;
|
533 |
|
534 | /**
|
535 | * @default junit
|
536 | */
|
537 | default_reporter?: string;
|
538 |
|
539 | /**
|
540 | * @default false
|
541 | */
|
542 | backwards_compatibility_mode?: boolean;
|
543 |
|
544 | disable_global_apis?: boolean;
|
545 | }
|
546 |
|
547 | export interface NightwatchGlobals {
|
548 | [key: string]: any;
|
549 | /**
|
550 | * this controls whether to abort the test execution when an assertion failed and skip the rest
|
551 | * it's being used in waitFor commands and expect assertions
|
552 | * @default true
|
553 | */
|
554 | abortOnAssertionFailure?: boolean | undefined;
|
555 |
|
556 | /**
|
557 | * this controls whether to abort the test execution when an assertion failed and skip the rest
|
558 | * it's being used in waitFor commands and expect assertions
|
559 | * @default false
|
560 | */
|
561 | abortOnElementLocateError?: boolean | undefined;
|
562 |
|
563 | /**
|
564 | * this will overwrite the default polling interval (currently 500ms) for waitFor commands
|
565 | * and expect assertions that use retry
|
566 | * @default 500
|
567 | */
|
568 | waitForConditionPollInterval?: number | undefined;
|
569 |
|
570 | /**
|
571 | * default timeout value in milliseconds for waitFor commands and implicit waitFor value for
|
572 | * expect assertions
|
573 | * @default 5000
|
574 | */
|
575 | waitForConditionTimeout?: number | undefined;
|
576 |
|
577 | /**
|
578 | * this will cause waitFor commands on elements to throw an error if multiple
|
579 | * elements are found using the given locate strategy and selector
|
580 | * @default false
|
581 | */
|
582 | throwOnMultipleElementsReturned?: boolean | undefined;
|
583 |
|
584 | /**
|
585 | * By default a warning is printed if multiple elements are found using the given locate strategy
|
586 | * and selector; set this to true to suppress those warnings
|
587 | * @default false
|
588 | */
|
589 | suppressWarningsOnMultipleElementsReturned: boolean | undefined;
|
590 |
|
591 | /**
|
592 | * controls the timeout time for async hooks. Expects the done() callback to be invoked within this time
|
593 | * or an error is thrown
|
594 | * @default 20000
|
595 | */
|
596 | asyncHookTimeout?: number | undefined;
|
597 |
|
598 | /**
|
599 | * controls the timeout value for when running async unit tests. Expects the done() callback to be invoked within this time
|
600 | * or an error is thrown
|
601 | * @default 2000
|
602 | */
|
603 | unitTestsTimeout?: number | undefined;
|
604 |
|
605 | /**
|
606 | * controls the timeout value for when executing the global async reporter. Expects the done() callback to be invoked within this time
|
607 | * or an error is thrown
|
608 | * @default 20000
|
609 | */
|
610 | customReporterCallbackTimeout?: number | undefined;
|
611 |
|
612 | /**
|
613 | * 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.
|
614 | */
|
615 | retryAssertionTimeout?: number | undefined;
|
616 |
|
617 | reporter: (results: any, cb: any) => void;
|
618 | beforeTestSuite(browser: any): Promise<void>;
|
619 | afterTestSuite(browser: any): Promise<void>;
|
620 | beforeTestCase(browser: any): Promise<void>;
|
621 | afterTestCase(browser: any): Promise<void>;
|
622 | onBrowserNavigate(browser: any): Promise<void>;
|
623 | onBrowserQuit(browser: any): Promise<void>;
|
624 | }
|
625 |
|
626 | export interface NightwatchSeleniumOptions {
|
627 | /**
|
628 | * Whether or not to manage the selenium process automatically.
|
629 | * @default false
|
630 | */
|
631 | start_process: boolean;
|
632 |
|
633 | /**
|
634 | * Whether or not to automatically start the Selenium session.
|
635 | */
|
636 | start_session: boolean;
|
637 |
|
638 | /**
|
639 | * 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
|
640 | */
|
641 | server_path: string;
|
642 |
|
643 | /**
|
644 | * The location where the selenium Selenium-debug.log file will be placed. Defaults to current directory. To disable Selenium logging, set this to false
|
645 | */
|
646 | log_path: string | boolean;
|
647 |
|
648 | /**
|
649 | * Usually not required and only used if start_process is true. Specify the IP address you wish Selenium to listen on.
|
650 | */
|
651 | host: string;
|
652 |
|
653 | /**
|
654 | * The port number Selenium will listen on.
|
655 | */
|
656 | port: number | undefined;
|
657 |
|
658 | /**
|
659 | * List of cli arguments to be passed to the Selenium process. Here you can set various options for browser drivers, such as:
|
660 | *
|
661 | * webdriver.firefox.profile: Selenium will be default create a new Firefox profile for each session.
|
662 | * If you wish to use an existing Firefox profile you can specify its name here.
|
663 | * Complete list of Firefox Driver arguments available https://code.google.com/p/selenium/wiki/FirefoxDriver.
|
664 | *
|
665 | * webdriver.chrome.driver: Nightwatch can run the tests using Chrome browser also. To enable this you have to download the ChromeDriver binary
|
666 | * (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
|
667 | * desiredCapabilities object.
|
668 | * More information can be found on the ChromeDriver website (https://sites.google.com/a/chromium.org/chromedriver/).
|
669 | *
|
670 | * webdriver.ie.driver: Nightwatch has support for Internet Explorer also. To enable this you have to download the IE Driver binary
|
671 | * (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
|
672 | * name in the desiredCapabilities object.
|
673 | */
|
674 | cli_args: {};
|
675 |
|
676 | /**
|
677 | * Time to wait (in ms) before starting to check the Webdriver server is up and running
|
678 | * @default 500
|
679 | */
|
680 | check_process_delay: number;
|
681 |
|
682 | /**
|
683 | * Maximum number of ping status check attempts before returning a timeout error
|
684 | * @default 15
|
685 | */
|
686 | max_status_poll_tries: number;
|
687 |
|
688 | /**
|
689 | * Interval (in ms) to use between status ping checks when checking if the Webdriver server is up and running
|
690 | * @default 200
|
691 | */
|
692 | status_poll_interval: number;
|
693 | }
|
694 |
|
695 | // TODO: Remove duplicates from NightwatchOptions
|
696 | export interface NightwatchTestSettingGeneric {
|
697 | /**
|
698 | * 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.
|
699 | */
|
700 | launch_url?: string | undefined;
|
701 |
|
702 | /**
|
703 | * The hostname/IP on which the selenium server is accepting connections.
|
704 | */
|
705 | selenium_host?: string | undefined;
|
706 |
|
707 | /**
|
708 | * The port number on which the selenium server is accepting connections.
|
709 | */
|
710 | selenium_port?: number | undefined;
|
711 |
|
712 | /**
|
713 | * Whether to show extended Selenium command logs.
|
714 | */
|
715 | silent?: boolean | undefined;
|
716 |
|
717 | /**
|
718 | * Use to disable terminal output completely.
|
719 | */
|
720 | output?: boolean | undefined;
|
721 |
|
722 | /**
|
723 | * Use to disable colored output in the terminal.
|
724 | */
|
725 | disable_colors?: boolean | undefined;
|
726 |
|
727 | /**
|
728 | * In case the selenium server requires credentials this username will be used to compute the Authorization header.
|
729 | * The value can be also an environment variable, in which case it will look like this: "username" : "${SAUCE_USERNAME}"
|
730 | */
|
731 | username?: string | undefined;
|
732 |
|
733 | /**
|
734 | * This field will be used together with username to compute the Authorization header.
|
735 | * Like username, the value can be also an environment variable: "access_key" : "${SAUCE_ACCESS_KEY}"
|
736 | */
|
737 | access_key?: string | undefined;
|
738 |
|
739 | /**
|
740 | * 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
|
741 | */
|
742 | proxy?: string | undefined;
|
743 |
|
744 | /**
|
745 | * 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.
|
746 | * Example:
|
747 | * "desiredCapabilities" : {
|
748 | * "browserName" : "firefox",
|
749 | * "acceptSslCerts" : true
|
750 | * }
|
751 | * You can view the complete list of capabilities https://code.google.com/p/selenium/wiki/DesiredCapabilities.
|
752 | */
|
753 | desiredCapabilities?: NightwatchDesiredCapabilities | undefined;
|
754 |
|
755 | /**
|
756 | * An object which will be made available within the test and can be overwritten per environment. Example:"globals" : { "myGlobal" : "some_global" }
|
757 | */
|
758 | globals?: NightwatchTestHooks | undefined;
|
759 |
|
760 | /**
|
761 | * An array of folders or file patterns to be skipped (relative to the main source folder).
|
762 | * Example: "exclude" : ["excluded-folder"] or: "exclude" : ["test-folder/*-smoke.js"]
|
763 | */
|
764 | exclude?: string[] | undefined;
|
765 |
|
766 | /**
|
767 | * Folder or file pattern to be used when loading the tests. Files that don't match this patter will be ignored.
|
768 | * Example: "filter" : "tests/*-smoke.js"
|
769 | */
|
770 | filter?: string | undefined;
|
771 |
|
772 | /**
|
773 | * Do not show the Base64 image data in the (verbose) log when taking screenshots.
|
774 | */
|
775 | log_screenshot_data?: boolean | undefined;
|
776 |
|
777 | /**
|
778 | * Use xpath as the default locator strategy
|
779 | */
|
780 | use_xpath?: boolean | undefined;
|
781 |
|
782 | /**
|
783 | * Same as Selenium settings cli_args. You can override the global cli_args on a per-environment basis.
|
784 | */
|
785 | cli_args?: any;
|
786 |
|
787 | /**
|
788 | * End the session automatically when the test is being terminated, usually after a failed assertion.
|
789 | */
|
790 | end_session_on_fail?: boolean | undefined;
|
791 |
|
792 | /**
|
793 | * Skip the rest of testcases (if any) when one testcase fails..
|
794 | */
|
795 | skip_testcases_on_fail?: boolean | undefined;
|
796 | }
|
797 |
|
798 | export interface NightwatchTestSettingScreenshots extends NightwatchTestSettingGeneric {
|
799 | /**
|
800 | * 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.
|
801 | * Since v0.7.5 you can disable screenshots for command errors by setting "on_error" to false.
|
802 | * Example:
|
803 | * "screenshots" : {
|
804 | * "enabled" : true,
|
805 | * "on_failure" : true,
|
806 | * "on_error" : false,
|
807 | * "path" : ""
|
808 | * }
|
809 | */
|
810 | screenshots: NightwatchScreenshotOptions;
|
811 | }
|
812 |
|
813 | export interface NightwatchTestOptions extends NightwatchTestSettingGeneric {
|
814 | screenshots: boolean;
|
815 | screenshotsPath: string;
|
816 | }
|
817 |
|
818 | export interface NightwatchTestSuite {
|
819 | name: string;
|
820 | module: string;
|
821 | group: string;
|
822 | results: any;
|
823 | }
|
824 |
|
825 | export interface NightwatchAssertionsError {
|
826 | name: string;
|
827 | message: string;
|
828 | showDiff: boolean;
|
829 | stack: string;
|
830 | }
|
831 |
|
832 | export interface NightwatchLanguageChains {
|
833 | to: Expect;
|
834 | be: Expect;
|
835 | been: Expect;
|
836 | is: Expect;
|
837 | that: Expect;
|
838 | which: Expect;
|
839 | and: Expect;
|
840 | has: Expect;
|
841 | have: Expect;
|
842 | with: Expect;
|
843 | at: Expect;
|
844 | of: Expect;
|
845 | }
|
846 |
|
847 | export interface NightwatchTestSettings {
|
848 | [key: string]: NightwatchTestSettingScreenshots;
|
849 | }
|
850 |
|
851 | export interface Expect extends NightwatchLanguageChains, NightwatchBrowser {
|
852 | /**
|
853 | * Returns the DOM Element
|
854 | */
|
855 | element(property: any): this;
|
856 |
|
857 | /**
|
858 | * These methods will perform assertions on the specified target on the current element.
|
859 | * The targets can be an attribute value, the element's inner text and a css property.
|
860 | */
|
861 | equal(value: string): this;
|
862 | equals(value: string): this;
|
863 | contain(value: string): this;
|
864 | contains(value: string): this;
|
865 | match(value: string | RegExp): this;
|
866 | startWith(value: string): this;
|
867 | startsWith(value: string): this;
|
868 | endWith(value: string): this;
|
869 | endsWith(value: string): this;
|
870 |
|
871 | /**
|
872 | * Negates any of assertions following in the chain.
|
873 | */
|
874 | not: this;
|
875 |
|
876 | /**
|
877 | * These methods perform the same thing which is essentially retrying the assertion for the given amount of time (in milliseconds).
|
878 | * before or after can be chained to any assertion and thus adding retry capability. You can change the polling interval by defining
|
879 | * a waitForConditionPollInterval property (in milliseconds) as a global property in your nightwatch.json or in
|
880 | * your external globals file. Similarly, a default timeout can be specified as a global waitForConditionTimeout property (in milliseconds).
|
881 | */
|
882 | before(value: number): this;
|
883 | after(value: number): this;
|
884 |
|
885 | /**
|
886 | * Checks if the type (i.e. tag name) of a specified element is of an expected value.
|
887 | */
|
888 | a(value: string, message?: string): this;
|
889 | an(value: string, message?: string): this;
|
890 |
|
891 | /**
|
892 | * Checks if a given attribute of an element exists and optionally if it has the expected value.
|
893 | */
|
894 | attribute(name: string, message?: string): this;
|
895 |
|
896 | /**
|
897 | * Checks a given css property of an element exists and optionally if it has the expected value.
|
898 | */
|
899 | css(property: string, message?: string): this;
|
900 |
|
901 | section(property: string): this;
|
902 |
|
903 | /**
|
904 | * Property that checks if an element is currently enabled.
|
905 | */
|
906 | enabled: this;
|
907 |
|
908 | /**
|
909 | * Property that checks if an element is present in the DOM.
|
910 | */
|
911 | present: this;
|
912 |
|
913 | /**
|
914 | * Property that checks if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected.
|
915 | */
|
916 | selected: this;
|
917 |
|
918 | /**
|
919 | * Property that retrieves the text contained by an element. Can be chained to check if contains/equals/matches the specified text or regex.
|
920 | */
|
921 | text: this;
|
922 |
|
923 | /**
|
924 | * Property that retrieves the value (i.e. the value attributed) of an element. Can be chained to check if contains/equals/matches the specified text or regex.
|
925 | */
|
926 | value: this;
|
927 |
|
928 | /**
|
929 | * Property that asserts the visibility of a specified element.
|
930 | */
|
931 | visible: this;
|
932 | }
|
933 |
|
934 | export interface NightwatchAssertions extends NightwatchCommonAssertions, NightwatchCustomAssertions {
|
935 | /**
|
936 | * Negates any of assertions following in the chain.
|
937 | */
|
938 | not: this;
|
939 | }
|
940 |
|
941 | export interface NightwatchCommonAssertions {
|
942 | /**
|
943 | * Checks if the given attribute of an element contains the expected value.
|
944 | *
|
945 | * ```
|
946 | * this.demoTest = function (client) {
|
947 | * browser.assert.attributeContains('#someElement', 'href', 'google.com');
|
948 | * };
|
949 | * ```
|
950 | */
|
951 | attributeContains(
|
952 | selector: string | ElementProperties,
|
953 | attribute: string,
|
954 | expected: string,
|
955 | message?: string,
|
956 | ): NightwatchAPI;
|
957 |
|
958 | /**
|
959 | * Checks if the given attribute of an element has the expected value.
|
960 | *
|
961 | * ```
|
962 | * this.demoTest = function (client) {
|
963 | * browser.assert.attributeEquals('body', 'data-attr', 'some value');
|
964 | * };
|
965 | * ```
|
966 | */
|
967 | attributeEquals(
|
968 | selector: string | ElementProperties,
|
969 | attribute: string,
|
970 | expected: string,
|
971 | message?: string,
|
972 | ): NightwatchAPI;
|
973 |
|
974 | /**
|
975 | * Checks if the given element contains the specified text.
|
976 | *
|
977 | * ```
|
978 | * this.demoTest = function (client) {
|
979 | * browser.assert.containsText('#main', 'The Night Watch');
|
980 | * };
|
981 | * ```
|
982 | */
|
983 | containsText(selector: string | ElementProperties, expectedText: string, message?: string): NightwatchAPI;
|
984 |
|
985 | /**
|
986 | * Checks if the given element has the specified CSS class.
|
987 | *
|
988 | * ```
|
989 | * this.demoTest = function (client) {
|
990 | * browser.assert.cssClassPresent('#main', 'container');
|
991 | * };
|
992 | * ```
|
993 | */
|
994 | cssClassPresent(selector: string | ElementProperties, className: string, message?: string): NightwatchAPI;
|
995 |
|
996 | /**
|
997 | * Checks if the specified css property of a given element has the expected value.
|
998 | *
|
999 | * ```
|
1000 | * this.demoTest = function (client) {
|
1001 | * browser.assert.cssProperty('#main', 'display', 'block');
|
1002 | * };
|
1003 | * ```
|
1004 | */
|
1005 | cssProperty(
|
1006 | selector: string | ElementProperties,
|
1007 | cssProperty: string,
|
1008 | expected: string | number,
|
1009 | msg?: string,
|
1010 | ): NightwatchAPI;
|
1011 |
|
1012 | deepEqual(value: any, expected: any, message?: string): NightwatchAPI;
|
1013 |
|
1014 | deepStrictEqual(value: any, expected: any, message?: string): NightwatchAPI;
|
1015 |
|
1016 | doesNotThrow(value: any, expected: any, message?: string): NightwatchAPI;
|
1017 |
|
1018 | /**
|
1019 | * Checks if the given element exists in the DOM.
|
1020 | *
|
1021 | * ```
|
1022 | * this.demoTest = function (client) {
|
1023 | * browser.assert.elementPresent("#main");
|
1024 | * };
|
1025 | * ```
|
1026 | */
|
1027 | elementPresent(selector: string | ElementProperties, msg?: string): NightwatchAPI;
|
1028 |
|
1029 | equal(value: any, expected: any, message?: string): NightwatchAPI;
|
1030 |
|
1031 | fail(actual?: any, expected?: any, message?: string, operator?: string): NightwatchAPI;
|
1032 |
|
1033 | ifError(value: any, message?: string): NightwatchAPI;
|
1034 |
|
1035 | notDeepEqual(actual: any, expected: any, message?: string): NightwatchAPI;
|
1036 |
|
1037 | notDeepStrictEqual(value: any, message?: string): NightwatchAPI;
|
1038 |
|
1039 | notEqual(actual: any, expected: any, message?: string): NightwatchAPI;
|
1040 |
|
1041 | notStrictEqual(value: any, expected: any, message?: string): NightwatchAPI;
|
1042 |
|
1043 | ok(actual: boolean, message?: string): NightwatchAPI;
|
1044 |
|
1045 | strictEqual(value: any, expected: any, message?: string): NightwatchAPI;
|
1046 |
|
1047 | throws(fn: () => void, message?: string): NightwatchAPI;
|
1048 |
|
1049 | /**
|
1050 | * Checks if the page title equals the given value.
|
1051 | * @deprecated in Nightwatch 2.0 and will be removed from future versions.
|
1052 | * @see assert.titleEquals()
|
1053 | * ```
|
1054 | * this.demoTest = function (client) {
|
1055 | * browser.assert.title("Nightwatch.js");
|
1056 | * };
|
1057 | * ```
|
1058 | */
|
1059 | title(expected: string, message?: string): NightwatchAPI;
|
1060 |
|
1061 | /**
|
1062 | * Checks if the page title equals the given value.
|
1063 | * @since 2.0
|
1064 | * ```
|
1065 | * this.demoTest = function (client) {
|
1066 | * browser.assert.titleEquals("Nightwatch.js");
|
1067 | * };
|
1068 | * ```
|
1069 | */
|
1070 | titleEquals(expected: string, message?: string): NightwatchAPI;
|
1071 |
|
1072 | /**
|
1073 | * Checks if the page title equals the given value.
|
1074 | *
|
1075 | * ```
|
1076 | * this.demoTest = function (client) {
|
1077 | * browser.assert.title("Nightwatch.js");
|
1078 | * };
|
1079 | * ```
|
1080 | */
|
1081 | titleContains(expected: string, message?: string): NightwatchAPI;
|
1082 |
|
1083 | /**
|
1084 | * Checks if the current URL contains the given value.
|
1085 | *
|
1086 | * ```
|
1087 | * this.demoTest = function (client) {
|
1088 | * browser.assert.urlContains('google');
|
1089 | * };
|
1090 | * ```
|
1091 | */
|
1092 | urlContains(expectedText: string, message?: string): NightwatchAPI;
|
1093 |
|
1094 | /**
|
1095 | * Checks if the current url equals the given value.
|
1096 | *
|
1097 | * ```
|
1098 | * this.demoTest = function (client) {
|
1099 | * browser.assert.urlEquals('https://www.google.com');
|
1100 | * };
|
1101 | * ```
|
1102 | */
|
1103 | urlEquals(expected: string, message?: string): NightwatchAPI;
|
1104 |
|
1105 | /**
|
1106 | * Checks if the given form element's value equals the expected value.
|
1107 | *
|
1108 | * ```
|
1109 | * this.demoTest = function (client) {
|
1110 | * browser.assert.value("form.login input[type=text]", "username");
|
1111 | * };
|
1112 | * ```
|
1113 | */
|
1114 | value(selector: string | ElementProperties, expectedText: string, message?: string): NightwatchAPI;
|
1115 |
|
1116 | /**
|
1117 | * Checks if the given form element's value contains the expected value.
|
1118 | *
|
1119 | * ```
|
1120 | * this.demoTest = function (client) {
|
1121 | * browser.assert.valueContains("form.login input[type=text]", "username");
|
1122 | * };
|
1123 | * ```
|
1124 | */
|
1125 | valueContains(selector: string | ElementProperties, expectedText: string, message?: string): NightwatchAPI;
|
1126 |
|
1127 | /**
|
1128 | * Checks if the given element is visible on the page.
|
1129 | *
|
1130 | * ```
|
1131 | * this.demoTest = function (client) {
|
1132 | * browser.assert.visible(".should_be_visible");
|
1133 | * };
|
1134 | * ```
|
1135 | */
|
1136 | visible(selector: string | ElementProperties, message?: string): NightwatchAPI;
|
1137 |
|
1138 | /**
|
1139 | * Checks if the given element is selected.
|
1140 | *
|
1141 | * @example
|
1142 | * this.demoTest = function (browser) {
|
1143 | * browser.assert.selected('.should_be_selected');
|
1144 | * browser.assert.selected({selector: '.should_be_selected'});
|
1145 | * browser.assert.selected({selector: '.should_be_selected', suppressNotFoundErrors: true});
|
1146 | * };
|
1147 | */
|
1148 | selected(selector: string | ElementProperties, message?: string): NightwatchAPI;
|
1149 |
|
1150 | /**
|
1151 | * Checks if the given element is enabled (as indicated by the 'disabled' attribute).
|
1152 | *
|
1153 | * @example
|
1154 | * this.demoTest = function (browser) {
|
1155 | * browser.assert.enabled('.should_be_enabled');
|
1156 | * browser.assert.enabled({selector: '.should_be_enabled'});
|
1157 | * browser.assert.enabled({selector: '.should_be_enabled', suppressNotFoundErrors: true});
|
1158 | * };
|
1159 | */
|
1160 | enabled(selector: string | ElementProperties, message?: string): NightwatchAPI;
|
1161 |
|
1162 | /**
|
1163 | * Checks if the specified DOM property of a given element has the expected value.
|
1164 | * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
|
1165 | * If the result value is JSON object or array, a deep equality comparison will be performed.
|
1166 | */
|
1167 | domPropertyEquals(
|
1168 | selector: string | ElementProperties,
|
1169 | domProperty: string,
|
1170 | expected: string | number,
|
1171 | msg?: string,
|
1172 | ): NightwatchAPI;
|
1173 |
|
1174 | /**
|
1175 | * Checks if the specified DOM property of a given element has the expected value.
|
1176 | * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
|
1177 | * Several properties can be specified (either as an array or command-separated list). Nightwatch will check each one for presence.
|
1178 | */
|
1179 | domPropertyContains(
|
1180 | selector: string | ElementProperties,
|
1181 | domProperty: string,
|
1182 | expected: string | number,
|
1183 | msg?: string,
|
1184 | ): NightwatchAPI;
|
1185 |
|
1186 | NightwatchAssertionsError: NightwatchAssertionsError;
|
1187 | }
|
1188 |
|
1189 | export interface ElementProperties {
|
1190 | /**
|
1191 | * the element selector name
|
1192 | *
|
1193 | * @example
|
1194 | * '@searchBar'
|
1195 | */
|
1196 | selector: string;
|
1197 |
|
1198 | /**
|
1199 | * locator strategy can be one of
|
1200 | * - css selector
|
1201 | * - link text
|
1202 | * - partial link text
|
1203 | * - tag name
|
1204 | * - xpath
|
1205 | *
|
1206 | * @example
|
1207 | * 'css selector'
|
1208 | */
|
1209 | locateStrategy?: LocateStrategy;
|
1210 |
|
1211 | /**
|
1212 | * used to target a specific element in a query that results in multiple elements returned. Normally,
|
1213 | * only the first element is used (index = 0) but using the index property, you can specify any element within the result.
|
1214 | */
|
1215 | index?: number;
|
1216 |
|
1217 | /**
|
1218 | * used to overwrite this setting when using waitForElement* commands.
|
1219 | */
|
1220 | abortOnFailure?: boolean;
|
1221 |
|
1222 | /**
|
1223 | * used to overwrite the default timeout for when using waitForElement* commands or assertions.
|
1224 | */
|
1225 | timeout?: number;
|
1226 |
|
1227 | /**
|
1228 | * used to overwrite the default retry interval for when using waitForElement* commands or assertions.
|
1229 | */
|
1230 | retryInterval?: number;
|
1231 |
|
1232 | /**
|
1233 | * Some element commands like .click() or .getText() will throw a NoSuchElement error if the element cannot be located, causing the test to fail.
|
1234 | * If this option is set to true then this error is ignored.
|
1235 | */
|
1236 | suppressNotFoundErrors?: boolean;
|
1237 | }
|
1238 |
|
1239 | export interface NightwatchTypedCallbackResult<T> {
|
1240 | status: 0;
|
1241 | value: T;
|
1242 | error: Error;
|
1243 | }
|
1244 | export interface NightwatchCallbackResultError {
|
1245 | status: 1; // we cannot use `number` so giving it a "symbolic" value allows to disjoint the union
|
1246 | value: {
|
1247 | message: string;
|
1248 | screen: string;
|
1249 | class: string;
|
1250 | stackTrace: Array<{
|
1251 | fileName: string;
|
1252 | lineNumber: number;
|
1253 | className: string;
|
1254 | methodName: string;
|
1255 | }>;
|
1256 | };
|
1257 | state: Error | string;
|
1258 | }
|
1259 |
|
1260 | export type NightwatchCallbackResult<T> = NightwatchTypedCallbackResult<T> | NightwatchCallbackResultError;
|
1261 |
|
1262 | export interface NightwatchLogEntry {
|
1263 | /**
|
1264 | * The log entry message.
|
1265 | */
|
1266 | message: string;
|
1267 |
|
1268 | /**
|
1269 | * The time stamp of log entry in seconds.
|
1270 | */
|
1271 | opt_timestamp: number;
|
1272 |
|
1273 | /**
|
1274 | * The log type, if known.
|
1275 | */
|
1276 | opt_type?: string;
|
1277 |
|
1278 | /**
|
1279 | * Severity level
|
1280 | */
|
1281 | level: 'ALL' | 'DEBUG' | 'FINE' | 'FINER' | 'FINEST' | 'INFO' | 'OFF' | 'SEVERE' | 'WARNING' | Level | number;
|
1282 | }
|
1283 |
|
1284 | export interface Level {
|
1285 | /**
|
1286 | * the level's name.
|
1287 | */
|
1288 | name: string;
|
1289 |
|
1290 | /**
|
1291 | * the level's numeric value.
|
1292 | */
|
1293 | level: number;
|
1294 | }
|
1295 |
|
1296 | export interface NightwatchKeys {
|
1297 | /** Releases all held modifier keys. */
|
1298 | NULL: string;
|
1299 | /** OS-specific keystroke sequence that performs a cancel action. */
|
1300 | CANCEL: string;
|
1301 | /** The help key. This key only appears on older Apple keyboards in place of the Insert key. */
|
1302 | HELP: string;
|
1303 | /** The backspace key. */
|
1304 | BACK_SPACE: string;
|
1305 | /** The tab key. */
|
1306 | TAB: string;
|
1307 | /** The clear key. This key only appears on full-size Apple keyboards in place of Num Lock key. */
|
1308 | CLEAR: string;
|
1309 | /** The return key. */
|
1310 | RETURN: string;
|
1311 | /** The enter (numpad) key. */
|
1312 | ENTER: string;
|
1313 | /** The shift key. */
|
1314 | SHIFT: string;
|
1315 | /** The control key. */
|
1316 | CONTROL: string;
|
1317 | /** The alt key. */
|
1318 | ALT: string;
|
1319 | /** The pause key. */
|
1320 | PAUSE: string;
|
1321 | /** The escape key. */
|
1322 | ESCAPE: string;
|
1323 |
|
1324 | /** The space bar. */
|
1325 | SPACE: string;
|
1326 | /** The page up key. */
|
1327 | PAGEUP: string;
|
1328 | /** The page down key. */
|
1329 | PAGEDOWN: string;
|
1330 | /** The end key. */
|
1331 | END: string;
|
1332 | /** The home key. */
|
1333 | HOME: string;
|
1334 | /** The left arrow. */
|
1335 | ARROW_LEFT: string;
|
1336 | LEFT_ARROW: string;
|
1337 | /** The up arrow. */
|
1338 | ARROW_UP: string;
|
1339 | UP_ARROW: string;
|
1340 | /** The right arrow. */
|
1341 | ARROW_RIGHT: string;
|
1342 | RIGHT_ARROW: string;
|
1343 | /** The down arrow. */
|
1344 | ARROW_DOWN: string;
|
1345 | DOWN_ARROW: string;
|
1346 | /** The insert key. */
|
1347 | INSERT: string;
|
1348 | /** The delete key. */
|
1349 | DELETE: string;
|
1350 | /** The semicolon key. */
|
1351 | SEMICOLON: string;
|
1352 | /** The equals key. */
|
1353 | EQUALS: string;
|
1354 |
|
1355 | /** The numpad zero key. */
|
1356 | NUMPAD0: string;
|
1357 | /** The numpad one key. */
|
1358 | NUMPAD1: string;
|
1359 | /** The numpad two key. */
|
1360 | NUMPAD2: string;
|
1361 | /** The numpad three key. */
|
1362 | NUMPAD3: string;
|
1363 | /** The numpad four key. */
|
1364 | NUMPAD4: string;
|
1365 | /** The numpad five key. */
|
1366 | NUMPAD5: string;
|
1367 | /** The numpad six key. */
|
1368 | NUMPAD6: string;
|
1369 | /** The numpad seven key. */
|
1370 | NUMPAD7: string;
|
1371 | /** The numpad eight key. */
|
1372 | NUMPAD8: string;
|
1373 | /** The numpad nine key. */
|
1374 | NUMPAD9: string;
|
1375 |
|
1376 | /** The numpad multiply (*) key. */
|
1377 | MULTIPLY: string;
|
1378 | /** The numpad add (+) key. */
|
1379 | ADD: string;
|
1380 | /** The numpad separator (=) key. */
|
1381 | SEPARATOR: string;
|
1382 | /** The numpad subtract (-) key. */
|
1383 | SUBTRACT: string;
|
1384 | /** The numpad decimal (.) key. */
|
1385 | DECIMAL: string;
|
1386 | /** The numpad divide (/) key. */
|
1387 | DIVIDE: string;
|
1388 |
|
1389 | /** The F1 key. */
|
1390 | F1: string;
|
1391 | /** The F2 key. */
|
1392 | F2: string;
|
1393 | /** The F3 key. */
|
1394 | F3: string;
|
1395 | /** The F4 key. */
|
1396 | F4: string;
|
1397 | /** The F5 key. */
|
1398 | F5: string;
|
1399 | /** The F6 key. */
|
1400 | F6: string;
|
1401 | /** The F7 key. */
|
1402 | F7: string;
|
1403 | /** The F8 key. */
|
1404 | F8: string;
|
1405 | /** The F9 key. */
|
1406 | F9: string;
|
1407 | /** The F10 key. */
|
1408 | F10: string;
|
1409 | /** The F11 key. */
|
1410 | F11: string;
|
1411 | /** The F12 key. */
|
1412 | F12: string;
|
1413 | /** The meta (Windows) key. */
|
1414 | META: string;
|
1415 | /** The command (⌘) key. */
|
1416 | COMMAND: string;
|
1417 | }
|
1418 |
|
1419 | export type NightwatchPage = {
|
1420 | [name: string]: () => EnhancedPageObject<any, any, any>;
|
1421 | } & {
|
1422 | [name: string]: NightwatchPage;
|
1423 | };
|
1424 |
|
1425 | export interface NightwatchAPI extends SharedCommands, WebDriverProtocol, NightwatchCustomCommands {
|
1426 | baseURL: string;
|
1427 | assert: NightwatchAssertions;
|
1428 | expect: Expect;
|
1429 | verify: NightwatchAssertions;
|
1430 |
|
1431 | page: NightwatchPage & NightwatchCustomPageObjects;
|
1432 |
|
1433 | /**
|
1434 | * SessionId of the session used by the Nightwatch api.
|
1435 | */
|
1436 | sessionId: string;
|
1437 |
|
1438 | /**
|
1439 | * Override the sessionId used by Nightwatch client with another session id.
|
1440 | */
|
1441 | setSessionId(sessionId: string): this;
|
1442 |
|
1443 | options: NightwatchTestOptions;
|
1444 |
|
1445 | Keys: NightwatchKeys;
|
1446 |
|
1447 | currentTest: NightwatchTestSuite;
|
1448 |
|
1449 | globals: NightwatchGlobals;
|
1450 |
|
1451 | launchUrl: string;
|
1452 | launch_url: string;
|
1453 | }
|
1454 |
|
1455 | // tslint:disable-next-line:no-empty-interface
|
1456 | export interface NightwatchCustomCommands {}
|
1457 |
|
1458 | // tslint:disable-next-line:no-empty-interface
|
1459 | export interface NightwatchCustomAssertions {}
|
1460 |
|
1461 | // tslint:disable-next-line:no-empty-interface
|
1462 | export interface NightwatchCustomPageObjects {}
|
1463 |
|
1464 | export interface NightwatchBrowser
|
1465 | extends NightwatchAPI,
|
1466 | NightwatchComponentTestingCommands,
|
1467 | NightwatchCustomCommands {}
|
1468 |
|
1469 | export interface NightwatchComponentTestingCommands {
|
1470 | importScript(scriptPath: string, options: { scriptType: string; componentTyp: string }, callback: () => void): this;
|
1471 | mountReactComponent(componentPath: string, props?: string | (() => void), callback?: () => void): this;
|
1472 | mountVueComponent(componentPath: string, options?: any, callback?: () => void): this;
|
1473 | launchComponentRenderer(): this;
|
1474 | }
|
1475 |
|
1476 | // tslint:disable-next-line
|
1477 | export interface NightwatchElement extends WebElement {}
|
1478 |
|
1479 | export type NightwatchTest = (browser?: NightwatchBrowser) => void;
|
1480 | export interface NightwatchTestFunctions {
|
1481 | before?: NightwatchTestHook | undefined;
|
1482 | after?: NightwatchTestHook | undefined;
|
1483 | beforeEach?: NightwatchTestHook | undefined;
|
1484 | afterEach?: NightwatchTestHook | undefined;
|
1485 | '@tags'?: string | string[] | undefined;
|
1486 | '@disabled'?: boolean | undefined;
|
1487 | [key: string]: any;
|
1488 | }
|
1489 |
|
1490 | export type NightwatchTestHook = GlobalNightwatchTestHookEach | GlobalNightwatchTestHook;
|
1491 |
|
1492 | export type GlobalNightwatchTestHookEach = (browser: NightwatchBrowser, done: (err?: any) => void) => void;
|
1493 |
|
1494 | export type GlobalNightwatchTestHook = (done: (err?: any) => void) => void;
|
1495 |
|
1496 | export interface NightwatchTestHooks extends NightwatchGlobals {
|
1497 | before?: GlobalNightwatchTestHook | undefined;
|
1498 | after?: GlobalNightwatchTestHook | undefined;
|
1499 | beforeEach?: GlobalNightwatchTestHookEach | undefined;
|
1500 | afterEach?: GlobalNightwatchTestHookEach | undefined;
|
1501 | }
|
1502 |
|
1503 | export function element(locator: string | ElementProperties | By | WebElement, options?: any): WebElement;
|
1504 |
|
1505 | export type NightwatchTests = NightwatchTestFunctions | NightwatchTestHooks;
|
1506 |
|
1507 | export class DescribeInstance {
|
1508 | '[instance]': any;
|
1509 | '[attributes]': {};
|
1510 | '[client]': NightwatchClient;
|
1511 | name(): string;
|
1512 | tags(): string | string[];
|
1513 | unitTest(): boolean;
|
1514 | endSessionOnFail(): boolean;
|
1515 | skipTestcasesOnFail(): boolean;
|
1516 | disabled(): boolean;
|
1517 | desiredCapabilities(): NightwatchDesiredCapabilities;
|
1518 | page(): any;
|
1519 | globals(): NightwatchGlobals;
|
1520 | settings(): NightwatchOptions;
|
1521 | argv(): any;
|
1522 | timeout(value: number): void;
|
1523 | waitForTimeout(value: number): number | void;
|
1524 | waitForRetryInterval(value: number): number | void;
|
1525 | retryInterval(value: number): void;
|
1526 | retries(n: any): void;
|
1527 | suiteRetries(n: any): void;
|
1528 | define(name: any, value: any): any;
|
1529 | }
|
1530 |
|
1531 | interface SuiteFunction {
|
1532 | (title: string, fn?: (this: DescribeInstance) => void): this;
|
1533 | only: ExclusiveSuiteFunction;
|
1534 | skip: PendingSuiteFunction;
|
1535 | }
|
1536 |
|
1537 | interface ExclusiveSuiteFunction {
|
1538 | (title: string, fn?: (this: DescribeInstance) => void): this;
|
1539 | }
|
1540 |
|
1541 | interface PendingSuiteFunction {
|
1542 | (title: string, fn: (this: DescribeInstance) => void): this | void;
|
1543 | }
|
1544 |
|
1545 | interface ExclusiveTestFunction {
|
1546 | (fn: NormalFunc | AsyncFunc): this;
|
1547 | (title: string, fn?: NormalFunc | AsyncFunc): this;
|
1548 | }
|
1549 |
|
1550 | interface PendingTestFunction {
|
1551 | (fn: NormalFunc | AsyncFunc): this;
|
1552 | (title: string, fn?: NormalFunc | AsyncFunc): this;
|
1553 | }
|
1554 |
|
1555 | type NormalFunc = (this: DescribeInstance) => any;
|
1556 | type AsyncFunc = (this: DescribeInstance) => PromiseLike<any>;
|
1557 | interface TestFunction {
|
1558 | (fn: NormalFunc | AsyncFunc): this;
|
1559 | (title: string, fn?: NormalFunc | AsyncFunc): this;
|
1560 | only: ExclusiveTestFunction;
|
1561 | skip: PendingTestFunction;
|
1562 | retries(n: number): void;
|
1563 | }
|
1564 |
|
1565 | export const describe: SuiteFunction;
|
1566 | export const xdescribe: PendingSuiteFunction;
|
1567 | export const context: SuiteFunction;
|
1568 | export const xcontext: PendingSuiteFunction;
|
1569 | export const test: TestFunction;
|
1570 | export const it: TestFunction;
|
1571 | export const xit: PendingTestFunction;
|
1572 | export const specify: TestFunction;
|
1573 | export const xspecify: PendingTestFunction;
|
1574 | export const before: GlobalNightwatchTestHook;
|
1575 | export const after: GlobalNightwatchTestHook;
|
1576 | export const beforeEach: GlobalNightwatchTestHookEach;
|
1577 | export const afterEach: GlobalNightwatchTestHookEach;
|
1578 | /**
|
1579 | * Performs an assertion
|
1580 | *
|
1581 | */
|
1582 | export type NightwatchAssert = (
|
1583 | passed: boolean,
|
1584 | receivedValue?: any,
|
1585 | expectedValue?: any,
|
1586 | message?: string,
|
1587 | abortOnFailure?: boolean,
|
1588 | originalStackTrace?: string,
|
1589 | ) => void;
|
1590 |
|
1591 | /**
|
1592 | * Abstract assertion class that will subclass all defined assertions
|
1593 | *
|
1594 | * All assertions must implement the following api:
|
1595 | *
|
1596 | * - @param {T|function} expected
|
1597 | * - @param {string} message
|
1598 | * - @param {function} pass
|
1599 | * - @param {function} value
|
1600 | * - @param {function} command
|
1601 | * - @param {function} - Optional failure
|
1602 | */
|
1603 | export interface NightwatchAssertion<T, U = any> {
|
1604 | expected: (() => T) | T;
|
1605 | message: string;
|
1606 | pass(value: T): any;
|
1607 | value(result: U): T;
|
1608 | command(callback: (result: U) => void): this;
|
1609 | failure?(result: U): boolean;
|
1610 | api: NightwatchAPI;
|
1611 | client: NightwatchClient;
|
1612 | }
|
1613 |
|
1614 | export interface NightwatchClient {
|
1615 | api: NightwatchAPI;
|
1616 | locateStrategy: LocateStrategy;
|
1617 | options: NightwatchOptions;
|
1618 | // TODO: Add reporter
|
1619 | // reporter: reporte
|
1620 | sessionID: string;
|
1621 | settings: NightwatchOptions;
|
1622 | }
|
1623 |
|
1624 | export interface CreateClientParams {
|
1625 | browserName: string | null;
|
1626 | headless?: boolean;
|
1627 | silent?: boolean;
|
1628 | output?: boolean;
|
1629 | useAsync?: boolean;
|
1630 | env?: string;
|
1631 | timeout?: number;
|
1632 | parallel?: boolean;
|
1633 | reporter?: null;
|
1634 | globals?: any;
|
1635 | devtools?: boolean;
|
1636 | debug?: boolean;
|
1637 | enable_global_apis?: boolean;
|
1638 | config?: string;
|
1639 | }
|
1640 |
|
1641 | export interface Nightwatch {
|
1642 | cli(callback: any): this;
|
1643 | client(settings: NightwatchOptions, reporter?: any, argv?: {}): this;
|
1644 | createClient({
|
1645 | headless,
|
1646 | silent,
|
1647 | output,
|
1648 | useAsync,
|
1649 | env,
|
1650 | timeout,
|
1651 | parallel,
|
1652 | reporter,
|
1653 | browserName,
|
1654 | globals,
|
1655 | devtools,
|
1656 | debug,
|
1657 | enable_global_apis,
|
1658 | config,
|
1659 | }: CreateClientParams): this;
|
1660 | cliRunner(argv?: {}): this;
|
1661 | initClient(opts: any): this;
|
1662 | runner(argv?: {}, done?: () => void, settings?: {}): this;
|
1663 | runTests(testSource: string | string[], settings?: any, ...args: any[]): any;
|
1664 | api: NightwatchAPI;
|
1665 | assert: NightwatchAssertions;
|
1666 | expect: Expect;
|
1667 | verify: NightwatchAssertions;
|
1668 | }
|
1669 |
|
1670 | export type LocateStrategy =
|
1671 | | 'class name'
|
1672 | | 'css selector'
|
1673 | | 'id'
|
1674 | | 'name'
|
1675 | | 'link text'
|
1676 | | 'partial link text'
|
1677 | | 'tag name'
|
1678 | | 'xpath';
|
1679 |
|
1680 | /**
|
1681 | * #### [Enhanced Element Instances](https://github.com/nightwatchjs/nightwatch/wiki/Page-Object-API#enhanced-element-instances)
|
1682 | * Element instances encapsulate the definition used to handle element selectors.
|
1683 | * Generally you won't need to access them directly,
|
1684 | * instead referring to them using their `@`-prefixed names for selector arguments,
|
1685 | * but they are available through a page object or section's elements property.
|
1686 | */
|
1687 | export interface EnhancedElementInstance<T> {
|
1688 | /**
|
1689 | * The name of the element as defined by its key in the parent section or the page object's `elements` definition.
|
1690 | * This is the same name used with the `@` prefix in selector arguments for page object commands that refer to the element.
|
1691 | */
|
1692 | name: string;
|
1693 |
|
1694 | /**
|
1695 | * The locate strategy to be used with `selector` when finding the element within the DOM.
|
1696 | */
|
1697 | locateStrategy: LocateStrategy;
|
1698 |
|
1699 | /**
|
1700 | * A reference to the parent object instance.
|
1701 | * This is the parent section or the page object that contained the definition for this object.
|
1702 | */
|
1703 | parent: T;
|
1704 |
|
1705 | /**
|
1706 | * The selector string used to find the element in the DOM.
|
1707 | */
|
1708 | selector: string;
|
1709 | }
|
1710 |
|
1711 | export type EnhancedSectionInstance<
|
1712 | Commands = {},
|
1713 | Elements = {},
|
1714 | Sections extends EnhancedPageObjectSections = {},
|
1715 | > = EnhancedPageObject<Commands, Elements, Sections>;
|
1716 |
|
1717 | export interface EnhancedPageObjectSections {
|
1718 | [name: string]: EnhancedSectionInstance<any, any, any>;
|
1719 | }
|
1720 |
|
1721 | /**
|
1722 | * #### [Enhanced Page Object Instances](https://github.com/nightwatchjs/nightwatch/wiki/Page-Object-API#enhanced-page-object-instances)
|
1723 | * 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.
|
1724 | * ```
|
1725 | * var myPageObject = browser.page.MyPage(); // defined in MyPage.js module
|
1726 | * ```
|
1727 | * Every time a factory function like MyPage above is called, a new instance of the page object is instantiated.
|
1728 | */
|
1729 | export type EnhancedPageObject<
|
1730 | Commands = {},
|
1731 | Elements = {},
|
1732 | Sections extends EnhancedPageObjectSections = {},
|
1733 | > = Nightwatch &
|
1734 | SharedCommands &
|
1735 | NightwatchCustomCommands &
|
1736 | Commands & {
|
1737 | /**
|
1738 | * 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.
|
1739 | */
|
1740 | elements: {
|
1741 | [name: string]: EnhancedElementInstance<EnhancedPageObject<Commands, Elements, Sections>>;
|
1742 | };
|
1743 |
|
1744 | section: Sections;
|
1745 |
|
1746 | /**
|
1747 | * The name of the page object as defined by its module name (not including the extension).
|
1748 | * This is the same name used to access the `page` object factory from the page reference in the command API.
|
1749 | */
|
1750 | name: string;
|
1751 |
|
1752 | /**
|
1753 | * This command is an alias to url and also a convenience method because when called without any arguments
|
1754 | * it performs a call to .url() with passing the value of `url` property on the page object.
|
1755 | * Uses `url` protocol command.
|
1756 | */
|
1757 | navigate(url?: string, callback?: () => void): EnhancedPageObject<Commands, Elements, Sections>;
|
1758 | };
|
1759 |
|
1760 | export interface Cookie {
|
1761 | name: string;
|
1762 | value: string;
|
1763 | path: string | undefined;
|
1764 | domain: string | undefined;
|
1765 | secure: boolean | undefined;
|
1766 | expiry: Date | number | undefined;
|
1767 | httpOnly: boolean | undefined;
|
1768 | }
|
1769 |
|
1770 | export interface SharedCommands extends ClientCommands, ElementCommands {}
|
1771 |
|
1772 | export type windowSizeAndPosition = { offsetX: number; offsetY: number } | { height: number; width: number };
|
1773 | export interface ClientCommands {
|
1774 | /**
|
1775 | * Close the current window. This can be useful when you're working with multiple windows open (e.g. an OAuth login).
|
1776 | * Uses `window` protocol command.
|
1777 | *
|
1778 | * @example
|
1779 | * this.demoTest = function () {
|
1780 | * browser.closeWindow();
|
1781 | * };
|
1782 | *
|
1783 | * @see window
|
1784 | */
|
1785 | closeWindow(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void): this;
|
1786 |
|
1787 | /**
|
1788 | * Delete the cookie with the given name. This command is a no-op if there is no such cookie visible to the current page.
|
1789 | *
|
1790 | * @example
|
1791 | * this.demoTest = function() {
|
1792 | * browser.deleteCookie("test_cookie", function() {
|
1793 | * // do something more in here
|
1794 | * });
|
1795 | * }
|
1796 | *
|
1797 | * @see cookie
|
1798 | */
|
1799 | deleteCookie(
|
1800 | cookieName: string,
|
1801 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
1802 | ): this;
|
1803 |
|
1804 | /**
|
1805 | * Delete all cookies visible to the current page.
|
1806 | *
|
1807 | * @example
|
1808 | * this.demoTest = function() {
|
1809 | * browser.deleteCookies(function() {
|
1810 | * // do something more in here
|
1811 | * });
|
1812 | * }
|
1813 | *
|
1814 | * @see cookie
|
1815 | */
|
1816 | deleteCookies(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void): this;
|
1817 |
|
1818 | /**
|
1819 | * Ends the session. Uses session protocol command.
|
1820 | *
|
1821 | * @example
|
1822 | * this.demoTest = function () {
|
1823 | * browser.end();
|
1824 | * };
|
1825 | *
|
1826 | * @see session
|
1827 | */
|
1828 | end(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void): this;
|
1829 |
|
1830 | /**
|
1831 | * Retrieve a single cookie visible to the current page. The cookie is returned as a cookie JSON object,
|
1832 | * as defined [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).
|
1833 | *
|
1834 | * Uses `cookie` protocol command.
|
1835 | *
|
1836 | * @example
|
1837 | * this.demoTest = function() {
|
1838 | * browser.getCookie(name, function callback(result) {
|
1839 | * this.assert.equal(result.value, '123456');
|
1840 | * this.assert.equals(result.name, 'test_cookie');
|
1841 | * });
|
1842 | * }
|
1843 | *
|
1844 | * @see cookie
|
1845 | */
|
1846 | getCookie(name: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Cookie>) => void): this;
|
1847 |
|
1848 | /**
|
1849 | * Retrieve all cookies visible to the current page. The cookies are returned as an array of cookie JSON object,
|
1850 | * as defined [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).
|
1851 | *
|
1852 | * Uses `cookie` protocol command.
|
1853 | *
|
1854 | * @example
|
1855 | * this.demoTest = function() {
|
1856 | * browser.getCookies(function callback(result) {
|
1857 | * this.assert.equal(result.value.length, 1);
|
1858 | * this.assert.equals(result.value[0].name, 'test_cookie');
|
1859 | * });
|
1860 | * }
|
1861 | *
|
1862 | * @see cookie
|
1863 | */
|
1864 | getCookies(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Cookie[]>) => void): this;
|
1865 |
|
1866 | /**
|
1867 | * Gets a log from Selenium.
|
1868 | *
|
1869 | * @example
|
1870 | * this.demoTest = function() {
|
1871 | * this.getLog('browser', function(logEntriesArray) {
|
1872 | * console.log('Log length: ' + logEntriesArray.length);
|
1873 | * logEntriesArray.forEach(function(log) {
|
1874 | * console.log('[' + log.level + '] ' + log.timestamp + ' : ' + log.message);
|
1875 | * });
|
1876 | * });
|
1877 | * };
|
1878 | *
|
1879 | * @see getLogTypes
|
1880 | */
|
1881 | getLog(typestring: string, callback?: (this: NightwatchAPI, log: NightwatchLogEntry[]) => void): this;
|
1882 |
|
1883 | /**
|
1884 | * Gets the available log types. More info about log types in WebDriver can be found here: https://github.com/SeleniumHQ/selenium/wiki/Logging
|
1885 | *
|
1886 | * @example
|
1887 | * this.demoTest = function() {
|
1888 | * this.getLogTypes(function(typesArray) {
|
1889 | * console.log(typesArray);
|
1890 | * });
|
1891 | * };
|
1892 | *
|
1893 | * @see sessionLogTypes
|
1894 | */
|
1895 | getLogTypes(
|
1896 | callback?: (
|
1897 | this: NightwatchAPI,
|
1898 | result: Array<'client' | 'driver' | 'browser' | 'server' | 'performance'>,
|
1899 | ) => void,
|
1900 | ): this;
|
1901 |
|
1902 | /**
|
1903 | * Returns the title of the current page. Uses title protocol command.
|
1904 | *
|
1905 | * @example
|
1906 | * this.demoTest = function () {
|
1907 | * browser.getTitle(function(title) {
|
1908 | * this.assert.equal(typeof title, 'string');
|
1909 | * this.assert.equal(title, 'Nightwatch.js');
|
1910 | * });
|
1911 | * };
|
1912 | *
|
1913 | * @see title
|
1914 | */
|
1915 | getTitle(callback?: (this: NightwatchAPI, result?: string) => void): this;
|
1916 |
|
1917 | /**
|
1918 | * This command is an alias to url and also a convenience method when called without any arguments in the sense
|
1919 | * that it performs a call to .url() with passing the value of `launch_url` field from the settings file.
|
1920 | * Uses `url` protocol command.
|
1921 | *
|
1922 | * @example
|
1923 | * this.demoTest = function () {
|
1924 | * browser.init();
|
1925 | * };
|
1926 | *
|
1927 | * @see url
|
1928 | */
|
1929 | init(url?: string): this;
|
1930 |
|
1931 | /**
|
1932 | * Utility command to load an external script into the page specified by url.
|
1933 | *
|
1934 | * @example
|
1935 | * this.demoTest = function() {
|
1936 | * this.injectScript("{script-url}", function() {
|
1937 | * // we're all done here.
|
1938 | * });
|
1939 | * };
|
1940 | */
|
1941 | injectScript(
|
1942 | scriptUrl: string,
|
1943 | id?: string,
|
1944 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
1945 | ): this;
|
1946 |
|
1947 | /**
|
1948 | * Utility command to test if the log type is available.
|
1949 | *
|
1950 | * @example
|
1951 | * this.demoTest = function() {
|
1952 | * browser.isLogAvailable('browser', function(isAvailable) {
|
1953 | * // do something more in here
|
1954 | * });
|
1955 | * }
|
1956 | *
|
1957 | * @see getLogTypes
|
1958 | */
|
1959 | isLogAvailable(typeString: string, callback?: (this: NightwatchAPI, result: boolean) => void): this;
|
1960 |
|
1961 | /**
|
1962 | * Maximizes the current window.
|
1963 | *
|
1964 | * @example
|
1965 | * this.demoTest = function () {
|
1966 | * browser.maximizeWindow();
|
1967 | * };
|
1968 | *
|
1969 | * @see windowMaximize
|
1970 | */
|
1971 | maximizeWindow(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
1972 |
|
1973 | /**
|
1974 | * Suspends the test for the given time in milliseconds. If the milliseconds argument is missing it will suspend the test indefinitely
|
1975 | *
|
1976 | * @example
|
1977 | * this.demoTest = function () {
|
1978 | * browser.pause(1000);
|
1979 | * // or suspend indefinitely
|
1980 | * browser.pause();
|
1981 | * };
|
1982 | */
|
1983 | pause(ms?: number, callback?: (this: NightwatchAPI) => void): this;
|
1984 |
|
1985 | /**
|
1986 | * 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.
|
1987 | *
|
1988 | * The callback signature can have up to two parameters.
|
1989 | * - no parameters: callback runs and perform completes immediately at the end of the execution of the callback.
|
1990 | * - one parameter: allows for asynchronous execution within the callback providing a done callback function for completion as the first argument.
|
1991 | * - two parameters: allows for asynchronous execution with the Nightwatch `api` object passed in as the first argument, followed by the done callback.
|
1992 | *
|
1993 | * @example
|
1994 | * this.demoTest = function () {
|
1995 | * var elementValue;
|
1996 | * browser
|
1997 | * .getValue('.some-element', function(result) {
|
1998 | * elementValue = result.value;
|
1999 | * })
|
2000 | * // other stuff going on ...
|
2001 | * //
|
2002 | * // self-completing callback
|
2003 | * .perform(function() {
|
2004 | * console.log('elementValue', elementValue);
|
2005 | * // without any defined parameters, perform
|
2006 | * // completes immediately (synchronously)
|
2007 | * })
|
2008 | * //
|
2009 | * // asynchronous completion
|
2010 | * .perform(function(done) {
|
2011 | * console.log('elementValue', elementValue);
|
2012 | * // potentially other async stuff going on
|
2013 | * // on finished, call the done callback
|
2014 | * done();
|
2015 | * })
|
2016 | * //
|
2017 | * // asynchronous completion including api (client)
|
2018 | * .perform(function(done) {
|
2019 | * console.log('elementValue', elementValue);
|
2020 | * // similar to before, but now with client
|
2021 | * // potentially other async stuff going on
|
2022 | * // on finished, call the done callback
|
2023 | * done();
|
2024 | * });
|
2025 | * };
|
2026 | */
|
2027 | perform(
|
2028 | callback:
|
2029 | | (() => undefined | Promise<any>)
|
2030 | | ((done: () => void) => void)
|
2031 | | ((client: NightwatchAPI, done: () => void) => void),
|
2032 | ): this;
|
2033 |
|
2034 | /**
|
2035 | * Resizes the current window.
|
2036 | *
|
2037 | * @example
|
2038 | * this.demoTest = function () {
|
2039 | * browser.resizeWindow(1000, 800);
|
2040 | * };
|
2041 | *
|
2042 | * @see windowSize
|
2043 | */
|
2044 | resizeWindow(
|
2045 | width: number,
|
2046 | height: number,
|
2047 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2048 | ): this;
|
2049 |
|
2050 | /**
|
2051 | * Take a screenshot of the current page and saves it as the given filename.
|
2052 | *
|
2053 | * @example
|
2054 | * this.demoTest = function ( ) {
|
2055 | * browser.saveScreenshot('/path/to/fileName.png');
|
2056 | * };
|
2057 | *
|
2058 | * @see screenshot
|
2059 | */
|
2060 | saveScreenshot(
|
2061 | fileName: string,
|
2062 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
2063 | ): this;
|
2064 |
|
2065 | /**
|
2066 | * Set a cookie, specified as a cookie JSON object, as defined [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).
|
2067 | *
|
2068 | * Uses `cookie` protocol command.
|
2069 | *
|
2070 | * @example
|
2071 | * this.demoTest = function() {
|
2072 | * browser.setCookie({
|
2073 | * name : "test_cookie",
|
2074 | * value : "test_value",
|
2075 | * path : "/", (Optional)
|
2076 | * domain : "example.org", (Optional)
|
2077 | * secure : false, (Optional)
|
2078 | * httpOnly : false, // (Optional)
|
2079 | * expiry : 1395002765 // (Optional) time in seconds since midnight, January 1, 1970 UTC
|
2080 | * });
|
2081 | * }
|
2082 | *
|
2083 | * @see cookie
|
2084 | */
|
2085 | setCookie(cookie: Cookie, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
2086 |
|
2087 | /**
|
2088 | * Sets the current window position.
|
2089 | *
|
2090 | * @example
|
2091 | * this.demoTest = function () {
|
2092 | * browser.setWindowPosition(0, 0);
|
2093 | * };
|
2094 | *
|
2095 | * @see windowPosition
|
2096 | */
|
2097 | setWindowPosition(
|
2098 | offsetX: number,
|
2099 | offsetY: number,
|
2100 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2101 | ): this;
|
2102 |
|
2103 | /**
|
2104 | * 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.
|
2105 | *
|
2106 | * Its JSON representation is the following:
|
2107 | * - `x` - window's screenX attribute;
|
2108 | * - `y` - window's screenY attribute;
|
2109 | * - `width` - outerWidth attribute;
|
2110 | * - `height` - outerHeight attribute.
|
2111 | *
|
2112 | * 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.
|
2113 | *
|
2114 | * @example
|
2115 | * module.exports = {
|
2116 | * 'demo test .setWindowRect()': function() {
|
2117 | *
|
2118 | * // Change the screenX and screenY attributes of the window rect.
|
2119 | * browser.setWindowRect({x: 500, y: 500});
|
2120 | *
|
2121 | * // Change the width and height attributes of the window rect.
|
2122 | * browser.setWindowRect({width: 600, height: 300});
|
2123 | *
|
2124 | * // Retrieve the attributes
|
2125 | * browser.setWindowRect(function(result) {
|
2126 | * console.log(result.value);
|
2127 | * });
|
2128 | * },
|
2129 | *
|
2130 | * 'setWindowRect ES6 demo test': async function() {
|
2131 | * await browser.setWindowRect({
|
2132 | * width: 600,
|
2133 | * height: 300,
|
2134 | * x: 100,
|
2135 | * y: 100
|
2136 | * });
|
2137 | * }
|
2138 | * }
|
2139 | *
|
2140 | * @see windowRect
|
2141 | */
|
2142 | setWindowRect(
|
2143 | options: windowSizeAndPosition,
|
2144 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2145 | ): this;
|
2146 |
|
2147 | /**
|
2148 | * Sets the current window position.
|
2149 | *
|
2150 | * @example
|
2151 | * this.demoTest = function () {
|
2152 | * browser.setWindowPosition(0, 0);
|
2153 | * };
|
2154 | *
|
2155 | * @see windowSize
|
2156 | *
|
2157 | */
|
2158 | setWindowSize(
|
2159 | width: number,
|
2160 | height: number,
|
2161 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2162 | ): this;
|
2163 |
|
2164 | /**
|
2165 | * 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.
|
2166 | *
|
2167 | * To find out the window handle use `windowHandles` command
|
2168 | *
|
2169 | * @example
|
2170 | * this.demoTest = function () {
|
2171 | * browser.windowHandles(function(result) {
|
2172 | * var handle = result.value[0];
|
2173 | * browser.switchWindow(handle);
|
2174 | * });
|
2175 | * };
|
2176 | *
|
2177 | * this.demoTestAsync = async function () {
|
2178 | * const result = browser.windowHandles();
|
2179 | * var handle = result.value[0];
|
2180 | * browser.switchWindow(handle);
|
2181 | * };
|
2182 | *
|
2183 | * @see window
|
2184 | */
|
2185 | switchWindow(
|
2186 | handleOrName: string,
|
2187 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2188 | ): this;
|
2189 |
|
2190 | /**
|
2191 | * Change or get the [window rect](https://w3c.github.io/webdriver/#dfn-window-rect).
|
2192 | * This is defined as a dictionary of the `screenX`, `screenY`, `outerWidth` and `outerHeight` attributes of the window.
|
2193 | *
|
2194 | * Its JSON representation is the following:
|
2195 | * - `x` - window's screenX attribute;
|
2196 | * - `y` - window's screenY attribute;
|
2197 | * - `width` - outerWidth attribute;
|
2198 | * - `height` - outerHeight attribute.
|
2199 | *
|
2200 | * 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.
|
2201 | *
|
2202 | * @example
|
2203 | * module.exports = {
|
2204 | * 'demo test .getWindowRect()': function() {
|
2205 | * // Retrieve the attributes
|
2206 | * browser.getWindowRect(function(value) {
|
2207 | * console.log(value);
|
2208 | * });
|
2209 | * },
|
2210 | *
|
2211 | * 'getWindowRect ES6 demo test': async function() {
|
2212 | * const resultValue = await browser.getWindowRect();
|
2213 | * console.log('result value', resultValue);
|
2214 | * }
|
2215 | * }
|
2216 | *
|
2217 | * @see windowRect
|
2218 | */
|
2219 | getWindowRect(
|
2220 | callback?: (
|
2221 | this: NightwatchAPI,
|
2222 | result: NightwatchCallbackResult<{ x: number; y: number; width: number; height: number }>,
|
2223 | ) => void,
|
2224 | ): this;
|
2225 |
|
2226 | /**
|
2227 | * Retrieves the current window size.
|
2228 | *
|
2229 | * For clients which are compatible with the [W3C Webdriver API](https://w3c.github.io/webdriver/), `getWindowSize` is an alias of `getWindowRect`.
|
2230 | *
|
2231 | * The `getWindowRect` command returns both dimensions and position of the window, using the `windowRect` protocol command.
|
2232 | *
|
2233 | * @example
|
2234 | * module.exports = {
|
2235 | * 'demo test .getWindowSize()': function() {
|
2236 | * // Retrieve the attributes
|
2237 | * browser.getWindowSize(function(value) {
|
2238 | * console.log(value);
|
2239 | * });
|
2240 | * },
|
2241 | *
|
2242 | * 'getWindowSize ES6 demo test': async function(browser) {
|
2243 | * const value = await browser.getWindowSize();
|
2244 | * console.log('value', value);
|
2245 | * }
|
2246 | * }
|
2247 | *
|
2248 | */
|
2249 | getWindowSize(
|
2250 | callback?: (
|
2251 | this: NightwatchAPI,
|
2252 | result: NightwatchCallbackResult<{ x: number; y: number; width: number; height: number }>,
|
2253 | ) => void,
|
2254 | ): this;
|
2255 |
|
2256 | /**
|
2257 | * Retrieves the current window position.
|
2258 | *
|
2259 | * For clients which are compatible with the [W3C Webdriver API](https://w3c.github.io/webdriver/), `getWindowPosition` is an alias of `getWindowRect`.
|
2260 | *
|
2261 | * The `getWindowRect` command returns both dimensions and position of the window, using the `windowRect` protocol command.
|
2262 | *
|
2263 | * @example
|
2264 | * module.exports = {
|
2265 | * 'demo test .getWindowPosition()': function(browser) {
|
2266 | * // Retrieve the attributes
|
2267 | * browser.getWindowPosition(function(value) {
|
2268 | * console.log(value);
|
2269 | * });
|
2270 | * },
|
2271 | *
|
2272 | * 'getWindowPosition ES6 demo test': async function(browser) {
|
2273 | * const value = await browser.getWindowPosition();
|
2274 | * console.log('value', value);
|
2275 | * }
|
2276 | * }
|
2277 | *
|
2278 | * @see windowRect
|
2279 | */
|
2280 | getWindowPosition(
|
2281 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ x: number; y: number }>) => void,
|
2282 | ): this;
|
2283 |
|
2284 | /**
|
2285 | * Returns the page source. Uses pageSource protocol command.
|
2286 | *
|
2287 | * @example
|
2288 | * this.demoTest = function (browser) {
|
2289 | * browser.pageSource(function(pageSource) {
|
2290 | * console.log(pageSource);
|
2291 | * });
|
2292 | * };
|
2293 | *
|
2294 | * @see pageSource
|
2295 | */
|
2296 | pageSource(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
2297 |
|
2298 | /**
|
2299 | * Convenience command that adds the specified hash (i.e. url fragment) to the current value of the `launch_url` as set in `nightwatch.json`.
|
2300 | *
|
2301 | * @example
|
2302 | * this.demoTest = function () {
|
2303 | * browser.urlHash('#hashvalue');
|
2304 | * // or
|
2305 | * browser.urlHash('hashvalue');
|
2306 | * };
|
2307 | *
|
2308 | * @see url
|
2309 | */
|
2310 | urlHash(hash: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
2311 |
|
2312 | /**
|
2313 | * Sets the locate strategy for selectors to `css selector`, therefore every following selector needs to be specified as css.
|
2314 | *
|
2315 | * @example
|
2316 | * this.demoTest = function () {
|
2317 | * browser
|
2318 | * .useCss() // we're back to CSS now
|
2319 | * .setValue('input[type=text]', 'nightwatch');
|
2320 | * };
|
2321 | */
|
2322 | useCss(callback?: (this: NightwatchAPI) => void): this;
|
2323 |
|
2324 | /**
|
2325 | * Sets the locate strategy for selectors to xpath, therefore every following selector needs to be specified as xpath.
|
2326 | *
|
2327 | * @example
|
2328 | * this.demoTest = function () {
|
2329 | * browser
|
2330 | * .useXpath() // every selector now must be xpath
|
2331 | * .click("//tr[@data-recordid]/span[text()='Search Text']");
|
2332 | * };
|
2333 | */
|
2334 | useXpath(callback?: (this: NightwatchAPI) => void): this;
|
2335 | }
|
2336 |
|
2337 | export interface ElementCommands {
|
2338 | /**
|
2339 | * Clear a textarea or a text input element's value.
|
2340 | * Starting with v1.1 `clearValue()` will wait for the element to be present (until the specified timeout).
|
2341 | *
|
2342 | * If the element is not found, an error is thrown which will cause the test to fail.
|
2343 | * Starting with `v1.2` you can suppress element not found errors by specifying the `suppressNotFoundErrors` flag.
|
2344 | *
|
2345 | * @example
|
2346 | * module.exports = {
|
2347 | * demoTest() {
|
2348 | * browser.clearValue('#login input[type=text]');
|
2349 | *
|
2350 | * browser.clearValue('#login input[type=text]', function(result) {
|
2351 | * console.log('clearValue result', result);
|
2352 | * });
|
2353 | *
|
2354 | * // with explicit locate strategy
|
2355 | * browser.clearValue('css selector', '#login input[type=text]');
|
2356 | *
|
2357 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
2358 | * browser.clearValue({
|
2359 | * selector: '#login input[type=text]',
|
2360 | * index: 1,
|
2361 | * suppressNotFoundErrors: true
|
2362 | * });
|
2363 | *
|
2364 | * browser.clearValue({
|
2365 | * selector: '#login input[type=text]',
|
2366 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
2367 | * });
|
2368 | * }
|
2369 | * }
|
2370 | *
|
2371 | * @see elementIdClear
|
2372 | */
|
2373 | clearValue(
|
2374 | selector: string | ElementProperties,
|
2375 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2376 | ): this;
|
2377 | clearValue(
|
2378 | using: LocateStrategy,
|
2379 | selector: string | ElementProperties,
|
2380 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2381 | ): this;
|
2382 |
|
2383 | /**
|
2384 | * Simulates a click event on the given DOM element.
|
2385 | * The element is scrolled into view if it is not already pointer-interactable.
|
2386 | * See the WebDriver specification for <a href="https://www.w3.org/TR/webdriver/#element-interactability" target="_blank">element interactability</a>.
|
2387 | *
|
2388 | * @example
|
2389 | * module.exports = {
|
2390 | * demoTest() {
|
2391 | * browser.click('#main ul li a.first');
|
2392 | *
|
2393 | * browser.click('#main ul li a.first', function(result) {
|
2394 | * console.log('Click result', result);
|
2395 | * });
|
2396 | *
|
2397 | * // with explicit locate strategy
|
2398 | * browser.click('css selector', '#main ul li a.first');
|
2399 | *
|
2400 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
2401 | * browser.click({
|
2402 | * selector: '#main ul li a',
|
2403 | * index: 1,
|
2404 | * suppressNotFoundErrors: true
|
2405 | * });
|
2406 | *
|
2407 | * browser.click({
|
2408 | * selector: '#main ul li a.first',
|
2409 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
2410 | * });
|
2411 | * },
|
2412 | *
|
2413 | * demoTestAsync: async function(browser) {
|
2414 | * const result = await browser.click('#main ul li a.first');
|
2415 | * console.log('Click result', result);
|
2416 | * }
|
2417 | * }
|
2418 | *
|
2419 | *
|
2420 | * @see elementIdClick
|
2421 | */
|
2422 | click(
|
2423 | selector: string | ElementProperties,
|
2424 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2425 | ): this;
|
2426 | click(
|
2427 | using: LocateStrategy,
|
2428 | selector: string | ElementProperties,
|
2429 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void,
|
2430 | ): this;
|
2431 |
|
2432 | /**
|
2433 | * Retrieve the value of an attribute for a given DOM element.
|
2434 | *
|
2435 | * @example
|
2436 | * module.exports = {
|
2437 | * demoTest() {
|
2438 | * browser.getAttribute('#main ul li a.first', 'href', function(result) {
|
2439 | * console.log('result', result);
|
2440 | * });
|
2441 | *
|
2442 | * // with explicit locate strategy
|
2443 | * browser.getAttribute('css selector', '#main ul li a.first', 'href', function(result) {
|
2444 | * console.log('result', result);
|
2445 | * });
|
2446 | *
|
2447 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
2448 | * browser.getAttribute({
|
2449 | * selector: '#main ul li a.first',
|
2450 | * index: 1,
|
2451 | * suppressNotFoundErrors: true
|
2452 | * }, 'href', function(result) {
|
2453 | * console.log('result', result);
|
2454 | * });
|
2455 | * },
|
2456 | *
|
2457 | * demoTestAsync: async function(browser) {
|
2458 | * const result = await browser.getAttribute('#main ul li a.first', 'href');
|
2459 | * console.log('attribute', result);
|
2460 | * }
|
2461 | * }
|
2462 | *
|
2463 | * @see elementIdAttribute
|
2464 | */
|
2465 | getAttribute(
|
2466 | selector: string | ElementProperties,
|
2467 | attribute: string,
|
2468 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string | null>) => void,
|
2469 | ): this;
|
2470 | getAttribute(
|
2471 | using: LocateStrategy,
|
2472 | selector: string | ElementProperties,
|
2473 | attribute: string,
|
2474 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string | null>) => void,
|
2475 | ): this;
|
2476 |
|
2477 | /**
|
2478 | * Retrieve the value of a css property for a given DOM element.
|
2479 | *
|
2480 | * @example
|
2481 | * module.exports = {
|
2482 | * demoTest() {
|
2483 | * browser.getCssProperty('#main ul li a.first', 'display', function(result) {
|
2484 | * console.log('result', result);
|
2485 | * });
|
2486 | *
|
2487 | * // with explicit locate strategy
|
2488 | * browser.getCssProperty('css selector', '#main ul li a.first', 'display', function(result) {
|
2489 | * console.log('result', result);
|
2490 | * });
|
2491 | *
|
2492 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
2493 | * browser.getCssProperty({
|
2494 | * selector: '#main ul li a.first',
|
2495 | * index: 1,
|
2496 | * suppressNotFoundErrors: true
|
2497 | * }, 'display', function(result) {
|
2498 | * console.log('result', result);
|
2499 | * });
|
2500 | * },
|
2501 | *
|
2502 | * demoTestAsync: async function(browser) {
|
2503 | * const result = await browser.getCssProperty('#main ul li a.first', 'display');
|
2504 | * console.log('display', result);
|
2505 | * }
|
2506 | * }
|
2507 | *
|
2508 | * @see elementIdCssProperty
|
2509 | */
|
2510 | getCssProperty(
|
2511 | selector: string | ElementProperties,
|
2512 | cssProperty: string,
|
2513 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
2514 | ): this;
|
2515 | getCssProperty(
|
2516 | using: LocateStrategy,
|
2517 | selector: string | ElementProperties,
|
2518 | cssProperty: string,
|
2519 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
2520 | ): this;
|
2521 |
|
2522 | /**
|
2523 | * Determine an element's size in pixels. For W3C Webdriver compatible clients (such as GeckoDriver), this command is equivalent to `getLocation` and both return
|
2524 | * the dimensions and coordinates of the given element:
|
2525 | * - x: X axis position of the top-left corner of the element, in CSS pixels
|
2526 | * - y: Y axis position of the top-left corner of the element, in CSS pixels
|
2527 | * - height: Height of the element’s bounding rectangle in CSS pixels;
|
2528 | * - width: Width of the web element’s bounding rectangle in CSS pixels.
|
2529 | *
|
2530 | * @example
|
2531 | * module.exports = {
|
2532 | * demoTest() {
|
2533 | * browser.getElementSize('#login', function(result) {
|
2534 | * console.log('result', result);
|
2535 | * });
|
2536 | *
|
2537 | * // with explicit locate strategy
|
2538 | * browser.getElementSize('css selector', '#login', function(result) {
|
2539 | * console.log('result', result);
|
2540 | * });
|
2541 | *
|
2542 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
2543 | * browser.getElementSize({
|
2544 | * selector: '#login',
|
2545 | * index: 1,
|
2546 | * suppressNotFoundErrors: true
|
2547 | * }, function(result) {
|
2548 | * console.log('result', result);
|
2549 | * });
|
2550 | * },
|
2551 | *
|
2552 | * demoTestAsync: async function(browser) {
|
2553 | * const result = await browser.getElementSize('#login');
|
2554 | * console.log('classList', result);
|
2555 | * }
|
2556 | * }
|
2557 | *
|
2558 | * @see elementIdSize
|
2559 | */
|
2560 | getElementSize(
|
2561 | selector: string | ElementProperties,
|
2562 | callback?: (
|
2563 | this: NightwatchAPI,
|
2564 | result: NightwatchCallbackResult<{ width: number; height: number; x: number; y: number }>,
|
2565 | ) => void,
|
2566 | ): this;
|
2567 | getElementSize(
|
2568 | using: LocateStrategy,
|
2569 | selector: string | ElementProperties,
|
2570 | callback?: (
|
2571 | this: NightwatchAPI,
|
2572 | result: NightwatchCallbackResult<{ width: number; height: number; x: number; y: number }>,
|
2573 | ) => void,
|
2574 | ): this;
|
2575 |
|
2576 | /**
|
2577 | * 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.
|
2578 | *
|
2579 | * For W3C Webdriver compatible clients (such as GeckoDriver), this command is equivalent to `getElementSize` and both return
|
2580 | * the dimensions and coordinates of the given element:
|
2581 | * - x: X axis position of the top-left corner of the element, in CSS pixels
|
2582 | * - y: Y axis position of the top-left corner of the element, in CSS pixels
|
2583 | * - height: Height of the element’s bounding rectangle in CSS pixels;
|
2584 | * - width: Width of the web element’s bounding rectangle in CSS pixels.
|
2585 | *
|
2586 | * @example
|
2587 | * module.exports = {
|
2588 | * demoTest() {
|
2589 | * browser.getLocation('#login', function(result) {
|
2590 | * console.log('result', result);
|
2591 | * });
|
2592 | *
|
2593 | * // with explicit locate strategy
|
2594 | * browser.getLocation('css selector', '#login', function(result) {
|
2595 | * console.log('result', result);
|
2596 | * });
|
2597 | *
|
2598 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
2599 | * browser.getLocation({
|
2600 | * selector: '#login',
|
2601 | * index: 1,
|
2602 | * suppressNotFoundErrors: true
|
2603 | * }, function(result) {
|
2604 | * console.log('result', result);
|
2605 | * });
|
2606 | * },
|
2607 | *
|
2608 | * demoTestAsync: async function(browser) {
|
2609 | * const result = await browser.getLocation('#login');
|
2610 | * console.log('location', result);
|
2611 | * }
|
2612 | * }
|
2613 | *
|
2614 | * @see elementIdLocation
|
2615 | */
|
2616 | getLocation(
|
2617 | selector: string | ElementProperties,
|
2618 | callback?: (
|
2619 | this: NightwatchAPI,
|
2620 | result: NightwatchCallbackResult<{ x: number; y: number; width: number; height: number }>,
|
2621 | ) => void,
|
2622 | ): this;
|
2623 | getLocation(
|
2624 | using: LocateStrategy,
|
2625 | selector: string | ElementProperties,
|
2626 | callback?: (
|
2627 | this: NightwatchAPI,
|
2628 | result: NightwatchCallbackResult<{ x: number; y: number; width: number; height: number }>,
|
2629 | ) => void,
|
2630 | ): this;
|
2631 |
|
2632 | /**
|
2633 | * Determine an element's location on the screen once it has been scrolled into view. Uses `elementIdLocationInView` protocol command.
|
2634 | *
|
2635 | * @example
|
2636 | * this.demoTest = function () {
|
2637 | * browser.getLocationInView("#main ul li a.first", function(result) {
|
2638 | * this.assert.equal(typeof result, "object");
|
2639 | * this.assert.equal(result.status, 0);
|
2640 | * this.assert.equal(result.value.x, 200);
|
2641 | * this.assert.equal(result.value.y, 200);
|
2642 | * });
|
2643 | * };
|
2644 | *
|
2645 | * @see elementIdLocationInView
|
2646 | */
|
2647 | getLocationInView(
|
2648 | selector: string | ElementProperties,
|
2649 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ x: number; y: number }>) => void,
|
2650 | ): this;
|
2651 | getLocationInView(
|
2652 | using: LocateStrategy,
|
2653 | selector: string | ElementProperties,
|
2654 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ x: number; y: number }>) => void,
|
2655 | ): this;
|
2656 |
|
2657 | /**
|
2658 | * Query for an element's tag name.
|
2659 | *
|
2660 | * @example
|
2661 | * module.exports = {
|
2662 | * demoTest() {
|
2663 | * browser.getTagName('#login', function(result) {
|
2664 | * console.log('result', result);
|
2665 | * });
|
2666 | *
|
2667 | * // with explicit locate strategy
|
2668 | * browser.getTagName('css selector', '#login', function(result) {
|
2669 | * console.log('result', result);
|
2670 | * });
|
2671 | *
|
2672 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
2673 | * browser.getTagName({
|
2674 | * selector: '#login',
|
2675 | * index: 1,
|
2676 | * suppressNotFoundErrors: true
|
2677 | * }, function(result) {
|
2678 | * console.log('result', result);
|
2679 | * });
|
2680 | * },
|
2681 | *
|
2682 | * demoTestAsync: async function(browser) {
|
2683 | * const result = await browser.getTagName('#login');
|
2684 | * console.log('tagName', result);
|
2685 | * }
|
2686 | * }
|
2687 | *
|
2688 | * @see elementIdName
|
2689 | */
|
2690 | getTagName(
|
2691 | selector: string | ElementProperties,
|
2692 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
2693 | ): this;
|
2694 | getTagName(
|
2695 | using: LocateStrategy,
|
2696 | selector: string | ElementProperties,
|
2697 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
2698 | ): this;
|
2699 |
|
2700 | /**
|
2701 | * Returns the visible text for the element.
|
2702 | *
|
2703 | * @example
|
2704 | * module.exports = {
|
2705 | * demoTest() {
|
2706 | * browser.getText('#main ul li a.first', function(result) {
|
2707 | * this.assert.equal(typeof result, 'object);
|
2708 | * this.assert.strictEqual(result.status, 0); // only when using Selenium / JSONWire
|
2709 | * this.assert.equal(result.value, 'nightwatchjs.org');
|
2710 | * });
|
2711 | *
|
2712 | * // with explicit locate strategy
|
2713 | * browser.getText('css selector', '#main ul li a.first', function(result) {
|
2714 | * console.log('getText result', result.value);
|
2715 | * });
|
2716 | *
|
2717 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
2718 | * browser.getText({
|
2719 | * selector: '#main ul li a',
|
2720 | * index: 1
|
2721 | * }, function(result) {
|
2722 | * console.log('getText result', result.value);
|
2723 | * });
|
2724 | *
|
2725 | * browser.getText({
|
2726 | * selector: '#main ul li a.first',
|
2727 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
2728 | * }, function(result) {
|
2729 | * console.log('getText result', result.value);
|
2730 | * });
|
2731 | * },
|
2732 | *
|
2733 | * demoTestAsync: async function() {
|
2734 | * const result = await browser.getText('#main ul li a.first');
|
2735 | * console.log('getText result', result);
|
2736 | * }
|
2737 | * }
|
2738 | *
|
2739 | * @see elementIdText
|
2740 | */
|
2741 | getText(
|
2742 | selector: string | ElementProperties,
|
2743 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
2744 | ): this;
|
2745 | getText(
|
2746 | using: LocateStrategy,
|
2747 | selector: string | ElementProperties,
|
2748 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
2749 | ): this;
|
2750 |
|
2751 | /**
|
2752 | * Returns a form element current value.
|
2753 | *
|
2754 | * @example
|
2755 | * module.exports = {
|
2756 | * demoTest() {
|
2757 | * browser.getValue('#login input[type=text]', function(result) {
|
2758 | * console.log('result', result);
|
2759 | * });
|
2760 | *
|
2761 | * // with explicit locate strategy
|
2762 | * browser.getValue('css selector', '#login input[type=text]', function(result) {
|
2763 | * console.log('result', result);
|
2764 | * });
|
2765 | *
|
2766 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
2767 | * browser.getValue({
|
2768 | * selector: '#login input[type=text]',
|
2769 | * index: 1,
|
2770 | * suppressNotFoundErrors: true
|
2771 | * }, function(result) {
|
2772 | * console.log('result', result);
|
2773 | * });
|
2774 | * },
|
2775 | *
|
2776 | * demoTestAsync: async function() {
|
2777 | * const result = await browser.getValue('#login input[type=text]');
|
2778 | * console.log('Value', result);
|
2779 | * }
|
2780 | * }
|
2781 | *
|
2782 | * @see elementIdValue
|
2783 | */
|
2784 | getValue(
|
2785 | selector: string | ElementProperties,
|
2786 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
2787 | ): this;
|
2788 | getValue(
|
2789 | using: LocateStrategy,
|
2790 | selector: string | ElementProperties,
|
2791 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
2792 | ): this;
|
2793 |
|
2794 | /**
|
2795 | * Determine if an element is currently displayed.
|
2796 | *
|
2797 | * @example
|
2798 | * module.exports = {
|
2799 | * demoTest() {
|
2800 | * browser.isVisible('#main ul li a.first', function(result) {
|
2801 | * this.assert.equal(typeof result, "object");
|
2802 | * this.assert.equal(result.status, 0);
|
2803 | * this.assert.equal(result.value, true);
|
2804 | * });
|
2805 | *
|
2806 | * // with explicit locate strategy
|
2807 | * browser.isVisible('css selector', '#main ul li a.first');
|
2808 | *
|
2809 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
2810 | * browser.isVisible({
|
2811 | * selector: '#main ul li a',
|
2812 | * index: 1,
|
2813 | * suppressNotFoundErrors: true
|
2814 | * });
|
2815 | *
|
2816 | * browser.isVisible({
|
2817 | * selector: '#main ul li a.first',
|
2818 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
2819 | * });
|
2820 | * },
|
2821 | *
|
2822 | * demoTestAsync: async function() {
|
2823 | * const result = await browser.isVisible('#main ul li a.first');
|
2824 | * console.log('isVisible result', result);
|
2825 | * }
|
2826 | * }
|
2827 | *
|
2828 | * @see elementIdDisplayed
|
2829 | */
|
2830 | isVisible(
|
2831 | selector: string | ElementProperties,
|
2832 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
2833 | ): this;
|
2834 | isVisible(
|
2835 | using: LocateStrategy,
|
2836 | selector: string | ElementProperties,
|
2837 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
2838 | ): this;
|
2839 |
|
2840 | /**
|
2841 | * 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.
|
2842 | * If the element is not visible, it will be scrolled into view.
|
2843 | *
|
2844 | * @example
|
2845 | * this.demoTest = function () {
|
2846 | * browser.moveToElement('#main', 10, 10);
|
2847 | * };
|
2848 | *
|
2849 | * @see moveTo
|
2850 | */
|
2851 | moveToElement(
|
2852 | selector: string | ElementProperties,
|
2853 | xoffset: number,
|
2854 | yoffset: number,
|
2855 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2856 | ): this;
|
2857 | moveToElement(
|
2858 | using: LocateStrategy,
|
2859 | selector: string | ElementProperties,
|
2860 | xoffset: number,
|
2861 | yoffset: number,
|
2862 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2863 | ): this;
|
2864 |
|
2865 | /**
|
2866 | * 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.
|
2867 | *
|
2868 | * <div class="alert alert-warning"><strong>setValue</strong> does not clear the existing value of the element. To do so, use the <strong>clearValue()</strong> command.</div>
|
2869 | *
|
2870 | * 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),
|
2871 | * is loaded onto the main Nightwatch instance as `browser.Keys`.
|
2872 | *
|
2873 | * @example
|
2874 | * // send some simple text to an input
|
2875 | * this.demoTest = function () {
|
2876 | * browser.setValue('input[type=text]', 'nightwatch');
|
2877 | * };
|
2878 | * //
|
2879 | * // send some text to an input and hit enter.
|
2880 | * this.demoTest = function () {
|
2881 | * browser.setValue('input[type=text]', ['nightwatch', browser.Keys.ENTER]);
|
2882 | * };
|
2883 | *
|
2884 | * @see elementIdValue
|
2885 | */
|
2886 | setValue(
|
2887 | selector: string | ElementProperties,
|
2888 | inputValue: string | string[],
|
2889 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2890 | ): this;
|
2891 | setValue(
|
2892 | using: LocateStrategy,
|
2893 | selector: string | ElementProperties,
|
2894 | inputValue: string | string[],
|
2895 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2896 | ): this;
|
2897 | /**
|
2898 | * Alias for `setValue`.
|
2899 | *
|
2900 | * Types a key sequence on the DOM element.
|
2901 | * Can be used to send a sequence of key strokes to an element. Any UTF-8 character may be specified.
|
2902 | *
|
2903 | *
|
2904 | * An object map with available keys and their respective UTF-8 characters,
|
2905 | * as defined on [W3C WebDriver draft spec](https://www.w3.org/TR/webdriver/#character-types),
|
2906 | * is loaded onto the main Nightwatch instance as `browser.Keys`.
|
2907 | *
|
2908 | * @example
|
2909 | * // send some simple text to an input
|
2910 | * this.demoTest = function () {
|
2911 | * browser.sendKeys('input[type=text]', 'nightwatch');
|
2912 | * };
|
2913 | * //
|
2914 | * // send some text to an input and hit enter.
|
2915 | * this.demoTest = function () {
|
2916 | * browser.sendKeys('input[type=text]', ['nightwatch', browser.Keys.ENTER]);
|
2917 | * };
|
2918 | *
|
2919 | * @see setValue
|
2920 | */
|
2921 | sendKeys: SharedCommands['setValue'];
|
2922 |
|
2923 | /**
|
2924 | * 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.
|
2925 | *
|
2926 | * @example
|
2927 | * this.demoTest = function () {
|
2928 | * browser.submitForm('form.login');
|
2929 | * };
|
2930 | *
|
2931 | * @see submit
|
2932 | */
|
2933 | submitForm(
|
2934 | selector: string | ElementProperties,
|
2935 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2936 | ): this;
|
2937 | submitForm(
|
2938 | using: LocateStrategy,
|
2939 | selector: string | ElementProperties,
|
2940 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
2941 | ): this;
|
2942 |
|
2943 | /**
|
2944 | * Opposite of `waitForElementPresent`. Waits a given time in milliseconds (default 5000ms)
|
2945 | * for an element to be not present (i.e. removed) in the page before performing
|
2946 | * any other commands or assertions.
|
2947 | * If the element is still present after the specified amount of time, the test fails.
|
2948 | *
|
2949 | * 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.
|
2950 | * Similarly, a default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
2951 | *
|
2952 | * @example
|
2953 | * module.exports = {
|
2954 | * 'demo Test': function() {
|
2955 | * // with default implicit timeout of 5000ms (can be overwritten in settings under 'globals.waitForConditionTimeout')
|
2956 | * browser.waitForElementNotPresent('#dialog');
|
2957 | *
|
2958 | * // specify the locate strategy (css selector/xpath) as the first argument
|
2959 | * browser.waitForElementNotPresent('css selector', '#dialog');
|
2960 | *
|
2961 | * // with explicit timeout (in milliseconds)
|
2962 | * browser.waitForElementNotPresent('#dialog', 1000);
|
2963 | *
|
2964 | * // continue if failed
|
2965 | * browser.waitForElementNotPresent('#dialog', 1000, false);
|
2966 | *
|
2967 | * // with callback
|
2968 | * browser.waitForElementNotPresent('#dialog', 1000, function() {
|
2969 | * // do something while we're here
|
2970 | * });
|
2971 | *
|
2972 | * // with custom output message - the locate strategy is required
|
2973 | * browser.waitForElementNotPresent('css selector', '#dialog', 'The dialog container is removed.');
|
2974 | *
|
2975 | * // with custom Spanish message
|
2976 | * browser.waitForElementNotPresent('#dialog', 1000, 'elemento %s no era presente en %d ms');
|
2977 | *
|
2978 | * // many combinations possible - the message is always the last argument
|
2979 | * browser.waitForElementNotPresent('#dialog', 1000, false, function() {}, 'elemento %s no era presente en %d ms');
|
2980 | * },
|
2981 | *
|
2982 | * 'demo Test with selector objects': function() {
|
2983 | * browser.waitForElementNotPresent({
|
2984 | * selector: '#dialog',
|
2985 | * timeout: 1000
|
2986 | * });
|
2987 | *
|
2988 | * browser.waitForElementNotPresent({
|
2989 | * selector: '#dialog',
|
2990 | * locateStrategy: 'css selector'
|
2991 | * }, 'Custom output message');
|
2992 | *
|
2993 | * browser.waitForElementNotPresent({
|
2994 | * selector: '.container',
|
2995 | * index: 2,
|
2996 | * retryInterval: 100,
|
2997 | * abortOnFailure: true
|
2998 | * });
|
2999 | * }
|
3000 | *
|
3001 | * 'page object demo Test': function () {
|
3002 | * var nightwatch = browser.page.nightwatch();
|
3003 | * nightwatch
|
3004 | * .navigate()
|
3005 | * .assert.titleContains('Nightwatch.js');
|
3006 | *
|
3007 | * nightwatch.api.waitForElementNotPresent('@dialogContainer', function(result) {
|
3008 | * console.log(result);
|
3009 | * });
|
3010 | * }
|
3011 | * }
|
3012 | *
|
3013 | * @see waitForElementPresent
|
3014 | * @since v0.4.0
|
3015 | */
|
3016 | waitForElementNotPresent(
|
3017 | selector: string | ElementProperties,
|
3018 | time?: number,
|
3019 | poll?: number,
|
3020 | abortOnFailure?: boolean,
|
3021 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3022 | message?: string,
|
3023 | ): this;
|
3024 | waitForElementNotPresent(
|
3025 | using: LocateStrategy,
|
3026 | selector: string | ElementProperties,
|
3027 | time?: number,
|
3028 | poll?: number,
|
3029 | abortOnFailure?: boolean,
|
3030 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3031 | message?: string,
|
3032 | ): this;
|
3033 |
|
3034 | /**
|
3035 | * Opposite of `waitForElementVisible`. Waits a given time in milliseconds (default 5000ms)
|
3036 | * for an element to be not visible (i.e. hidden but existing) in the page before
|
3037 | * performing any other commands or assertions.
|
3038 | * If the element fails to be hidden in the specified amount of time, the test fails.
|
3039 | *
|
3040 | * 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.
|
3041 | * Similarly, a default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
3042 | *
|
3043 | * @example
|
3044 | * module.exports = {
|
3045 | * 'demo Test': function() {
|
3046 | * // with default implicit timeout of 5000ms (can be overwritten in settings under 'globals.waitForConditionTimeout')
|
3047 | * browser.waitForElementNotVisible('#dialog');
|
3048 | *
|
3049 | * // specify the locate strategy (css selector/xpath) as the first argument
|
3050 | * browser.waitForElementNotVisible('css selector', '#dialog');
|
3051 | *
|
3052 | * // with explicit timeout (in milliseconds)
|
3053 | * browser.waitForElementNotVisible('#dialog', 1000);
|
3054 | *
|
3055 | * // continue if failed
|
3056 | * browser.waitForElementNotVisible('#dialog', 1000, false);
|
3057 | *
|
3058 | * // with callback
|
3059 | * browser.waitForElementNotVisible('#dialog', 1000, function() {
|
3060 | * // do something while we're here
|
3061 | * });
|
3062 | *
|
3063 | * // with custom output message - the locate strategy is required
|
3064 | * browser.waitForElementNotVisible('css selector', '#dialog', 'The dialog container is not visible.');
|
3065 | *
|
3066 | * // with custom Spanish message
|
3067 | * browser.waitForElementNotVisible('#dialog', 1000, 'elemento %s no era visible en %d ms');
|
3068 | *
|
3069 | * // many combinations possible - the message is always the last argument
|
3070 | * browser.waitForElementNotVisible('#dialog', 1000, false, function() {}, 'elemento %s no era visible en %d ms');
|
3071 | * },
|
3072 | *
|
3073 | * 'demo Test with selector objects': function() {
|
3074 | * browser.waitForElementNotVisible({
|
3075 | * selector: '#dialog',
|
3076 | * timeout: 1000
|
3077 | * });
|
3078 | *
|
3079 | * browser.waitForElementNotVisible({
|
3080 | * selector: '#dialog',
|
3081 | * locateStrategy: 'css selector'
|
3082 | * }, 'Custom output message');
|
3083 | *
|
3084 | * browser.waitForElementNotVisible({
|
3085 | * selector: '.container',
|
3086 | * index: 2,
|
3087 | * retryInterval: 100,
|
3088 | * abortOnFailure: true
|
3089 | * });
|
3090 | * }
|
3091 | *
|
3092 | * 'page object demo Test': function () {
|
3093 | * var nightwatch = browser.page.nightwatch();
|
3094 | * nightwatch
|
3095 | * .navigate()
|
3096 | * .assert.titleContains('Nightwatch.js');
|
3097 | *
|
3098 | * nightwatch.api.waitForElementNotVisible('@mainDialog', function(result) {
|
3099 | * console.log(result);
|
3100 | * });
|
3101 | * }
|
3102 | * }
|
3103 | *
|
3104 | * @since v0.4.0
|
3105 | * @see waitForElementVisible
|
3106 | */
|
3107 | waitForElementNotVisible(
|
3108 | selector: string | ElementProperties,
|
3109 | time?: number,
|
3110 | poll?: number,
|
3111 | abortOnFailure?: boolean,
|
3112 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3113 | message?: string,
|
3114 | ): this;
|
3115 | waitForElementNotVisible(
|
3116 | using: LocateStrategy,
|
3117 | selector: string | ElementProperties,
|
3118 | time?: number,
|
3119 | poll?: number,
|
3120 | abortOnFailure?: boolean,
|
3121 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3122 | message?: string,
|
3123 | ): this;
|
3124 |
|
3125 | /**
|
3126 | * Waits a given time in milliseconds (default 5000ms) for an element to be present in the page before performing any other commands or assertions.
|
3127 | * 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`.
|
3128 | *
|
3129 | * 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.
|
3130 | * Similarly, the default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
3131 | *
|
3132 | * @example
|
3133 | * module.exports = {
|
3134 | * 'demo Test': function() {
|
3135 | * // with default implicit timeout of 5000ms (can be overwritten in settings under 'globals.waitForConditionTimeout')
|
3136 | * browser.waitForElementPresent('#index-container');
|
3137 | *
|
3138 | * // specify the locate strategy (css selector/xpath) as the first argument
|
3139 | * browser.waitForElementPresent('css selector', '#index-container');
|
3140 | *
|
3141 | * // with explicit timeout (in milliseconds)
|
3142 | * browser.waitForElementPresent('#index-container', 1000);
|
3143 | *
|
3144 | * // continue if failed
|
3145 | * browser.waitForElementPresent('#index-container', 1000, false);
|
3146 | *
|
3147 | * // with callback
|
3148 | * browser.waitForElementPresent('#index-container', 1000, function() {
|
3149 | * // do something while we're here
|
3150 | * });
|
3151 | *
|
3152 | * // with custom output message - the locate strategy is required
|
3153 | * browser.waitForElementPresent('css selector', '#index-container', 'The index container is found.');
|
3154 | *
|
3155 | * // with custom Spanish message
|
3156 | * browser.waitForElementPresent('#index-container', 1000, 'elemento %s no era presente en %d ms');
|
3157 | *
|
3158 | * // many combinations possible - the message is always the last argument
|
3159 | * browser.waitForElementPresent('#index-container', 1000, false, function() {}, 'elemento %s no era presente en %d ms');
|
3160 | * },
|
3161 | *
|
3162 | * 'demo Test with selector objects': function() {
|
3163 | * browser.waitForElementPresent({
|
3164 | * selector: '#index-container',
|
3165 | * timeout: 1000
|
3166 | * });
|
3167 | *
|
3168 | * browser.waitForElementPresent({
|
3169 | * selector: '#index-container',
|
3170 | * locateStrategy: 'css selector'
|
3171 | * }, 'Custom output message');
|
3172 | *
|
3173 | * browser.waitForElementPresent({
|
3174 | * selector: '.container',
|
3175 | * index: 2,
|
3176 | * retryInterval: 100,
|
3177 | * abortOnFailure: true
|
3178 | * });
|
3179 | * }
|
3180 | *
|
3181 | * 'page object demo Test': function () {
|
3182 | * var nightwatch = browser.page.nightwatch();
|
3183 | * nightwatch
|
3184 | * .navigate()
|
3185 | * .assert.titleContains('Nightwatch.js');
|
3186 | *
|
3187 | * nightwatch.api.waitForElementPresent('@featuresList', function(result) {
|
3188 | * console.log(result);
|
3189 | * });
|
3190 | * }
|
3191 | * }
|
3192 | *
|
3193 | */
|
3194 | waitForElementPresent(
|
3195 | selector: string | ElementProperties,
|
3196 | time?: number,
|
3197 | poll?: number,
|
3198 | abortOnFailure?: boolean,
|
3199 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3200 | message?: string,
|
3201 | ): this;
|
3202 | waitForElementPresent(
|
3203 | using: LocateStrategy,
|
3204 | selector: string | ElementProperties,
|
3205 | time?: number,
|
3206 | poll?: number,
|
3207 | abortOnFailure?: boolean,
|
3208 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3209 | message?: string,
|
3210 | ): this;
|
3211 |
|
3212 | /**
|
3213 | * Waits a given time in milliseconds for an element to be visible in the page before performing any other commands or assertions.
|
3214 | *
|
3215 | * 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`.
|
3216 | *
|
3217 | * 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.
|
3218 | *
|
3219 | * Similarly, a default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
3220 | *
|
3221 | * @example
|
3222 | * this.demoTest = function (browser) {
|
3223 | * browser.waitForElementVisible('body', 1000);
|
3224 | * // continue if failed
|
3225 | * browser.waitForElementVisible('body', 1000, false);
|
3226 | * // with callback
|
3227 | * browser.waitForElementVisible('body', 1000, function() {
|
3228 | * // do something while we're here
|
3229 | * });
|
3230 | * // custom Spanish message
|
3231 | * browser.waitForElementVisible('body', 1000, 'elemento %s no era visible en %d ms');
|
3232 | * // many combinations possible - the message is always the last argument
|
3233 | * browser.waitForElementVisible('body', 1000, false, function() {}, 'elemento %s no era visible en %d ms');
|
3234 | * };
|
3235 | */
|
3236 | waitForElementVisible(
|
3237 | selector: string | ElementProperties,
|
3238 | time?: number,
|
3239 | poll?: number,
|
3240 | abortOnFailure?: boolean,
|
3241 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3242 | message?: string,
|
3243 | ): this;
|
3244 |
|
3245 | waitForElementVisible(
|
3246 | using: LocateStrategy,
|
3247 | selector: string | ElementProperties,
|
3248 | time?: number,
|
3249 | poll?: number,
|
3250 | abortOnFailure?: boolean,
|
3251 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3252 | message?: string,
|
3253 | ): this;
|
3254 |
|
3255 | /**
|
3256 | * Returns the computed WAI-ARIA label of an element.
|
3257 | *
|
3258 | * @example
|
3259 | * module.exports = {
|
3260 | * demoTest() {
|
3261 | * browser.getAccessibleName('*[name="search"]', function(result) {
|
3262 | * this.assert.equal(typeof result, 'object);
|
3263 | * this.assert.equal(result.value, 'search input');
|
3264 | * });
|
3265 | *
|
3266 | * // with explicit locate strategy
|
3267 | * browser.getAccessibleName('css selector', '*[name="search"]', function(result) {
|
3268 | * console.log('getAccessibleName result', result.value);
|
3269 | * });
|
3270 | *
|
3271 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3272 | * browser.getAccessibleName({
|
3273 | * selector: '*[name="search"]',
|
3274 | * index: 1
|
3275 | * }, function(result) {
|
3276 | * console.log('getAccessibleName result', result.value);
|
3277 | * });
|
3278 | *
|
3279 | * browser.getAccessibleName({
|
3280 | * selector: '*[name="search"]',
|
3281 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
3282 | * }, function(result) {
|
3283 | * console.log('getAccessibleName result', result.value);
|
3284 | * });
|
3285 | * },
|
3286 | *
|
3287 | * demoTestAsync: async function() {
|
3288 | * const result = await browser.getAccessibleName('*[name="search"]');
|
3289 | * console.log('getAccessibleName result', result);
|
3290 | * }
|
3291 | * }
|
3292 | *
|
3293 | */
|
3294 | getAccessibleName(
|
3295 | selector: string | ElementProperties,
|
3296 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3297 | ): this;
|
3298 | getAccessibleName(
|
3299 | using: LocateStrategy,
|
3300 | selector: string | ElementProperties,
|
3301 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3302 | ): this;
|
3303 |
|
3304 | /**
|
3305 | * Returns the computed WAI-ARIA role of an element.
|
3306 | *
|
3307 | * @example
|
3308 | * module.exports = {
|
3309 | * demoTest(browser) {
|
3310 | * browser.getAriaRole('*[name="search"]', function(result) {
|
3311 | * this.assert.equal(typeof result, 'object');
|
3312 | * this.assert.equal(result.value, 'combobox');
|
3313 | * });
|
3314 | *
|
3315 | * // with explicit locate strategy
|
3316 | * browser.getAriaRole('css selector', '*[name="search"]', function(result) {
|
3317 | * console.log('getAriaRole result', result.value);
|
3318 | * });
|
3319 | *
|
3320 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3321 | * browser.getAriaRole({
|
3322 | * selector: '*[name="search"]',
|
3323 | * index: 1
|
3324 | * }, function(result) {
|
3325 | * console.log('getAriaRole result', result.value);
|
3326 | * });
|
3327 | *
|
3328 | * browser.getAriaRole({
|
3329 | * selector: '*[name="search"]',
|
3330 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
3331 | * }, function(result) {
|
3332 | * console.log('getAriaRole result', result.value);
|
3333 | * });
|
3334 | * },
|
3335 | *
|
3336 | * demoTestAsync: async function(browser) {
|
3337 | * const result = await browser.getAriaRole('*[name="search"]');
|
3338 | * console.log('getAriaRole result', result);
|
3339 | * }
|
3340 | * }
|
3341 | *
|
3342 | */
|
3343 | getAriaRole(
|
3344 | selector: string | ElementProperties,
|
3345 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3346 | ): this;
|
3347 | getAriaRole(
|
3348 | using: LocateStrategy,
|
3349 | selector: string | ElementProperties,
|
3350 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
3351 | ): this;
|
3352 |
|
3353 | /**
|
3354 | * Determine an element's size in pixels. For W3C Webdriver compatible clients (such as GeckoDriver), this command is equivalent to `getLocation` and both return
|
3355 | * the dimensions and coordinates of the given element:
|
3356 | * - x: X axis position of the top-left corner of the element, in CSS pixels
|
3357 | * - y: Y axis position of the top-left corner of the element, in CSS pixels
|
3358 | * - height: Height of the element’s bounding rectangle in CSS pixels;
|
3359 | * - width: Width of the web element’s bounding rectangle in CSS pixels.
|
3360 | *
|
3361 | * @example
|
3362 | * module.exports = {
|
3363 | * demoTest() {
|
3364 | * browser.getElementSize('#login', function(result) {
|
3365 | * console.log('result', result);
|
3366 | * });
|
3367 | *
|
3368 | * // with explicit locate strategy
|
3369 | * browser.getElementSize('css selector', '#login', function(result) {
|
3370 | * console.log('result', result);
|
3371 | * });
|
3372 | *
|
3373 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3374 | * browser.getElementSize({
|
3375 | * selector: '#login',
|
3376 | * index: 1,
|
3377 | * suppressNotFoundErrors: true
|
3378 | * }, function(result) {
|
3379 | * console.log('result', result);
|
3380 | * });
|
3381 | * },
|
3382 | *
|
3383 | * demoTestAsync: async function() {
|
3384 | * const result = await browser.getElementSize('#login');
|
3385 | * console.log('classList', result);
|
3386 | * }
|
3387 | * }
|
3388 | */
|
3389 | getElementRect(
|
3390 | selector: string | ElementProperties,
|
3391 | callback?: (
|
3392 | this: NightwatchAPI,
|
3393 | result: NightwatchCallbackResult<{ height: number; width: number; x: number; y: number }>,
|
3394 | ) => void,
|
3395 | ): this;
|
3396 | getElementRect(
|
3397 | using: LocateStrategy,
|
3398 | selector: string | ElementProperties,
|
3399 | callback?: (
|
3400 | this: NightwatchAPI,
|
3401 | result: NightwatchCallbackResult<{ height: number; width: number; x: number; y: number }>,
|
3402 | ) => void,
|
3403 | ): this;
|
3404 |
|
3405 | /**
|
3406 | *
|
3407 | * Uploads file to an element using absolute file path.
|
3408 | *
|
3409 | *
|
3410 | * @example
|
3411 | * // send a file to for upload to a field.
|
3412 | * this.demoTest = function (browser) {
|
3413 | * browser.uploadFile('#myFile', '/path/file.pdf');
|
3414 | * };
|
3415 | *
|
3416 | *
|
3417 | */
|
3418 | uploadFile(
|
3419 | selector: string | ElementProperties,
|
3420 | filePath: string,
|
3421 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3422 | ): this;
|
3423 | uploadFile(
|
3424 | using: LocateStrategy,
|
3425 | selector: string | ElementProperties,
|
3426 | filePath: string,
|
3427 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3428 | ): this;
|
3429 |
|
3430 | /**
|
3431 | * Drag an element to the given position or destination element.
|
3432 | *
|
3433 | * @example
|
3434 | * module.exports = {
|
3435 | * demoTest(browser) {
|
3436 | * browser.dragAndDrop('#main', {x: 100, y:100}):
|
3437 | *
|
3438 | *
|
3439 | *
|
3440 | * //using webElement as a destination
|
3441 | * demoTestAsync: async function(browser) {
|
3442 | * const destination = await browser.findElement('#upload');
|
3443 | * browser.dragAndDrop('#main', destination.getId());
|
3444 | * }
|
3445 | * }
|
3446 | *
|
3447 | */
|
3448 | dragAndDrop(
|
3449 | selector: string | ElementProperties,
|
3450 | destination: NightwatchElement | { x: number; y: number },
|
3451 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3452 | ): this;
|
3453 | dragAndDrop(
|
3454 | using: LocateStrategy,
|
3455 | selector: string | ElementProperties,
|
3456 | destination: NightwatchElement | { x: number; y: number },
|
3457 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3458 | ): this;
|
3459 |
|
3460 | /**
|
3461 | * 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).
|
3462 | * First argument is the element selector, either specified as a string or as an object (with 'selector' and 'locateStrategy' properties).
|
3463 | *
|
3464 | * @example
|
3465 | * module.exports = {
|
3466 | * 'demo Test': function(browser) {
|
3467 | * const resultElement = await browser.findElement('.features-container li:first-child');
|
3468 | *
|
3469 | * console.log('Element Id:', resultElement.getId());
|
3470 | * },
|
3471 | *
|
3472 | *
|
3473 | */
|
3474 | findElement(
|
3475 | selector: string | ElementProperties,
|
3476 | callback?: (
|
3477 | this: NightwatchAPI,
|
3478 | result: NightwatchCallbackResult<{ value: WebElement; status: number; WebdriverElementId: WebElement }>,
|
3479 | ) => void,
|
3480 | ): WebElementPromise;
|
3481 | findElement(
|
3482 | using: LocateStrategy,
|
3483 | selector: string | ElementProperties,
|
3484 | callback?: (
|
3485 | this: NightwatchAPI,
|
3486 | result: NightwatchCallbackResult<{ value: WebElement; status: number; WebdriverElementId: WebElement }>,
|
3487 | ) => void,
|
3488 | ): WebElementPromise;
|
3489 |
|
3490 | /**
|
3491 | * 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).
|
3492 | * First argument is the element selector, either specified as a string or as an object (with 'selector' and 'locateStrategy' properties).
|
3493 | *
|
3494 | *
|
3495 | * @example
|
3496 | * module.exports = {
|
3497 | * 'demo Test': function(browser) {
|
3498 | * const resultElements = await browser.findElements('.features-container li');
|
3499 | *
|
3500 | * resultElements.forEach(item => console.log('Element Id:', item.getId()));
|
3501 | * },
|
3502 | *
|
3503 | */
|
3504 | findElements(
|
3505 | selector: string | ElementProperties,
|
3506 | callback?: (
|
3507 | this: NightwatchAPI,
|
3508 | result: NightwatchCallbackResult<{
|
3509 | value: WebElement[];
|
3510 | status: number;
|
3511 | WebdriverElementId: WebElement;
|
3512 | }>,
|
3513 | ) => void,
|
3514 | ): WebElement[];
|
3515 | findElements(
|
3516 | using: LocateStrategy,
|
3517 | selector: string | ElementProperties,
|
3518 | callback?: (
|
3519 | this: NightwatchAPI,
|
3520 | result: NightwatchCallbackResult<{
|
3521 | value: WebElement[];
|
3522 | status: number;
|
3523 | WebdriverElementId: WebElement;
|
3524 | }>,
|
3525 | ) => void,
|
3526 | ): WebElement[];
|
3527 |
|
3528 | /**
|
3529 | * Retrieve the value of a specified DOM property for the given element.
|
3530 | * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
|
3531 | *
|
3532 | * @example
|
3533 | * module.exports = {
|
3534 | * demoTest(browser) {
|
3535 | * browser.getElementProperty('#login input[type=text]', 'classList', function(result) {
|
3536 | * console.log('result', result);
|
3537 | * });
|
3538 | *
|
3539 | * // with explicit locate strategy
|
3540 | * browser.getElementProperty('css selector', '#login input[type=text]', 'classList', function(result) {
|
3541 | * console.log('result', result);
|
3542 | * });
|
3543 | *
|
3544 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3545 | * browser.getElementProperty({
|
3546 | * selector: '#login input[type=text]',
|
3547 | * index: 1,
|
3548 | * suppressNotFoundErrors: true
|
3549 | * }, 'classList', function(result) {
|
3550 | * console.log('result', result);
|
3551 | * });
|
3552 | * },
|
3553 | *
|
3554 | * demoTestAsync: async function(browser) {
|
3555 | * const result = await browser.getElementProperty('#login input[type=text]', 'classList');
|
3556 | * console.log('classList', result);
|
3557 | * }
|
3558 | * }
|
3559 | *
|
3560 | */
|
3561 | getElementProperty(
|
3562 | selector: string | ElementProperties,
|
3563 | property: string,
|
3564 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void,
|
3565 | ): this;
|
3566 | getElementProperty(
|
3567 | using: LocateStrategy,
|
3568 | selector: string | ElementProperties,
|
3569 | property: string,
|
3570 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void,
|
3571 | ): this;
|
3572 |
|
3573 | /**
|
3574 | *
|
3575 | * Determines if an element is enabled, as indicated by the 'disabled' attribute.
|
3576 | *
|
3577 | * @example
|
3578 | * module.exports = {
|
3579 | * demoTest(browser) {
|
3580 | * browser.isEnabled('#main select option.first', function(result) {
|
3581 | * this.assert.equal(typeof result, "object");
|
3582 | * this.assert.equal(result.status, 0);
|
3583 | * this.assert.equal(result.value, true);
|
3584 | * });
|
3585 | *
|
3586 | * // with explicit locate strategy
|
3587 | * browser.isEnabled('css selector', '#main select option.first');
|
3588 | *
|
3589 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3590 | * browser.isEnabled({
|
3591 | * selector: '#main ul li a',
|
3592 | * index: 1,
|
3593 | * suppressNotFoundErrors: true
|
3594 | * });
|
3595 | *
|
3596 | * browser.isEnabled({
|
3597 | * selector: '#main select option.first',
|
3598 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
3599 | * });
|
3600 | * },
|
3601 | *
|
3602 | * demoTestAsync: async function(browser) {
|
3603 | * const result = await browser.isEnabled('#main select option.first');
|
3604 | * console.log('isVisible result', result);
|
3605 | * }
|
3606 | * }
|
3607 | */
|
3608 | isEnabled(
|
3609 | selector: string | ElementProperties,
|
3610 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
3611 | ): this;
|
3612 | isEnabled(
|
3613 | using: LocateStrategy,
|
3614 | selector: string | ElementProperties,
|
3615 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
3616 | ): this;
|
3617 |
|
3618 | /**
|
3619 | *
|
3620 | * Determines if an element is selected.
|
3621 | *
|
3622 | * @example
|
3623 | * module.exports = {
|
3624 | * demoTest(browser) {
|
3625 | * browser.isSelected('#main select option.first', function(result) {
|
3626 | * this.assert.equal(typeof result, "object");
|
3627 | * this.assert.equal(result.status, 0);
|
3628 | * this.assert.equal(result.value, true);
|
3629 | * });
|
3630 | *
|
3631 | * // with explicit locate strategy
|
3632 | * browser.isSelected('css selector', '#main select option.first');
|
3633 | *
|
3634 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3635 | * browser.isSelected({
|
3636 | * selector: '#main ul li a',
|
3637 | * index: 1,
|
3638 | * suppressNotFoundErrors: true
|
3639 | * });
|
3640 | *
|
3641 | * browser.isSelected({
|
3642 | * selector: '#main select option.first',
|
3643 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
3644 | * });
|
3645 | * },
|
3646 | *
|
3647 | * demoTestAsync: async function(browser) {
|
3648 | * const result = await browser.isSelected('#main select option.first');
|
3649 | * console.log('isVisible result', result);
|
3650 | * }
|
3651 | * }
|
3652 | */
|
3653 | isSelected(
|
3654 | selector: string | ElementProperties,
|
3655 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
3656 | ): this;
|
3657 | isSelected(
|
3658 | using: LocateStrategy,
|
3659 | selector: string | ElementProperties,
|
3660 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
3661 | ): this;
|
3662 |
|
3663 | /**
|
3664 | *
|
3665 | * Set the value of a specified DOM attribute for the given element.
|
3666 | * For all the available DOM attributes, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
|
3667 | *
|
3668 | * @example
|
3669 | * module.exports = {
|
3670 | * demoTest(browser) {
|
3671 | * browser.setAttribute('#login input[type=text]', 'disabled', 'true', function(result) {
|
3672 | * console.log('result', result);
|
3673 | * });
|
3674 | *
|
3675 | * // with explicit locate strategy
|
3676 | * browser.setAttribute('css selector', '#login input[type=text]', 'disabled', 'true', function(result) {
|
3677 | * console.log('result', result);
|
3678 | * });
|
3679 | *
|
3680 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3681 | * browser.setAttribute({
|
3682 | * selector: '#login input[type=text]',
|
3683 | * index: 1,
|
3684 | * suppressNotFoundErrors: true
|
3685 | * }, 'disabled', 'true', function(result) {
|
3686 | * console.log('result', result);
|
3687 | * });
|
3688 | * },
|
3689 | *
|
3690 | * demoTestAsync: async function(browser) {
|
3691 | * await browser.setAttribute('#login input[type=text]', 'disabled', 'true');
|
3692 | * }
|
3693 | * }
|
3694 | */
|
3695 | setAttribute(
|
3696 | selector: string | ElementProperties,
|
3697 | attribute: string,
|
3698 | value: string,
|
3699 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3700 | ): this;
|
3701 | setAttribute(
|
3702 | using: LocateStrategy,
|
3703 | selector: string | ElementProperties,
|
3704 | attribute: string,
|
3705 | value: string,
|
3706 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3707 | ): this;
|
3708 |
|
3709 | /**
|
3710 | *
|
3711 | * An alias of "setValue" command, but hides the content from the nightwatch logs.
|
3712 | *
|
3713 | * <div class="alert alert-warning"><strong>setValue/setPassword</strong> do not clear
|
3714 | * the existing value of the element. To do so, use the <strong>clearValue()</strong> command.</div>
|
3715 | *
|
3716 | * An object map with available keys and their respective UTF-8 characters,
|
3717 | * 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`.
|
3718 | *
|
3719 | * @example
|
3720 | * // send some simple text to an input
|
3721 | * this.demoTest = function (browser) {
|
3722 | * browser.setPassword('input[type=text]', 'nightwatch');
|
3723 | * };
|
3724 | * //
|
3725 | * // send some text to an input and hit enter.
|
3726 | * this.demoTest = function (browser) {
|
3727 | * browser.setPassword('input[type=text]', ['nightwatch', browser.Keys.ENTER]);
|
3728 | * };
|
3729 | *
|
3730 | */
|
3731 | setPassword(
|
3732 | selector: string | ElementProperties,
|
3733 | inputValue: string,
|
3734 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3735 | ): this;
|
3736 | setPassword(
|
3737 | using: LocateStrategy,
|
3738 | selector: string | ElementProperties,
|
3739 | inputValue: string,
|
3740 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3741 | ): this;
|
3742 |
|
3743 | /**
|
3744 | *
|
3745 | * Take a screenshot of the visible region encompassed by this element's bounding rectangle.
|
3746 | *
|
3747 | * @example
|
3748 | * module.exports = {
|
3749 | * demoTest(browser) {
|
3750 | * browser.takeElementScreenshot('#main', function (imageData, err) {
|
3751 | * require('fs').writeFile('out.png', imageData.value, 'base64', function (err) {
|
3752 | * console.log(err);
|
3753 | * });
|
3754 | * });
|
3755 | *
|
3756 | * // with explicit locate strategy
|
3757 | * browser.takeElementScreenshot('css selector', '#main', function(imageData, err) {
|
3758 | * require('fs').writeFile('out.png', imageData.value, 'base64', function (err) {
|
3759 | * console.log(err);
|
3760 | * });
|
3761 | * });
|
3762 | *
|
3763 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
3764 | * browser.takeElementScreenshot({
|
3765 | * selector: '#main ul li a',
|
3766 | * index: 1
|
3767 | * }, function(imageData, err) {
|
3768 | * require('fs').writeFile('out.png', imageData.value, 'base64', function (err) {
|
3769 | * console.log(err);
|
3770 | * });
|
3771 | * });
|
3772 | * },
|
3773 | *
|
3774 | * demoTestAsync: async function(browser) {
|
3775 | * const data = await browser.takeElementScreenshot('#main');
|
3776 | * require('fs').writeFile('out.png', data, 'base64');
|
3777 | * }
|
3778 | * }
|
3779 | *
|
3780 | */
|
3781 | takeElementScreenshot(
|
3782 | selector: string | ElementProperties,
|
3783 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => string,
|
3784 | ): this;
|
3785 | takeElementScreenshot(
|
3786 | using: LocateStrategy,
|
3787 | selector: string | ElementProperties,
|
3788 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => string,
|
3789 | ): this;
|
3790 | }
|
3791 |
|
3792 | export interface WebDriverProtocol
|
3793 | extends WebDriverProtocolSessions,
|
3794 | WebDriverProtocolNavigation,
|
3795 | WebDriverProtocolCommandContexts,
|
3796 | WebDriverProtocolElements,
|
3797 | WebDriverProtocolElementState,
|
3798 | WebDriverProtocolElementInteraction,
|
3799 | WebDriverProtocolElementLocation,
|
3800 | WebDriverProtocolDocumentHandling,
|
3801 | WebDriverProtocolCookies,
|
3802 | WebDriverProtocolUserActions,
|
3803 | WebDriverProtocolUserPrompts,
|
3804 | WebDriverProtocolScreenCapture,
|
3805 | WebDriverProtocolMobileRelated {}
|
3806 |
|
3807 | export interface WebDriverProtocolSessions {
|
3808 | /**
|
3809 | * Get info about, delete or create a new session. Defaults to the current session.
|
3810 | *
|
3811 | * @example
|
3812 | * this.demoTest = function (browser) {
|
3813 | * browser.session(function(result) {
|
3814 | * console.log(result.value);
|
3815 | * });
|
3816 | * //
|
3817 | * browser.session('delete', function(result) {
|
3818 | * console.log(result.value);
|
3819 | * });
|
3820 | * //
|
3821 | * browser.session('delete', '12345-abc', function(result) {
|
3822 | * console.log(result.value);
|
3823 | * });
|
3824 | * }
|
3825 | */
|
3826 | session(
|
3827 | action?: string,
|
3828 | sessionId?: string,
|
3829 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Record<string, any>>) => void,
|
3830 | ): this;
|
3831 |
|
3832 | /**
|
3833 | * Returns a list of the currently active sessions.
|
3834 | *
|
3835 | * @example
|
3836 | * this.demoTest = function (browser) {
|
3837 | * browser.sessions(function(result) {
|
3838 | * console.log(result.value);
|
3839 | * });
|
3840 | * }
|
3841 | */
|
3842 | sessions(
|
3843 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Array<Record<string, any>>>) => void,
|
3844 | ): this;
|
3845 |
|
3846 | /**
|
3847 | * 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.
|
3848 | *
|
3849 | * @example
|
3850 | * this.demoTest = function (browser) {
|
3851 | * browser.timeouts('script', 10000, function(result) {
|
3852 | * console.log(result);
|
3853 | * });
|
3854 | * }
|
3855 | */
|
3856 | timeouts(
|
3857 | typeOfOperation: string,
|
3858 | ms: number,
|
3859 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3860 | ): this;
|
3861 | timeouts(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
3862 |
|
3863 | /**
|
3864 | * 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.
|
3865 | *
|
3866 | * @example
|
3867 | * this.demoTest = function (browser) {
|
3868 | * browser.timeoutsAsyncScript(10000, function(result) {
|
3869 | * console.log(result);
|
3870 | * });
|
3871 | * }
|
3872 | */
|
3873 | timeoutsAsyncScript(
|
3874 | ms: number,
|
3875 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3876 | ): this;
|
3877 |
|
3878 | /**
|
3879 | * 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.
|
3880 | *
|
3881 | * @example
|
3882 | * this.demoTest = function (browser) {
|
3883 | * browser.timeoutsImplicitWait(10000, function(result) {
|
3884 | * console.log(result);
|
3885 | * });
|
3886 | * }
|
3887 | */
|
3888 | timeoutsImplicitWait(
|
3889 | ms: number,
|
3890 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
3891 | ): this;
|
3892 |
|
3893 | /**
|
3894 | * Query the server's current status.
|
3895 | */
|
3896 | status(
|
3897 | callback?: (
|
3898 | this: NightwatchAPI,
|
3899 | result: NightwatchCallbackResult<{
|
3900 | build: { version: string; revision: string; time: string };
|
3901 | status: { arch: string; name: string; version: string };
|
3902 | }>,
|
3903 | ) => void,
|
3904 | ): this;
|
3905 |
|
3906 | /**
|
3907 | * Gets the text of the log type specified. To find out the available log types, use `.getLogTypes()`.
|
3908 | *
|
3909 | * Returns a [log entry JSON object](https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#log-entry-json-object).
|
3910 | *
|
3911 | * @example
|
3912 | * this.demoTest = function (browser) {
|
3913 | * browser.sessionLog('client', function(result) {
|
3914 | * console.log(result.value);
|
3915 | * });
|
3916 | * }
|
3917 | */
|
3918 | sessionLog(typeString: string, callback?: (this: NightwatchAPI, log: NightwatchLogEntry[]) => void): this;
|
3919 |
|
3920 | /**
|
3921 | * 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.
|
3922 | *
|
3923 | * @example
|
3924 | * this.demoTest = function (browser) {
|
3925 | * browser.sessionLogTypes(function(result) {
|
3926 | * console.log(result.value);
|
3927 | * });
|
3928 | * }
|
3929 | */
|
3930 | sessionLogTypes(
|
3931 | callback?: (
|
3932 | this: NightwatchAPI,
|
3933 | result: NightwatchCallbackResult<Array<'client' | 'driver' | 'browser' | 'server'>>,
|
3934 | ) => void,
|
3935 | ): this;
|
3936 | }
|
3937 |
|
3938 | export interface WebDriverProtocolNavigation {
|
3939 | /**
|
3940 | * Retrieve the URL of the current page or navigate to a new URL.
|
3941 | *
|
3942 | * @example
|
3943 | * module.exports = {
|
3944 | * 'demo Test' : function(browser) {
|
3945 | * browser.url(function(result) {
|
3946 | * // return the current url
|
3947 | * console.log(result);
|
3948 | * });
|
3949 | * //
|
3950 | * // navigate to new url:
|
3951 | * browser.url('{URL}');
|
3952 | * //
|
3953 | * //
|
3954 | * // navigate to new url:
|
3955 | * browser.url('{URL}', function(result) {
|
3956 | * console.log(result);
|
3957 | * });
|
3958 | * }
|
3959 | * }
|
3960 | */
|
3961 | url(url?: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
3962 | url(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
3963 |
|
3964 | /**
|
3965 | * Navigate backwards in the browser history, if possible.
|
3966 | */
|
3967 | back(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
3968 |
|
3969 | /**
|
3970 | * Navigate forwards in the browser history, if possible.
|
3971 | */
|
3972 | forward(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
3973 |
|
3974 | /**
|
3975 | * Refresh the current page.
|
3976 | */
|
3977 | refresh(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
3978 |
|
3979 | /**
|
3980 | * Get the current page title.
|
3981 | *
|
3982 | * @example
|
3983 | * this.demoTest = function (browser) {
|
3984 | * browser.title(function(result) {
|
3985 | * console.log(result.value);
|
3986 | * });
|
3987 | * }
|
3988 | */
|
3989 | title(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
3990 | }
|
3991 |
|
3992 | export interface WebDriverProtocolCommandContexts {
|
3993 | /**
|
3994 | * Change focus to another window or close the current window. Shouldn't normally be used directly, instead `.switchWindow()` and `.closeWindow()` should be used.
|
3995 | */
|
3996 | window(
|
3997 | method: string,
|
3998 | handleOrName?: string,
|
3999 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4000 | ): this;
|
4001 |
|
4002 | /**
|
4003 | * Retrieve the current window handle.
|
4004 | *
|
4005 | * @example
|
4006 | * this.demoTest = function (browser) {
|
4007 | * browser.windowHandle(function(result) {
|
4008 | * console.log(result.value);
|
4009 | * });
|
4010 | * }
|
4011 | */
|
4012 | windowHandle(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
4013 |
|
4014 | /**
|
4015 | * Retrieve the list of all window handles available to the session.
|
4016 | *
|
4017 | * @example
|
4018 | * this.demoTest = function (browser) {
|
4019 | * browser.windowHandles(function(result) {
|
4020 | * // An array of window handles.
|
4021 | * console.log(result.value);
|
4022 | * });
|
4023 | * }
|
4024 | */
|
4025 | windowHandles(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string[]>) => void): this;
|
4026 |
|
4027 | /**
|
4028 | * Increases the window to the maximum available size without going full-screen.
|
4029 | *
|
4030 | * @example
|
4031 | * this.demoTest = function (browser) {
|
4032 | * browser.windowMaximize('current', function(result) {
|
4033 | * console.log(result);
|
4034 | * });
|
4035 | * }
|
4036 | */
|
4037 | windowMaximize(
|
4038 | handleOrName?: string,
|
4039 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4040 | ): this;
|
4041 |
|
4042 | /**
|
4043 | * Change or get the position of the specified window. If the second argument is a function it will be used as a callback and
|
4044 | * the call will perform a get request to retrieve the existing window position.
|
4045 | *
|
4046 | * @example
|
4047 | * this.demoTest = function (browser) {
|
4048 | *
|
4049 | * // Change the position of the specified window.
|
4050 | * // If the :windowHandle URL parameter is "current", the currently active window will be moved.
|
4051 | * browser.windowPosition('current', 0, 0, function(result) {
|
4052 | * console.log(result);
|
4053 | * });
|
4054 | *
|
4055 | * // Get the position of the specified window.
|
4056 | * // If the :windowHandle URL parameter is "current", the position of the currently active window will be returned.
|
4057 | * browser.windowPosition('current', function(result) {
|
4058 | * console.log(result.value);
|
4059 | * });
|
4060 | * }
|
4061 | */
|
4062 | windowPosition(
|
4063 | windowHandle: string,
|
4064 | offsetX: number,
|
4065 | offsetY: number,
|
4066 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4067 | ): this;
|
4068 | windowPosition(
|
4069 | windowHandle: string,
|
4070 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ x: number; y: number }>) => void,
|
4071 | ): this;
|
4072 |
|
4073 | /**
|
4074 | * 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.
|
4075 | *
|
4076 | * @example
|
4077 | * this.demoTest = function (browser) {
|
4078 | *
|
4079 | * // Return the size of the specified window. If the :windowHandle URL parameter is "current", the size of the currently active window will be returned.
|
4080 | * browser.windowSize('current', function(result) {
|
4081 | * console.log(result.value);
|
4082 | * });
|
4083 | *
|
4084 | * // Change the size of the specified window.
|
4085 | * // If the :windowHandle URL parameter is "current", the currently active window will be resized.
|
4086 | * browser.windowSize('current', 300, 300, function(result) {
|
4087 | * console.log(result.value);
|
4088 | * });
|
4089 | * }
|
4090 | */
|
4091 | windowSize(
|
4092 | windowHandle: string,
|
4093 | width: number,
|
4094 | height: number,
|
4095 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4096 | ): this;
|
4097 | windowSize(
|
4098 | windowHandle: string,
|
4099 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ width: number; height: number }>) => void,
|
4100 | ): this;
|
4101 |
|
4102 | /**
|
4103 | *
|
4104 | * Change or get the [window rect](https://w3c.github.io/webdriver/#dfn-window-rect).
|
4105 | * This is defined as a dictionary of the `screenX`, `screenY`, `outerWidth` and `outerHeight` attributes of the window.
|
4106 | *
|
4107 | * Its JSON representation is the following:
|
4108 | * - `x` - window's screenX attribute;
|
4109 | * - `y` - window's screenY attribute;
|
4110 | * - `width` - outerWidth attribute;
|
4111 | * - `height` - outerHeight attribute.
|
4112 | *
|
4113 | * 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.
|
4114 | *
|
4115 | * @example
|
4116 | * module.exports = {
|
4117 | * 'demo test .windowRect()': function(browser) {
|
4118 | *
|
4119 | * // Change the screenX and screenY attributes of the window rect.
|
4120 | * browser.windowRect({x: 500, y: 500});
|
4121 | *
|
4122 | * // Change the width and height attributes of the window rect.
|
4123 | * browser.windowRect({width: 600, height: 300});
|
4124 | *
|
4125 | * // Retrieve the attributes
|
4126 | * browser.windowRect(function(result) {
|
4127 | * console.log(result.value);
|
4128 | * });
|
4129 | * },
|
4130 | *
|
4131 | * 'windowRect ES6 demo test': async function(browser) {
|
4132 | * const resultValue = await browser.windowRect();
|
4133 | * console.log('result value', resultValue);
|
4134 | * }
|
4135 | * }
|
4136 | */
|
4137 | windowRect(
|
4138 | options: { width?: number; height?: number; x?: number; y?: number },
|
4139 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4140 | ): this;
|
4141 |
|
4142 | /**
|
4143 | * 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.
|
4144 | *
|
4145 | * @example
|
4146 | * this.demoTest = function (browser) {
|
4147 | * browser.frame('<ID>', function(result) {
|
4148 | * console.log(result);
|
4149 | * });
|
4150 | * }
|
4151 | */
|
4152 | frame(
|
4153 | frameId?: WebElement | string | number | null,
|
4154 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4155 | ): this;
|
4156 |
|
4157 | /**
|
4158 | * Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged.
|
4159 | *
|
4160 | * @example
|
4161 | * this.demoTest = function (browser) {
|
4162 | * browser.frameParent(function(result) {
|
4163 | * console.log(result);
|
4164 | * });
|
4165 | * }
|
4166 | *
|
4167 | * @since v0.4.8
|
4168 | */
|
4169 | frameParent(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
4170 | }
|
4171 |
|
4172 | export interface WebDriverProtocolElements {
|
4173 | /**
|
4174 | * Search for an element on the page, starting from the document root. The located element will be returned as a web element JSON object.
|
4175 | * First argument to be passed is the locator strategy, which is detailed on the [WebDriver docs](https://www.w3.org/TR/webdriver/#locator-strategies).
|
4176 | *
|
4177 | * The locator stragy can be one of:
|
4178 | * - `css selector`
|
4179 | * - `link text`
|
4180 | * - `partial link text`
|
4181 | * - `tag name`
|
4182 | * - `xpath`
|
4183 | *
|
4184 | * @example
|
4185 | * module.exports = {
|
4186 | * 'demo Test' : function(browser) {
|
4187 | * browser.element('css selector', 'body', function(result) {
|
4188 | * console.log(result.value)
|
4189 | * });
|
4190 | * },
|
4191 | *
|
4192 | * 'es6 async demo Test': async function(browser) {
|
4193 | * const result = await browser.element('css selector', 'body');
|
4194 | * console.log('result value is:', result.value);
|
4195 | * }
|
4196 | * }
|
4197 | */
|
4198 | element(
|
4199 | using: LocateStrategy,
|
4200 | value: string,
|
4201 | callback: (this: NightwatchAPI, result: NightwatchCallbackResult<{ ELEMENT: string }>) => void,
|
4202 | ): this;
|
4203 |
|
4204 | /**
|
4205 | * Search for multiple elements on the page, starting from the document root. The located elements will be returned as web element JSON objects.
|
4206 | * First argument to be passed is the locator strategy, which is detailed on the [WebDriver docs](https://www.w3.org/TR/webdriver/#locator-strategies).
|
4207 | *
|
4208 | * * The locator strategy can be one of:
|
4209 | * - `css selector`
|
4210 | * - `link text`
|
4211 | * - `partial link text`
|
4212 | * - `tag name`
|
4213 | * - `xpath`
|
4214 | *
|
4215 | * @example
|
4216 | * module.exports = {
|
4217 | * 'demo Test' : function(browser) {
|
4218 | * browser.elements('css selector', 'ul li', function(result) {
|
4219 | * console.log(result.value)
|
4220 | * });
|
4221 | * },
|
4222 | *
|
4223 | * 'es6 async demo Test': async function(browser) {
|
4224 | * const result = await browser.elements('css selector', 'ul li');
|
4225 | * console.log('result value is:', result.value);
|
4226 | * },
|
4227 | *
|
4228 | * 'page object demo Test': function (browser) {
|
4229 | * var nightwatch = browser.page.nightwatch();
|
4230 | * nightwatch
|
4231 | * .navigate()
|
4232 | * .assert.titleContains('Nightwatch.js');
|
4233 | *
|
4234 | * nightwatch.api.elements('@featuresList', function(result) {
|
4235 | * console.log(result);
|
4236 | * });
|
4237 | *
|
4238 | * browser.end();
|
4239 | * }
|
4240 | * }
|
4241 | */
|
4242 | elements(
|
4243 | using: LocateStrategy,
|
4244 | value: string,
|
4245 | callback: (this: NightwatchAPI, result: NightwatchCallbackResult<Array<{ ELEMENT: string }>>) => void,
|
4246 | ): this;
|
4247 |
|
4248 | /**
|
4249 | * Search for an element on the page, starting from the identified element. The located element will be returned as a Web Element JSON object.
|
4250 | *
|
4251 | * This command operates on a protocol level and requires a [Web Element ID](https://www.w3.org/TR/webdriver1/#dfn-web-elements).
|
4252 | * Read more on [Element retrieval](https://www.w3.org/TR/webdriver1/#element-retrieval) on the W3C WebDriver spec page.
|
4253 | *
|
4254 | * @example
|
4255 | * module.exports = {
|
4256 | * 'demo Test' : function(browser) {
|
4257 | * browser.elementIdElement('<WebElementId>', 'css selector', '.new-element', function(result) {
|
4258 | * console.log(result.value)
|
4259 | * });
|
4260 | * },
|
4261 | *
|
4262 | * 'es6 async demo Test': async function(browser) {
|
4263 | * const result = await browser.elementIdElement('<WebElementId>', 'css selector', '.new-element');
|
4264 | * console.log(result.value);
|
4265 | * }
|
4266 | * }
|
4267 | */
|
4268 | elementIdElement(
|
4269 | id: string,
|
4270 | using: LocateStrategy,
|
4271 | value: string,
|
4272 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ ELEMENT: string }>) => void,
|
4273 | ): this;
|
4274 |
|
4275 | /**
|
4276 | * Search for multiple elements on the page, starting from the identified element. The located element will be returned as a web element JSON objects.
|
4277 | *
|
4278 | * @example
|
4279 | * module.exports = {
|
4280 | * 'demo Test' : function(browser) {
|
4281 | * browser.elementIdElements('<WebElementId>', 'css selector', 'ul li', function(result) {
|
4282 | * console.log(result.value)
|
4283 | * });
|
4284 | * },
|
4285 | *
|
4286 | * 'es6 async demo Test': async function(browser) {
|
4287 | * const result = await browser.elementIdElements('<WebElementId>', 'css selector', 'ul li');
|
4288 | * console.log(result.value);
|
4289 | * }
|
4290 | * }
|
4291 | */
|
4292 | elementIdElements(
|
4293 | id: string,
|
4294 | using: LocateStrategy,
|
4295 | value: string,
|
4296 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<Array<{ ELEMENT: string }>>) => void,
|
4297 | ): this;
|
4298 |
|
4299 | /**
|
4300 | * Test if two web element IDs refer to the same DOM element.
|
4301 | *
|
4302 | * This command is __deprecated__ and is only available on the [JSON Wire protocol](https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidelementidequalsother)
|
4303 | *
|
4304 | * @example
|
4305 | * module.exports = {
|
4306 | * 'demo Test' : function(browser) {
|
4307 | * browser.elementIdEquals('<ID-1>', '<ID-2>', function(result) {
|
4308 | * console.log(result.value)
|
4309 | * });
|
4310 | * }
|
4311 | * }
|
4312 | */
|
4313 | elementIdEquals(
|
4314 | id: string,
|
4315 | otherId: string,
|
4316 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4317 | ): this;
|
4318 |
|
4319 | /**
|
4320 | * Get the element on the page that currently has focus. The element will be returned as a [Web Element](https://www.w3.org/TR/webdriver1/#dfn-web-elements) JSON object.
|
4321 | *
|
4322 | * @example
|
4323 | * module.exports = {
|
4324 | * 'demo Test' : function(browser) {
|
4325 | * browser.elementActive(function(result) {
|
4326 | * console.log(result.value)
|
4327 | * });
|
4328 | * }
|
4329 | * }
|
4330 | */
|
4331 | elementActive(
|
4332 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ ELEMENT: string }>) => void,
|
4333 | ): this;
|
4334 | }
|
4335 |
|
4336 | export interface WebDriverProtocolElementState {
|
4337 | /**
|
4338 | * Get the value of an element's attribute.
|
4339 | */
|
4340 | elementIdAttribute(
|
4341 | id: string,
|
4342 | attributeName: string,
|
4343 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string | null>) => void,
|
4344 | ): this;
|
4345 |
|
4346 | /**
|
4347 | * Retrieve the computed value of the given CSS property of the given element.
|
4348 | *
|
4349 | * 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).
|
4350 | */
|
4351 | elementIdCssProperty(
|
4352 | id: string,
|
4353 | cssPropertyName: string,
|
4354 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void,
|
4355 | ): this;
|
4356 |
|
4357 | /**
|
4358 | * Determine if an element is currently displayed.
|
4359 | */
|
4360 | elementIdDisplayed(
|
4361 | id: string,
|
4362 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4363 | ): this;
|
4364 |
|
4365 | /**
|
4366 | * Determine if an element is currently enabled.
|
4367 | */
|
4368 | elementIdEnabled(
|
4369 | id: string,
|
4370 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4371 | ): this;
|
4372 |
|
4373 | /**
|
4374 | * Retrieve the qualified tag name of the given element.
|
4375 | */
|
4376 | elementIdName(id: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
4377 |
|
4378 | /**
|
4379 | * Determine if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected.
|
4380 | */
|
4381 | elementIdSelected(
|
4382 | id: string,
|
4383 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<boolean>) => void,
|
4384 | ): this;
|
4385 |
|
4386 | /**
|
4387 | * Determine an element's size in pixels. The size will be returned as a JSON object with width and height properties.
|
4388 | */
|
4389 | elementIdSize(
|
4390 | id: string,
|
4391 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ width: number; height: number }>) => void,
|
4392 | ): this;
|
4393 |
|
4394 | /**
|
4395 | * Returns the visible text for the element.
|
4396 | */
|
4397 | elementIdText(id: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
4398 | }
|
4399 |
|
4400 | export interface WebDriverProtocolElementInteraction {
|
4401 | /**
|
4402 | * 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.
|
4403 | *
|
4404 | * @example
|
4405 | * browser.elementIdClear(elementId);
|
4406 | */
|
4407 | elementIdClear(id: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
4408 |
|
4409 | /**
|
4410 | * Scrolls into view the element and clicks the in-view center point. If the element is not pointer-interactable, an <code>element not interactable</code> error is returned.
|
4411 | *
|
4412 | * @example
|
4413 | * browser.elementIdClick(elementId);
|
4414 | */
|
4415 | elementIdClick(id: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
4416 |
|
4417 | /**
|
4418 | * Scrolls into view the form control element and then sends the provided keys to the element, or returns the current value of the element.
|
4419 | * In case the element is not keyboard interactable, an <code>element not interactable error</code> is returned.
|
4420 | */
|
4421 | elementIdValue(
|
4422 | id: string,
|
4423 | value?: string,
|
4424 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4425 | ): this;
|
4426 | elementIdValue(
|
4427 | id: string,
|
4428 | value: string,
|
4429 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4430 | ): this;
|
4431 |
|
4432 | /**
|
4433 | * Send a sequence of key strokes to the active element. The sequence is defined in the same format as the `sendKeys` command.
|
4434 | * 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),
|
4435 | * is loaded onto the main Nightwatch instance as `client.Keys`.
|
4436 | *
|
4437 | * 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,
|
4438 | * so mouse interactions can be performed while modifier keys are depressed.
|
4439 | *
|
4440 | * @example
|
4441 | * browser
|
4442 | * .keys(browser.Keys.CONTROL) // hold down CONTROL key
|
4443 | * .click('#element')
|
4444 | * .keys(browser.Keys.NULL) // release all keys
|
4445 | */
|
4446 | keys(
|
4447 | keysToSend: string | string[],
|
4448 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4449 | ): this;
|
4450 |
|
4451 | /**
|
4452 | * Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element.
|
4453 | *
|
4454 | * @example
|
4455 | * browser.submit(elementID);
|
4456 | */
|
4457 | submit(id: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
4458 | }
|
4459 |
|
4460 | export interface WebDriverProtocolElementLocation {
|
4461 | /**
|
4462 | * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page.
|
4463 | *
|
4464 | * The element's coordinates are returned as a JSON object with x and y properties.
|
4465 | *
|
4466 | * @deprecated
|
4467 | */
|
4468 | elementIdLocation(
|
4469 | id: string,
|
4470 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ x: number; y: number }>) => void,
|
4471 | ): this;
|
4472 |
|
4473 | /**
|
4474 | * Determine an element's location on the screen once it has been scrolled into view.
|
4475 | *
|
4476 | * @deprecated
|
4477 | */
|
4478 | elementIdLocationInView(
|
4479 | id: string,
|
4480 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<{ x: number; y: number }>) => void,
|
4481 | ): this;
|
4482 | }
|
4483 |
|
4484 | export interface WebDriverProtocolDocumentHandling {
|
4485 | /**
|
4486 | * Returns a string serialisation of the DOM of the current page.
|
4487 | *
|
4488 | * @example
|
4489 | * browser.source();
|
4490 | */
|
4491 | source(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
4492 |
|
4493 | /**
|
4494 | * 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.
|
4495 | * 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.
|
4496 | *
|
4497 | * The function will be invoked with the provided args array and the values may be accessed via the arguments object in the order specified.
|
4498 | *
|
4499 | * 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.
|
4500 | *
|
4501 | * To ensure cross-browser compatibility, the specified function should not be in ES6 format (i.e. `() => {}`).
|
4502 | * If the execution of the function fails, the first argument of the callback contains error information.
|
4503 | *
|
4504 | * @example
|
4505 | * this.demoTest = function (browser) {
|
4506 | * browser.execute(function(imageData) {
|
4507 | * // resize operation
|
4508 | * return true;
|
4509 | * }, [imageData], function(result) {
|
4510 | * // result.value === true
|
4511 | * });
|
4512 | * }
|
4513 | */
|
4514 | execute<T>(
|
4515 | body: ((this: undefined, ...data: any[]) => T) | string,
|
4516 | args?: any[],
|
4517 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<T>) => void,
|
4518 | ): this;
|
4519 |
|
4520 | /**
|
4521 | * 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.
|
4522 | *
|
4523 | * The function to be injected receives the `done` callback as argument which needs to be called when the asynchronous operation finishes.
|
4524 | * The value passed to the `done` callback is returned to the client.
|
4525 | * Additional arguments for the injected function may be passed as a non-empty array which will be passed before the `done` callback.
|
4526 | *
|
4527 | * 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.
|
4528 | *
|
4529 | * @example
|
4530 | * this.demoTest = function (browser) {
|
4531 | * browser.executeAsync(function(done) {
|
4532 | * setTimeout(function() {
|
4533 | * done(true);
|
4534 | * }, 500);
|
4535 | * }, function(result) {
|
4536 | * // result.value === true
|
4537 | * });
|
4538 | *
|
4539 | * browser.executeAsync(function(arg1, arg2, done) {
|
4540 | * setTimeout(function() {
|
4541 | * done(true);
|
4542 | * }, 500);
|
4543 | * }, [arg1, arg2], function(result) {
|
4544 | * // result.value === true
|
4545 | * });
|
4546 | * }
|
4547 | */
|
4548 | executeAsync(
|
4549 | script: ((this: undefined, ...data: any[]) => any) | string,
|
4550 | args?: any[],
|
4551 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void,
|
4552 | ): this;
|
4553 | }
|
4554 |
|
4555 | export interface WebDriverProtocolCookies {
|
4556 | /**
|
4557 | * 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:
|
4558 | * <code>getCookie</code>, <code>getCookies</code>, <code>setCookie</code>, <code>deleteCookie</code>, <code>deleteCookies</code>.
|
4559 | *
|
4560 | * @see getCookies
|
4561 | * @see getCookie
|
4562 | * @see setCookie
|
4563 | * @see deleteCookie
|
4564 | * @see deleteCookies
|
4565 | */
|
4566 | cookie(method: string, callbackOrCookie?: () => void): this;
|
4567 | }
|
4568 |
|
4569 | export interface WebDriverProtocolUserActions {
|
4570 | /**
|
4571 | * Move to the element and peforms a double-click in the middle of the element.
|
4572 | *
|
4573 | * @example
|
4574 | * module.exports = {
|
4575 | * demoTest() {
|
4576 | * browser.doubleClick('#main ul li a.first');
|
4577 | *
|
4578 | * browser.doubleClick('#main ul li a.first', function(result) {
|
4579 | * console.log('double click result', result);
|
4580 | * });
|
4581 | *
|
4582 | * // with explicit locate strategy
|
4583 | * browser.doubleClick('css selector', '#main ul li a.first');
|
4584 | *
|
4585 | * // with selector object - see https://nightwatchjs.org/guide#element-properties
|
4586 | * browser.doubleClick({
|
4587 | * selector: '#main ul li a',
|
4588 | * index: 1,
|
4589 | * suppressNotFoundErrors: true
|
4590 | * });
|
4591 | *
|
4592 | * browser.doubleClick({
|
4593 | * selector: '#main ul li a.first',
|
4594 | * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
|
4595 | * });
|
4596 | * },
|
4597 | *
|
4598 | * demoTestAsync: async function() {
|
4599 | * const result = await browser.doubleClick('#main ul li a.first');
|
4600 | * console.log('double click result', result);
|
4601 | * }
|
4602 | * }
|
4603 | */
|
4604 | doubleClick(
|
4605 | selector: string,
|
4606 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4607 | ): this;
|
4608 | doubleClick(
|
4609 | using: LocateStrategy,
|
4610 | selector: string,
|
4611 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4612 | ): this;
|
4613 |
|
4614 | /**
|
4615 | * Click at the current mouse coordinates (set by `.moveTo()`).
|
4616 | *
|
4617 | * The button can be (0, 1, 2) or ('left', 'middle', 'right'). It defaults to left mouse button.
|
4618 | *
|
4619 | * @deprecated
|
4620 | */
|
4621 | mouseButtonClick(
|
4622 | button: 0 | 1 | 2 | 'left' | 'middle' | 'right',
|
4623 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4624 | ): this;
|
4625 |
|
4626 | /**
|
4627 | * 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` .
|
4628 | * Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour.
|
4629 | *
|
4630 | * 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,
|
4631 | * and if you don't pass in a button but do pass in a callback, it will handle it correctly.
|
4632 | *
|
4633 | * **Since v2.0, this command is deprecated.** It is only available on older JSONWire-based drivers.
|
4634 | * Please use the new [User Actions API](/api/useractions/).
|
4635 | *
|
4636 | * @deprecated
|
4637 | */
|
4638 | mouseButtonDown(
|
4639 | button: 0 | 1 | 2 | 'left' | 'middle' | 'right',
|
4640 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4641 | ): this;
|
4642 |
|
4643 | /**
|
4644 | * Releases the mouse button previously held (where the mouse is currently at). Must be called once for every `mouseButtonDown` command issued.
|
4645 | *
|
4646 | * 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,
|
4647 | * and if you don't pass in a button but do pass in a callback, it will handle it correctly.
|
4648 | *
|
4649 | * **Since v2.0, this command is deprecated.** It is only available on older JSONWire-based drivers.
|
4650 | * Please use the new [User Actions API](/api/useractions/).
|
4651 | *
|
4652 | * @deprecated
|
4653 | */
|
4654 | mouseButtonUp(
|
4655 | button: 0 | 1 | 2 | 'left' | 'middle' | 'right',
|
4656 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4657 | ): this;
|
4658 |
|
4659 | /**
|
4660 | * 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.
|
4661 | * If an element is provided but no offset, the mouse will be moved to the center of the element.
|
4662 | *
|
4663 | * 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.
|
4664 | *
|
4665 | * @example
|
4666 | * this.demoTest = function (browser) {
|
4667 | * browser.moveTo(null, 110, 100);
|
4668 | * };
|
4669 | */
|
4670 | moveTo(
|
4671 | element: string | null,
|
4672 | xoffset: number,
|
4673 | yoffset: number,
|
4674 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4675 | ): this;
|
4676 | }
|
4677 |
|
4678 | export interface WebDriverProtocolUserPrompts {
|
4679 | /**
|
4680 | * Accepts the currently displayed alert dialog. Usually, this is equivalent to clicking on the 'OK' button in the dialog.
|
4681 | *
|
4682 | * @example
|
4683 | * browser.acceptAlert()
|
4684 | */
|
4685 | acceptAlert(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
4686 |
|
4687 | /**
|
4688 | * Dismisses the currently displayed alert dialog. For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button.
|
4689 | *
|
4690 | * For alert() dialogs, this is equivalent to clicking the 'OK' button.
|
4691 | *
|
4692 | * @example
|
4693 | * browser.dismissAlert();
|
4694 | */
|
4695 | dismissAlert(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
4696 |
|
4697 | /**
|
4698 | * Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog.
|
4699 | *
|
4700 | * @example
|
4701 | * browser.getAlertText();
|
4702 | */
|
4703 | getAlertText(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string>) => void): this;
|
4704 |
|
4705 | /**
|
4706 | * Sends keystrokes to a JavaScript prompt() dialog.
|
4707 | *
|
4708 | * @example
|
4709 | * browser.setAlertText('randomalert');
|
4710 | */
|
4711 | setAlertText(value: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): this;
|
4712 | }
|
4713 |
|
4714 | export interface WebDriverProtocolScreenCapture {
|
4715 | /**
|
4716 | * Take a screenshot of the current page.
|
4717 | *
|
4718 | * @example
|
4719 | * browser.screenshot(true);
|
4720 | */
|
4721 | screenshot(log_screenshot_data: boolean, callback?: (screenshotEncoded: string) => void): this;
|
4722 | }
|
4723 |
|
4724 | export interface WebDriverProtocolMobileRelated {
|
4725 | /**
|
4726 | * Get the current browser orientation.
|
4727 | *
|
4728 | * @example
|
4729 | * browser.getOrientation()
|
4730 | */
|
4731 | getOrientation(
|
4732 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<'LANDSCAPE' | 'PORTRAIT'>) => void,
|
4733 | ): this;
|
4734 |
|
4735 | /**
|
4736 | * Sets the browser orientation.
|
4737 | *
|
4738 | * @example
|
4739 | * browser.setOrientation(orientation)
|
4740 | */
|
4741 | setOrientation(
|
4742 | orientation: 'LANDSCAPE' | 'PORTRAIT',
|
4743 | callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
|
4744 | ): this;
|
4745 |
|
4746 | /**
|
4747 | * Get a list of the available contexts.
|
4748 | *
|
4749 | * @example
|
4750 | * browser.contexts();
|
4751 | *
|
4752 | * 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.
|
4753 | */
|
4754 | contexts(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void): this;
|
4755 |
|
4756 | /**
|
4757 | * Get current context.
|
4758 | *
|
4759 | * @example
|
4760 | * browser.currentContext();
|
4761 | */
|
4762 | currentContext(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void): this;
|
4763 |
|
4764 | /**
|
4765 | * Sets the context.
|
4766 | *
|
4767 | * @example
|
4768 | * browser.setContext(context);
|
4769 | */
|
4770 | setContext(context: string, callback?: () => void): this;
|
4771 | }
|
4772 |
|
4773 | /**
|
4774 | * Map of DOM element locators as shorthand string selectors based on
|
4775 | * global selector setting or ElementLocator
|
4776 | *
|
4777 | * @example
|
4778 | * const elements: PageElements {
|
4779 | * header: "h1",
|
4780 | * banner: {
|
4781 | * locateStrategy: "css selector",
|
4782 | * selector: "#bannerId"
|
4783 | * }
|
4784 | * }
|
4785 | */
|
4786 | export interface PageElements {
|
4787 | [key: string]: string | ElementProperties;
|
4788 | }
|
4789 |
|
4790 | /**
|
4791 | * Type for defining page object models allowing for optional type-safe
|
4792 | * inclusion of url, elements, sections, commands, and props properties.
|
4793 | */
|
4794 | export interface PageObjectModel {
|
4795 | url?: string | ((...args: any) => string);
|
4796 | elements?: PageElements;
|
4797 | sections?: EnhancedPageObjectSections;
|
4798 | commands?: any;
|
4799 | props?: any;
|
4800 | }
|
4801 |
|
\ | No newline at end of file |