Principle:Nightwatchjs Nightwatch Extension Path Configuration
| Knowledge Sources | |
|---|---|
| Domains | Testing, Extensibility, Configuration |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A configuration pattern that registers directory paths from which custom commands and assertions are automatically loaded and registered on the test API.
Description
Extension Path Configuration tells the Nightwatch test runner where to find custom command and assertion modules. By specifying custom_commands_path and custom_assertions_path in the configuration file, all JavaScript modules in those directories are automatically discovered, loaded, and registered on the browser and browser.assert namespaces respectively. Subdirectories create namespaces (e.g., commands/angular/ → browser.angular.commandName()).
This auto-discovery mechanism eliminates manual registration and enables a plug-and-play approach to extending the testing API.
Usage
Configure extension paths in nightwatch.conf.js whenever creating custom commands or assertions. Paths can be strings or arrays of strings to support multiple directories.
Theoretical Basis
The auto-loading pattern follows these steps:
- Scan configured directories for JavaScript modules
- Register each module on the appropriate namespace
- Subdirectories become namespace prefixes
- Filename (without extension) becomes the command/assertion name