This guide provides setup instructions and development guidelines for the project.
- Development Setup
- Development Workflow
- AI Assistance
- Writing Tests
- Commit Guidelines
- Dependencies
- Troubleshooting
- Configuration Files
- Node.js: >= 24.0.0
- Bun: >= 1.3.1 (package manager and runtime)
- Git: Latest version
# Clone the repository
git clone https://github.com/m3au/playwright-bdd-cursor-template.git
cd playwright-bdd-cursor-template
# Install dependencies
bun install
# Copy environment file
cp .env.example .envRequired: Configure environment variables in .env. The .env file should be created from .env.example during installation (see Installation).
See Environment Configuration for detailed variable descriptions and CI/CD setup.
| Command | Suite | Purpose |
|---|---|---|
bun run test |
E2E | Generates BDD stubs, then runs all Playwright projects |
bun run test:automationexercise |
E2E | Runs only the AutomationExercise challenge (pretest included) |
bun run test:uitestingplayground |
E2E | Runs only the UITestingPlayground challenge (pretest included) |
bun ui |
E2E | Run tests in UI mode |
bun headed |
E2E | Run tests in headed mode (visible browser) |
bun debug |
E2E | Run tests in debug mode (with Playwright Inspector) |
bun failed |
E2E | Run only failed tests |
bun pretest |
E2E | Generate test files from BDD features (pre-step, normally via test) |
bun test |
Unit | Run Bun unit tests with coverage (configured via bunfig.toml) |
Unit tests use Bun's built-in test runner and achieve 100% code coverage for utility functions (tests/utils/) and scripts (scripts/). Tests are located in tests/unit/ and bunfig.toml is configured with root = "tests/unit" so bun test only runs unit tests. Coverage is enabled by default, with tests/utils/decorators.ts excluded from coverage due to Bun's tooling limitations with decorators.
Unit tests cover all utility modules (attachments, browser-project, bug-reporter, decorators, environment, format, locators, network, pagination, random) and all scripts (bump-version, changelog, lint, pin-versions, update-coverage-badge).
- Unit tests run automatically before every commit (pre-commit hook)
- Pre-flight checks (lint + unit tests) run first in CI/CD before other tests (E2E, Lighthouse, Axe)
Test GitHub Actions workflows locally using act:
# List all available workflows (use act directly)
act -l
# Test individual workflows
make test # Test E2E tests workflow locally
make lighthouse # Test Lighthouse audit workflow locally
make axe # Test Axe audit workflow locally
make publish # Test publish reports workflow locally
make ci # Test main CI workflow locally
make test-dryrun # Dry run E2E tests workflow (list what would run)Prerequisites:
- Docker installed and running (
docker psshould work) actinstalled (brew install act)
Environment Variables:
- All environment variables come from
.env.production(committed to repo) in CI - For local testing with act, ensure
.envfile contains all requiredBASE_URL_<CHALLENGE>variables and audit targets (BASE_URL_AXE_*,BASE_URL_LIGHTHOUSE_*) - Act reads environment variables from
.envfile via the--secret-fileflag (this is just the flag name, not actual secrets)
For detailed setup and troubleshooting, including prerequisites like Docker, see the Act Testing Documentation.
This project enforces high code quality standards through linting, formatting, type checking, and spell checking.
For detailed configuration and tools, see Code Quality Files Reference.
Editor Integration:
VS Code workspace settings (main.code-workspace) configure automatic code quality on save:
- Format on Save: Prettier automatically formats files
- Auto-fix on save: ESLint and markdownlint automatically fix issues
- Ruler at 100 characters: Visual guide for line length
- TypeScript: Real-time type checking
- CSpell: Spell checking integrated into ESLint
- EditorConfig: Consistent formatting across editors
Recommended Extensions:
editorconfig.editorconfig- EditorConfig supportesbenp.prettier-vscode- Prettier formatterdbaeumer.vscode-eslint- ESLint integration (includes Markdown linting via @eslint/markdown)ms-playwright.playwright- Playwright test supportstreetsidesoftware.code-spell-checker- CSpell spell checkingstreetsidesoftware.code-spell-checker-german- German spell checkingalexkrechik.cucumberautocomplete- Cucumber/Gherkin autocompletecucumberopen.cucumber-official- Cucumber official supportredhat.vscode-yaml- YAML support for GitHub workflowsusernamehw.errorlens- Inline error displayyoavbls.pretty-ts-errors- Enhanced TypeScript error displayamatiasq.sort-imports- Automatic import sorting
These settings ensure code quality is maintained automatically as you type and save files.
Scripts:
# Run all linters (TypeScript → ESLint → ShellCheck with progress)
bun lint
# Fix linting errors automatically (ESLint including JSON, HTML, Markdown, YAML)
bun lint:fix
# Run individual linters
bun lint:typescript # TypeScript type checking only
bun lint:eslint # ESLint only (TS, MJS, JSON, HTML, Markdown, YAML, .mdc)
bun lint:markdown # Markdown linting only
bun lint:shellcheck # ShellCheck only (Husky git hooks)Husky Git hooks enforce code quality and commit message standards. They run unit tests, update the coverage badge, and run lint-staged (ESLint, Prettier, ShellCheck on staged files) on pre-commit and TypeScript type checking on pre-push.
For detailed configuration, see Code Quality Files Reference.
Bypassing hooks temporarily:
git commit --no-verifyThis project is configured for AI-assisted development with Cursor IDE. Rules guide AI assistants to follow project conventions and maintain code quality.
Quick Start: Rules automatically apply when editing files (context-aware based on file patterns). Use @browser for browser automation, @playwright for Playwright test features.
For detailed configuration, rules, and MCP integrations, see AI Tuning Documentation.
- Create a
.featurefile intests/e2e/challenges/<challenge-name>/features/ - Write Gherkin scenarios
- Implement step definitions in POMs using decorators
- Create a new file in
tests/e2e/challenges/<challenge-name>/poms/pages/ortests/e2e/challenges/<challenge-name>/poms/components/ - Use
@Fixturedecorator to register the POM (use PascalCase for fixture name matching class name) - Use
@Given,@When,@Thendecorators for step definitions - Use
@Stepdecorator for internal helper methods (imported from@world, defined intests/utils/decorators.ts) - Register the POM fixture in
tests/e2e/world.ts
For a complete implementation example, refer to tests/e2e/challenges/uitestingplayground/poms/pages/home-page.ts or tests/e2e/challenges/uitestingplayground/poms/pages/ajax-data-page.ts.
- Use Page Object Model Pattern: All page interactions go through POMs
- Use Decorators: Step definitions are decorators on POM methods
- PascalCase Fixtures: Fixture names should match class names (e.g.,
@Fixture('HomePage'),@Fixture('AjaxDataPage')) - Wait Strategically: Use Playwright's built-in waiting mechanisms
- Follow BDD Conventions: Given/When/Then structure
- Step Naming: Always start steps with "I" (e.g., "I navigate", "I click", "I see")
- Avoid "should": Use "I see" instead of "I should see"
- One Action Per Step: Never use "and"/"or" in the middle of a step description
- Use environment variables for configuration (accessed via
getEnvironment()from@world) - Environment configuration is centralized in
tests/utils/environment.ts - Avoid hardcoded values - use
.envfiles for all configuration
# Run with Playwright Inspector
bun debug
# Run in headed mode
bun headed
# Run with UI mode
bun uiNote: For code quality tool configuration reference, see Code Quality Files.
We use Conventional Commits:
<type>(<scope>): <subject>
<body>
<footer>
feat- New featurefix- Bug fixdocs- Documentationstyle- Formattingrefactor- Code refactoringtest- Adding testschore- Maintenance tasks
feat(playwright): add manufacturer selection step
fix(tests): resolve timeout in basket validation
docs: update contributing guideVersion bumping and changelog generation happen automatically on commit:
| Commit Type/Keyword | Version Bump |
|---|---|
feat: |
Minor (e.g., 0.1.0 → 0.2.0) |
fix:, perf:, refactor: |
Patch (e.g., 0.1.0 → 0.1.1) |
BREAKING CHANGE or feat!: |
Major (e.g., 0.1.0 → 1.0.0) |
docs:, style:, test:, chore: (etc.) |
No version bump |
The prepare-commit-msg hook automatically:
- Bumps
package.jsonversion based on commit type - Updates
CHANGELOG.mdwith the new entry - Stages both files for commit
No manual version management needed - just follow Conventional Commits format and versions are handled automatically.
Add dependencies using standard Bun commands (bun add <package-name> or bun add -d <package-name> for dev dependencies).
Important: Always run bun pin after adding any dependency to pin versions to exact versions (no ^ or ~).
bun pin# Update all dependencies
bun bump
# This runs: ncu -u && bun install && bun pin- Check environment variables match CI values
- Verify timeout values are appropriate
- Ensure network connectivity
- Review browser version differences
-
playwright.config.ts: Unified Playwright configuration with multiple projects:- Browser projects:
chromium,firefox,webkit(configurable via environment variables) lighthouse: Performance testing with Lighthouseaxe: Accessibility testing with Axe
The config uses
defineBddConfigto generate BDD tests and follows a pattern of defining default local configuration, then overriding CI-specific settings (likeforbidOnlyand reporters) when running in CI/CD environments. - Browser projects:
The config includes error handling that throws if .env file is missing.
Files:
.env: Local environment file (gitignored, must be created manually).env.example: Template for local development (copy to.env).env.production: Production defaults for CI/CD (committed to repo, used in GitHub Actions workflows)
Important: All values must be provided via .env files (no hardcoded defaults in code). All Playwright configs throw errors if .env is missing or if required environment variables are not set.
Environment Variables:
The .env file supports comprehensive Playwright configuration options. See .env.example for the complete list with descriptions. Key categories include:
Test Execution:
BASE_URL_AXE_W3C_BAD,BASE_URL_AXE_W3C_AFTER,BASE_URL_AXE_DEQUE_MARS– Accessibility audit targets (used by Axe smoke tests)BASE_URL_LIGHTHOUSE_POLYMER,BASE_URL_LIGHTHOUSE_W3C_BAD– Performance audit targets (used by Lighthouse smoke tests)BASE_URL_<CHALLENGE>– Challenge-specific base URLs (required for each challenge)BASE_URL_UITESTINGPLAYGROUND– Base URL for UITestingPlayground challengeBASE_URL_AUTOMATIONEXERCISE– Base URL for AutomationExercise challenge- Each challenge must have its own
BASE_URL_<CHALLENGE>variable (no fallback)
TIMEOUT– Global timeout for all Playwright actions in milliseconds (required)EXPECT_TIMEOUT– Timeout for assertions in milliseconds (required)WORKERS- Number of parallel test workers (number or percentage like50%) (required)RETRIES- Number of times to retry failed tests (required)REPEAT_EACH- Number of times to repeat each test (0= disabled) (required)FULLY_PARALLEL- Run tests fully parallel (trueorfalse) (required)FORBID_ONLY- Prevent test.only() from running (trueorfalse)MAX_FAILURES- Maximum number of test failures before stopping (0= unlimited)
Browser Selection:
CHROMIUM- Enable/disable Chromium browser tests (1= enabled, empty = disabled)FIREFOX- Enable/disable Firefox browser tests (1= enabled, empty = disabled)WEBKIT- Enable/disable WebKit browser tests (1= enabled, empty = disabled)BROWSER_CHANNEL- Browser channel (e.g.,chrome,msedge,chrome-beta)
Browser Behavior:
HEADED- Run tests in headed mode (1= headed, empty = headless)SLOW_MO- Slow down operations by specified milliseconds for debugging (0= disabled)BROWSER_ARGS- Browser launch arguments (comma-separated)
Viewport & Device:
VIEWPORT_WIDTH/VIEWPORT_HEIGHT- Viewport dimensions in pixelsDEVICE_SCALE_FACTOR- Device scale factor (1 = normal, 2 = retina)USER_AGENT- Custom user agent stringLOCALE- Browser locale (e.g.,en-US,de-DE)TIMEZONE_ID- Timezone (e.g.,America/New_York,Europe/Berlin)- **
GEOLOCATION