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 Object Usage In Tests

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

Overview

A factory-based instantiation pattern for accessing page objects within test cases via a centralized namespace on the browser instance.

Description

Page Object Usage in Tests describes how test code instantiates and interacts with page objects. Rather than importing page object files directly, tests access them through the browser.page namespace, which acts as a factory. Calling browser.page.namespace.pageName() creates an instance of the page object with all its elements, sections, commands, and the navigate() method.

This factory pattern ensures page objects are properly initialized with the current browser context and provides consistent instantiation across all tests.

Usage

Use this pattern in every test that interacts with page objects. Instantiate page objects at the test suite level or within individual test cases as needed.

Theoretical Basis

The factory pattern provides:

  1. Lazy instantiation: Page objects are created only when needed
  2. Context binding: Each instance is bound to the current browser session
  3. Namespace isolation: Directory structure creates natural namespaces
  4. Navigation integration: The navigate() method uses the page object's URL

Related Pages

Implemented By

Page Connections

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