Nightwatch Inspector
Overview
The Nightwatch inspector is designed to simplify authoring tests. Major advantages of using this are:
- Save time identifying selectors
- Build more robust tests
- 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.
Explore mode
To get selector recommendations, you have to enable the 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:
Click on any element to get the suggestion in the selector history.
Try commands
Try out Nightwatch commands from the Nightwatch Inspector itself using the selectors from the selector history.
All successful commands will show up in Command History as shown below
You can directly copy paste these in your test files and complete your test authoring very easily. Enjoy authoring tests with the Nightwatch inspector!