Reusable Playwright Visual Regression Testing runners for:
- local-to-local comparisons
- Pantheon-to-local comparisons
- Pantheon-to-Pantheon comparisons in CI
The package ships three CLI entrypoints:
playwright-vrt: compatibility alias forplaywright-vrt-localplaywright-vrt-local: baseline and candidate URLs are provided locallyplaywright-vrt-ci: baseline and candidate Pantheon environments are built from CI environment variables
Install the package together with Playwright in the consuming project.
If you are developing against this local repository before publishing it:
npm install --save-dev @playwright/test ../playwright-vrt-scriptsAfter the package is published, install it from npm:
npm install --save-dev @playwright/test @fourkitchens/playwright-vrt-scriptsThen add package scripts in the consuming project's package.json:
{
"scripts": {
"vrt": "playwright-vrt",
"vrt:local": "playwright-vrt-local",
"vrt:ci": "playwright-vrt-ci"
}
}The runners execute playwright test in the consuming project. Your Playwright config should read REMOTE_ENV_BASE_URL.
Example config:
const { defineConfig, devices } = require('@playwright/test');
const configuredBaseURL = (process.env.REMOTE_ENV_BASE_URL || 'http://example.ddev.site')
.trim()
.replace(/\/+$/, '');
module.exports = defineConfig({
testDir: './tests',
timeout: 100000,
reporter: 'html',
use: {
baseURL: `${configuredBaseURL}/`,
trace: 'on'
},
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome']
}
}
]
});Notes:
- If your config file is not the default
playwright.config.js, setVRT_CONFIGbefore running the VRT command. - If your tests live outside the current working directory, set
VRT_CWDto the directory that contains the consumer's Playwright project. - Screenshot-specific global styling is intentionally not bundled. If a project needs masking or admin-toolbar hiding, configure
expect.toHaveScreenshot.stylePathinside that project.
The runners execute tagged Playwright tests in two passes:
- baseline run with
--update-snapshots - candidate run without updating snapshots
Default grep tag: @vrt
Example VRT spec:
const { test, expect } = require('@playwright/test');
test('front page VRT @vrt', async ({ page }) => {
await page.goto('/components-test-page-vrt');
await page.waitForLoadState('networkidle');
await page.addStyleTag({
content: `
* {
animation: none !important;
transition: none !important;
}
`
});
await expect(page).toHaveScreenshot('frontpage.png', { fullPage: true });
});The CLI entrypoints load environment variables with dotenv, so you can keep local values in a .env file.
Example:
BASELINE_URL=https://test-example-site.pantheonsite.io
CANDIDATE_URL=http://example.ddev.site
BASELINE_TERMINUS_ENV=test
BASELINE_TERMINUS_SITE=example-site
BASIC_USER=your-basic-auth-user
BASIC_PASS=your-basic-auth-passUse playwright-vrt-local when you want to compare:
- local against local
- Pantheon against local
- one remote URL against another remote URL
Interactive:
npm run vrt:localNon-interactive:
BASELINE_URL="http://mcny.ddev.site" \
CANDIDATE_URL="https://feature-branch-example.pantheonsite.io" \
npm run vrt:localIf you want to run a specific config file:
VRT_CONFIG="./test/playwright/playwright.config.js" \
BASELINE_URL="https://test-example-site.pantheonsite.io" \
CANDIDATE_URL="http://example.ddev.site" \
npm run vrt:localUse playwright-vrt-ci when both runs target Pantheon environments and the site/environment values come from CI variables.
VRT_PANTHEON_SITE="example-site" \
VRT_SOURCE_ENV="feature-branch" \
VRT_TARGET_ENV="live" \
npm run vrt:ciThe CI runner generates Pantheon URLs in this format:
https://<basic-auth-if-present><env>-<site>.pantheonsite.io/
VRT_TAG: grep tag for Playwright. Default:@vrtVRT_TEST: optional single test file path to runVRT_CONFIG: optional Playwright config pathPLAYWRIGHT_CONFIG: fallback alias forVRT_CONFIGVRT_CWD: optional working directory for the Playwright commandBASIC_USER: optional HTTP basic auth username used for generated Pantheon URLsBASIC_PASS: optional HTTP basic auth password used for generated Pantheon URLs
BASELINE_URL: baseline URLCANDIDATE_URL: candidate URLVRT_BASELINE_URL: fallback alias forBASELINE_URLVRT_CANDIDATE_URL: fallback alias forCANDIDATE_URLBASELINE_TERMINUS_ENV: optional explicit Pantheon env for the baseline passCANDIDATE_TERMINUS_ENV: optional explicit Pantheon env for the candidate passVRT_BASELINE_TERMINUS_ENV: alias forBASELINE_TERMINUS_ENVVRT_CANDIDATE_TERMINUS_ENV: alias forCANDIDATE_TERMINUS_ENVBASELINE_TERMINUS_SITE: optional explicit Pantheon site for the baseline passCANDIDATE_TERMINUS_SITE: optional explicit Pantheon site for the candidate passVRT_BASELINE_TERMINUS_SITE: alias forBASELINE_TERMINUS_SITEVRT_CANDIDATE_TERMINUS_SITE: alias forCANDIDATE_TERMINUS_SITE
VRT_PANTHEON_SITE: Pantheon site shared by baseline and target passesVRT_SOURCE_ENV: Pantheon environment for the baseline passVRT_TARGET_ENV: Pantheon environment for the compare passVRT_COMPARE_ENV: fallback alias forVRT_TARGET_ENVTERMINUS_SITE: fallback Pantheon siteTERMINUS_ENV: fallback baseline environmentCANONICAL_ENV: fallback target environmentVRT_SOURCE_SITE: legacy fallback siteVRT_TARGET_SITE: legacy fallback site
- Pantheon URLs are inferred automatically for standard
*.pantheonsite.ioURLs in local mode. - If a pass resolves to a Pantheon environment, the runner executes
terminus env:wakebefore Playwright starts. - Local and CI Pantheon flows expect Terminus to already be authenticated.
- Custom Pantheon domains cannot be inferred automatically. Set explicit
*_TERMINUS_ENVand*_TERMINUS_SITEvalues when using custom domains.
This package exports the shared helpers from scripts/vrt.shared.js.
Missing peer dependency @playwright/test: install@playwright/testin the consuming project.Missing URLs: setBASELINE_URLandCANDIDATE_URLfor local runs.Missing required environment variable: set the CI variables required byplaywright-vrt-ci.Pantheon access requires an existing Terminus login: runterminus auth:loginand retry.- Protected Pantheon environment:
set
BASIC_USERandBASIC_PASS.