Principle:Nightwatchjs Nightwatch Command Namespacing
| Knowledge Sources | |
|---|---|
| Domains | Testing, Extensibility, Organization |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
An organizational pattern that uses directory structure to create namespaced groups of related custom commands under logical prefixes.
Description
Command Namespacing uses the file system hierarchy within the custom_commands_path to automatically group related commands under namespace prefixes. When a command file is placed in a subdirectory (e.g., custom-commands/angular/getElementsInList.js), it becomes accessible as browser.angular.getElementsInList() rather than browser.getElementsInList(). This prevents naming collisions and improves API organization for large command libraries.
Usage
Use namespacing when creating sets of related commands that belong to a logical group, such as framework-specific utilities (angular, react), domain-specific operations (checkout, auth), or utility categories (validation, navigation).
Theoretical Basis
Namespacing follows the filesystem-to-API mapping convention:
- Root directory commands → browser.commandName()
- Subdirectory commands → browser.directoryName.commandName()
- Nested subdirectories → deeper namespace nesting