nightwatch

  • Version 3.7.0
  • Published
  • 1.89 MB
  • 34 dependencies
  • MIT license

Install

npm i nightwatch
yarn add nightwatch
pnpm add nightwatch

Overview

Easy to use Node.js based end-to-end testing solution for web applications using the W3C WebDriver API.

Index

Variables

Functions

Classes

Interfaces

Type Aliases

Namespaces

Variables

variable _default

const _default: Nightwatch;

    variable alerts

    const alerts: AlertsNsCommands<unknown>;

      variable app

      const app: NightwatchAPI;

        variable appium

        const appium: AppiumCommands<unknown>;

          variable assert

          const assert: Assert<unknown>;

            variable browser

            const browser: NightwatchAPI;

              variable chrome

              const chrome: ChromeNsCommands<unknown>;

                variable cookies

                const cookies: CookiesNsCommands<unknown>;

                  variable document

                  const document: DocumentNsCommands<unknown>;

                    variable element

                    const element: ElementFunction;

                      variable ELEMENT_KEY

                      const ELEMENT_KEY: string;

                        variable expect

                        const expect: Expect;

                          variable firefox

                          const firefox: FirefoxNsCommands<unknown>;

                            variable verify

                            const verify: Assert<unknown>;

                              variable window

                              const window: WindowNsCommands<unknown>;

                                Functions

                                function globalElement

                                globalElement: (
                                locator: Definition,
                                options?: { isComponent?: boolean; type: string }
                                ) => ElementGlobal;

                                  Classes

                                  class DescribeInstance

                                  class DescribeInstance {}

                                    property '[attributes]'

                                    '[attributes]': {};

                                      property '[client]'

                                      '[client]': NightwatchClient;

                                        property '[instance]'

                                        '[instance]': any;

                                          property argv

                                          readonly argv: { [key: string]: any };
                                          • Get all current cli arguments.

                                          property desiredCapabilities

                                          desiredCapabilities: NightwatchDesiredCapabilities;
                                          • Get or set testsuite specific capabilities.

                                          property disabled

                                          disabled: boolean;
                                          • Set to true if you'd like this test suite to be skipped by the test runner.

                                          property endSessionOnFail

                                          endSessionOnFail: boolean;
                                          • Set to false if you'd like the browser window to be kept open in case of a failure or error (useful for debugging).

                                          property globals

                                          readonly globals: NightwatchGlobals;
                                          • Get all current globals.

                                          property mochaOptions

                                          readonly mochaOptions: { [key: string]: any };
                                          • Get all current mocha options.

                                          property name

                                          readonly name: string;
                                          • Title of the describe suite.

                                          property page

                                          readonly page: {
                                          [name: string]: () => EnhancedPageObject<any, any, any, {}, string>;
                                          } & { [name: string]: NightwatchPage } & NightwatchCustomPageObjects;
                                          • Get available page objects.

                                          property settings

                                          readonly settings: NightwatchOptions;
                                          • Get all current settings.

                                          property skipTestcasesOnFail

                                          skipTestcasesOnFail: boolean;
                                          • Set to false if you'd like the rest of the test cases/test steps to be executed in the event of an assertion failure/error.

                                          property tags

                                          tags: string | string[];
                                          • Get or set tags for the test suite.

                                            See Also

                                            • https://nightwatchjs.org/guide/running-tests/filtering-by-test-tags.html

                                          property unitTest

                                          unitTest: boolean;
                                          • Enable if the current test is a unit/integration test (no webdriver session is required).

                                          method retries

                                          retries: (n: number) => void;
                                          • How many time to retry a failed testcase inside this test suite

                                          method retryInterval

                                          retryInterval: (value: number) => void;
                                          • Control the polling interval between re-tries for assertions or element commands.

                                            Parameter value

                                            Time interval in ms

                                          method suiteRetries

                                          suiteRetries: (n: number) => void;
                                          • How many times to retry the current test suite in case of an assertion failure or error

                                          method timeout

                                          timeout: (value: number) => void;
                                          • Control the unit test timeout.

                                            Control the assertion and element commands timeout until when an element should be located or assertion passed.

                                            Parameter value

                                            Timeout in ms

                                          method waitForRetryInterval

                                          waitForRetryInterval: { (): number; (value: number): void };
                                          • Get the polling interval between re-tries for assertions or element commands.

                                            Returns

                                            Time interval in ms

                                          • Control the polling interval between re-tries for assertions or element commands.

                                            Parameter value

                                            Time interval in ms

                                          method waitForTimeout

                                          waitForTimeout: { (): number; (value: number): void };
                                          • Get the assertion and element commands timeout until when an element would be located or assertion passed.

                                            Returns

                                            Timeout in ms

                                          • Control the assertion and element commands timeout until when an element should be located or assertion passed.

                                            Parameter value

                                            Timeout in ms

                                          class Element

                                          class Element {}

                                            property abortOnFailure

                                            abortOnFailure?: boolean;

                                              property index

                                              index: number;

                                                property locateStrategy

                                                locateStrategy: LocateStrategy;

                                                  property message

                                                  message?: string;

                                                    property name

                                                    name: string;

                                                      property parent

                                                      parent: any;

                                                        property pseudoSelector

                                                        pseudoSelector: string;

                                                          property resolvedElement

                                                          resolvedElement: string;

                                                            property retryInterval

                                                            retryInterval?: number;

                                                              property selector

                                                              selector: string;

                                                                property suppressNotFoundErrors

                                                                suppressNotFoundErrors?: boolean;

                                                                  property timeout

                                                                  timeout?: number;

                                                                    property usingRecursion

                                                                    usingRecursion: boolean;

                                                                      property webElement

                                                                      webElement?: WebElement;

                                                                        property webElementId

                                                                        webElementId?: string;

                                                                          class ElementAssertions

                                                                          class ElementAssertions {}

                                                                            constructor

                                                                            constructor(element: ScopedElement, options: ElementAssertionsOptions);

                                                                              property not

                                                                              readonly not: ElementAssertions;

                                                                                method enabled

                                                                                enabled: (message?: string) => Promise<WebElement>;

                                                                                  method hasAttribute

                                                                                  hasAttribute: (name: string, message?: string) => Promise<WebElement>;

                                                                                    method hasClass

                                                                                    hasClass: (name: string, message?: string) => Promise<WebElement>;

                                                                                      method hasDescendants

                                                                                      hasDescendants: (message?: string) => Promise<WebElement>;

                                                                                        method present

                                                                                        present: (message?: string) => Promise<WebElement>;

                                                                                          method selected

                                                                                          selected: (message?: string) => Promise<WebElement>;

                                                                                            method visible

                                                                                            visible: (message?: string) => Promise<WebElement>;

                                                                                              class ElementLocator

                                                                                              class ElementLocator {}

                                                                                                constructor

                                                                                                constructor(selector: any, nightwatchInstance: NightwatchClient);

                                                                                                  property abortOnFailure

                                                                                                  abortOnFailure: boolean;

                                                                                                    property condition

                                                                                                    condition: any;

                                                                                                      property index

                                                                                                      index: number;

                                                                                                        property locateStrategy

                                                                                                        locateStrategy: LocateStrategy;

                                                                                                          property retryInterval

                                                                                                          retryInterval: number;

                                                                                                            property suppressNotFoundErrors

                                                                                                            suppressNotFoundErrors: boolean;

                                                                                                              property timeout

                                                                                                              timeout: number;

                                                                                                                class Elements

                                                                                                                class Elements implements PromiseLike<WebElement[]> {}

                                                                                                                  constructor

                                                                                                                  constructor(
                                                                                                                  selector: any,
                                                                                                                  parentScopedElement: ScopedElement,
                                                                                                                  nightwatchInstance: NightwatchClient
                                                                                                                  );

                                                                                                                    method count

                                                                                                                    count: () => ElementValue<number>;

                                                                                                                      method nth

                                                                                                                      nth: (index: number) => ScopedElement;

                                                                                                                        method then

                                                                                                                        then: <R1 = WebElement[], R2 = never>(
                                                                                                                        onfulfilled?: (value: WebElement[]) => R1 | PromiseLike<R1>,
                                                                                                                        onrejected?: (reason: any) => R2 | PromiseLike<R2>
                                                                                                                        ) => PromiseLike<R1 | R2>;

                                                                                                                          class ElementsAssertions

                                                                                                                          class ElementsAssertions {}

                                                                                                                            constructor

                                                                                                                            constructor(elements: Elements, options: ElementsAssertionsOptions);

                                                                                                                              property not

                                                                                                                              readonly not: ElementsAssertions;

                                                                                                                                class ElementValue

                                                                                                                                class ElementValue<T> implements PromiseLike<T> {}

                                                                                                                                  constructor

                                                                                                                                  constructor(value: T | PromiseLike<T>, nightwatchInstance: NightwatchClient);

                                                                                                                                    property assert

                                                                                                                                    readonly assert: ValueAssertions<T>;

                                                                                                                                      property value

                                                                                                                                      value: Promise<T>;

                                                                                                                                        method map

                                                                                                                                        map: <K>(callback: (value: T) => K | PromiseLike<K>) => ElementValue<K>;

                                                                                                                                          method then

                                                                                                                                          then: <R1 = T, R2 = never>(
                                                                                                                                          onfulfilled?: (value: T) => R1 | PromiseLike<R1>,
                                                                                                                                          onrejected?: (reason: any) => R2 | PromiseLike<R2>
                                                                                                                                          ) => PromiseLike<R1 | R2>;

                                                                                                                                            class ValueAssertions

                                                                                                                                            class ValueAssertions<T> {}

                                                                                                                                              constructor

                                                                                                                                              constructor(scopedValue: ElementValue<T>, options: ValueAssertionsOptions);

                                                                                                                                                property not

                                                                                                                                                readonly not: ValueAssertions<T>;

                                                                                                                                                  property scopedValue

                                                                                                                                                  scopedValue: ElementValue<T>;

                                                                                                                                                    method contains

                                                                                                                                                    contains: (expected: string, message?: string) => Promise<T>;

                                                                                                                                                      method equals

                                                                                                                                                      equals: (expected: T, message?: string) => Promise<T>;

                                                                                                                                                        method matches

                                                                                                                                                        matches: (expected: string | RegExp, message?: string) => Promise<T>;

                                                                                                                                                          Interfaces

                                                                                                                                                          interface AlertsNsCommands

                                                                                                                                                          interface AlertsNsCommands<ReturnType = unknown> {}

                                                                                                                                                            method accept

                                                                                                                                                            accept: (
                                                                                                                                                            callback?: (
                                                                                                                                                            this: NightwatchAPI,
                                                                                                                                                            result: NightwatchCallbackResult<null>
                                                                                                                                                            ) => void
                                                                                                                                                            ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                            • Accepts the currently displayed alert dialog. Usually, this is equivalent to clicking on the 'OK' button in the dialog.

                                                                                                                                                              Example 1

                                                                                                                                                              module.exports = { 'accept open alert': function (browser) { browser .alerts.accept(function () { console.log('alert accepted successfully'); }); },

                                                                                                                                                              'accept open alert with ES6 async/await': async function (browser) { await browser.alerts.accept(); } };

                                                                                                                                                            method dismiss

                                                                                                                                                            dismiss: (
                                                                                                                                                            callback?: (
                                                                                                                                                            this: NightwatchAPI,
                                                                                                                                                            result: NightwatchCallbackResult<null>
                                                                                                                                                            ) => void
                                                                                                                                                            ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                            • Dismisses the currently displayed alert dialog.

                                                                                                                                                              For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button. For alert() dialogs, this is equivalent to clicking the 'OK' button.

                                                                                                                                                              Example 1

                                                                                                                                                              module.exports = { 'dismiss open alert': function (browser) { browser .alerts.dismiss(function () { console.log('alert dismissed successfully'); }); },

                                                                                                                                                              'dismiss open alert with ES6 async/await': async function (browser) { await browser.alerts.dismiss(); } };

                                                                                                                                                            method getText

                                                                                                                                                            getText: (
                                                                                                                                                            callback?: (
                                                                                                                                                            this: NightwatchAPI,
                                                                                                                                                            result: NightwatchCallbackResult<string>
                                                                                                                                                            ) => void
                                                                                                                                                            ) => Awaitable<IfUnknown<ReturnType, this>, string>;
                                                                                                                                                            • Get the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog.

                                                                                                                                                              Example 1

                                                                                                                                                              module.exports = { 'get open alert text': function (browser) { browser .alerts.getText(function (result) { console.log('text on open alert:', result.value); }); },

                                                                                                                                                              'get open alert text with ES6 async/await': async function (browser) { const alertText = await browser.alerts.getText(); console.log('text on open alert:', alertText); } };

                                                                                                                                                            method setText

                                                                                                                                                            setText: (
                                                                                                                                                            value: string,
                                                                                                                                                            callback?: (
                                                                                                                                                            this: NightwatchAPI,
                                                                                                                                                            result: NightwatchCallbackResult<null>
                                                                                                                                                            ) => void
                                                                                                                                                            ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                            • Send keystrokes to a JavaScript prompt() dialog.

                                                                                                                                                              Example 1

                                                                                                                                                              module.exports = { 'set text on JS prompt': function (browser) { browser .alerts.setText('some text', function () { console.log('text sent to JS prompt successfully'); }); },

                                                                                                                                                              'set text on JS prompt with ES6 async/await': async function (browser) { await browser.alerts.setText('some text'); } };

                                                                                                                                                            interface AppiumCommands

                                                                                                                                                            interface AppiumCommands<ReturnType = unknown> {}

                                                                                                                                                              method getContext

                                                                                                                                                              getContext: (
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<string | null>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, string | null>;
                                                                                                                                                              • Get the current context in which Appium is running. Used when testing hybrid mobile apps using Appium.

                                                                                                                                                                More info here: https://appium.io/docs/en/commands/context/get-context/

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'get current context': function (app) { app .appium.getContext(function (result) { console.log('the current context is:', result.value); }); },

                                                                                                                                                                'get current context with ES6 async/await': async function (app) { const context = await app.appium.getContext(); console.log('the current context is:', context); } };

                                                                                                                                                              method getContexts

                                                                                                                                                              getContexts: (
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<string[]>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, string[]>;
                                                                                                                                                              • Get a list of the available contexts. Used when testing hybrid mobile apps using Appium.

                                                                                                                                                                More info here: https://appium.io/docs/en/commands/context/get-contexts/

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'get available contexts': function (app) { app .appium.getContexts(function (result) { console.log('the available contexts are:', result.value); }); },

                                                                                                                                                                'get available contexts with ES6 async/await': async function (app) { const contexts = await app.appium.getContexts(); console.log('the available contexts are:', contexts); } };

                                                                                                                                                              method getCurrentActivity

                                                                                                                                                              getCurrentActivity: (
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<string>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, string>;
                                                                                                                                                              • Get the name of the current Android activity.

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'get current activity name': function (app) { app .appium.getCurrentActivity(function (result) { console.log('current android activity is:', result.value); }); },

                                                                                                                                                                'get current activity name with ES6 async/await': async function (app) { const activity = await app.appium.getCurrentActivity(); console.log('current android activity is:', activity); } };

                                                                                                                                                              method getCurrentPackage

                                                                                                                                                              getCurrentPackage: (
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<string>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, string>;
                                                                                                                                                              • Get the name of the current Android package.

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'get current package name': function (app) { app .appium.getCurrentPackage(function (result) { console.log('current android package is:', result.value); }); },

                                                                                                                                                                'get current package name with ES6 async/await': async function (app) { const packageName = await app.appium.getCurrentPackage(); console.log('current android package is:', packageName); } };

                                                                                                                                                              method getGeolocation

                                                                                                                                                              getGeolocation: (
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<AppiumGeolocation>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, AppiumGeolocation>;
                                                                                                                                                              • Get the current geolocation of the mobile device.

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'get device geolocation': function (app) { app .appium.getGeolocation(function (result) { console.log('current device geolocation is:', result.value); }); },

                                                                                                                                                                'get device geolocation with ES6 async/await': async function (app) { const location = await app.appium.getGeolocation(); console.log('current device geolocation is:', location); } };

                                                                                                                                                              method getOrientation

                                                                                                                                                              getOrientation: (
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<'LANDSCAPE' | 'PORTRAIT'>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, 'LANDSCAPE' | 'PORTRAIT'>;
                                                                                                                                                              • Get the current device orientation.

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'get current device orientation': function (app) { app .appium.getOrientation(function (result) { console.log('current device orientation is:', result.value); }); },

                                                                                                                                                                'get current device orientation with ES6 async/await': async function (app) { const orientation = await app.appium.getOrientation(); console.log('current device orientation is:', orientation); } };

                                                                                                                                                              method hideKeyboard

                                                                                                                                                              hideKeyboard: (
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<boolean>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, boolean>;
                                                                                                                                                              • Hide soft keyboard.

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'hide device soft keyboard': function (app) { app .appium.hideKeyboard(); },

                                                                                                                                                                'hide device soft keyboard with ES6 async/await': async function (app) { await app.appium.hideKeyboard(); } };

                                                                                                                                                              method isKeyboardShown

                                                                                                                                                              isKeyboardShown: (
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<boolean>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, boolean>;
                                                                                                                                                              • Whether or not the soft keyboard is shown.

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'whether keyboard is shown': function (app) { app .appium.isKeyboardShown(function (result) { console.log('result value of whether keyboard is shown:', result.value); }); },

                                                                                                                                                                'whether keyboard is shown with ES6 async/await': async function (app) { const result = await app.appium.isKeyboardShown(); console.log('result value of whether keyboard is shown:', result); } };

                                                                                                                                                              method longPressKeyCode

                                                                                                                                                              longPressKeyCode: {
                                                                                                                                                              (
                                                                                                                                                              keycode: number,
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<null>
                                                                                                                                                              ) => void
                                                                                                                                                              ): Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                              (
                                                                                                                                                              keycode: number,
                                                                                                                                                              metastate?: number,
                                                                                                                                                              flags?: number,
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<null>
                                                                                                                                                              ) => void
                                                                                                                                                              ): Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                              };
                                                                                                                                                              • Press and hold a particular key on an Android Device.

                                                                                                                                                                See [official Android Developers docs](https://developer.android.com/reference/android/view/KeyEvent.html) for reference of available Android key code values.

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'long press e with caps lock on (keycode 33 and metastate 1048576)': function (app) { app .appium.longPressKeyCode(33, 1048576); },

                                                                                                                                                                'long press g (keycode 35) with ES6 async/await': async function (app) { await app.appium.longPressKeyCode(35); } };

                                                                                                                                                              method pressKeyCode

                                                                                                                                                              pressKeyCode: {
                                                                                                                                                              (
                                                                                                                                                              keycode: number,
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<null>
                                                                                                                                                              ) => void
                                                                                                                                                              ): Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                              (
                                                                                                                                                              keycode: number,
                                                                                                                                                              metastate?: number,
                                                                                                                                                              flags?: number,
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<null>
                                                                                                                                                              ) => void
                                                                                                                                                              ): Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                              };
                                                                                                                                                              • Press a particular key on an Android Device.

                                                                                                                                                                See [official Android Developers docs](https://developer.android.com/reference/android/view/KeyEvent.html) for reference of available Android key code values.

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'press e with caps lock on (keycode 33 and metastate 1048576)': function (app) { app .appium.pressKeyCode(33, 1048576); },

                                                                                                                                                                'press g (keycode 35) with ES6 async/await': async function (app) { await app.appium.pressKeyCode(35); } };

                                                                                                                                                              method resetApp

                                                                                                                                                              resetApp: (
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<null>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                              • Reset the current session (run delete and create session).

                                                                                                                                                                More info here: https://appium.io/docs/en/2.3/commands/base-driver/#reset

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'start an android activity': function (app) { app .appium.resetApp(); },

                                                                                                                                                                'reset the app activity and wait for onboarding activity to start': function (app) { app .appium.resetApp(); } };

                                                                                                                                                              method setContext

                                                                                                                                                              setContext: (
                                                                                                                                                              context: string,
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<null>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                              • Set the context to be automated. Used when testing hybrid mobile apps using Appium.

                                                                                                                                                                More info here: https://appium.io/docs/en/commands/context/set-context/

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'switch to webview context': async function (app) { app .waitUntil(async function() { // wait for webview context to be available // initially, this.getContexts() only returns ['NATIVE_APP'] const contexts = await this.appium.getContexts();

                                                                                                                                                                return contexts.length > 1; }) .perform(async function() { // switch to webview context const contexts = await this.appium.getContexts(); // contexts: ['NATIVE_APP', 'WEBVIEW_'] await this.appium.setContext(contexts[1]); }); },

                                                                                                                                                                'switch to native context': function (app) { app.appium.setContext('NATIVE_APP'); } };

                                                                                                                                                              method setGeolocation

                                                                                                                                                              setGeolocation: (
                                                                                                                                                              coordinates: AppiumGeolocation,
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<AppiumGeolocation>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, AppiumGeolocation>;
                                                                                                                                                              • Set the current geolocation of the mobile device.

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'set geolocation to Tokyo, Japan': function (app) { app .appium.setGeolocation({latitude: 35.689487, longitude: 139.691706, altitude: 5}); },

                                                                                                                                                                'set geolocation to Tokyo, Japan with ES6 async/await': async function (app) { await app.appium.setGeolocation({latitude: 35.689487, longitude: 139.691706}); } };

                                                                                                                                                              method setOrientation

                                                                                                                                                              setOrientation: (
                                                                                                                                                              orientation: 'LANDSCAPE' | 'PORTRAIT',
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<'LANDSCAPE' | 'PORTRAIT'>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, 'LANDSCAPE' | 'PORTRAIT'>;
                                                                                                                                                              • Set the current device orientation.

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'set orientation to LANDSCAPE': function (app) { app .appium.setOrientation('LANDSCAPE'); } };

                                                                                                                                                              method startActivity

                                                                                                                                                              startActivity: (
                                                                                                                                                              opts: {
                                                                                                                                                              appPackage: string;
                                                                                                                                                              appActivity: string;
                                                                                                                                                              appWaitPackage?: string;
                                                                                                                                                              appWaitActivity?: string;
                                                                                                                                                              intentAction?: string;
                                                                                                                                                              intentCategory?: string;
                                                                                                                                                              intentFlags?: string;
                                                                                                                                                              optionalIntentArguments?: string;
                                                                                                                                                              dontStopAppOnReset?: boolean;
                                                                                                                                                              },
                                                                                                                                                              callback?: (
                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                              result: NightwatchCallbackResult<null>
                                                                                                                                                              ) => void
                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                              • Start an Android activity by providing package name, activity name and other optional parameters.

                                                                                                                                                                More info here: https://appium.io/docs/en/commands/device/activity/start-activity/

                                                                                                                                                                Example 1

                                                                                                                                                                module.exports = { 'start an android activity': function (app) { app .appium.startActivity({ appPackage: 'com.android.chrome', appActivity: 'com.google.android.apps.chrome.Main' }); },

                                                                                                                                                                'start the main Android activity and wait for onboarding activity to start': function (app) { app .appium.startActivity({ appPackage: 'org.wikipedia', appActivity: 'org.wikipedia.main.MainActivity', appWaitActivity: 'org.wikipedia.onboarding.InitialOnboardingActivity' }); } };

                                                                                                                                                              interface AppiumGeolocation

                                                                                                                                                              interface AppiumGeolocation {}

                                                                                                                                                                property altitude

                                                                                                                                                                altitude?: number;

                                                                                                                                                                  property latitude

                                                                                                                                                                  latitude: number;

                                                                                                                                                                    property longitude

                                                                                                                                                                    longitude: number;

                                                                                                                                                                      interface Assert

                                                                                                                                                                      interface Assert<ReturnType = unknown>
                                                                                                                                                                      extends NightwatchAssertions<ReturnType>,
                                                                                                                                                                      NightwatchNodeAssertions<ReturnType> {}

                                                                                                                                                                        interface ChromeNsCommands

                                                                                                                                                                        interface ChromeNsCommands<ReturnType = unknown> {}

                                                                                                                                                                          method deleteNetworkConditions

                                                                                                                                                                          deleteNetworkConditions: () => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                          • Delete Chromium network emulation settings.

                                                                                                                                                                          method getCastIssueMessage

                                                                                                                                                                          getCastIssueMessage: () => Awaitable<IfUnknown<ReturnType, this>, string>;
                                                                                                                                                                          • Returns an error message when there is any issue in a Cast session.

                                                                                                                                                                          method getCastSinks

                                                                                                                                                                          getCastSinks: () => Awaitable<IfUnknown<ReturnType, this>, string[]>;
                                                                                                                                                                          • Returns the list of cast sinks (Cast devices) available to the Chrome media router.

                                                                                                                                                                            An array of Strings containing the friendly device names of available cast sink targets.

                                                                                                                                                                          method getNetworkConditions

                                                                                                                                                                          getNetworkConditions: () => Awaitable<
                                                                                                                                                                          IfUnknown<ReturnType, this>,
                                                                                                                                                                          NetworkConditionsSpec
                                                                                                                                                                          >;
                                                                                                                                                                          • Get Chromium network emulation settings.

                                                                                                                                                                            Network conditions must be set before it can be retrieved.

                                                                                                                                                                          method launchApp

                                                                                                                                                                          launchApp: (id: string) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                          • Launch Chrome App with given ID.

                                                                                                                                                                            Parameter id

                                                                                                                                                                            ID of the App to launch.

                                                                                                                                                                          method sendAndGetDevToolsCommand

                                                                                                                                                                          sendAndGetDevToolsCommand: (
                                                                                                                                                                          cmd: string,
                                                                                                                                                                          params?: { [key: string]: any }
                                                                                                                                                                          ) => Awaitable<IfUnknown<ReturnType, this>, unknown>;
                                                                                                                                                                          • Sends an arbitrary devtools command to the browser and get the result.

                                                                                                                                                                            Parameter cmd

                                                                                                                                                                            The name of the command to send.

                                                                                                                                                                            Parameter params

                                                                                                                                                                            The command parameters.

                                                                                                                                                                            See Also

                                                                                                                                                                            • <https://chromedevtools.github.io/devtools-protocol/>

                                                                                                                                                                          method sendDevToolsCommand

                                                                                                                                                                          sendDevToolsCommand: (
                                                                                                                                                                          cmd: string,
                                                                                                                                                                          params?: { [key: string]: any }
                                                                                                                                                                          ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                          • Sends an arbitrary devtools command to the browser.

                                                                                                                                                                            Parameter cmd

                                                                                                                                                                            The name of the command to send.

                                                                                                                                                                            Parameter params

                                                                                                                                                                            The command parameters.

                                                                                                                                                                            See Also

                                                                                                                                                                            • <https://chromedevtools.github.io/devtools-protocol/>

                                                                                                                                                                          method setCastSinkToUse

                                                                                                                                                                          setCastSinkToUse: (
                                                                                                                                                                          deviceName: string
                                                                                                                                                                          ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                          • Selects a cast sink (Cast device) as the recipient of media router intents (connect or play).

                                                                                                                                                                            Parameter deviceName

                                                                                                                                                                            name of the target device.

                                                                                                                                                                          method setDownloadPath

                                                                                                                                                                          setDownloadPath: (path: string) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                          • Sends a DevTools command to change the browser's download directory.

                                                                                                                                                                            Parameter path

                                                                                                                                                                            The desired download directory.

                                                                                                                                                                            See Also

                                                                                                                                                                            • chrome.sendDevToolsCommand

                                                                                                                                                                          method setNetworkConditions

                                                                                                                                                                          setNetworkConditions: (
                                                                                                                                                                          spec: NetworkConditionsSpec
                                                                                                                                                                          ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                          • Set Chromium network emulation settings.

                                                                                                                                                                            Parameter spec

                                                                                                                                                                            Defines the network conditions to set

                                                                                                                                                                            Example 1

                                                                                                                                                                            describe('set network conditions', function() { it('sets the network conditions', function() { browser .chrome.setNetworkConditions({ offline: false, latency: 5, // Additional latency (ms). download_throughput: 500 * 1024, // Maximal aggregated download throughput. upload_throughput: 500 * 1024 // Maximal aggregated upload throughput. }); }); });

                                                                                                                                                                          method setPermission

                                                                                                                                                                          setPermission: (
                                                                                                                                                                          name: string,
                                                                                                                                                                          state: 'granted' | 'denied' | 'prompt'
                                                                                                                                                                          ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                          • Set a permission state to the given value.

                                                                                                                                                                            Parameter name

                                                                                                                                                                            A name of the permission to update.

                                                                                                                                                                            Parameter state

                                                                                                                                                                            State to set permission to.

                                                                                                                                                                            See Also

                                                                                                                                                                            • <https://w3c.github.io/permissions/#permission-registry> for valid names

                                                                                                                                                                          method startCastTabMirroring

                                                                                                                                                                          startCastTabMirroring: (
                                                                                                                                                                          deviceName: string
                                                                                                                                                                          ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                          • Initiates tab mirroring for the current browser tab on the specified device.

                                                                                                                                                                            Parameter deviceName

                                                                                                                                                                            name of the target device.

                                                                                                                                                                          method stopCasting

                                                                                                                                                                          stopCasting: (
                                                                                                                                                                          deviceName: string
                                                                                                                                                                          ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                          • Stops casting from media router to the specified device, if connected.

                                                                                                                                                                            Parameter deviceName

                                                                                                                                                                            name of the target device.

                                                                                                                                                                          interface ChromiumClientCommands

                                                                                                                                                                          interface ChromiumClientCommands {}

                                                                                                                                                                            property captureBrowserConsoleLogs

                                                                                                                                                                            captureBrowserConsoleLogs: LogsNsCommands<this>['captureBrowserConsoleLogs'];

                                                                                                                                                                              property captureBrowserExceptions

                                                                                                                                                                              captureBrowserExceptions: LogsNsCommands<this>['captureBrowserExceptions'];

                                                                                                                                                                                property captureNetworkRequests

                                                                                                                                                                                captureNetworkRequests: NetworkNsCommands<this>['captureRequests'];

                                                                                                                                                                                  property mockNetworkResponse

                                                                                                                                                                                  mockNetworkResponse: NetworkNsCommands<this>['mockResponse'];

                                                                                                                                                                                    property setNetworkConditions

                                                                                                                                                                                    setNetworkConditions: NetworkNsCommands<this>['setConditions'];

                                                                                                                                                                                      method enablePerformanceMetrics

                                                                                                                                                                                      enablePerformanceMetrics: (
                                                                                                                                                                                      enable?: boolean,
                                                                                                                                                                                      callback?: (
                                                                                                                                                                                      this: NightwatchAPI,
                                                                                                                                                                                      result: NightwatchCallbackResult<null>
                                                                                                                                                                                      ) => void
                                                                                                                                                                                      ) => Awaitable<this, null>;
                                                                                                                                                                                      • Enable/disable the collection of performance metrics in the browser. Metrics collection only begin after this command is called.

                                                                                                                                                                                        Example 1

                                                                                                                                                                                        describe('collect performance metrics', function() { it('enables the metrics collection, does some stuff and collects the metrics', function() { browser .enablePerformanceMetrics() .navigateTo('https://www.google.com') .getPerformanceMetrics((result) => { if (result.status === 0) { const metrics = result.value; console.log(metrics); } }); }); });

                                                                                                                                                                                        See Also

                                                                                                                                                                                        • https://web.dev/metrics/

                                                                                                                                                                                        • https://pptr.dev/api/puppeteer.page.metrics/

                                                                                                                                                                                      method getPerformanceMetrics

                                                                                                                                                                                      getPerformanceMetrics: (
                                                                                                                                                                                      callback?: (
                                                                                                                                                                                      this: NightwatchAPI,
                                                                                                                                                                                      result: NightwatchCallbackResult<{ [metricName: string]: number }>
                                                                                                                                                                                      ) => void
                                                                                                                                                                                      ) => Awaitable<this, { [metricName: string]: number }>;
                                                                                                                                                                                      • Get the performance metrics from the browser. Metrics collection only begin after enablePerformanceMetrics() command is called.

                                                                                                                                                                                        Returns

                                                                                                                                                                                        A promise that contains metrics collected between the last call to enablePerformanceMetrics() command and this command.

                                                                                                                                                                                        Example 1

                                                                                                                                                                                        describe('collect performance metrics', function() { it('enables the metrics collection, does some stuff and collects the metrics', function() { browser .enablePerformanceMetrics() .navigateTo('https://www.google.com') .getPerformanceMetrics((result) => { if (result.status === 0) { const metrics = result.value; console.log(metrics); } }); }); });

                                                                                                                                                                                        See Also

                                                                                                                                                                                        • https://web.dev/metrics/

                                                                                                                                                                                        • https://pptr.dev/api/puppeteer.page.metrics/

                                                                                                                                                                                      method setDeviceDimensions

                                                                                                                                                                                      setDeviceDimensions: (
                                                                                                                                                                                      metrics?: {
                                                                                                                                                                                      width?: number;
                                                                                                                                                                                      height?: number;
                                                                                                                                                                                      deviceScaleFactor?: number;
                                                                                                                                                                                      mobile?: boolean;
                                                                                                                                                                                      },
                                                                                                                                                                                      callback?: (
                                                                                                                                                                                      this: NightwatchAPI,
                                                                                                                                                                                      result: NightwatchCallbackResult<null>
                                                                                                                                                                                      ) => void
                                                                                                                                                                                      ) => Awaitable<this, null>;
                                                                                                                                                                                      • Override device mode/dimensions.

                                                                                                                                                                                        Example 1

                                                                                                                                                                                        describe('modify device dimensions', function() { it('modifies the device dimensions and then resets it', function() { browser .setDeviceDimensions({ width: 400, height: 600, deviceScaleFactor: 50, mobile: true }) .navigateTo('https://www.google.com') .pause(1000) .setDeviceDimensions() // resets the device dimensions .navigateTo('https://www.google.com') .pause(1000); }); });

                                                                                                                                                                                        See Also

                                                                                                                                                                                        • https://nightwatchjs.org/guide/mobile-web-testing/override-device-dimensions.html

                                                                                                                                                                                      method setGeolocation

                                                                                                                                                                                      setGeolocation: (
                                                                                                                                                                                      coordinates?: { latitude: number; longitude: number; accuracy?: number },
                                                                                                                                                                                      callback?: (
                                                                                                                                                                                      this: NightwatchAPI,
                                                                                                                                                                                      result: NightwatchCallbackResult<null>
                                                                                                                                                                                      ) => void
                                                                                                                                                                                      ) => Awaitable<this, null>;
                                                                                                                                                                                      • Mock the geolocation of the browser.

                                                                                                                                                                                        Call without any arguments to reset the geolocation.

                                                                                                                                                                                        Example 1

                                                                                                                                                                                        describe('mock geolocation', function() { it('sets the geolocation to Tokyo, Japan and then resets it', () => { browser .setGeolocation({ latitude: 35.689487, longitude: 139.691706, accuracy: 100 }) // sets the geolocation to Tokyo, Japan .navigateTo('https://www.gps-coordinates.net/my-location') .pause(3000) .setGeolocation() // resets the geolocation .navigateTo('https://www.gps-coordinates.net/my-location') .pause(3000); }); });

                                                                                                                                                                                        See Also

                                                                                                                                                                                        • https://nightwatchjs.org/guide/network-requests/mock-geolocation.html

                                                                                                                                                                                      method takeHeapSnapshot

                                                                                                                                                                                      takeHeapSnapshot: (
                                                                                                                                                                                      heapSnapshotLocation?: string,
                                                                                                                                                                                      callback?: (
                                                                                                                                                                                      this: NightwatchAPI,
                                                                                                                                                                                      result: NightwatchCallbackResult<string>
                                                                                                                                                                                      ) => void
                                                                                                                                                                                      ) => Awaitable<this, string>;
                                                                                                                                                                                      • Take heap snapshot and save it as a .heapsnapshot file. The saved snapshot file can then be loaded into Chrome DevTools' Memory tab for inspection.

                                                                                                                                                                                        The contents of the heap snapshot are also available in the value property of the result argument passed to the callback, in string-serialized JSON format.

                                                                                                                                                                                        Returns

                                                                                                                                                                                        A promise that contains heap snapshot in string-serialized JSON format.

                                                                                                                                                                                        Example 1

                                                                                                                                                                                        describe('take heap snapshot', function() { it('takes heap snapshot and saves it as snap.heapsnapshot file', function() { browser .navigateTo('https://www.google.com') .takeHeapSnapshot('./snap.heapsnapshot'); }); });

                                                                                                                                                                                        See Also

                                                                                                                                                                                        • https://nightwatchjs.org/guide/running-tests/take-heap-snapshot.html

                                                                                                                                                                                      interface ClientCommands

                                                                                                                                                                                      interface ClientCommands extends ChromiumClientCommands {}

                                                                                                                                                                                        method axeInject

                                                                                                                                                                                        axeInject: () => Awaitable<this, null>;
                                                                                                                                                                                        • Injects the [axe-core](https://github.com/dequelabs/axe-core) js library into the current page (using the .executeScript() command). To be paired with .axeRun() to evaluate the axe-core accessibility rules.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          describe('accessibility testing', function () { it('accessibility rule subset', function (browser) { browser .url('https://www.w3.org/WAI/demos/bad/after/home.html') .assert.titleEquals('Welcome to CityLights! [Accessible Home Page]') .axeInject() .axeRun('body', { runOnly: ['color-contrast', 'image-alt'], }); }); });

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/axeInject.html

                                                                                                                                                                                        method axeRun

                                                                                                                                                                                        axeRun: (
                                                                                                                                                                                        context?: unknown,
                                                                                                                                                                                        options?: { [key: string]: any },
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<{ [key: string]: any }>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, { [key: string]: any }>;
                                                                                                                                                                                        • Analyzes the current page against applied axe rules.

                                                                                                                                                                                          Parameter context

                                                                                                                                                                                          Defines the scope of the analysis, will cascade to child elements. See [axe-core docs](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#context-parameter) for more details.

                                                                                                                                                                                          Parameter options

                                                                                                                                                                                          Allows configuration of what rules will be run (accessibility standard or rules to enable/disable). See [axe-core docs](https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter) for more details.

                                                                                                                                                                                          Parameter callback

                                                                                                                                                                                          Optional callback function which is called with the results.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          describe('accessibility testing', function () { it('accessibility rule subset', function (browser) { browser .url('https://www.w3.org/WAI/demos/bad/after/home.html') .assert.titleEquals('Welcome to CityLights! [Accessible Home Page]') .axeInject() .axeRun('body', { runOnly: ['color-contrast', 'image-alt'], }); });

                                                                                                                                                                                          it('accessibility rule subset 2', function (browser) { browser .url('https://nightwatchjs.org') .axeInject() .axeRun(['#navBar', 'nav'], { rules: { 'color-contrast': { enabled: false }, } }); }); });

                                                                                                                                                                                          See Also

                                                                                                                                                                                        method closeWindow

                                                                                                                                                                                        closeWindow: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Close the current window. This can be useful when you're working with multiple windows open (e.g. an OAuth login). Uses window protocol command.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          describe('closeWindow command demo' , function (result) { test('demo test', function () { browser.closeWindow(); }); });

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/closeWindow.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.close().

                                                                                                                                                                                        method debug

                                                                                                                                                                                        debug: (
                                                                                                                                                                                        config?: { useGlobal?: boolean; preview?: boolean; timeout?: number },
                                                                                                                                                                                        callback?: (this: NightwatchAPI) => void
                                                                                                                                                                                        ) => Awaitable<this, undefined>;
                                                                                                                                                                                        • This command halts the test execution and provides users with a REPL interface where they can type any of the available Nightwatch commands and the command will be executed in the running browser in real-time.

                                                                                                                                                                                          This can be used to debug why a certain command in not working as expected, find the correct locators for your assertions or just play around with the available Nightwatch commands.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          // async function is required while using the debug // command to get the correct result as output. this.demoTest = async function (browser) { browser.debug();

                                                                                                                                                                                          // with no auto-complete browser.debug({preview: false});

                                                                                                                                                                                          // with a timeout of 6000 ms (time for which the interface // would wait for a result). browser.debug({timeout: 6000}) };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/debug.html

                                                                                                                                                                                        method deleteCookie

                                                                                                                                                                                        deleteCookie: (
                                                                                                                                                                                        cookieName: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Delete the cookie with the given name. This command is a no-op if there is no such cookie visible to the current page.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function() { browser.deleteCookie("test_cookie", function() { // do something more in here }); }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/deleteCookie.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .cookies.delete().

                                                                                                                                                                                        method deleteCookies

                                                                                                                                                                                        deleteCookies: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Delete all cookies visible to the current page.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function() { browser.deleteCookies(function() { // do something more in here }); }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/deleteCookies.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .cookies.deleteAll().

                                                                                                                                                                                        method end

                                                                                                                                                                                        end: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Ends the session. Uses session protocol command.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.end(); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/end.html

                                                                                                                                                                                        method fullscreenWindow

                                                                                                                                                                                        fullscreenWindow: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Sets the current window state to fullscreen.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          module.exports = { 'demo Test': function(browser) { browser.fullscreenWindow(function(result) { console.log(result); }); },

                                                                                                                                                                                          'ES6 async demo Test': async function(browser) { const result = await browser.fullscreenWindow(); console.log('result value is:', result.value); } }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/fullscreenWindow.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.fullscreen().

                                                                                                                                                                                        method getCookie

                                                                                                                                                                                        getCookie: (
                                                                                                                                                                                        name: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<Cookie>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, Cookie>;
                                                                                                                                                                                        • Retrieve a single cookie visible to the current page. The cookie is returned as a cookie JSON object, as defined [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).

                                                                                                                                                                                          Uses cookie protocol command.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function() { browser.getCookie(name, function callback(result) { this.assert.equal(result.value, '123456'); this.assert.equals(result.name, 'test_cookie'); }); }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/getCookie.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .cookies.get().

                                                                                                                                                                                        method getCookies

                                                                                                                                                                                        getCookies: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<Cookie[]>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, Cookie[]>;
                                                                                                                                                                                        • Retrieve all cookies visible to the current page. The cookies are returned as an array of cookie JSON object, as defined [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).

                                                                                                                                                                                          Uses cookie protocol command.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function() { browser.getCookies(function callback(result) { this.assert.equal(result.value.length, 1); this.assert.equals(result.value[0].name, 'test_cookie'); }); }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/getCookies.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .cookies.getAll().

                                                                                                                                                                                        method getCurrentUrl

                                                                                                                                                                                        getCurrentUrl: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<string>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, string>;
                                                                                                                                                                                        • Retrieve the URL of the current page.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          describe('Navigation commands demo', function() { test('demoTest', function(browser) { // navigate to new url: browser.navigateTo('https://nightwatchjs.org');

                                                                                                                                                                                          // Retrieve to url with callback: browser.getCurrentUrl(function(result) { console.log(result.value); }); });

                                                                                                                                                                                          test('demoTestAsync', async function(browser) { const currentUrl = await browser.navigateTo('https://nightwatchjs.org').getCurrentUrl(); console.log('currentUrl:', currentUrl); // will print 'https://nightwatchjs.org' });

                                                                                                                                                                                          });

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/getCurrentUrl.html

                                                                                                                                                                                        method getLog

                                                                                                                                                                                        getLog: (
                                                                                                                                                                                        typestring: string,
                                                                                                                                                                                        callback?: (this: NightwatchAPI, log: NightwatchLogEntry[]) => void
                                                                                                                                                                                        ) => Awaitable<this, NightwatchLogEntry[]>;
                                                                                                                                                                                        • Gets a log from Selenium.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function() { this.getLog('browser', function(logEntriesArray) { console.log('Log length: ' + logEntriesArray.length); logEntriesArray.forEach(function(log) { console.log('[' + log.level + '] ' + log.timestamp + ' : ' + log.message); }); }); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/getLog.html

                                                                                                                                                                                        method getLogTypes

                                                                                                                                                                                        getLogTypes: (
                                                                                                                                                                                        callback?: (this: NightwatchAPI, result: NightwatchLogTypes[]) => void
                                                                                                                                                                                        ) => Awaitable<this, NightwatchLogTypes[]>;
                                                                                                                                                                                        • Gets the available log types. More info about log types in WebDriver can be found here: https://github.com/SeleniumHQ/selenium/wiki/Logging

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function() { this.getLogTypes(function(typesArray) { console.log(typesArray); }); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/getLogTypes.html

                                                                                                                                                                                        method getTitle

                                                                                                                                                                                        getTitle: (
                                                                                                                                                                                        callback?: (this: NightwatchAPI, result: string) => void
                                                                                                                                                                                        ) => Awaitable<this, string>;
                                                                                                                                                                                        • Returns the title of the current page. Uses title protocol command.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.getTitle(function(title) { this.assert.equal(typeof title, 'string'); this.assert.equal(title, 'Nightwatch.js'); }); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/getTitle.html

                                                                                                                                                                                        method getWindowPosition

                                                                                                                                                                                        getWindowPosition: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<WindowPosition>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, WindowPosition>;
                                                                                                                                                                                        • Retrieves the current window position.

                                                                                                                                                                                          For clients which are compatible with the [W3C Webdriver API](https://w3c.github.io/webdriver/), getWindowPosition is an alias of getWindowRect.

                                                                                                                                                                                          The getWindowRect command returns both dimensions and position of the window, using the windowRect protocol command.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          module.exports = { 'demo test .getWindowPosition()': function(browser) { // Retrieve the attributes browser.getWindowPosition(function(value) { console.log(value); }); },

                                                                                                                                                                                          'getWindowPosition ES6 demo test': async function(browser) { const value = await browser.getWindowPosition(); console.log('value', value); } }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/getWindowPosition.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.getPosition().

                                                                                                                                                                                        method getWindowRect

                                                                                                                                                                                        getWindowRect: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<WindowSizeAndPosition>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, WindowSizeAndPosition>;
                                                                                                                                                                                        • Change or get 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.

                                                                                                                                                                                          Its JSON representation is the following: - x - window's screenX attribute; - y - window's screenY attribute; - width - outerWidth attribute; - height - outerHeight attribute.

                                                                                                                                                                                          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.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          module.exports = { 'demo test .getWindowRect()': function() { // Retrieve the attributes browser.getWindowRect(function(value) { console.log(value); }); },

                                                                                                                                                                                          'getWindowRect ES6 demo test': async function() { const resultValue = await browser.getWindowRect(); console.log('result value', resultValue); } }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/getWindowRect.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.getRect().

                                                                                                                                                                                        method getWindowSize

                                                                                                                                                                                        getWindowSize: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<WindowSizeAndPosition>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, WindowSizeAndPosition>;
                                                                                                                                                                                        • Retrieves the current window size.

                                                                                                                                                                                          For clients which are compatible with the [W3C Webdriver API](https://w3c.github.io/webdriver/), getWindowSize is an alias of getWindowRect.

                                                                                                                                                                                          The getWindowRect command returns both dimensions and position of the window, using the windowRect protocol command.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          module.exports = { 'demo test .getWindowSize()': function() { // Retrieve the attributes browser.getWindowSize(function(value) { console.log(value); }); },

                                                                                                                                                                                          'getWindowSize ES6 demo test': async function(browser) { const value = await browser.getWindowSize(); console.log('value', value); } }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/getWindowSize.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.getRect().

                                                                                                                                                                                        method init

                                                                                                                                                                                        init: (
                                                                                                                                                                                        url?: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • This command is an alias to url and also a convenience method when called without any arguments in the sense that it performs a call to .url() with passing the value of launch_url field from the settings file. Uses url protocol command.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.init(); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/init.html

                                                                                                                                                                                        method injectScript

                                                                                                                                                                                        injectScript: {
                                                                                                                                                                                        (
                                                                                                                                                                                        scriptUrl: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<WebElement>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ): Awaitable<this, WebElement>;
                                                                                                                                                                                        (
                                                                                                                                                                                        scriptUrl: string,
                                                                                                                                                                                        id: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<WebElement>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ): Awaitable<this, WebElement>;
                                                                                                                                                                                        };
                                                                                                                                                                                        • Utility command to load an external script into the page specified by url.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function() { this.injectScript("{script-url}", function() { // we're all done here. }); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/injectScript.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .document.injectScript().

                                                                                                                                                                                        method isLogAvailable

                                                                                                                                                                                        isLogAvailable: (
                                                                                                                                                                                        typeString: string,
                                                                                                                                                                                        callback?: (this: NightwatchAPI, result: boolean) => void
                                                                                                                                                                                        ) => Awaitable<this, boolean>;
                                                                                                                                                                                        • Utility command to test if the log type is available.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function() { browser.isLogAvailable('browser', function(isAvailable) { // do something more in here }); }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/isLogAvailable.html

                                                                                                                                                                                        method maximizeWindow

                                                                                                                                                                                        maximizeWindow: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Maximizes the current window.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.maximizeWindow(); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/maximizeWindow.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.maximize().

                                                                                                                                                                                        method minimizeWindow

                                                                                                                                                                                        minimizeWindow: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Hides the window in the system tray. If the window happens to be in fullscreen mode, it is restored the normal state then it will be "iconified" - minimize or hide the window from the visible screen.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          module.exports = { 'demo Test': function(browser) { browser.minimizeWindow(function(result) { console.log(result); }); },

                                                                                                                                                                                          'ES6 async demo Test': async function(browser) { const result = await browser.minimizeWindow(); console.log('result value is:', result.value); } }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/minimizeWindow.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.minimize().

                                                                                                                                                                                        method navigateTo

                                                                                                                                                                                        navigateTo: (
                                                                                                                                                                                        url: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Navigate to a new URL. This method will also call the onBrowserNavigate() test global, right after the page is loaded.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          describe('Navigation commands demo', function() { test('demoTest', function(browser) { // navigate to new url: browser.navigateTo('https://nightwatchjs.org');

                                                                                                                                                                                          // Retrieve to url with callback: browser.getCurrentUrl(function(result) { console.log(result.value); }); });

                                                                                                                                                                                          test('demoTestAsync', async function(browser) { const currentUrl = await browser.navigateTo('https://nightwatchjs.org').getCurrentUrl(); console.log('currentUrl:', currentUrl); // will print 'https://nightwatchjs.org' }); });

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/navigateTo.html

                                                                                                                                                                                        method openNewWindow

                                                                                                                                                                                        openNewWindow: (
                                                                                                                                                                                        type?: WindowType,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Opens a new top-level browser window, which can be either a tab (default) or a separate new window.

                                                                                                                                                                                          This command is only available for W3C Webdriver compatible browsers.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          module.exports = { 'demo Test': function(browser) { // open a new window tab (default) browser.openNewWindow(function(result) { console.log(result); });

                                                                                                                                                                                          // open a new window browser.openNewWindow('window', function(result) { console.log(result); }); },

                                                                                                                                                                                          'ES6 async demo Test': async function(browser) { const result = await browser.openNewWindow(); console.log('result value is:', result.value); } }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/openNewWindow.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.open().

                                                                                                                                                                                        method pageSource

                                                                                                                                                                                        pageSource: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<string>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, string>;
                                                                                                                                                                                        • Returns the page source. Uses pageSource protocol command.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function (browser) { browser.pageSource(function(pageSource) { console.log(pageSource); }); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/pageSource.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .document.pageSource().

                                                                                                                                                                                        method pause

                                                                                                                                                                                        pause: (
                                                                                                                                                                                        ms?: number,
                                                                                                                                                                                        callback?: (this: NightwatchAPI) => void
                                                                                                                                                                                        ) => Awaitable<this, undefined>;
                                                                                                                                                                                        • Suspends the test for the given time in milliseconds. If the milliseconds argument is missing it will suspend the test indefinitely

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.pause(1000); // or suspend indefinitely browser.pause(); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/pause.html

                                                                                                                                                                                        method perform

                                                                                                                                                                                        perform: {
                                                                                                                                                                                        <ReturnValue>(
                                                                                                                                                                                        callback: (this: NightwatchAPI) => ReturnValue | Promise<ReturnValue>
                                                                                                                                                                                        ): Awaitable<this, ReturnValue>;
                                                                                                                                                                                        <ReturnValue>(
                                                                                                                                                                                        callback: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        client: NightwatchAPI,
                                                                                                                                                                                        done: (result?: ReturnValue) => void
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ): Awaitable<this, ReturnValue>;
                                                                                                                                                                                        <ReturnValue>(
                                                                                                                                                                                        callback: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        done: (result?: ReturnValue) => void
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ): Awaitable<this, ReturnValue>;
                                                                                                                                                                                        };
                                                                                                                                                                                        • 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.

                                                                                                                                                                                          The callback signature can have up to two parameters. - no parameters: callback runs and perform completes immediately at the end of the execution of the callback. - one parameter: allows for asynchronous execution within the callback providing a done callback function for completion as the first argument. - two parameters: allows for asynchronous execution with the Nightwatch api object passed in as the first argument, followed by the done callback.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          describe('perform example', function() { var elementValue;

                                                                                                                                                                                          it('basic perform', function(browser) { browser .getValue('.some-element', function(result) { elementValue = result.value; }) // other stuff going on ...

                                                                                                                                                                                          // self-completing callback .perform(function() { console.log('elementValue', elementValue); // without any defined parameters, perform // completes immediately (synchronously) })

                                                                                                                                                                                          // returning a Promise .perform(async function() { // this can be used to directly access Nightwatch API const sessionId = await this.sessionId; console.log('session id', sessionId); })

                                                                                                                                                                                          // DEPRECATED: asynchronous completion using done .perform(function(done: (result: string) => void) { // potentially some async stuff going on // this can be used to directly access Nightwatch API this.getTitle((result) => { // when finished, call the done callback done(result.value); }); })

                                                                                                                                                                                          // DEPRECATED: asynchronous completion including api (client) .perform(function(client: NightwatchAPI, done: () => void) { this.navigateTo('https://google.com/', () => { done(); }); }); });

                                                                                                                                                                                          it('perform with async', function(browser) { const result = await browser.perform(async function() { // this can be used to directly access Nightwatch API const pageTitle = await this.getTitle();

                                                                                                                                                                                          return 100; }); console.log('result:', result); // 100 }) };

                                                                                                                                                                                        method quit

                                                                                                                                                                                        quit: (
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Ends the session and closes down the test WebDriver server, if one is running. This is similar to calling the .end() command, but the former doesn't quit the WebDriver session.

                                                                                                                                                                                          This command will also execute the onBrowserQuit() global, if one is defined.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function (browser) { browser.quit(function(result) { console.log(result.value); }); }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/quit.html

                                                                                                                                                                                        method resizeWindow

                                                                                                                                                                                        resizeWindow: (
                                                                                                                                                                                        width: number,
                                                                                                                                                                                        height: number,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Resizes the current window.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.resizeWindow(1000, 800); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/resizeWindow.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.resize().

                                                                                                                                                                                        method saveScreenshot

                                                                                                                                                                                        saveScreenshot: (
                                                                                                                                                                                        fileName: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<string>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, string>;
                                                                                                                                                                                        • Take a screenshot of the current page and saves it as the given filename.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function ( ) { browser.saveScreenshot('/path/to/fileName.png'); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/saveScreenshot.html

                                                                                                                                                                                        method setCookie

                                                                                                                                                                                        setCookie: (
                                                                                                                                                                                        cookie: Cookie,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Set a cookie, specified as a cookie JSON object, as defined [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).

                                                                                                                                                                                          Uses cookie protocol command.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function() { browser.setCookie({ name : "test_cookie", value : "test_value", path : "/", (Optional) domain : "example.org", (Optional) secure : false, (Optional) httpOnly : false, // (Optional) expiry : 1395002765 // (Optional) time in seconds since midnight, January 1, 1970 UTC }); }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/setCookie.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .cookies.set().

                                                                                                                                                                                        method setWindowPosition

                                                                                                                                                                                        setWindowPosition: (
                                                                                                                                                                                        offsetX: number,
                                                                                                                                                                                        offsetY: number,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Sets the current window position.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.setWindowPosition(0, 0); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/setWindowPosition.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.setPosition().

                                                                                                                                                                                        method setWindowRect

                                                                                                                                                                                        setWindowRect: (
                                                                                                                                                                                        options: WindowSizeAndPosition,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • 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.

                                                                                                                                                                                          Its JSON representation is the following: - x - window's screenX attribute; - y - window's screenY attribute; - width - outerWidth attribute; - height - outerHeight attribute.

                                                                                                                                                                                          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.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          module.exports = { 'demo test .setWindowRect()': function() {

                                                                                                                                                                                          // Change the screenX and screenY attributes of the window rect. browser.setWindowRect({x: 500, y: 500});

                                                                                                                                                                                          // Change the width and height attributes of the window rect. browser.setWindowRect({width: 600, height: 300});

                                                                                                                                                                                          // Retrieve the attributes browser.setWindowRect(function(result) { console.log(result.value); }); },

                                                                                                                                                                                          'setWindowRect ES6 demo test': async function() { await browser.setWindowRect({ width: 600, height: 300, x: 100, y: 100 }); } }

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/setWindowRect.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.setRect().

                                                                                                                                                                                        method setWindowSize

                                                                                                                                                                                        setWindowSize: (
                                                                                                                                                                                        width: number,
                                                                                                                                                                                        height: number,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Sets the current window position.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.setWindowPosition(0, 0); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/setWindowSize.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.setSize().

                                                                                                                                                                                        method switchToWindow

                                                                                                                                                                                        switchToWindow: (
                                                                                                                                                                                        handleOrName: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • 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.

                                                                                                                                                                                          To find out the window handle use windowHandles command

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.windowHandles(function(result) { const handle = result.value[0]; browser.switchToWindow(handle); }); };

                                                                                                                                                                                          this.demoTestAsync = async function () { const result = await browser.windowHandles(); const handle = result[0]; browser.switchToWindow(handle); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/switchToWindow.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.switchTo().

                                                                                                                                                                                        method switchWindow

                                                                                                                                                                                        switchWindow: (
                                                                                                                                                                                        handleOrName: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • 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.

                                                                                                                                                                                          To find out the window handle use windowHandles command

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.windowHandles(function(result) { const handle = result.value[0]; browser.switchWindow(handle); }); };

                                                                                                                                                                                          this.demoTestAsync = async function () { const result = await browser.windowHandles(); const handle = result[0]; browser.switchWindow(handle); };

                                                                                                                                                                                          switchToWindow

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/switchWindow.html

                                                                                                                                                                                          Deprecated

                                                                                                                                                                                          In favour of .window.switch().

                                                                                                                                                                                        method urlHash

                                                                                                                                                                                        urlHash: (
                                                                                                                                                                                        hash: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ) => Awaitable<this, null>;
                                                                                                                                                                                        • Convenience command that adds the specified hash (i.e. url fragment) to the current value of the launch_url as set in nightwatch.json.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser.urlHash('#hashvalue'); // or browser.urlHash('hashvalue'); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/urlHash.html

                                                                                                                                                                                        method useCss

                                                                                                                                                                                        useCss: (callback?: (this: NightwatchAPI) => void) => Awaitable<this, undefined>;
                                                                                                                                                                                        • Sets the locate strategy for selectors to css selector, therefore every following selector needs to be specified as css.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser .useCss() // we're back to CSS now .setValue('input[type=text]', 'nightwatch'); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/useCss.html

                                                                                                                                                                                        method useXpath

                                                                                                                                                                                        useXpath: (
                                                                                                                                                                                        callback?: (this: NightwatchAPI) => void
                                                                                                                                                                                        ) => Awaitable<this, undefined>;
                                                                                                                                                                                        • Sets the locate strategy for selectors to xpath, therefore every following selector needs to be specified as xpath.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          this.demoTest = function () { browser .useXpath() // every selector now must be xpath .click("//tr[@data-recordid]/span[text()='Search Text']"); };

                                                                                                                                                                                          See Also

                                                                                                                                                                                          • https://nightwatchjs.org/api/useXpath.html

                                                                                                                                                                                        method waitUntil

                                                                                                                                                                                        waitUntil: {
                                                                                                                                                                                        (
                                                                                                                                                                                        conditionFn: (this: NightwatchAPI) => void,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ): Awaitable<this, null>;
                                                                                                                                                                                        (
                                                                                                                                                                                        conditionFn: (this: NightwatchAPI) => void,
                                                                                                                                                                                        waitTimeMs: number,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ): Awaitable<this, null>;
                                                                                                                                                                                        (
                                                                                                                                                                                        conditionFn: (this: NightwatchAPI) => void,
                                                                                                                                                                                        waitTimeMs: number,
                                                                                                                                                                                        retryInterval: number,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ): Awaitable<this, null>;
                                                                                                                                                                                        (
                                                                                                                                                                                        conditionFn: (this: NightwatchAPI) => void,
                                                                                                                                                                                        waitTimeMs: number,
                                                                                                                                                                                        retryInterval: number,
                                                                                                                                                                                        message: string,
                                                                                                                                                                                        callback?: (
                                                                                                                                                                                        this: NightwatchAPI,
                                                                                                                                                                                        result: NightwatchCallbackResult<null>
                                                                                                                                                                                        ) => void
                                                                                                                                                                                        ): Awaitable<this, null>;
                                                                                                                                                                                        };
                                                                                                                                                                                        • Waits for a condition to evaluate to a "truthy" value. The condition may be specified by any function which returns the value to be evaluated or a Promise to wait for.

                                                                                                                                                                                          An optional wait time can be specified, otherwise the global waitForConditionTimeout value will be used.

                                                                                                                                                                                          Example 1

                                                                                                                                                                                          describe('waitUntil Example', function() { it('demo Test', function(browser) { browser .url('https://nightwatchjs.org') .waitUntil(async function() { const title = await this.execute(function() { return document.title; });

                                                                                                                                                                                          return title === 'Nightwatch.js'; }, 1000); }); });

                                                                                                                                                                                        interface Cookie {}

                                                                                                                                                                                          property domain

                                                                                                                                                                                          domain?: string;

                                                                                                                                                                                            property expiry

                                                                                                                                                                                            expiry?: number;

                                                                                                                                                                                              property httpOnly

                                                                                                                                                                                              httpOnly?: boolean;

                                                                                                                                                                                                property name

                                                                                                                                                                                                name: string;

                                                                                                                                                                                                  property path

                                                                                                                                                                                                  path?: string;

                                                                                                                                                                                                    property sameSite

                                                                                                                                                                                                    sameSite?: 'Lax' | 'Strict' | 'None';

                                                                                                                                                                                                      property secure

                                                                                                                                                                                                      secure?: boolean;

                                                                                                                                                                                                        property value

                                                                                                                                                                                                        value: string;

                                                                                                                                                                                                          interface CookiesNsCommands

                                                                                                                                                                                                          interface CookiesNsCommands<ReturnType = unknown> {}

                                                                                                                                                                                                            method delete

                                                                                                                                                                                                            delete: (
                                                                                                                                                                                                            cookieName: string,
                                                                                                                                                                                                            callback?: (
                                                                                                                                                                                                            this: NightwatchAPI,
                                                                                                                                                                                                            result: NightwatchCallbackResult<null>
                                                                                                                                                                                                            ) => void
                                                                                                                                                                                                            ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                                                            • Delete the cookie with the given name. This command is a no-op if there is no such cookie visible to the current page.

                                                                                                                                                                                                              Example 1

                                                                                                                                                                                                              module.exports = { 'delete a cookie': function (browser) { browser .cookies.delete('test_cookie', function () { console.log('cookie deleted successfully'); }); },

                                                                                                                                                                                                              'delete a cookie with ES6 async/await': async function (browser) { await browser.cookies.delete('test_cookie'); } };

                                                                                                                                                                                                            method deleteAll

                                                                                                                                                                                                            deleteAll: (
                                                                                                                                                                                                            callback?: (
                                                                                                                                                                                                            this: NightwatchAPI,
                                                                                                                                                                                                            result: NightwatchCallbackResult<null>
                                                                                                                                                                                                            ) => void
                                                                                                                                                                                                            ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                                                            • Delete all cookies visible to the current page.

                                                                                                                                                                                                              Example 1

                                                                                                                                                                                                              module.exports = { 'delete all cookies': function (browser) { browser .cookies.deleteAll(function() { console.log('all cookies deleted successfully'); }); },

                                                                                                                                                                                                              'delete all cookies with ES6 async/await': async function (browser) { await browser.cookies.deleteAll(); } };

                                                                                                                                                                                                            method get

                                                                                                                                                                                                            get: (
                                                                                                                                                                                                            name: string,
                                                                                                                                                                                                            callback?: (
                                                                                                                                                                                                            this: NightwatchAPI,
                                                                                                                                                                                                            result: NightwatchCallbackResult<Cookie | null>
                                                                                                                                                                                                            ) => void
                                                                                                                                                                                                            ) => Awaitable<IfUnknown<ReturnType, this>, Cookie | null>;
                                                                                                                                                                                                            • Retrieve a single cookie visible to the current page.

                                                                                                                                                                                                              The cookie is returned as a cookie JSON object, with properties as defined [here](https://www.w3.org/TR/webdriver/#dfn-table-for-cookie-conversion).

                                                                                                                                                                                                              Example 1

                                                                                                                                                                                                              module.exports = { 'get a cookie': function (browser) { browser .cookies.get('test_cookie', function (result) { const cookie = result.value; this.assert.equal(cookie.name, 'test_cookie'); this.assert.equal(cookie.value, '123456'); }); },

                                                                                                                                                                                                              'get a cookie with ES6 async/await': async function (browser) { const cookie = await browser.cookies.get('test_cookie'); browser.assert.equal(cookie.name, 'test_cookie'); browser.assert.equal(cookie.value, '123456'); } };

                                                                                                                                                                                                            method getAll

                                                                                                                                                                                                            getAll: (
                                                                                                                                                                                                            callback?: (
                                                                                                                                                                                                            this: NightwatchAPI,
                                                                                                                                                                                                            result: NightwatchCallbackResult<Cookie[]>
                                                                                                                                                                                                            ) => void
                                                                                                                                                                                                            ) => Awaitable<IfUnknown<ReturnType, this>, Cookie[]>;
                                                                                                                                                                                                            • Retrieve all cookies visible to the current page.

                                                                                                                                                                                                              The cookies are returned as an array of cookie JSON object, with properties as defined [here](https://www.w3.org/TR/webdriver/#dfn-table-for-cookie-conversion).

                                                                                                                                                                                                              Example 1

                                                                                                                                                                                                              module.exports = { 'get all cookies': function (browser) { browser .cookies.getAll(function (result) { this.assert.equal(result.value.length, 1); this.assert.equal(result.value[0].name, 'test_cookie'); }); },

                                                                                                                                                                                                              'get all cookies with ES6 async/await': async function (browser) { const cookies = await browser.cookies.getAll(); browser.assert.equal(cookies.length, 1); browser.assert.equal(cookies[0].name, 'test_cookie'); } };

                                                                                                                                                                                                            method set

                                                                                                                                                                                                            set: (
                                                                                                                                                                                                            cookie: Cookie,
                                                                                                                                                                                                            callback?: (
                                                                                                                                                                                                            this: NightwatchAPI,
                                                                                                                                                                                                            result: NightwatchCallbackResult<null>
                                                                                                                                                                                                            ) => void
                                                                                                                                                                                                            ) => Awaitable<IfUnknown<ReturnType, this>, null>;
                                                                                                                                                                                                            • Set a cookie, specified as a cookie JSON object, with properties as defined [here](https://www.w3.org/TR/webdriver/#dfn-table-for-cookie-conversion).

                                                                                                                                                                                                              Example 1

                                                                                                                                                                                                              module.exports = { 'set a cookie': function (browser) { browser .cookies.set({ name: "test_cookie", value: "test_value", path: "/", // (Optional) domain: "example.org", // (Optional) secure: false, // (Optional) httpOnly: false, // (Optional) expiry: 1395002765 // (Optional) time in seconds since midnight, January 1, 1970 UTC }); },

                                                                                                                                                                                                              'set a cookie with ES6 async/await': async function (browser) { await browser.cookies.set({ name: 'test_cookie', value: 'test_value', domain: 'example.org', // (Optional) sameSite: 'Lax' // (Optional) }); } };

                                                                                                                                                                                                            interface CreateClientParams

                                                                                                                                                                                                            interface CreateClientParams {}

                                                                                                                                                                                                              property browserName

                                                                                                                                                                                                              browserName?: string | null;

                                                                                                                                                                                                                property config

                                                                                                                                                                                                                config?: string;

                                                                                                                                                                                                                  property debug

                                                                                                                                                                                                                  debug?: boolean;

                                                                                                                                                                                                                    property devtools

                                                                                                                                                                                                                    devtools?: boolean;

                                                                                                                                                                                                                      property enable_global_apis

                                                                                                                                                                                                                      enable_global_apis?: boolean;

                                                                                                                                                                                                                        property env

                                                                                                                                                                                                                        env?: string | null;

                                                                                                                                                                                                                          property globals

                                                                                                                                                                                                                          globals?: Partial<NightwatchGlobals>;

                                                                                                                                                                                                                            property headless

                                                                                                                                                                                                                            headless?: boolean;

                                                                                                                                                                                                                              property output

                                                                                                                                                                                                                              output?: boolean;

                                                                                                                                                                                                                                property parallel

                                                                                                                                                                                                                                parallel?: boolean;

                                                                                                                                                                                                                                  property reporter

                                                                                                                                                                                                                                  reporter?: any;

                                                                                                                                                                                                                                    property silent

                                                                                                                                                                                                                                    silent?: boolean;

                                                                                                                                                                                                                                      property test_settings

                                                                                                                                                                                                                                      test_settings?: Partial<NightwatchOptions>;

                                                                                                                                                                                                                                        property timeout

                                                                                                                                                                                                                                        timeout?: number | null;

                                                                                                                                                                                                                                          property useAsync

                                                                                                                                                                                                                                          useAsync?: boolean;

                                                                                                                                                                                                                                            interface DocumentNsCommands

                                                                                                                                                                                                                                            interface DocumentNsCommands<ReturnType = unknown> {}

                                                                                                                                                                                                                                              method injectScript

                                                                                                                                                                                                                                              injectScript: {
                                                                                                                                                                                                                                              (
                                                                                                                                                                                                                                              scriptUrl: string,
                                                                                                                                                                                                                                              callback?: (
                                                                                                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                                                                                                              result: NightwatchCallbackResult<WebElement>
                                                                                                                                                                                                                                              ) => void
                                                                                                                                                                                                                                              ): Awaitable<IfUnknown<ReturnType, this>, WebElement>;
                                                                                                                                                                                                                                              (
                                                                                                                                                                                                                                              scriptUrl: string,
                                                                                                                                                                                                                                              id: string,
                                                                                                                                                                                                                                              callback?: (
                                                                                                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                                                                                                              result: NightwatchCallbackResult<WebElement>
                                                                                                                                                                                                                                              ) => void
                                                                                                                                                                                                                                              ): Awaitable<IfUnknown<ReturnType, this>, WebElement>;
                                                                                                                                                                                                                                              };
                                                                                                                                                                                                                                              • Utility command to load an external script into the page specified by url.

                                                                                                                                                                                                                                                Example 1

                                                                                                                                                                                                                                                module.exports = { 'inject external script': function (browser) { browser.document.injectScript('', function () { console.log('script injected successfully'); }); },

                                                                                                                                                                                                                                                'inject external script using ES6 async/await': async function (browser) { await browser.document.injectScript('', 'injected-script'); } };

                                                                                                                                                                                                                                              method pageSource

                                                                                                                                                                                                                                              pageSource: (
                                                                                                                                                                                                                                              callback?: (
                                                                                                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                                                                                                              result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                              ) => void
                                                                                                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, string>;
                                                                                                                                                                                                                                              • Get the string serialized source of the current page.

                                                                                                                                                                                                                                                Example 1

                                                                                                                                                                                                                                                module.exports = { 'get page source': function (browser) { browser.document.pageSource(function (result) { console.log('current page source:', result.value); }); },

                                                                                                                                                                                                                                                'get page source using ES6 async/await': async function (browser) { const pageSource = await browser.document.pageSource(); console.log('current page source:', pageSource); } };

                                                                                                                                                                                                                                                document.source

                                                                                                                                                                                                                                              method source

                                                                                                                                                                                                                                              source: (
                                                                                                                                                                                                                                              callback?: (
                                                                                                                                                                                                                                              this: NightwatchAPI,
                                                                                                                                                                                                                                              result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                              ) => void
                                                                                                                                                                                                                                              ) => Awaitable<IfUnknown<ReturnType, this>, string>;
                                                                                                                                                                                                                                              • Get the string serialized source of the current page.

                                                                                                                                                                                                                                                Example 1

                                                                                                                                                                                                                                                module.exports = { 'get page source': function (browser) { browser.document.source(function (result) { console.log('current page source:', result.value); }); },

                                                                                                                                                                                                                                                'get page source using ES6 async/await': async function (browser) { const pageSource = await browser.document.source(); console.log('current page source:', pageSource); } };

                                                                                                                                                                                                                                                document.pageSource

                                                                                                                                                                                                                                              interface ElementCommands

                                                                                                                                                                                                                                              interface ElementCommands {}

                                                                                                                                                                                                                                                method check

                                                                                                                                                                                                                                                check: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Will check, click, on an unchecked checkbox or radio input if not already checked.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest(browser) { browser.check('input[type=checkbox]:not(:checked)');

                                                                                                                                                                                                                                                  browser.check('input[type=checkbox]:not(:checked)', function(result) { console.log('Check result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.check('css selector', 'input[type=checkbox]:not(:checked)');

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide#element-properties browser.check({ selector: 'input[type=checkbox]:not(:checked)', index: 1, suppressNotFoundErrors: true });

                                                                                                                                                                                                                                                  browser.check({ selector: 'input[type=checkbox]:not(:checked)', timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.check('input[type=checkbox]:not(:checked)'); console.log('Check result', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/check.html

                                                                                                                                                                                                                                                method clearValue

                                                                                                                                                                                                                                                clearValue: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Clear a textarea or a text input element's value. Starting with v1.1 clearValue() will wait for the element to be present (until the specified timeout).

                                                                                                                                                                                                                                                  If the element is not found, an error is thrown which will cause the test to fail. Starting with v1.2 you can suppress element not found errors by specifying the suppressNotFoundErrors flag.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  describe('clearValue Command demo', function() { test('demo test', function() { browser.clearValue('#login input[type=text]');

                                                                                                                                                                                                                                                  browser.clearValue('#login input[type=text]', function(result) { console.log('clearValue result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.clearValue('css selector', '#login input[type=text]');

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.clearValue({ selector: '#login input[type=text]', index: 1, suppressNotFoundErrors: true });

                                                                                                                                                                                                                                                  browser.clearValue({ selector: '#login input[type=text]', timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present });

                                                                                                                                                                                                                                                  });

                                                                                                                                                                                                                                                  });

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/clearValue.html

                                                                                                                                                                                                                                                method click

                                                                                                                                                                                                                                                click: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Simulates a click event on the given DOM element. The element is scrolled into view if it is not already pointer-interactable. See the WebDriver specification for element interactability.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.click('#main ul li a.first');

                                                                                                                                                                                                                                                  browser.click('#main ul li a.first', function(result) { console.log('Click result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.click('css selector', '#main ul li a.first');

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.click({ selector: '#main ul li a', index: 1, suppressNotFoundErrors: true });

                                                                                                                                                                                                                                                  browser.click({ selector: '#main ul li a.first', timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.click('#main ul li a.first'); console.log('Click result', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/click.html

                                                                                                                                                                                                                                                method dragAndDrop

                                                                                                                                                                                                                                                dragAndDrop: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                destination: NightwatchElement | NightwatchPosition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                destination: NightwatchPosition | NightwatchElement,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Drag an element to the given position or destination element.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest(browser) { browser.dragAndDrop('#main', {x: 100, y:100}):

                                                                                                                                                                                                                                                  //using webElement as a destination demoTestAsync: async function(browser) { const destination = await browser.findElement('#upload'); browser.dragAndDrop('#main', destination.getId()); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/dragAndDrop.html

                                                                                                                                                                                                                                                method findElement

                                                                                                                                                                                                                                                findElement: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • 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). First argument is the element selector, either specified as a string or as an object (with 'selector' and 'locateStrategy' properties).

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { 'demo Test': function(browser) { const resultElement = await browser.findElement('.features-container li:first-child');

                                                                                                                                                                                                                                                  console.log('Element Id:', resultElement.getId()); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/findElement.html

                                                                                                                                                                                                                                                method findElements

                                                                                                                                                                                                                                                findElements: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT[]>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT[]>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT[]>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT[]>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • 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). First argument is the element selector, either specified as a string or as an object (with 'selector' and 'locateStrategy' properties).

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { 'demo Test': function(browser) { const resultElements = await browser.findElements('.features-container li');

                                                                                                                                                                                                                                                  resultElements.forEach(item => console.log('Element Id:', item.getId())); },

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/findElements.html

                                                                                                                                                                                                                                                method getAccessibleName

                                                                                                                                                                                                                                                getAccessibleName: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Returns the computed WAI-ARIA label of an element.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.getAccessibleName('*[name="search"]', function(result) { this.assert.equal(typeof result, 'object); this.assert.equal(result.value, 'search input'); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getAccessibleName('css selector', '*[name="search"]', function(result) { console.log('getAccessibleName result', result.value); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getAccessibleName({ selector: '*[name="search"]', index: 1 }, function(result) { console.log('getAccessibleName result', result.value); });

                                                                                                                                                                                                                                                  browser.getAccessibleName({ selector: '*[name="search"]', timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present }, function(result) { console.log('getAccessibleName result', result.value); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function() { const result = await browser.getAccessibleName('*[name="search"]'); console.log('getAccessibleName result', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getAccessibleName.html

                                                                                                                                                                                                                                                method getAriaRole

                                                                                                                                                                                                                                                getAriaRole: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Returns the computed WAI-ARIA role of an element.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest(browser) { browser.getAriaRole('*[name="search"]', function(result) { this.assert.equal(typeof result, 'object'); this.assert.equal(result.value, 'combobox'); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getAriaRole('css selector', '*[name="search"]', function(result) { console.log('getAriaRole result', result.value); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getAriaRole({ selector: '*[name="search"]', index: 1 }, function(result) { console.log('getAriaRole result', result.value); });

                                                                                                                                                                                                                                                  browser.getAriaRole({ selector: '*[name="search"]', timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present }, function(result) { console.log('getAriaRole result', result.value); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.getAriaRole('*[name="search"]'); console.log('getAriaRole result', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getAriaRole.html

                                                                                                                                                                                                                                                method getAttribute

                                                                                                                                                                                                                                                getAttribute: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                attribute: string,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string | null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string | null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                attribute: string,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Retrieve the value of an attribute for a given DOM element.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.getAttribute('#main ul li a.first', 'href', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getAttribute('css selector', '#main ul li a.first', 'href', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getAttribute({ selector: '#main ul li a.first', index: 1, suppressNotFoundErrors: true }, 'href', function(result) { console.log('result', result); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.getAttribute('#main ul li a.first', 'href'); console.log('attribute', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getAttribute.html

                                                                                                                                                                                                                                                method getCssProperty

                                                                                                                                                                                                                                                getCssProperty: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                cssProperty: string,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                cssProperty: string,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Retrieve the value of a css property for a given DOM element.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.getCssProperty('#main ul li a.first', 'display', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getCssProperty('css selector', '#main ul li a.first', 'display', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getCssProperty({ selector: '#main ul li a.first', index: 1, suppressNotFoundErrors: true }, 'display', function(result) { console.log('result', result); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.getCssProperty('#main ul li a.first', 'display'); console.log('display', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getCssProperty.html

                                                                                                                                                                                                                                                method getElementProperty

                                                                                                                                                                                                                                                getElementProperty: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                property: string,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<any>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, any>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                property: string,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<any>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, any>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Retrieve the value of a specified DOM property for the given element. For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest(browser) { browser.getElementProperty('#login input[type=text]', 'classList', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getElementProperty('css selector', '#login input[type=text]', 'classList', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getElementProperty({ selector: '#login input[type=text]', index: 1, suppressNotFoundErrors: true }, 'classList', function(result) { console.log('result', result); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.getElementProperty('#login input[type=text]', 'classList'); console.log('classList', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getElementProperty.html

                                                                                                                                                                                                                                                method getElementRect

                                                                                                                                                                                                                                                getElementRect: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<NightwatchSizeAndPosition>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, NightwatchSizeAndPosition>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<WindowSizeAndPosition>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, WindowSizeAndPosition>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Determine an element's size in pixels. For W3C Webdriver compatible clients (such as GeckoDriver), this command is equivalent to getLocation and both return the dimensions and coordinates of the given element: - x: X axis position of the top-left corner of the element, in CSS pixels - y: Y axis position of the top-left corner of the element, in CSS pixels - height: Height of the element’s bounding rectangle in CSS pixels; - width: Width of the web element’s bounding rectangle in CSS pixels.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.getElementSize('#login', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getElementSize('css selector', '#login', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getElementSize({ selector: '#login', index: 1, suppressNotFoundErrors: true }, function(result) { console.log('result', result); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function() { const result = await browser.getElementSize('#login'); console.log('classList', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getElementRect.html

                                                                                                                                                                                                                                                method getElementSize

                                                                                                                                                                                                                                                getElementSize: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<NightwatchSizeAndPosition>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, NightwatchSizeAndPosition>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<WindowSizeAndPosition>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, WindowSizeAndPosition>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Determine an element's size in pixels. For W3C Webdriver compatible clients (such as GeckoDriver), this command is equivalent to getLocation and both return the dimensions and coordinates of the given element: - x: X axis position of the top-left corner of the element, in CSS pixels - y: Y axis position of the top-left corner of the element, in CSS pixels - height: Height of the element’s bounding rectangle in CSS pixels; - width: Width of the web element’s bounding rectangle in CSS pixels.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.getElementSize('#login', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getElementSize('css selector', '#login', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getElementSize({ selector: '#login', index: 1, suppressNotFoundErrors: true }, function(result) { console.log('result', result); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.getElementSize('#login'); console.log('classList', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getElementSize.html

                                                                                                                                                                                                                                                method getFirstElementChild

                                                                                                                                                                                                                                                getFirstElementChild: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Returns an element's first child. The child element will be returned as web element JSON object (with an added .getId() convenience method).

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { 'demo Test': function(browser) { const resultElement = await browser.getFirstElementChild('.features-container');

                                                                                                                                                                                                                                                  console.log('last child element Id:', resultElement.getId()); },

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getFirstElementChild.html

                                                                                                                                                                                                                                                method getLastElementChild

                                                                                                                                                                                                                                                getLastElementChild: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Returns an element's last child. The child element will be returned as web element JSON object (with an added .getId() convenience method).

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { 'demo Test': function(browser) { const resultElement = await browser.getLastElementChild('.features-container');

                                                                                                                                                                                                                                                  console.log('last child element Id:', resultElement.getId()); },

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getLastElementChild.html

                                                                                                                                                                                                                                                method getLocation

                                                                                                                                                                                                                                                getLocation: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<NightwatchSizeAndPosition>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, NightwatchSizeAndPosition>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<WindowSizeAndPosition>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, WindowSizeAndPosition>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • 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.

                                                                                                                                                                                                                                                  For W3C Webdriver compatible clients (such as GeckoDriver), this command is equivalent to getElementSize and both return the dimensions and coordinates of the given element: - x: X axis position of the top-left corner of the element, in CSS pixels - y: Y axis position of the top-left corner of the element, in CSS pixels - height: Height of the element’s bounding rectangle in CSS pixels; - width: Width of the web element’s bounding rectangle in CSS pixels.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.getLocation('#login', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getLocation('css selector', '#login', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getLocation({ selector: '#login', index: 1, suppressNotFoundErrors: true }, function(result) { console.log('result', result); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.getLocation('#login'); console.log('location', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getLocation.html

                                                                                                                                                                                                                                                method getLocationInView

                                                                                                                                                                                                                                                getLocationInView: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<NightwatchPosition>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, NightwatchPosition>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<NightwatchPosition>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, NightwatchPosition>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Determine an element's location on the screen once it has been scrolled into view.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  this.demoTest = function () { browser.getLocationInView("#main ul li a.first", function(result) { this.assert.equal(typeof result, "object"); this.assert.equal(result.status, 0); this.assert.equal(result.value.x, 200); this.assert.equal(result.value.y, 200); }); };

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getLocationInView.html

                                                                                                                                                                                                                                                  Deprecated

                                                                                                                                                                                                                                                  This is JSON Wire Protocol command and is no longer supported.

                                                                                                                                                                                                                                                method getNextSibling

                                                                                                                                                                                                                                                getNextSibling: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Returns the element immediately following the specified one in their parent's childNodes. The element will be returned as web element JSON object (with an added .getId() convenience method).

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { 'demo Test': function(browser) { const resultElement = await browser.getNextSibling('.features-container li:first-child');

                                                                                                                                                                                                                                                  console.log('next sibling element Id:', resultElement.getId()); },

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getNextSibling.html

                                                                                                                                                                                                                                                method getPreviousSibling

                                                                                                                                                                                                                                                getPreviousSibling: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<JSON_WEB_OBJECT>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, JSON_WEB_OBJECT>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Returns the element immediately preceding the specified one in its parent's child elements list. The element will be returned as web element JSON object (with an added .getId() convenience method).

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { 'demo Test': function(browser) { const resultElement = await browser.getPreviousSibling('.features-container li:second-child');

                                                                                                                                                                                                                                                  console.log('previous sibling element Id:', resultElement.getId()); },

                                                                                                                                                                                                                                                  browser.getPreviousSibling('#web-button', function(result) {

                                                                                                                                                                                                                                                  console.log(result.value) }}) await browser.getPreviousSibling('#web-button') await browser.getPreviousSibling({selector: '#web-button', locateStrategy: 'css selector'})

                                                                                                                                                                                                                                                  // with global element(): const formEl = element('form'); const result = await browser.getPreviousSibling(formEl)

                                                                                                                                                                                                                                                  // with Selenium By() locators // https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_By.html const locator = by.tagName('form'); const result = await browser.getPreviousSibling(locator)

                                                                                                                                                                                                                                                  // with browser.findElement() const formEl = await browser.findElement('form'); const result = await browser.getPreviousSibling(formEl)

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getPreviousSibling.html

                                                                                                                                                                                                                                                method getShadowRoot

                                                                                                                                                                                                                                                getShadowRoot: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<ElementGlobal | null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, ElementGlobal | null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<ElementGlobal>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, ElementGlobal>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Returns the shadowRoot read-only property which represents the shadow root hosted by the element. This can further be used to retrieve elements part of the shadow root element.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  describe('Shadow Root example test', function() { it('retrieve the shadowRoot', async function(browser) { await browser .navigateTo('https://mdn.github.io/web-components-examples/popup-info-box-web-component/') .waitForElementVisible('form');

                                                                                                                                                                                                                                                  const shadowRootEl = await browser.getShadowRoot('popup-info'); const infoElement = await shadowRootEl.find('.info');

                                                                                                                                                                                                                                                  await expect(infoElement.property('innerHTML')).to.include('card validation code'); const iconElement = await shadowRootEl.find('.icon'); const firstElement = await browser.getFirstElementChild(iconElement);

                                                                                                                                                                                                                                                  await expect.element(firstElement).to.be.an('img'); }); });

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getShadowRoot.html

                                                                                                                                                                                                                                                method getTagName

                                                                                                                                                                                                                                                getTagName: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Query for an element's tag name.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.getTagName('#login', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getTagName('css selector', '#login', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getTagName({ selector: '#login', index: 1, suppressNotFoundErrors: true }, function(result) { console.log('result', result); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.getTagName('#login'); console.log('tagName', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getTagName.html

                                                                                                                                                                                                                                                method getText

                                                                                                                                                                                                                                                getText: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Returns the visible text for the element.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.getText('#main ul li a.first', function(result) { this.assert.equal(typeof result, 'object); this.assert.strictEqual(result.status, 0); // only when using Selenium / JSONWire this.assert.equal(result.value, 'nightwatchjs.org'); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getText('css selector', '#main ul li a.first', function(result) { console.log('getText result', result.value); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getText({ selector: '#main ul li a', index: 1 }, function(result) { console.log('getText result', result.value); });

                                                                                                                                                                                                                                                  browser.getText({ selector: '#main ul li a.first', timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present }, function(result) { console.log('getText result', result.value); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function() { const result = await browser.getText('#main ul li a.first'); console.log('getText result', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getText.html

                                                                                                                                                                                                                                                method getValue

                                                                                                                                                                                                                                                getValue: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Returns a form element current value.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.getValue('#login input[type=text]', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.getValue('css selector', '#login input[type=text]', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.getValue({ selector: '#login input[type=text]', index: 1, suppressNotFoundErrors: true }, function(result) { console.log('result', result); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function() { const result = await browser.getValue('#login input[type=text]'); console.log('Value', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/getValue.html

                                                                                                                                                                                                                                                method hasDescendants

                                                                                                                                                                                                                                                hasDescendants: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Returns true or false based on whether the DOM has any child nodes

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { 'demo Test': function(browser) { const result = await browser.hasDescendants('.features-container');

                                                                                                                                                                                                                                                  console.log('true or false:', result); },

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/hasDescendants.html

                                                                                                                                                                                                                                                method isEnabled

                                                                                                                                                                                                                                                isEnabled: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Determines if an element is enabled, as indicated by the 'disabled' attribute.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest(browser) { browser.isEnabled('#main select option.first', function(result) { this.assert.equal(typeof result, "object"); this.assert.equal(result.status, 0); this.assert.equal(result.value, true); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.isEnabled('css selector', '#main select option.first');

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.isEnabled({ selector: '#main ul li a', index: 1, suppressNotFoundErrors: true });

                                                                                                                                                                                                                                                  browser.isEnabled({ selector: '#main select option.first', timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.isEnabled('#main select option.first'); console.log('isVisible result', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/isEnabled.html

                                                                                                                                                                                                                                                method isPresent

                                                                                                                                                                                                                                                isPresent: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Determines if an element is present in the DOM.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest(browser) { browser.isPresent('#main ul li a.first', function(result) { this.assert.equal(typeof result, "object"); this.assert.equal(result.status, 0); this.assert.equal(result.value, true); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.isPresent('css selector', '#main ul li a.first');

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.isPresent({ selector: '#main ul li a', index: 1, });

                                                                                                                                                                                                                                                  browser.isPresent({ selector: '#main ul li a.first', timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.isPresent('#main ul li a.first'); console.log('isPresent result', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/isPresent.html

                                                                                                                                                                                                                                                method isSelected

                                                                                                                                                                                                                                                isSelected: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Determines if an element is selected.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest(browser) { browser.isSelected('#main select option.first', function(result) { this.assert.equal(typeof result, "object"); this.assert.equal(result.status, 0); this.assert.equal(result.value, true); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.isSelected('css selector', '#main select option.first');

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.isSelected({ selector: '#main ul li a', index: 1, suppressNotFoundErrors: true });

                                                                                                                                                                                                                                                  browser.isSelected({ selector: '#main select option.first', timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const result = await browser.isSelected('#main select option.first'); console.log('isVisible result', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/isSelected.html

                                                                                                                                                                                                                                                method isVisible

                                                                                                                                                                                                                                                isVisible: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Determine if an element is currently displayed.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest() { browser.isVisible('#main ul li a.first', function(result) { this.assert.equal(typeof result, "object"); this.assert.equal(result.status, 0); this.assert.equal(result.value, true); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.isVisible('css selector', '#main ul li a.first');

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.isVisible({ selector: '#main ul li a', index: 1, suppressNotFoundErrors: true });

                                                                                                                                                                                                                                                  browser.isVisible({ selector: '#main ul li a.first', timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function() { const result = await browser.isVisible('#main ul li a.first'); console.log('isVisible result', result); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/isVisible.html

                                                                                                                                                                                                                                                method moveToElement

                                                                                                                                                                                                                                                moveToElement: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                xoffset: number,
                                                                                                                                                                                                                                                yoffset: number,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                xoffset: number,
                                                                                                                                                                                                                                                yoffset: number,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • 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. If the element is not visible, it will be scrolled into view.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  this.demoTest = function () { browser.moveToElement('#main', 10, 10); };

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/moveToElement.html

                                                                                                                                                                                                                                                method sendKeys

                                                                                                                                                                                                                                                sendKeys: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                inputValue: string | string[],
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                inputValue: string | string[],
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Types a key sequence on the DOM element. Can be used to send a sequence of key strokes to an element. Any UTF-8 character may be specified.

                                                                                                                                                                                                                                                  **sendKeys** does not clear the existing value of the element. To do so, use **setValue()** instead.

                                                                                                                                                                                                                                                  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), is loaded onto the main Nightwatch instance as browser.Keys.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  // send some simple text to an input this.demoTest = function () { browser.sendKeys('input[type=text]', 'nightwatch'); }; // // send some text to an input and hit enter. this.demoTest = function () { browser.sendKeys('input[type=text]', ['nightwatch', browser.Keys.ENTER]); };

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/sendKeys.html

                                                                                                                                                                                                                                                method setAttribute

                                                                                                                                                                                                                                                setAttribute: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                attribute: string,
                                                                                                                                                                                                                                                value: string,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                attribute: string,
                                                                                                                                                                                                                                                value: string,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<boolean>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, boolean>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Set the value of a specified DOM attribute for the given element. For all the available DOM attributes, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest(browser) { browser.setAttribute('#login input[type=text]', 'disabled', 'true', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.setAttribute('css selector', '#login input[type=text]', 'disabled', 'true', function(result) { console.log('result', result); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.setAttribute({ selector: '#login input[type=text]', index: 1, suppressNotFoundErrors: true }, 'disabled', 'true', function(result) { console.log('result', result); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { await browser.setAttribute('#login input[type=text]', 'disabled', 'true'); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/setAttribute.html

                                                                                                                                                                                                                                                method setPassword

                                                                                                                                                                                                                                                setPassword: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                inputValue: string | string[],
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                inputValue: string | string[],
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • An alias of "setValue" command, but hides the content from the nightwatch logs.

                                                                                                                                                                                                                                                  setValue/setPassword do not clear the existing value of the element. To do so, use the clearValue() command.

                                                                                                                                                                                                                                                  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), is loaded onto the main Nightwatch instance as browser.Keys.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  // send some simple text to an input this.demoTest = function (browser) { browser.setPassword('input[type=text]', 'nightwatch'); }; // // send some text to an input and hit enter. this.demoTest = function (browser) { browser.setPassword('input[type=text]', ['nightwatch', browser.Keys.ENTER]); };

                                                                                                                                                                                                                                                method setValue

                                                                                                                                                                                                                                                setValue: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                inputValue: string | string[],
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                inputValue: string | string[],
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • 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.

                                                                                                                                                                                                                                                  From Nightwatch v2, **setValue** also clears the existing value of the element by calling the **clearValue()** beforehand.

                                                                                                                                                                                                                                                  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), is loaded onto the main Nightwatch instance as browser.Keys.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  // send some simple text to an input this.demoTest = function () { browser.setValue('input[type=text]', 'nightwatch'); }; // // send some text to an input and hit enter. this.demoTest = function () { browser.setValue('input[type=text]', ['nightwatch', browser.Keys.ENTER]); };

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/setValue.html

                                                                                                                                                                                                                                                method submitForm

                                                                                                                                                                                                                                                submitForm: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • 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.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  this.demoTest = function () { browser.submitForm('form.login'); };

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/submitForm.html

                                                                                                                                                                                                                                                method takeElementScreenshot

                                                                                                                                                                                                                                                takeElementScreenshot: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<string>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, string>;
                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                • Take a screenshot of the visible region encompassed by this element's bounding rectangle.

                                                                                                                                                                                                                                                  Example 1

                                                                                                                                                                                                                                                  module.exports = { demoTest(browser) { browser.takeElementScreenshot('#main', function (imageData, err) { require('fs').writeFile('out.png', imageData.value, 'base64', function (err) { console.log(err); }); });

                                                                                                                                                                                                                                                  // with explicit locate strategy browser.takeElementScreenshot('css selector', '#main', function(imageData, err) { require('fs').writeFile('out.png', imageData.value, 'base64', function (err) { console.log(err); }); });

                                                                                                                                                                                                                                                  // with selector object - see https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html#postdoc-element-properties browser.takeElementScreenshot({ selector: '#main ul li a', index: 1 }, function(imageData, err) { require('fs').writeFile('out.png', imageData.value, 'base64', function (err) { console.log(err); }); }); },

                                                                                                                                                                                                                                                  demoTestAsync: async function(browser) { const data = await browser.takeElementScreenshot('#main'); require('fs').writeFile('out.png', data, 'base64'); } }

                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                  • https://nightwatchjs.org/api/takeElementScreenshot.html

                                                                                                                                                                                                                                                method uncheck

                                                                                                                                                                                                                                                uncheck: {
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                selector: Definition,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI,
                                                                                                                                                                                                                                                result: NightwatchCallbackResult<null>
                                                                                                                                                                                                                                                ) => void
                                                                                                                                                                                                                                                ): Awaitable<this, null>;
                                                                                                                                                                                                                                                (
                                                                                                                                                                                                                                                using: LocateStrategy,
                                                                                                                                                                                                                                                selector: any,
                                                                                                                                                                                                                                                callback?: (
                                                                                                                                                                                                                                                this: NightwatchAPI