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 Step Definition Implementation

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

Overview

A pattern-matching implementation pattern that maps Gherkin natural language steps to executable browser automation code via regex or string patterns.

Description

Step Definition Implementation is the bridge between human-readable Gherkin scenarios and executable test code. Each step definition registers a pattern (regex or string) via Given(), When(), or Then() functions from @cucumber/cucumber. When the Cucumber runner encounters a Gherkin step matching a pattern, it executes the corresponding callback function.

In the Nightwatch integration, the browser global is automatically available in step definition callbacks, providing access to all Nightwatch commands (navigateTo, click, setValue, assert, etc.) without explicit initialization.

Usage

Create step definition files in the src_folders directory. Each file imports Given/When/Then from @cucumber/cucumber and defines patterns that match Gherkin steps. Use the browser global for all browser interactions.

Theoretical Basis

Step definitions follow the adapter pattern:

  1. Pattern registration: Given/When/Then functions register regex → callback mappings
  2. Pattern matching: Cucumber matches Gherkin step text against registered patterns
  3. Capture groups: Regex capture groups become callback arguments
  4. Browser integration: The global browser object provides Nightwatch commands

Related Pages

Implemented By

Page Connections

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