Testland
Browse all skills & agents

bdd-step-library-curator

Keeps a BDD step-definition library DRY across a Cucumber / Behave / Reqnroll project - inventories every step definition, detects duplicates (different patterns matching the same intent), recommends canonical consolidations, reorganizes steps by domain, publishes a step-library README the team greps for "is there already a step for X?" before authoring new ones, and builds a scenario coverage map that fingerprints new Gherkin scenarios against the live suite to classify each as duplicate, partial overlap, or genuine gap before any test is authored. Use when a BDD project's step count grows past ~50, on a quarterly step-library review, when a new engineer is about to write a duplicate step, or when fresh .feature files need a covered-already check.

Install with skills.sh (any agent)

npx skills add testland/qa --skill bdd-step-library-curator
View source

bdd-step-library-curator

Overview

After 6 months of a BDD project, step definitions proliferate:

  • Two engineers write Given a user and Given a logged-in user for the same fixture.
  • Three slightly-different "I click X" steps (one for buttons, one for links, one for arbitrary elements) - all do the same thing.
  • A new engineer can't find existing steps and writes a fourth variant.

The result: step library bloat → Gherkin features hard to read, step ambiguities, runtime errors, drift.

This skill builds a curation workflow.

When to use

  • A BDD project's step count exceeds ~50 (proliferation threshold).
  • A new engineer reports "I couldn't find a step for X."
  • Quarterly: scheduled step review.
  • Before adopting BDD across multiple teams (proactively design the step library shape).

How to use

Work through Steps 1-6 below in order: inventory -> detect duplicates -> recommend consolidations -> reorganize and publish the README -> gate new steps pre-merge -> repeat on a cadence.

Step 1 - Inventory step definitions

Extract every declared step pattern across the project. Each runner uses its own annotation syntax (@Given in Cucumber-JVM, @given in Behave, [Given] in Reqnroll / SpecFlow) - the per-runner extraction commands are in references/step-extraction-and-overlap.md.

The inventory produces a step audit:

Total step definitions: 142
Unique patterns: 138    (4 ambiguous duplicates already)
Per Gherkin verb:
  Given: 58
  When:  34
  Then:  47
  And:    3

Step 2 - Detect duplicates / overlaps

Two patterns are likely duplicates when:

  • Same wording, different phrasing: Given a user vs Given an existing user vs Given the user.
  • Same parameters, different verbs: When I click {label} vs When I press {label} vs When I tap {label}.
  • Same fixture, different shape: Given a cart with {n} items vs Given a cart containing {n} items.

Normalize each pattern (lowercase, drop articles, collapse parameters) and group by the normalized form; any group of size greater than one is a candidate cluster. The overlap script that does this is in references/step-extraction-and-overlap.md.

Step 3 - Recommend consolidation

For each duplicate group:

**Duplicate group:** 4 step definitions with normalized "user is
logged in"

| Pattern                            | File / line                |
|------------------------------------|----------------------------|
| `Given a user is logged in`         | `auth_steps.py:12`         |
| `Given the user is logged in`        | `cart_steps.py:8`           |
| `Given an authenticated user`        | `checkout_steps.py:5`       |
| `Given a logged-in user`            | `profile_steps.py:14`       |

**Recommendation:** Consolidate to **`Given a logged-in user`**
(highest count of usage in current Gherkin; clearest wording).

Replace the other 3 step definitions with a single canonical one
in `shared_steps.py`. Update the Gherkin features that use the
deprecated patterns.

Verify: consolidation is destructive - it deletes step definitions and rewrites .feature files. After each group, run the full BDD suite and assert zero undefined or ambiguous steps and no orphaned scenarios before declaring the refactor complete. If a scenario reports an undefined step, a .feature file still references a deprecated pattern - fix that reference and re-run.

Step 4 - Domain organization

Group steps per domain area:

features/steps/
├── shared/                      # cross-domain (login, navigation, etc.)
│   ├── auth_steps.py
│   ├── navigation_steps.py
│   └── data_steps.py
├── checkout/                    # checkout-specific
│   ├── promo_steps.py
│   ├── payment_steps.py
│   └── cart_steps.py
├── account/                     # account-specific
│   └── profile_steps.py
└── README.md                    # step library index

The README is the discoverability artifact:

# Step library

## Shared (cross-domain)

### Auth
- `Given a logged-in user` (auth_steps.py:12) - creates and logs in a generic test user.
- `Given a logged-in admin` (auth_steps.py:25) - logged-in user with admin role.
- `Given an unauthenticated visitor` (auth_steps.py:38) - no session.

### Navigation
- `When I navigate to {path}` - go to URL.
- `When I click {label}` - click any element with this label.

## Checkout

### Cart
- `Given the cart contains {qty} of {sku} at ${price}` - seed a cart.
- `Given the cart is empty` - empty cart.

### Promo codes
- `Given promo code {code} is active` - pre-seed a promo in the admin.
- `When I enter {code} in the promo input` - type the code.
- `When I click {label}` - (uses shared step).

(...)

The README + grep is the team's "is there a step for X?" tool.

Step 5 - Pre-merge step gate

Add a CI check that flags new step definitions so no engineer adds a duplicate unknowingly. The check warns (doesn't block), forcing the author to acknowledge the new step and grep the README first. The check-new-steps.sh script is in references/step-extraction-and-overlap.md.

Scenario coverage map (pre-authoring duplicate check)

The same duplicate-prevention discipline applies one level up, at the scenario layer. When new .feature files land (typically from gherkin-from-stories), fingerprint each new scenario by its ordered, keyword-stripped step texts and diff against the existing suite's step-usage index before any test is authored:

  • DUPLICATE - every step already covered under one existing scenario: do not author.
  • PARTIAL - some steps overlap: author only the new step definitions, reuse the rest.
  • GAP - nothing matches: author in full.

Fingerprint on the step text, not the keyword - per the Gherkin reference, "keywords are not taken into account when looking for a step definition." Prefer the Cucumber JSON report over re-parsing source .feature files when one exists, exclude Background steps from the fingerprint, and halt on an empty or tiny index (a map against an empty suite is vacuous). The full method, output templates, tag-match handling, and hard-reject conditions: references/coverage-map.md.

Step 6 - Quarterly cadence

CadenceTrigger
QuarterlyScheduled step library review.
New team memberOnboarding: walk the README.
Step count exceeds thresholdTriggered review.
New domain areaAdd steps; update README.

Worked example

Curating a 142-step library in a mixed Behave project, end to end.

1. Inventory. The Behave extraction over features/steps/ yields the Step 1 audit: 142 step definitions, 138 unique patterns - so 4 are already ambiguous duplicates the runner would flag at match time.

2. Detect. The overlap script surfaces one cluster - the four user is logged in variants listed in Step 3's duplicate-group table.

3. Consolidate. Pick Given a logged-in user as canonical (clearest wording, most-used in current Gherkin). Move it into features/steps/shared/auth_steps.py, delete the other three definitions, and rewrite the .feature files that used the deprecated phrasings - edit the Gherkin first so no scenario is left orphaned, then run the Step 3 verification.

4. Reorganize + publish. Split the flat features/steps/ into shared/, checkout/, and account/, then regenerate the README index. The library now advertises Given a logged-in user (auth_steps.py) - creates and logs in a generic test user under Shared → Auth.

5. Gate. Add the pre-merge new-step check. The next PR that adds Given the customer is signed in trips the warning; the author greps the README, finds Given a logged-in user, and reuses it instead of adding a fifth variant.

Result: 142 → 139 step definitions, zero ambiguous duplicates, one discoverable index the whole team searches before writing a step.

Anti-patterns

Anti-patternWhy it failsFix
Per-engineer step files (alice_steps.py)Ownership without domain alignment; duplication across files.Domain-organized files (Step 4).
Step library README missingDiscoverability nil; engineers re-implement.README per Step 4.
Ambiguous step deletion without grepBreaks scenarios silently.Replace canonical → deprecated; update all Gherkin first.
Step "shared library" that's a giant helpers.pyAll engineers conflict on it; merge hell.Domain split (Step 4).
Reviewing step count quarterly onlyProliferation outpaces review; library bloats.Pre-merge gate (Step 5).

Limitations

  • Heuristic duplicate detection. Some patterns are legitimately distinct (Given a user for auth vs Given a user with profile data for profile tests).
  • Domain organization is per-team. What's "shared" varies.
  • Consolidation cost. Each refactor touches Gherkin + step definitions; not free.
  • Doesn't fix Gherkin quality. A clean step library doesn't prevent imperative-style Gherkin scenarios. Pair with a Gherkin style review.

References

  • Step extraction commands, the overlap-detection script, and the pre-merge gate: references/step-extraction-and-overlap.md.
  • Scenario-level coverage map (fingerprinting, output templates, hard-reject conditions): references/coverage-map.md.
  • cucumber-testing, behave-testing, reqnroll-testing - per-language runners this curator works alongside.

Scenario coverage map - fingerprint new Gherkin against the live suite

View source (opens in new window)

Scenario coverage map - fingerprint new Gherkin against the live suite

Deep reference for bdd-step-library-curator (the "scenario coverage map" section). Consult before authoring tests for freshly generated .feature files: it classifies each new scenario as already-covered, partially covered, or a genuine gap.

Cucumber's Gherkin reference makes the step text - not the keyword - the stable identity unit: "Keywords are not taken into account when looking for a step definition. This means you cannot have a Given, When, Then, And or But step with the same text as another step." (cucumber.io/docs/gherkin/reference (opens in new window)) Fingerprint on the text.

This is a structural check on the step layer; it does not execute assertions or report pass/fail - never a substitute for running the suite.

Step 1 - Collect the new scenarios

Read each new .feature file (typically produced by gherkin-from-stories). For each Scenario and Scenario Outline, collect:

  • The scenario title.
  • The full ordered list of step texts, stripped of their keyword prefix (Given, When, Then, And, But) - keywords are cosmetic; the text is what step definitions match (gherkin-ref (opens in new window)).
  • Any @tags declared on the scenario or inherited from the Feature block (cucumber.io/docs/cucumber/api (opens in new window)).
  • For Scenario Outline, note the parameter names from the Examples: table as placeholder tokens (e.g., "<status>").

Output: a new-scenario list of { id, title, tags[], steps[] } objects.

Step 2 - Build the step-usage index from the existing suite

Glob all existing .feature files (excluding the new ones). Extract every step text with the same keyword-strip rule; normalize whitespace and lower-case. Build a step-usage index: normalized_step_text -> [{ feature_file, scenario_title, line_number }].

If the project produces Cucumber's json report (cucumber.io/docs/cucumber/reporting (opens in new window)), prefer loading the report over re-parsing - it contains every executed step with its text, status, and parent scenario, guaranteed to reflect the last run:

# Cucumber-JS
npx cucumber-js --format json:reports/cucumber.json

# JVM (Maven)
mvn test -Dcucumber.plugin="json:target/cucumber.json"

Step 3 - Fingerprint and classify

A scenario fingerprint is the ordered tuple of its normalized step texts.

StatusCondition
DUPLICATEAll steps already present in the index under one existing scenario
PARTIALAt least two steps overlap; one or more steps are new
GAPZero steps match any entry in the index

Step 4 - Resolve tag coverage

Tags on a new scenario may correspond to existing test runs (tag expressions like @smoke and @fast / not @wip per cucumber-api (opens in new window)). A @smoke-tagged PARTIAL scenario may already be executed in a @smoke run; flag it explicitly as PARTIAL (tag match).

Step 5 - Emit the coverage map

## Coverage map for `<story-id>` (<date>)

**New scenarios evaluated:** N
**Exact duplicates:** A (skip these)
**Partial overlaps:** B (extend step definitions only)
**Genuine gaps:** C (author full scenarios)
**Step-usage index built from:** M existing .feature files / JSON report

### Duplicates (do not author - already covered)

| New Scenario | Existing Scenario | File |
|---|---|---|
| "User logs in with valid credentials" | "User submits correct password" | `auth/login.feature:14` |

### Partial overlaps (author only the new steps)

**Scenario: "Admin resets user password"**
- Already covered steps (3): step text A, step text B, step text C
- New steps required (1): "the user receives a password-reset email"
- Recommendation: add one new step definition; reuse the 3 covered steps.

### Gaps (author full scenario)

- "Password reset rate-limits after 5 attempts" (0 of 4 steps covered)

Step 6 - Hard-reject conditions

Halt and report the blocker (a BLOCKED message naming the condition and remediation) instead of emitting a map when:

  • No existing .feature files and no Cucumber JSON report exist - a map against an empty suite is vacuous (everything is GAP).
  • The new .feature files contain unparseable Gherkin (missing Feature: keyword, unclosed Examples: table, illegal step keyword) - fix the syntax first.
  • The step-usage index has fewer than 5 distinct step texts - a suite that small has no coverage baseline; the map would mislead.

Anti-patterns

Anti-patternWhy it failsFix
Stripping keywords but not normalizing whitespace"Given the user is logged in" and "Given the user…" fingerprint differently; false GAPsCollapse whitespace and trim before comparing
Treating Scenario Outline rows as separate scenariosEach Examples row shares the same step templateFingerprint the template (placeholder tokens), not expanded rows
Ignoring the JSON report when one existsSource files may include scenarios never runPrefer the report; flag when only source parsing was possible
Counting Background steps toward DUPLICATEBackground steps are shared context, not scenario identityExclude Background steps from fingerprint comparison

Worked example

New password-reset.feature has three scenarios. The index (built from auth/login.feature + auth/session.feature) shows: scenario 1's 4 steps all present at auth/login.feature:32DUPLICATE (do not author); scenario 3 shares 2 of 5 steps with auth/session.feature:18PARTIAL (author 3 new step definitions, reuse 2); scenario 2 matches nothing → GAP (author in full).

Step extraction, overlap detection, and the pre-merge gate

View source (opens in new window)

Step extraction, overlap detection, and the pre-merge gate

Deep reference for the bdd-step-library-curator SKILL. Consult when running the inventory against a specific BDD runner, wiring the programmatic overlap detector, or adding the pre-merge new-step CI gate.

Per-runner step extraction

Each BDD runner declares steps with its own annotation syntax; extract the raw patterns per runner and combine the output into a single list.

# Cucumber-JVM
grep -rE '@(Given|When|Then|And|But)\(' src/test/java/ | \
  sed -E 's/.*@(Given|When|Then|And|But)\("([^"]*)".*/\2/'

# Behave
grep -rE '^@(given|when|then|step)\(' features/steps/ | \
  sed -E 's/.*@(given|when|then|step)\("([^"]*)".*/\2/'

# Reqnroll / SpecFlow
grep -rE '\[(Given|When|Then|And|But)\(' Tests/Steps/ | \
  sed -E 's/.*\[(Given|When|Then|And|But)\("([^"]*)".*/\2/'

Each command emits one step pattern per line; feed the combined list into the overlap detector below.

Programmatic overlap detection

Normalize each pattern (lowercase, strip articles, collapse every parameter to a single placeholder) and group patterns that collapse to the same normalized form. Any group of size greater than one is a candidate duplicate cluster.

# scripts/step-overlap.py
import re

def normalize(pattern):
    """Lower; strip articles; remove parameter type hints."""
    p = pattern.lower()
    p = re.sub(r'\b(a|an|the)\b', '', p)
    p = re.sub(r'\{[^}]+\}', '{var}', p)
    p = re.sub(r'\s+', ' ', p).strip()
    return p

steps = [...]   # from the extraction step

normalized = {}
for s in steps:
    n = normalize(s['pattern'])
    normalized.setdefault(n, []).append(s)

for n, group in normalized.items():
    if len(group) > 1:
        print(f"Likely duplicates ({len(group)}):")
        for s in group:
            print(f"  {s['pattern']} - {s['file']}:{s['line']}")

The detector is a heuristic - review each cluster before consolidating, since some collisions are legitimately distinct steps.

Pre-merge new-step gate

A CI check that warns (does not block) whenever a PR adds new step definitions, forcing the author to confirm the step is not already in the library.

# scripts/check-new-steps.sh
NEW_STEPS=$(git diff --diff-filter=A origin/main...HEAD -- '**/steps/*.py' '**/Steps/*.cs' '**/steps/*.java' \
  | grep -E '^\+' | grep -E '@(Given|When|Then)' | wc -l)

if [ $NEW_STEPS -gt 0 ]; then
  echo "::warning::This PR adds $NEW_STEPS new step definitions."
  echo "Before merging, verify these aren't duplicates of existing steps."
  echo "Run: bash scripts/step-overlap.py"
fi

The warning is intentionally non-blocking - it forces acknowledgment of a new step without stopping legitimately-new ones.

Related skills

behave-testing

Configures Behave for Python BDD scenarios - `pip install behave`, authors `.feature` files in Gherkin, writes step implementations in `features/steps/*.py`, configures via `environment.py` for setup/teardown hooks, organizes via tags, runs via `behave`. Use for Python codebases that want Cucumber-family BDD without Cucumber-Ruby / Cucumber-JS.

cucumber-testing

Configures Cucumber for BDD scenarios - Cucumber-JVM (Java/Kotlin via JUnit 5), Cucumber-JS (Node), Cucumber-Ruby. Authors `.feature` files in Gherkin, writes step definitions in the host language, runs via the framework's runner, integrates with JUnit XML reporting. Use when the user mentions Cucumber, Gherkin, `.feature` files, or behavior-driven (BDD) tests in Java, Kotlin, JavaScript, or Ruby, as the canonical wrapper for any of the three official implementations.

gherkin-from-stories

Converts requirements in any input shape into Gherkin scenarios - a user story ("As a … I want … so that …"), a signed-off acceptance-criteria list (ATDD: @AC-N-tagged scenarios, NotImplementedError step stubs, AC-to-test traceability table), existing manual test steps (declarative rewrite that strips UI mechanics), or a raw spec / PRD section (acceptance-criteria extraction with Gherkin or plain-list output). Maps criteria to Scenario blocks, detects Scenario Outline opportunities, factors shared Background, reuses the curated step library, and flags implicit preconditions instead of fabricating them. Emits Gherkin (plus stubs in ATDD mode): runner detection and full step wiring belong to bdd-scenario-author. Use whenever requirements text of any shape needs to become a .feature file.

living-documentation-publisher

Converts passing Cucumber JSON output into stakeholder-facing living documentation: generates HTML reports via multiple-cucumber-html-reporter (Node) or Serenity BDD aggregate (JVM), applies Gherkin tags to drive report sections, and publishes to GitHub/GitLab Pages in CI. Use when BDD scenarios are in use and the team needs an always-current, non-test-engineer-readable document showing which acceptance criteria pass.

reqnroll-testing

Configures Reqnroll (the canonical .NET BDD framework) - install via `dotnet add package Reqnroll`, author `.feature` files in Gherkin, write step bindings as `[Given/When/Then]`-decorated methods in any C# class, runs via `dotnet test`. Reqnroll is the SpecFlow successor (SpecFlow reached end-of-life 2024-12-31); covers the SpecFlow-to-Reqnroll migration path, and references/specflow-legacy.md maintains not-yet-migrated SpecFlow projects. Use for .NET projects starting BDD, migrating from SpecFlow, or maintaining legacy SpecFlow suites.