PetFolio UI tests¶
The PetFolio UI Tests can be found within the apps folder, see petfolio-ui-tests. The purpose of the application is to provide UI tests that capture high level integration between pages of the PetFolio UI applications.
Stack¶
- Playwright for browser automation
- playwright-bdd for Gherkin (BDD) support - feature files and step definitions
- Page Object Model for maintainable locator management
Project structure¶
Features¶
Gherkin .feature files live in src/features/. Each file describes a user-facing scenario in plain language:
Steps¶
Step definitions in src/steps/ implement the Gherkin steps using createBdd from playwright-bdd. Each step receives a Playwright page fixture and uses page objects for interactions and assertions.
Pages¶
Page objects in src/pages/ encapsulate locators and actions for a given page, keeping step definitions clean and avoiding duplicated selectors.
Running tests¶
| Command | Description |
|---|---|
npx nx e2e petfolio-ui-tests |
Run all e2e tests (headless) |
npx nx e2e petfolio-ui-tests --ui |
Run in Playwright UI mode |
npx nx e2e petfolio-ui-tests --headed |
Run in headed browsers |
npx nx e2e petfolio-ui-tests --debug |
Run with Playwright Inspector |
npx nx e2e petfolio-ui-tests --browser=firefox |
Run in a specific browser |
The e2e target automatically runs bddgen first to generate Playwright spec files from the feature files, then executes the tests.
How it works¶
bddgenreads.featurefiles and step definitions, then generates intermediate Playwright spec files into.features-gen/(git-ignored).- Playwright runs the generated specs as standard tests.
- The
webServerconfig inplaywright.config.tsautomatically starts thepetfolio-businessdev server if it isn't already running.
CI integration¶
UI tests run automatically in the CI pipeline when petfolio-business is affected. The pipeline builds a Docker image, then runs Playwright against the containerised application.
Pipeline flow¶
graph LR
A[Build Docker Image] --> B[Download Image Artefact]
B --> C[Start Container]
C --> D[Run Playwright Tests]
D --> E[Upload Reports]
E --> F[Stop Container]
classDef layer-infra fill:#f5a6232e,stroke:#f5a623,stroke-width:2px
classDef layer-domain fill:#7ed32126,stroke:#7ed321,stroke-width:2px
classDef neutral fill:#c8c8c826,stroke:#999999,stroke-width:1.5px
class A layer-infra
class B,C,F neutral
class D layer-domain
class E layer-domain
Diagram key
- Orange (Infrastructure): Docker image build step
- Green (Domain): Test execution and reporting
- Grey (Neutral): Container lifecycle steps
- The
build_docker_imagejob builds and uploads the Docker image as a CI artefact. - The
run_ui_testsjob downloads the image, starts a container via thestart-docker-containercomposite action, and waits for the healthcheck to pass. - Playwright runs chromium-only tests against the container on
localhost:4200. - Test results are appended to the CI summary PR comment and included in any failure issues created on the
mainbranch.
Composite action - start-docker-container¶
A reusable composite action at .github/actions/start-docker-container/ handles container lifecycle:
- Starts the container with configurable port mapping and environment variables
- Polls until the container is running (up to 60s)
- Polls the Docker healthcheck status (up to 90s)
- On healthcheck failure, captures container logs and uploads them as an artefact
Reports and artefacts¶
Playwright is configured with two reporters:
| Reporter | Output Path | Purpose |
|---|---|---|
| HTML | dist/.playwright/apps/petfolio-ui-tests/playwright-report/ |
Interactive test report |
| JUnit | dist/.playwright/apps/petfolio-ui-tests/test-results/junit.xml |
CI summary generation |
Both are uploaded as CI artifacts with a 7 day retention period. The JUnit XML is parsed to produce a test summary table in the GitHub Actions step summary and the PR comment.