Playwright end-to-end tests (E2E)¶
End-to-end tests for this module use Playwright. Tests are under tests/src/Playwright.
This document provides a short Quickstart, examples for local/Docker usage and troubleshooting tips.
Prerequisites¶
- Composer dev dependencies (run from repository root):
- Node and package manager (node >= 20, npm or Yarn). From the module folder install JS deps:
- Install Playwright browsers (recommended with system deps):
See the Playwright installation docs for more details.
Notes:
- On some Linux distributions (e.g. Fedora support) you may need extra system packages before installing browsers. See the Playwright installation docs for distro-specific packages. As a workaround on Fedora, install the following packages:
Playwright will throw an error on install but tests will work except for Webkit.
Quickstart¶
- Copy env and adjust if needed:
- Run the
basetests with firefox locally:
npx playwright test -c playwright.local.config.ts --project=firefox -g @base
# or use npm script
npm run test
The package.json scripts wrap the same commands:
| Script | Runs |
|---|---|
npm run pw -- <args> |
playwright test -c playwright.local.config.ts, pass your own flags |
npm run test |
Firefox, @base tagged specs |
npm run test:extra |
Firefox, @extra tagged specs |
npm run test:failed |
Firefox, last failures only |
npm run test:headed / test:ui / test:debug |
The debugging variants |
npm run test:update |
Refresh the aria snapshots under __snapshots__ |
npm run test:clean |
Delete playwright-report and test-results |
If you need to run a single test file or grep-style selection:
npx playwright test -c playwright.local.config.ts --project=firefox page.spec.ts
npx playwright test -c playwright.local.config.ts --project=firefox -g 'Page Layout'
Use --headed or --ui while debugging:
npx playwright test -c playwright.local.config.ts --project=firefox -g 'Page Layout' --headed
npx playwright test -c playwright.local.config.ts --project=firefox -g 'Page Layout' --ui
More information on Playwright running and debugging tests.
Important env/settings notes:
DRUPAL_TEST_BASE_URLmust point to your site base:http://localhost:8000with the PHP web server thatplaywright.local.config.tslaunches automatically, orhttp://localhost:8000/webfor a manualphp -S localhost:8000from the Drupal root.DRUPAL_TEST_SKIP_INSTALLallow a more specific behavior by having an installed Drupal with a running stack.- Without it,
DRUPAL_TEST_SETUP_FILE(path totests/src/TestSite/DisplayBuilderTestSetup.php, relative to the web root) andDRUPAL_TEST_DB_URLset up the site to install. DRUPAL_TEST_DRUSH_PREFIXprefixes Drush calls (e.g.ddev),PLAYWRIGHT_DEBUG_LEVELsets the test reporter verbosity.- For tests run against an installed Drupal, enable in
settings.php:
- Modules that MUST be enabled for tests (as installed by
tests/src/TestSite/DisplayBuilderTestSetup.php): - breakpoint
- language, with a
delanguage and path prefix negotiation - ui_patterns
- ui_styles
- display_builder
- display_builder_ui
- display_builder_page_layout
- display_builder_test
- display_builder_page_layout_test
Specs needing more (entity view, Views, ui_skins) enable their modules themselves.
Theme MUST be display_builder_theme_test by default, unless test is
specific for a theme.
Copy and adapt the .env.dist file as .env to set your environment.
There are different cases for running tests with a full installation or on a running Drupal instance to avoid the install step.
PHPUnit¶
PHPUnit tests live in tests/src/Unit, tests/src/Kernel and
tests/src/FunctionalJavascript, and in each submodule's tests/src/Kernel
and tests/src/Functional. Groups are declared with #[Group(...)]
attributes, one per module: display_builder, display_builder_entity_view,
display_builder_page_layout, display_builder_ui, display_builder_views.
Run them with Drupal core's PHPUnit configuration, for example:
Accessibility¶
tests/src/Playwright/Tests/accessibility.spec.ts runs
axe (@axe-core/playwright, a
devDependency) over the .display-builder element and fails on:
- any violation whose rule id is not listed in the spec's
KNOWN_VIOLATIONSarray; - anything of
criticalimpact, listed or not.
KNOWN_VIOLATIONS is currently empty — the builder has zero axe
violations. Adding an id to it is admitting a regression: prefer fixing the
violation, and never add an entry without a comment saying why.
Two Shoelace-specific traps, both handled centrally, worth knowing before adding UI:
- Icon-only buttons.
sl-button's focusable element is the<button part="base">inside its shadow root, which anaria-labelon the host does not name. The accessible name has to come from the slotted<sl-icon label="…">— seecomponents/shoelace/button/button.twig. - Inputs. A placeholder is not a name. Pass a
labeltodisplay_builder:inputso Shoelace renders a real<label for>; hide it visually if the design has no room for it (seecomponents/library_panel/search.css).
Docker: remote Playwright server¶
When you cannot install native browsers, run a Playwright server in Docker and connect to it. See the Playwright remote browsers docs.
The image tag and the playwright@ version MUST match the
@playwright/test version in package.json, otherwise the client refuses to
connect. Read it first:
- Run Playwright server container, with
PWset to that version:
PW=1.63.0
docker pull mcr.microsoft.com/playwright:v$PW-noble
docker run --add-host=hostmachine:host-gateway --rm -it -p 3000:3000 \
--workdir /home/pwuser --user pwuser \
mcr.microsoft.com/playwright:v$PW-noble \
/bin/sh -c "npx -y playwright@$PW run-server --port 3000 --host 0.0.0.0"
- Run Webserver from Drupal root:
- Launch tests pointing to the remote WS endpoint:
PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:3000/ \
DRUPAL_TEST_BASE_URL='http://localhost:8000' \
npx playwright test --project=firefox -g '@base'
Tips:
- Ensure ports and host mappings allow the test runner to reach the Docker container.
- If you use
--add-host=hostmachine:host-gatewayyou may need to use that hostname in the container to reach the host.
Reporting and debugging¶
- The config already collects traces/screenshots/videos on failures per
playwright.config.ts. - To open the HTML report locally after a run, open
playwright-report/index.htmlin the module folder. - To collect a trace for a failing test, re-run with
--trace onor rely on the config:trace: 'on-first-retry'inplaywright.config.ts,trace: 'retain-on-first-failure'inplaywright.local.config.ts. View traces with the Playwright trace viewer.
Troubleshooting (common issues)¶
- Playwright browser install fails: install system dependencies for your distro or use the Docker image.
- WebKit tests: WebKit is unreliable or unsupported on many Linux CI images — skip or use Chromium/Firefox in CI.
- Docker WS connection: ensure
PW_TEST_CONNECT_WS_ENDPOINTpoints to the container and firewall rules allow the connection. - Failing Drupal tests: verify required modules are enabled (see the list above), the test theme is active (
display_builder_theme_test), andextension_discovery_scan_testsis enabled when running against an installed site. - Timeouts:
DRUPAL_TEST_SKIP_INSTALLtoggles shorter timeouts inplaywright.config.ts— unset it for full install flows.playwright.local.config.tsuses a fixed 180s test timeout.
Where to look in this repo¶
package.jsonfor test scripts- Local Playwright config:
playwright.local.config.ts - DDEV Playwright config:
playwright.ddev.config.ts(https://display-builder.ddev.site, no retries, no traces) - Main Playwright config:
playwright.config.ts
Fast debug checklist¶
- Run a single failing spec with
--headedand--ui. - Re-run with
--traceor open the trace in the Playwright trace viewer. - Check
playwright-reportfor screenshots/videos.