Implementation:Nightwatchjs Nightwatch Nightwatch Module Exports
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Testing, API, Module_System |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete module exports from the Nightwatch.js package providing createClient, runTests, cli, CliRunner, and namespaced API proxies.
Description
The nightwatch module exports a main object with factory methods (createClient, runTests, cli, CliRunner, initClient) and named exports for API namespaces (browser, element, assert, expect, verify, plus framework-specific namespaces). It also re-exports By, Key, and Capabilities from selenium-webdriver for convenience.
Usage
Import the nightwatch module using require('nightwatch'). Destructure named exports as needed.
Code Reference
Source Location
- Repository: nightwatch
- File: lib/index.js (lines 14, 423-493)
Signature
const Nightwatch = require('nightwatch');
// Factory methods
Nightwatch.createClient(options) -> ClientWrapper
Nightwatch.runTests(testSource?, settings?) -> Promise<boolean>
Nightwatch.cli(callback) -> void
Nightwatch.CliRunner(argv?) -> CliRunner
Nightwatch.initClient(opts?) -> NightwatchClient
// Named exports (Proxy-based)
const {
browser, // Global browser proxy
app, // Alias for browser
element, // Element factory proxy
assert, // Assert namespace proxy
verify, // Verify namespace proxy
expect, // Expect namespace proxy
appium, // Appium commands
alerts, // Alert handling
cookies, // Cookie management
document, // Document commands
window, // Window commands
chrome, // Chrome-specific commands
firefox // Firefox-specific commands
} = require('nightwatch');
// Re-exports from selenium-webdriver
Nightwatch.by // selenium-webdriver By
Nightwatch.Key // selenium-webdriver Key
Nightwatch.Capabilities // selenium-webdriver Capabilities
// Utilities
Nightwatch.Logger // Logging utility
Nightwatch.utils // { HttpRequest, cdp }
Import
const Nightwatch = require('nightwatch');
// or
const { createClient, runTests, browser, element, assert, expect } = require('nightwatch');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| require('nightwatch') | Module import | Yes | Node.js require statement |
Outputs
| Name | Type | Description |
|---|---|---|
| Nightwatch | Object | Main module with createClient, runTests, cli, CliRunner, initClient |
| Named exports | Proxies | browser, element, assert, expect, verify, etc. |
| Re-exports | Classes | By, Key, Capabilities from selenium-webdriver |
Usage Examples
Import and Use
const Nightwatch = require('nightwatch');
// Use factory methods
const client = Nightwatch.createClient({ browserName: 'chrome' });
// Or destructure named exports
const { browser, element, assert, expect } = require('nightwatch');
Related Pages
Implements Principle
Requires Environment
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment