The Nightwatch inspector is designed to simplify authoring tests. Major advantages of using this are:

  1. Save time identifying selectors
  2. Build more robust tests
  3. Reduced back and forth between test file & browser as you can test commands in the browser itself

Start Nightwatch Inspector

Follow these to start the Nightwatch Inspector:

Step 1 - Add debug line

Add browser.debug() in the test at a line where you want to start the Nightwatch inspector.

Step 2 - Run test with debug flag

Run the specific Nightwatch test with --debug test:

npx nightwatch /test/inspector_demo.js --env chrome --debug

Step 3 - Open Nightwatch selector

Running the test would have opened up a browser and it would be paused at the line where .debug() was present. Now open dev-tools, click on >> and select Nightwatch Inspector.

Nightwatch Inspector

Explore mode

To get selector recommendations, you have to enable the explore mode.

Explore mode

Once the explore mode is enabled and you point and click in the browser window, you will get selector recommendations as shown below:

Selector recommendations

Click on any element to get the suggestion in the selector history.

Selector history

Try commands

Try out Nightwatch commands from the Nightwatch Inspector itself using the selectors from the selector history.

You can copy the selector using copy button in the `Selector History` & paste it while using the commands.

Selector copy

All successful commands will show up in Command History as shown below

Command history

You can directly copy paste these in your test files and complete your test authoring very easily. Enjoy authoring tests with the Nightwatch inspector!