playwright baseURL ignored in some tests: how to fix
Fixes tests that ignore the Playwright baseURL config. Use when page.goto('/path') works but some tests hit the wrong host. Not for baseURL missing entirely.
TL;DR
baseURL only applies to relative URLs, so any absolute URL in a test or fixture bypasses it. Find the absolute URLs, make them relative, and build fixture URLs from the config instead of hardcoding hosts.
The query
playwright baseURL ignored in some tests: how to fixUse this when
- some tests ignore baseURL
- tests pass locally but hit the wrong host in CI
- fixtures hardcode hosts
Not for
- baseURL unset in the config
- multi-origin testing (use absolute URLs deliberately there)
- API base URLs
Steps
- Search the spec and its fixtures for 'http' to find absolute URLs. Expected output: a list of absolute URLs that bypass baseURL.
- Convert page.goto calls to relative paths like page.goto('/dashboard'). Expected output: all navigations use relative paths.
- Check fixtures and helpers that construct URLs; derive them from the baseURL config value instead of a hardcoded host. Expected output: no hardcoded hosts in fixtures.
- Confirm the config's baseURL is set in the right project, since it can differ per project. Expected output: the active project shows the expected baseURL.
- Re-run against a non-default baseURL to prove the tests follow the config. Expected output: tests hit the overridden host.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_lFI6dieLQRgB9pJsFplChA
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.