Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ dist/
coverage/
test/results.json
playwright-report/
test-results/
test-results/
e2e/_results_/downloads/*.pdf
36 changes: 30 additions & 6 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@ The suite uses a three-layer architecture. Tests read like plain English, driver

```
tests/*.spec.js ← Specifications (what to test)
↓ fixtures (steps / mapSteps)
test-runner-api/ ← FormDriver & MapDriver (how to interact)
↓ fixtures (steps / mapSteps / pdfDriver)
test-runner-api/ ← FormDriver, MapDriver & PdfDriver (how to interact)
pages/ ← Page definitions & control factories
```

### Fixtures (`fixtures.js`)

[Playwright fixtures](https://playwright.dev/docs/test-fixtures) provide two drivers to every test:
[Playwright fixtures](https://playwright.dev/docs/test-fixtures) make three drivers available to tests (most tests use `steps` and/or `mapSteps`; PDF tests use `pdfDriver`):

| Fixture | Class | Purpose |
|------------|-------------|---------|
| `steps` | `FormDriver` | Standard GOV.UK form page interactions |
| `mapSteps` | `MapDriver` | Map-specific interactions (extends `FormDriver`) |
| `pdfDriver` | `PdfDriver` | PDF download, parsing, and PDF content assertions |

```js
import { test } from '../../fixtures.js'

test('example', async ({ steps, mapSteps }) => {
test('example', async ({ steps, mapSteps, pdfDriver }) => {
await steps.open(pages.home.page)
// ...
})
Expand Down Expand Up @@ -72,6 +73,19 @@ All Playwright locator logic lives here. Tests never call `page.getByRole(...)`
| `addSquare()` | Open the location menu and click "Add square" |
| `confirmBoundaryAndContinue()` | Click "Finish" then "Get summary report" |

**PdfDriver** — handles PDF download capture, parsing, and PDF-specific assertions:

| Method | Description |
|--------|-------------|
| `clearPdfFiles()` | Remove previously generated PDFs from `_results_/downloads` |
| `waitForDownload(triggerDownload, timeout)` | Wait for a PDF via browser download event or PDF response capture |
| `parsePdf(filePath)` | Parse PDF text and links using `pdf-parse` |
| `expectCoreContent(pdf, { reference, scale })` | Validate core report text, reference handling, and scale formatting |
| `expectFloodZone(pdf, floodZone)` | Validate zone text in PDF matches expected flood zone |
| `expectLocation(pdf, polygonString)` | Validate centroid easting/northing rendered in PDF |
| `expectRequiredLinks(pdf, expectedLinks)` | Validate required static links are embedded in PDF |
| `expectAllLinksAreValid(pdf)` | Validate extracted links are syntactically valid URLs |

### Page Objects (`pages/`)

Each page is defined with `definePage({ slug, title })` and exports typed control handles built from factory functions.
Expand Down Expand Up @@ -142,7 +156,7 @@ await test.step('Home → Triage', async () => {

## Prerequisites

- Node.js 18+ (LTS recommended)
- Node.js 20.16+ (required by `pdf-parse`)
- Browsers — install whichever you need to run:

```bash
Expand All @@ -166,6 +180,15 @@ npm install
npx playwright install # all browsers, or pick one as above
```

## PDF Test Artifacts

PDF tests generate files in `_results_/downloads/`.

- The folder is cleared once at the start of the PDF suite.
- Files generated during that run are retained (for example, 6 PDF tests produce 6 PDFs).
- On the next run, the folder is cleared again before new PDF files are created.
- Generated PDFs are ignored by git (`e2e/_results_/downloads/*.pdf`), so they are not committed.

## Docker (WIP)

Tests can be run in Docker using the Playwright base image. This is a work in progress.
Expand Down Expand Up @@ -289,7 +312,8 @@ e2e/
├── test-runner-api/
│ ├── form-driver.js # FormDriver — GOV.UK form interactions
│ └── map-driver.js # MapDriver — Esri map interactions
│ ├── map-driver.js # MapDriver — Esri map interactions
│ └── pdf-driver.js # PdfDriver — PDF download/parse/assertions
├── pages/
│ ├── .utils/
Expand Down
4 changes: 4 additions & 0 deletions e2e/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test as base } from '@playwright/test'
import { FormDriver } from './test-runner-api/form-driver.js'
import { MapDriver } from './test-runner-api/map-driver.js'
import { PdfDriver } from './test-runner-api/pdf-driver.js'

export const test = base.extend({
steps: async ({ page }, run) => {
Expand All @@ -9,6 +10,9 @@ export const test = base.extend({
mapSteps: async ({ page }, run) => {
await run(new MapDriver(page))
},
pdfDriver: async ({ page }, run) => {
await run(new PdfDriver(page))
},
})

export { expect } from '@playwright/test'
232 changes: 231 additions & 1 deletion e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"scripts": {
"test": "npx playwright test --project=public-chromium --project=internal-chromium",
"test:ui": "npx playwright test --ui --project=public-chromium --project=internal-chromium",
"test:urlCheck": "npx playwright test --project=urlCheck-chrome",
"test:local": "TEST_ENV=local npx playwright test --project=noDeps-local-chrome",
"test:urlCheck": "npx playwright test --project=urlCheck-chromium",
"test:local": "TEST_ENV=local npx playwright test --project=noDeps-local-chromium",
"test:tst": "TEST_ENV=tst npm run test",
"test:dev": "TEST_ENV=dev npm run test",
"test:edge": "npx playwright test --project=public-edge --project=internal-edge",
"test:firefox": "npx playwright test --project=public-firefox --project=internal-firefox",
"test:e2e": "npx playwright test --project=e2e-public-chromium --project=e2e-internal-chromium",
"test:all-browsers": "npx playwright test",
"report:open": "npx playwright show-report",
"prepare": "husky"
Expand All @@ -20,6 +21,7 @@
"devDependencies": {
"@mapbox/polyline": "^1.2.1",
"@playwright/test": "^1.50.0",
"husky": "^9.1.7"
"husky": "^9.1.7",
"pdf-parse": "^2.4.5"
}
}
1 change: 1 addition & 0 deletions e2e/pages/.utils/form-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const footerLink = (text, url) => ({ type: 'footerLink', text, url: url =
export const errorText = (text) => ({ type: 'errorText', text })
export const button = (text) => ({ type: 'button', text })
export const selectInput = (text) => ({ type: 'selectInput', text })
export const details = (text) => ({ type: 'details', text })
Loading
Loading