Implementation:Nightwatchjs Nightwatch Globals Type Definitions
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Type_System, Test_Lifecycle |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
TypeScript type definitions for Nightwatch's external test globals interface, including timeout settings, lifecycle hooks, and custom reporter configuration.
Description
The globals.d.ts file defines:
- NightwatchGlobals — The user-facing globals interface extending `NightwatchInternalGlobals` with an index signature for custom properties.
- NightwatchInternalGlobals — Built-in global settings including:
- Timeout controls: `waitForConditionTimeout` (default 5000ms), `waitForConditionPollInterval` (default 500ms), `asyncHookTimeout` (default 10000ms), `unitTestsTimeout` (default 2000ms), `customReporterCallbackTimeout` (default 20000ms), `retryAssertionTimeout` (default 5000ms).
- Behavior flags: `abortOnAssertionFailure` (default true), `abortOnElementLocateError` (default false), `throwOnMultipleElementsReturned` (default false), `suppressWarningsOnMultipleElementsReturned` (default false), `reuseBrowserSession` (default false).
- Lifecycle hooks: `before(done)`, `after(done)`, `beforeEach(browser, done)`, `afterEach(browser, done)`.
- Navigation hooks: `onBrowserNavigate(browser)`, `onBrowserQuit(browser)`.
- Custom reporter: `reporter(results, done)`.
Usage
These types are used when defining an external globals module (referenced by `globals_path` in config) or when setting `globals` inline in `nightwatch.conf.ts`. They provide autocompletion for all timeout values, behavior flags, and lifecycle hooks.
Code Reference
Source Location
- Repository: Nightwatchjs_Nightwatch
- File: types/globals.d.ts
- Lines: 1-214
Signature
export interface NightwatchGlobals extends NightwatchInternalGlobals {
[key: string]: any;
}
export interface NightwatchInternalGlobals {
abortOnAssertionFailure?: boolean;
waitForConditionPollInterval?: number;
waitForConditionTimeout?: number;
abortOnElementLocateError?: boolean;
throwOnMultipleElementsReturned?: boolean;
suppressWarningsOnMultipleElementsReturned?: boolean;
asyncHookTimeout?: number;
unitTestsTimeout?: number;
customReporterCallbackTimeout?: number;
retryAssertionTimeout?: number;
reuseBrowserSession?: boolean;
reporter?(results: unknown, done: (...args: unknown[]) => void): void;
before?(done: (err?: unknown) => void): void;
after?(done: (err?: unknown) => void): void;
beforeEach?(browser: NightwatchAPI, done: (err?: unknown) => void): void;
afterEach?(browser: NightwatchAPI, done: (err?: unknown) => void): void;
onBrowserNavigate?(browser: NightwatchAPI): Promise<void>;
onBrowserQuit?(browser: NightwatchAPI): Promise<void>;
}
Import
import { NightwatchGlobals } from 'nightwatch';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| waitForConditionTimeout | number | No | Default timeout for waitFor commands (ms) |
| abortOnAssertionFailure | boolean | No | Whether to abort test on first assertion failure |
| before/after | function | No | Global lifecycle hooks |
| Custom properties | any | No | User-defined globals accessible in tests |
Outputs
| Name | Type | Description |
|---|---|---|
| Globals object | NightwatchGlobals | Available as `browser.globals` in all tests |
Usage Examples
External Globals Module
import { NightwatchGlobals } from 'nightwatch';
const globals: NightwatchGlobals = {
waitForConditionTimeout: 10000,
waitForConditionPollInterval: 500,
abortOnAssertionFailure: true,
retryAssertionTimeout: 5000,
// Custom properties
testEnv: 'staging',
apiUrl: 'https://api.staging.example.com',
// Global hooks
before(done) {
console.log('Starting test run...');
done();
},
afterEach(browser, done) {
console.log(`Finished: ${browser.currentTest.name}`);
done();
},
onBrowserNavigate(browser) {
return Promise.resolve();
},
};
export default globals;
Inline Globals in Config
import { NightwatchOptions } from 'nightwatch';
const config: NightwatchOptions = {
globals_path: './globals.ts',
test_settings: {
default: {
globals: {
waitForConditionTimeout: 15000,
myCustomData: { key: 'value' },
},
},
},
};
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment