Principle:Nightwatchjs Nightwatch Session Cleanup
| Knowledge Sources | |
|---|---|
| Domains | Testing, API, Resource_Management |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A resource cleanup pattern that terminates browser sessions, empties command queues, and frees allocated resources after test execution completes.
Description
Session Cleanup ensures that all resources allocated during test execution are properly released. This includes terminating the WebDriver session (closing the browser), emptying the command queue, resetting the logger, and removing event listeners. Proper cleanup prevents resource leaks in long-running processes and is essential in programmatic usage where multiple test cycles may run in a single Node.js process.
Usage
Always call cleanup methods after test execution completes, especially in programmatic usage where the process continues after tests finish.
Theoretical Basis
Cleanup follows a two-level resource release pattern:
- Browser level: end() or quit() terminates the WebDriver session
- Client level: cleanup() empties queues, resets loggers, removes listeners
- Both levels must be called for complete cleanup