Skip to content

About

Spec-driven testing on the native Playwright runner. Write specs in Markdown or Gherkin - tests run straight from step definitions, no generated files to keep in sync. Steps not automated yet are walked by a person (Cyborg Tests). Director UI built into Playwright UI.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

64 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎭 Playwright BDD Director

Write the Script, We'll Play the Show

A spec-driven testing framework for Playwright: test cases are written in Markdown or Gherkin, each step is automated once by a step definition, and every test runs from day one - the steps without automation are walked by a person.

Part of CyborgTests - a modern testing ecosystem combining human insight with automation power.

πŸš€ Quick Start

1. Install Node.js

  1. Open Node.js Downloads in browser
  2. Select your operating system and CPU architecture
  3. Download the LTS version - Node.js 22 or newer is required, 24 LTS is recommended
  4. Run the downloaded installer and follow the installation steps
  5. Open a terminal and verify that Node.js was installed successfully (v22 or higher):
node --version

2. Download Playwright BDD Director

Clone with Git:

  1. Open a terminal in the folder where you want to clone the repository
  2. Run the commands below:
git clone https://github.com/CyborgTests/playwright-bdd-director
cd playwright-bdd-director

or download ZIP:

  1. Open the repository page on GitHub
  2. Click Code β†’ Download ZIP
  3. Extract the archive to any folder
  4. Open a terminal in the extracted folder

3. Install dependencies

npm install

4. Build the Director UI

npm run build

This builds the Director UI (React/Vite) and patches Playwright to embed it into the Playwright UI interface.

5. Install Playwright browsers

npx playwright install

6. Launch the UI

npm run show

This opens the combined interface in your browser:

  • Director UI (built as part of this project) - file explorer, editor, staging controls
  • Playwright UI (built-in Playwright feature) - test runner, traces and screenshots

Together they form a unified workspace for the full testing workflow.

Director UI - Combined interface

7. Create your first test suite

In the Director UI:

  1. File Explorer - click New File button
  2. Enter filename: login.md
  3. File Editor - paste the following (saves automatically as you type):
@ui
## Login Tests

---

### User can login
#### Navigate to login page
#### Enter credentials
#### Click login button
#### Verify dashboard visible

@ui above the suite heading is its layer - every test is @api, @ui or @e2e.

8. Run it

The test is in the Playwright UI list right away - tests are generated from the specs on every run and every change. No step has a step definition yet, so it is a cyborg test: run it and the Cyborg Tests control panel walks you through the steps.

npm run play cyborg login        # the same from a terminal

9. Automate it step by step

npm run dress            # which steps a person still walks
npm run steps login      # step definition skeletons β†’ src/steps/login.steps.ts

Implement a skeleton with Page Objects and its step runs automatically on the next run; once every step is implemented, the test is an automated test (@auto):

Step('Navigate to login page', async ({ loginPage }) => {
  await loginPage.navigateToLogin()
})
npm run play auto login

10. View detailed results

After tests finish, close the UI window - the terminal will become available again. Then open the HTML report:

npm run review

Every run also writes reports for test management tools and CI:

  • test-results/cucumber/<device>/cucumber-report.json - Cucumber JSON (Xray, Zephyr Scale, ...) per device (Playwright project): import each as a run on that device - one test in the tool, a result per device. Every test, Markdown specs included: Feature / Background / Scenario (Outline) and steps come from the spec, step results from the run (manual steps too). Failed steps carry the error and screenshots. Xray links a scenario to its Jira test by a tag with the test key - use the format your Xray expects (often @TEST_PROJ-123) - a tags line above the heading in both formats
  • test-results/cucumber/<device>/cucumber-messages.ndjson - Cucumber messages, the newer Cucumber format, per device as well
  • test-results/cucumber/cucumber-report.html - the Cucumber HTML report of all devices for people (one offline file): a section per device and spec, tablet/test-suites/cart.feature
  • A known bug (@fail, @fail:tablet) stays failed in Cucumber reports - the tool shows the product as it is - with Expected to fail (@fail:tablet): a known bug in the message; a test that passes despite the tag fails: the bug looks fixed
  • The folder is cleared on every run, so a run on fewer devices leaves no reports of the others
  • test-results/junit.xml - JUnit XML (TestRail, Zephyr, any CI)

11. Check coverage

See which tests are automated, which a person still walks, how many steps are automated and how each test did in its last run - the matrix itself runs no test:

npm run matrix                           # console table
npm run matrix -- --html --json --md     # + test-results/coverage-matrix.{html,json,md}
npm run matrix -- --md=docs/coverage.md  # any format to a custom path
npm run matrix -- --min=80               # exit 1 when automated tests are below 80%
npm run matrix -- @smoke                 # only tests tagged @smoke
  Site Navigation  test-suites/navigation.md
  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘  67% automated 2/3

    Test                                            Layer  Devices  Status      Steps auto  Last run
    Open "Signup / Login" Page from Header          UI     all      βœ” auto      4/4         βœ” passed 4/4
    Open "Polo" Brand Products from Sidebar         UI     all      βœ” auto      4/4         ✘ failed 2/4 (failed: firefox; not run: mobile)
    Subscribe to Newsletter from Footer             UI     all      βœ‹ cyborg    1/5         Β· not run

  By tag

    Tag           Tests  Automated     Cyborg  Last run
    @all-devices      8  88% 7/8            1  passed 26/29 runs Β· failed 1
    @smoke            5  100% 5/5           0  passed 14/14 runs

    A test with several tags counts in each of them; 6 tests (9 runs) without a tag are not listed.

  Total  16 tests Β· 38 runs in 4 suite(s)
  Automated       β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘  94% 15/16
  Cyborg          β–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘   6% 1/16
  Fixme (API)     β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘   0% 0/16
  Disabled        β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘   0% 0/16
  Steps automated β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘  91% 41/45
  Last run        passed 35/38 runs Β· failed 1 Β· flaky 0 Β· skipped 0 Β· not run 2 Β· 2026-10-26 23:00 UTC
  • Status: auto every step automated Β· cyborg a person walks the rest Β· fixme an API test waiting for step definitions Β· disabled @skip / @fixme / @fail in the spec
  • Steps auto: automated / total steps of the test, Background included
  • Runs: a test runs once per device that picks it (Playwright project: API once, UI on desktops, @all-devices on tablets and mobiles too, cyborg in its own project) - npm run dress counts the same runs
  • Last run: the latest result of every run of the test - passed / runs, in brackets the devices where it failed, was flaky or has not run yet; the totals and By tag count runs too. Each run replaces the results of the tests it ran and keeps the others (npm run play cyborg leaves the automated results), in test-results/last-run.json (LAST_RUN_FILE). A known bug (@fail) failing as expected counts as passed
  • Run history: a run started with npm run play ... -- --record (RECORD_RUN=1 for any other command, the Record run checkbox in UI mode) also keeps its own coverage matrix - every spec and the results of the tests this run ran - in run-history/<end of the run>.json (RUN_HISTORY_DIR, gitignored), one file per run, none overwritten. It is the data for a coverage trend
  • By tag: the same counts for every spec tag across suites, most tests first; run settings (@retries:N, @timeout:N, @fail:<device>) get no row. The rows do not add up to the total: a test with several tags counts in each, tests without a tag are only counted in the note under the table. npm run matrix -- @smoke keeps only the tests with the tag
  • HTML is a single self-contained file with filters by status and light/dark theme; JSON is the same data for CI, TMS or agents

12. Run in CI

One command for any CI service (GitHub Actions, GitLab CI, Jenkins, Azure DevOps, ...):

npm ci                                # install dependencies
npx playwright install --with-deps    # browsers
npm run ci                            # dress -> automated tests -> coverage matrix
  • dress fails first on invalid specs or ambiguous steps - no test runs then
  • Runs every automated test (play auto); cyborg tests need a person and are skipped
  • Failed tests do not stop the coverage matrix and reports; the exit code is 1 when any stage failed
  • CI_MIN_COVERAGE=80 npm run ci also fails when automated tests are below 80%
  • RECORD_RUN=1 npm run ci keeps the run in the run history: point RUN_HISTORY_DIR at a cached or persistent directory, CI workspaces start empty
  • Keep test-results/ as the job artifacts: junit.xml (most CI services show it as test results, the device in hostname), cucumber/, monocart-report/, coverage-matrix.{html,json,md}

⚑ Spec-Driven Testing Platform

Playwright BDD Director is part of the CyborgTests ecosystem - a suite of tools that combine human insight with automation power.

It brings together:

  • Playwright for automated E2E, UI, and API testing
  • @cyborgtests/test for the steps a person walks
  • Markdown or Gherkin specs as the single source of truth
  • Step definitions - each step automated once, reused everywhere
  • Built-in Director UI for visual test management

πŸ’‘ Why Spec-First Testing?

1. Readable beyond engineering

Manual QA, managers, and non-technical stakeholders can review and update test specifications without touching TypeScript.

2. One spec, one test - always in sync

The spec is the test: its tests are generated on every run, so they cannot drift from it. There are no test files to keep in sync, review for wording or archive.

3. Works before automation

A new spec runs at once as a cyborg test - a person walks its steps. Automation is added step by step: each implemented step definition stops asking a person on the next run, in every test that uses the step.

4. Built for Playwright

Steps in traces and reports point to their spec lines (cart.feature:32) through a source map in the generated file. The generated tests are plain Playwright tests: fixtures, projects, traces, UI mode, the VS Code extension, parallel runs and reporters work as usual, with full TypeScript support.

πŸ€– AI-Friendly by Design

Playwright BDD Director is designed to work naturally with AI coding assistants (GitHub Copilot, Cursor, Claude Code, etc.) inside your IDE.

The key advantage: specs and step definitions live in the same repository. An AI assistant sees both at once - it reads auth.md, the list of steps without definitions from npm run dress and the Page Objects, and writes exactly the missing code.

  • Write test cases with AI - describe a feature, ask AI to write the spec in test-suites/; it runs immediately as a cyborg test
  • Automate with AI - npm run steps <suite> writes skeletons, AI implements them with Page Objects and clients
  • Review coverage with AI - point AI at test-suites/ and npm run matrix -- --json and ask what is missing
1. Ask AI to write test cases β†’ test-suites/auth.md
2. npm run play cyborg auth  β†’ a person walks them today
3. npm run steps auth        β†’ skeletons; ask AI to implement them
4. npm run play auto auth    β†’ automated

πŸ“ Playwright BDD Director vs Cucumber vs Pure Playwright

Feature Cucumber + PW Pure Playwright PW BDD Director
Main Runner Cucumber Playwright Playwright
Native PW Features Partial Full Full
TypeScript Support Medium Excellent Excellent
Debugging Harder Excellent Excellent
Readability High Medium High
AI Friendliness Medium High Very High
Runtime Complexity High Low Low
Performance Medium High High
Maintenance Cost High Low Low
Flexibility Medium High Very High
Visual UI No Basic Advanced
Before automation Nothing runs Nothing runs Cyborg tests

Playwright BDD Director is a modern middle-ground:

  • Keeps readable human-friendly scenarios like Cucumber - in Markdown or Gherkin
  • Keeps native Playwright runner with full TypeScript support
  • Removes Cucumber pain points: runtime complexity, shared context chaos, heavy abstraction layers
  • Runs unautomated steps by hand instead of failing or skipping them
  • Adds AI-native workflow on top

Best for: modern Playwright projects, teams moving from manual to automated testing, AI-assisted automation, teams that want readable scenarios without Cucumber complexity.

🎨 Director UI

A combined visual interface - the Director UI (built in this project) together with Playwright UI (built-in Playwright feature) form a unified workspace:

Director UI (our part):

  • File Explorer - browse and edit Markdown and Gherkin specs with File Editor: both formats highlighted alike (titles, Gherkin keywords, tags, notes, "strings", <placeholders>, tables); Preview shows either as a document - headings with their tags, steps, examples tables
  • Stage - format the Markdown specs
  • Rename and convert - double-click the file name above the editor: type a new name (Enter) or pick the other format from the .md / .feature list. A new format runs npm run adapt, a new name runs npm run rename, both - the conversion first, and only when the name is free; Escape cancels. The output (the "Not finished" warning too) goes to Output
  • Reword - F2 or a double click on a step or title line: the field above the editor shows the pattern of the step definition (Step pattern:), the text of a manual step (Step:) or the title (Suite:, Rule:, Test case:). Enter runs npm run reword: a step changes in every spec and in its pattern, a title on its line only (refused when two test cases would share it); Escape cancels. The code of a step does not change: Output warns to check that it still does what the new words say
  • Record run - checkbox in Testing Options: every run started while it is on keeps its coverage matrix in the run history (as npm run play -- --record)

Playwright UI (Playwright's part):

  • View all tests, run individually or in batches with real-time status - the list follows the specs as you edit them
  • Detailed test execution view with step-by-step breakdown
  • Traces, screenshots, and video on failure

Launch:

npm run show

Director UI - File explorer and test runner

🎯 Core Idea

1 spec file = 1 test suite = 1 generated test file 1 step = 1 step definition, reused by every test

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ test-suites/navigation.md    β”‚     β”‚ src/steps/*.steps.ts         β”‚
β”‚ ## Site Navigation  @ui      β”‚     β”‚ Step('Open Home Page', …)    β”‚
β”‚ ### Open Signup Page         β”‚     β”‚ Step('Click {string} …', …)  β”‚
β”‚ #### Open Home Page          β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ #### Click "Signup" Button   β”‚                    β”‚
β”‚ #### Verify Form is visible  β”‚                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β–Ό  on every run
          .director/tests/navigation.test.ts (generated)
          test('Open Signup Page', { tag: ['@cyborg', '@ui'] }, …)
            await autoStep('Open Home Page', { homePage })     ← has a definition
            await autoStep('Click "Signup" Button', …)
            await manualStep('Verify Form is visible')         ← a person walks it
  • A step with a step definition is automated (autoStep); without one - or with one without code - a person walks it (manualStep)
  • A test with any manual step is a cyborg test (@cyborg, UI / E2E only): headed, one at a time, no time limit. A test with all steps automated is an automated test (@auto)
  • An API test with a missing step stays fixme - nobody walks API by hand
  • The Director commands:
    • npm run dress - check before a run: invalid specs, missing layers, ambiguous steps; tests and runs per spec and project; steps a person walks; disabled tests; unused step definitions
    • npm run steps <suite...> - step definition skeletons for the steps without one
    • npm run stage - formats the Markdown specs (--- before every test case)
    • npm run adapt <suite...> - moves a spec between Markdown and Gherkin
    • npm run rename <suite> <new-name> - renames a spec and its step file
    • npm run reword "<old>" "<new>" - rewords a step in every spec and in its step definition pattern; -- --at <suite> <line> "<title>" - a suite, rule or test case title
    • npm run migrate <file.spec.ts...> - turns Playwright tests built of test.step into a spec and step definitions
    • npm run play - runs tests by type, suite and tag

πŸ“ Specs

1. Markdown

@ui
## Test Suite Title
- Optional details

---

@smoke
### Test Case title
#### Step Title
- Optional details, test data, expected results
#### Another Step
## β†’ Test Suite
### β†’ Test Case (### Background - steps before every test case)
#### β†’ Test Step
@tags β†’ tags of the suite / test case, in a line above its heading (as in Gherkin)
Lists (-) β†’ notes for people, not part of the test
--- β†’ separator before every test case, the only blank lines - npm run stage keeps the rest dense, as in Gherkin

2. Gherkin

Any .feature file the Gherkin parser accepts: Background, Rule (with its own Background), Scenario Outline with Examples (tagged too), DataTable, DocString, # language:. Write the layer tag above Feature::

@ui
Feature: Cart
  Background:
    Given user opens the products page

  @all-devices @smoke
  Scenario: Add "Blue Top" to cart
    When user adds "Blue Top" to cart
    And user opens the cart
    Then cart has "Blue Top"

Both formats work the same way and can live side by side; pick per suite what reads best for its authors. Base names are unique across test-suites/** (auth.md and auth.feature cannot coexist) - the name is the suite tag (npm run play auth).

npm run adapt <suite...> moves a suite to the other format and removes the old file - tags, [ID]s, Background, examples and notes move along (notes become descriptions and comments in Gherkin). Gherkin steps lose their keywords; step definitions match the step text either way, so the tests stay the same. Markdown β†’ Gherkin is not finished by adapt: Markdown steps have no keywords, so every step comes out as * - set Given / When / Then before using the .feature file (which one fits takes understanding the step, adapt warns about it). A suite with what Markdown cannot hold (Rule, DataTable, DocString, tagged or named Examples) stays in Gherkin: adapt lists it and changes nothing.

3. Layers

Every test is exactly one of @api, @ui, @e2e: a suite tag for all its test cases, a test case (Rule, Examples) tag overrides it. A test without a layer stops the run. Cyborg tests are UI or E2E only.

4. Tags

Both formats tag the same way: a line of @tags right above the heading - ## suite and ### test case in Markdown, Feature / Rule / Scenario / Examples in Gherkin:

@ui @all-devices
## Authentication Tests

---

@smoke @JIRA-123
### User Login
  • The suite carries what holds for all its tests: the layer, and @all-devices, @slow... only when every test needs it. A test carries its exceptions and additions.
  • Order in a line: layer β†’ @all-devices β†’ special tags β†’ own tags (@smoke, @logged-in, ticket keys) - @e2e @all-devices @retries:1 @smoke
  • Tags become Playwright tags of the generated tests, next to @auto / @cyborg, the layer and the suite tag @<file name>
  • A tag starts with @ followed by letters, digits, _ . : / -; several tags are separated by spaces
  • Background cannot be tagged (as in Gherkin)
  • Special tags @skip, @fixme, @fail (also for one device: @fail:tablet), @slow, @retries:N, @timeout:N become Playwright modifiers
  • Run and measure by tag: npm run play @smoke, npm run play ui auth @smoke, npm run matrix -- @smoke

Where the example uses each kind of tag:

Tag Example
Layer @ui / @api / @e2e every suite; @e2e overrides the suite on a Rule (cart.feature) and a scenario (products.feature)
@all-devices suite navigation.md; test cases cart.feature (adding, placing an order)
@retries:N, @timeout:N cart.feature: placing an order, Rule Checkout
@fail, @fail:<device> cart.feature: quantity 0, placing an order on a tablet (real bugs)
Own tags @smoke in every suite, tagged Examples in cart.feature; @logged-in picks a Before hook (cart.feature)

5. Parametrized test cases

A Markdown test case that runs once per data row gets an examples table right under its heading; its title and steps use <column> placeholders. In Gherkin it is a Scenario Outline with Examples.

### Login as <role>
| role  | password |
| ----- | -------- |
| admin | secret   |
| guest | guest    |
#### Log in as "<role>" with "<password>"
  • One test per row, title and steps filled with the row values: Login as admin runs Log in as "admin" with "secret"
  • The title needs a placeholder of a column with unique values - Playwright requires unique test titles

6. IDs

Optional IDs in brackets stay in the test titles and reports: ## [TS01] Suite, ### [TC01-01] Test case. Test case IDs are unique within a spec; [] is an empty ID. Other formats (TC-001:) are part of the title.

7. Step definitions

// src/steps/navigation.steps.ts
import { Step } from './bdd' // createBdd(test) - typed with the project fixtures

Step('Click {string} Brand in Sidebar', async ({ homePage }, brand: string) => {
  await homePage.clickBrand(brand)
})
  • Patterns: Cucumber Expressions or RegExp; the keyword does not affect matching; Markdown steps use Step(…)
  • Fixtures: the first parameter destructures what the step needs; all steps of a test share the fixtures
  • No code (empty body or comments only) = no definition: the step stays manual
  • Ambiguous step β†’ dress and the run fail with the definitions' locations; unused definition β†’ dress warns
  • Hooks Before/After/BeforeAll/AfterAll/BeforeStep/AfterStep with tag expressions (@cyborg matches the tests a person walks)
  • Step context bdd next to the fixtures: tags, test title, step title, skip(), attach(), the step error in AfterStep
  • Migration: existing Cucumber suites move over without rewriting their steps; plain Playwright tests built of test.step become a spec and step definitions with npm run migrate (guide)

Full guide: docs/step-definitions.md.

πŸ“ Project Structure

playwright-bdd-director/
β”œβ”€β”€ test-suites/           # Specs (source of truth): *.md, *.feature
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ steps/             # Step definitions (*.steps.ts) and hooks; bdd.ts binds them to the fixtures
β”‚   β”œβ”€β”€ fixtures/          # Playwright fixtures (base, auth, shop); index.ts - test of the generated tests
β”‚   β”œβ”€β”€ pages/             # Page objects (home, login, signup, products, cart, checkout)
β”‚   β”œβ”€β”€ clients/           # API clients (BaseClient, AuthClient, ProductsClient)
β”‚   β”œβ”€β”€ schemas/           # API response schemas and types
β”‚   β”œβ”€β”€ test-helpers/      # Test-specific helpers (masking secrets in reports)
β”‚   β”œβ”€β”€ test-utils/        # General test utilities (APIExpect, logger, schema-validator)
β”‚   β”œβ”€β”€ config/            # Playwright projects, devices
β”‚   └── framework/         # The Director, unit tests (*.test.ts) next to the modules
β”‚       β”œβ”€β”€ bdd/           # Step registry, generator, runtime (autoStep), build, skeletons
β”‚       β”œβ”€β”€ core/          # Parsers (Markdown, Gherkin, spec document)
β”‚       β”œβ”€β”€ validation/    # Markdown structure check and formatting
β”‚       β”œβ”€β”€ reporting/     # Coverage matrix, Cucumber reports, console output
β”‚       β”œβ”€β”€ constants/ errors/ utils/
β”‚       └── config.ts      # Framework configuration (env-overridable paths)
β”œβ”€β”€ scripts/               # CLI: play, dress, stage, adapt, rename, steps, matrix, ci; generate-tests (run by the config)
β”œβ”€β”€ packages/              # Director UI & Playwright integration
└── .director/tests/       # Generated tests (gitignored, rewritten on every run)

πŸ“š Working Example

The repository automates automationexercise.com:

Spec Shows Steps and code
test-suites/auth.md @ui Markdown suite, Background, fixtures with cleanup (testUser, registeredUser) src/steps/auth.steps.ts
test-suites/auth-api.md @api API layer through clients; "Update User City" has a step without code, so the API test stays fixme src/steps/auth-api.steps.ts
test-suites/products-api.md @api Catalog API: products list, unsupported method (405), search; a step function reused by an e2e scenario src/steps/products-api.steps.ts, src/clients/ProductsClient.ts
test-suites/navigation.md @ui Markdown examples table (brands); the newsletter case is a cyborg test: one automated step, the rest skeletons without code src/steps/navigation.steps.ts
test-suites/cart.feature @ui Gherkin: Background, Scenario Outline with tagged Examples, DataTable, DocString, Rule with its own Background, @e2e and @timeout:90000 on a Rule, @retries:1, @fail on a real bug (quantity 0 and -2 get into the cart), @fail:tablet on a tablet-only one, own parameter type {price}, one step calling others, a cyborg scenario (invoice); adding to cart and placing an order on all devices (@all-devices) src/steps/cart.steps.ts
test-suites/products.feature @ui Steps on Page Object methods (@StepsFor, a migration path); a desktop-only @e2e scenario (catalog price = API price) src/pages/ProductsPage.ts, src/steps/products.steps.ts
test-suites/contact-us.feature @ui A suite migrated from Cucumber: World style steps on this; BeforeAll / AfterAll create and remove the file it uploads src/steps/contact-us.steps.ts

Hooks (src/steps/hooks.steps.ts): BeforeAll checks the catalog API once per worker for @cart, Before logs in a fresh user for @logged-in, AfterStep attaches the page URL under a failed step (bdd.step).

npm run dress             # specs and step definitions, what a person still walks
npm run play auto         # all automated tests (headless, parallel)
npm run play cyborg       # all cyborg tests (headed, one at a time)
npm run play api auth-api # API auth tests only
npm run play ui auth      # UI auth tests only
npm run show              # Playwright UI mode with the Director

βš™οΈ Configuration

1. Environment Variables

All paths support environment variable overrides via src/framework/config.ts:

Variable Default Description
TEST_SUITES_DIR test-suites Specs directory
GENERATED_TESTS_DIR .director/tests Generated tests (Playwright testDir)
BDD_STEPS src/steps/**/*.steps.ts Step definition files
BDD_STEPS_DIR src/steps Where npm run steps writes skeletons
COVERAGE_MATRIX_FILE test-results/coverage-matrix Coverage matrix reports path (without extension)
CUCUMBER_REPORTS_DIR test-results/cucumber Cucumber JSON and messages per device, HTML of all devices
DRESS_REPORT_FILE test-results/dress-rehearsal.md Report of npm run dress
GENERATION_ERRORS_FILE test-results/generation-errors.md Failed generation with stack traces (the console omits them)
JUNIT_REPORT_FILE test-results/junit.xml JUnit XML of every run
LAST_RUN_FILE test-results/last-run.json Latest result per test and device for the coverage matrix
RUN_HISTORY_DIR run-history Coverage matrix of every recorded run, one file each
RECORD_RUN - 1 records the run in the run history (play -- --record)
CI_MIN_COVERAGE - npm run ci fails below this automated tests share

2. Playwright Config

playwright.config.ts generates the tests when Playwright loads it (prepareTests(); UI mode and IDE servers on start, then on every change of specs or source), then runs them in projects that pick their tests by tag (src/config/projects.ts, devices in src/config/devices.ts):

Project Device Tests
api no browser @auto + @api - once, not per device
chrome, firefox Desktop Chrome, Desktop Firefox every @auto UI and E2E test
tablet, mobile Galaxy Tab S9 landscape, Galaxy S24 @auto UI and E2E tests tagged @all-devices in the spec
cyborg Desktop Chrome, headed @cyborg: one worker, no time limit

Automated projects run headless and in parallel, with trace and video on failure. A new device is one entry in devices.ts. npm run play builds the --grep; a device name selects its project (npm run play e2e mobile).

3. Path Aliases

@/* β†’ src/* (tsconfig.json), in step definitions, fixtures, scripts and framework code:

import { AuthClient } from '@/clients/AuthClient'

4. Cyborg Tests Analytics

The control panel of cyborg tests (@cyborgtests/test) sends usage analytics to Google Analytics by default, while a person walks the manual steps. Per the package README it collects:

  • a unique user ID, generated on the first run
  • test execution events (start of a test) and results (passed / failed)
  • external link clicks
  • browser, OS and country

No spec content, step data or credentials are listed. To turn it off, add to src/fixtures/base.fixture.ts:

import { config } from '@cyborgtests/test'

config.setConfig({ analyticsEnabled: false })

Automated runs (@auto, CI) do not open the control panel and send nothing.

πŸ§ͺ Development & Testing

Play CLI

Types, suites, spec tags and devices are freely combinable - test types first, then suite names (spec file names), spec tags (@smoke) and devices (chrome, firefox, tablet, mobile) anywhere:

npm run play <types...> [suites...] [@tags...] [devices...]

npm run play auto                   # All automated tests
npm run play cyborg                 # All cyborg tests
npm run play api                    # Automated API tests
npm run play cyborg ui              # Cyborg UI tests
npm run play ui auth                # Automated UI tests of auth.md
npm run play api ui auth auth-api   # API + UI tests of two suites
npm run play auth                   # All tests of auth.md (any type)
npm run play @smoke                 # All tests tagged @smoke
npm run play ui auth @smoke         # UI auth tests tagged @smoke
npm run play e2e mobile             # E2E tests on the mobile device
npm run play auto chrome firefox    # Automated tests on desktop browsers only
npm run play auto -- --record       # Automated tests, the run kept in the run history

Supported test types: auto, cyborg, api, ui, e2e. Help: npm run play -- --help.

Director Commands

npm run dress        # check specs and step definitions; report in test-results/dress-rehearsal.md
npm run steps auth   # step definition skeletons for steps of auth.md without one
npm run stage        # format the Markdown specs
npm run adapt auth   # auth.md β†’ auth.feature (and back)
npm run rename auth login  # auth.md β†’ login.md, src/steps/auth.steps.ts β†’ login.steps.ts
npm run reword "user adds {string} to cart" "user puts {string} in the cart"  # a step everywhere
npm run migrate tests/login.spec.ts  # Playwright tests (test.step) β†’ login.md + login.steps.ts
npm run show         # Playwright UI mode with the Director
npm run lint:fix     # ESLint fix
npm run format       # Prettier format

dress answers three questions before a run: will it start (errors), what runs where (tests per spec, runs per project), what is left to do (steps a person walks, by test; disabled tests and known bugs; step definitions no spec uses). It never changes specs, steps or tests; the same report goes to test-results/dress-rehearsal.md (DRESS_REPORT_FILE):

  Spec                Layer    Tests  Auto  Cyborg  Fixme  Runs
  auth-api.md         api          6     5       -      1     6
  cart.feature        ui, e2e      8     7       1      -    21
  ...
  Total                           35    32       2      1    75

  Runs: cyborg 2 Β· api 13 Β· chrome 20 Β· firefox 20 Β· tablet 10 Β· mobile 10

βœ‹  To automate
  cart.feature
    Check invoice of placed order (cyborg: a person walks these steps)
      β€’ And user downloads the invoice - definition without code: src/steps/cart.steps.ts:69

πŸ’€  Disabled and known bugs
  cart.feature β€Ί Quantity 0 is not added to cart    @fail
  cart.feature β€Ί Place order with delivery comment  @fail:tablet

βœ…  Ready for the show: 35 tests, 75 runs
    Report: test-results/dress-rehearsal.md

Unit Tests

npm test              # Run tests in watch mode
npm run test:run      # Run tests once (CI mode)
npm run test:ui       # Open visual test UI
npm run test:coverage # Generate coverage report

πŸ”§ Framework Core

Step definitions (src/framework/bdd/):

  • registry.ts - createBdd, Given/When/Then/Step, hooks, parameter types, Page Object decorators; a definition without code is pending
  • generator.ts - one test file per spec: autoStep / manualStep, @auto / @cyborg, layers, hooks by tags, special tags, snippets
  • build.ts - generates all specs in memory (dress, steps, matrix) and writes them (scripts/generate-tests.ts)
  • prepare.ts - generation when Playwright loads the config; regenerates on changes in UI mode and the IDE
  • runtime.ts - autoStep, hooks and the bdd context of generated tests
  • skeletons.ts - step definition skeletons for npm run steps
  • migrate.ts - Playwright tests built of test.step as a spec and step definitions (npm run migrate)
  • step-reword.ts - new text for a step in every spec and its definition pattern, or for a title on its line, all or nothing (npm run reword)

Parsers (src/framework/core/):

  • md-parser.ts - Markdown structure (headings, IDs, tags, examples)
  • gherkin-parser.ts - Gherkin documents
  • spec-document.ts - a spec of either format as one Gherkin document for the generator
  • spec-converter.ts - Markdown ↔ Gherkin with notes kept (npm run adapt)
  • spec-rename.ts - a new name for a spec and its step file, all or nothing (npm run rename)

Validation (src/framework/validation/): md-validator.ts - Markdown structure check and formatting (stage).

Reporting (src/framework/reporting/): coverage matrix and its renderers, last-run reporter (results for the matrix, run history of recorded runs), dress report, Cucumber JSON / messages / HTML reporter, console formatter.

Test Utilities (src/test-utils/):

  • APIExpect - Playwright APIResponse wrapper: status, content type and schema assertions; the body is parsed once and attached to the report with secrets masked
  • logger.ts - attaches logs and files to Playwright test reports
  • schema-validator.ts - small schema validator for API responses (required fields and their types), no dependencies

Test Helpers (src/test-helpers/):

  • test.helpers.ts - sanitizeObject for masking sensitive data (emails, passwords, tokens) in logs and reports; partial email masking preserves debuggability

πŸŽ“ Philosophy

1. The spec is the source of truth

  • The spec defines what is tested: test cases, steps, data, tags, layer
  • Step definitions define how a step is automated - once, for every test
  • The Director generates the tests from both on every run - nothing to sync, nothing to drift

2. Manual and automated are one test

  • A test runs from the moment it is written - a person walks what is not automated yet
  • Automation grows step by step; a test becomes automated when its last step is
  • Cyborg and automated are not two copies of a test, but two states of the same one

3. One spec file = One Test Suite

  • Multiple test cases per file, one layer each
  • Logical grouping by feature/functionality

πŸ“Š Reports

1. View test results

npm run review    # Open Monocart HTML report (after test run)
npm run show      # Open Playwright UI mode (before/during test run)

2. Report includes

  • Test execution summary
  • Screenshots on failure
  • Detailed step-by-step logs, manual steps included

3. Centralized Report Storage (Optional)

For teams needing centralized report storage, you can add:

πŸ“„ License

MIT

See also: THIRD_PARTY_NOTICES.md (licenses for dependencies like Cyborgtests and Monocart Reporter).

About

Spec-driven testing on the native Playwright runner. Write specs in Markdown or Gherkin - tests run straight from step definitions, no generated files to keep in sync. Steps not automated yet are walked by a person (Cyborg Tests). Director UI built into Playwright UI.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages