Principle:Nightwatchjs Nightwatch Browser Command Execution
| Knowledge Sources | |
|---|---|
| Domains | Testing, Browser_Automation, API |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A command execution pattern for performing browser actions programmatically via the NightwatchAPI instance returned by the client launcher.
Description
Browser Command Execution describes how browser commands are invoked from the programmatic API context. Once launchBrowser() returns the browser object, all standard Nightwatch commands are available: navigateTo, waitForElementVisible, click, setValue, assert.*, element.find(), etc. Commands are chainable and support async/await.
This is the same API surface available in standard test files, but accessed from arbitrary Node.js code rather than within the test runner framework.
Usage
Use these commands after obtaining a browser instance from launchBrowser() to perform any browser automation task programmatically.
Theoretical Basis
The command execution model uses an async command tree:
- Commands are queued in the AsyncTree for sequential execution
- Each command sends WebDriver protocol requests
- Results are returned as Promises
- Commands can be chained (fluent API) or awaited individually