Principle:Nightwatchjs Nightwatch Client Initialization
| Knowledge Sources | |
|---|---|
| Domains | Testing, API, Session_Management |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A factory initialization pattern that creates a configured client, establishes a WebDriver session, and returns a ready-to-use browser API instance.
Description
Client Initialization is the two-step process of creating a client wrapper via createClient() and then launching the browser via launchBrowser(). The first step configures settings and creates the internal NightwatchClient. The second step initializes the Nightwatch API, creates a WebDriver session (starting the browser process), and returns the browser API object.
This separation allows configuration to be adjusted (via updateCapabilities()) between creation and launch, and supports both API-loaded and bare WebDriver modes.
Usage
Use this pattern in programmatic scripts when you need to control the full lifecycle of the browser session, from creation through execution to cleanup.
Theoretical Basis
The initialization follows a two-phase factory pattern:
- Phase 1 (Create): Configure settings, create internal client
- Phase 2 (Launch): Initialize APIs, create WebDriver session, return browser
- Optional: Update capabilities between phases