Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Nightwatchjs Nightwatch Page Commands

From Leeroopedia
Knowledge Sources
Domains Testing, Design_Patterns, Page_Object_Model
Last Updated 2026-02-12 00:00 GMT

Overview

A command encapsulation pattern that bundles multi-step page interactions into reusable, named methods on page objects.

Description

Page Commands are methods defined on page objects that encapsulate complex multi-step interactions into single, semantically named operations. Instead of tests repeating sequences like "wait for element, type text, click submit," a page command wraps this into page.submit(). Commands have access to all page object elements via the @ alias prefix and should return this for method chaining.

Commands can be defined as object literals (placed in an array) or as ES6 classes. The this context within commands is bound to the page object instance, providing access to all Nightwatch commands and the page's elements.

Usage

Define page commands for any multi-step interaction that is reused across multiple tests. Each command should represent a meaningful user action (e.g., "login", "search", "submit form") rather than a low-level browser operation.

Theoretical Basis

Page commands follow the Command pattern from object-oriented design:

  1. Each command encapsulates a sequence of operations
  2. Commands use the page object's element references (not raw selectors)
  3. Commands return this to enable fluent chaining
  4. Commands abstract implementation details from test logic

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment