Configure visual tests for Playwright
You can enhance your Playwright and Chromatic tests further by configuring them using the options outlined in the following sections.
Playwright options
The Chromatic Playwright Fixture can be configured with use like all Playwright options. You can set the available options globally in your Playwright configuration file as follows:
import { defineConfig } from "@playwright/test";
import { ChromaticConfig } from "@chromatic-com/playwright";
export default defineConfig<ChromaticConfig>({
use: {
// 👇 Sets the option at the project level.
disableAutoSnapshot: true,
},
// Other project configuration options
}); import { defineConfig } from "@playwright/test";
export default defineConfig({
use: {
// 👇 Sets the option at the project level.
disableAutoSnapshot: true,
},
// Other project configuration options
}); You can also override them for specific tests by adding the test.use() method in your test file and provide the required options:
test.describe('HomePage', () => {
// 👇 Overrides the option in the test.
test.use({ disableAutoSnapshot: true });
test('Loads the page with auto snapshotting disabled', async ({ page }) => {
await page.goto('/');
});
});
E2E options
These options control how the Chromatic archive fixture behaves.
| Option | Type | Description |
|---|---|---|
disableAutoSnapshot | boolean | When true, it will disable the snapshot that happens automatically at the end of a test when using the Chromatic test fixture. |
cropToViewport | boolean | When true, the snapshot will be clipped to the height of the viewport. |
resourceArchiveTimeout | number | Maximum amount of time each test will wait for the network to be idle while archiving resources. |
assetDomains | array[string] | A list of domains external to the test location that you want Chromatic to also capture assets from, e.g., [‘other-domain.com’,‘our-cdn.com’]. |
Chromatic options
These options control how Chromatic behaves when capturing snapshots of your pages.
| Option | Type | Chromatic Docs |
|---|---|---|
delay | number | Delay |
diffIncludeAntiAliasing | boolean | Threshold for changes |
diffThreshold | number | Threshold for changes |
ignoreSelectors | array[string] | Ignore elements |
forcedColors | string | Media Features |
pauseAnimationAtEnd | boolean | Animations |
prefersReducedMotion | string | Media Features |
Environment variables
Some options can be configured through environment variables.
| Environment variable | Description |
|---|---|
CHROMATIC_ARCHIVE_LOCATION | If you have configured your project’s outputDir option to be different than the default, you must set the CHROMATIC_ARCHIVE_LOCATION environment variable to the same value. This ensures that the Chromatic can find the archives generated by Playwright tests. |
Working in Monorepos
Often, when using a monorepo, developers tend to keep their e2e tests in a subdirectory instead of in the root of the project. At the same time, the Chromatic configuration lives at the project’s root. In these cases, set the CHROMATIC_ARCHIVE_LOCATION environment variable to the directory where your test archives are stored so that Chromatic can find them. For example, set it on the chromatic command that runs in CI:
CHROMATIC_ARCHIVE_LOCATION=path/to/test-results npx chromatic --playwright --project-token=<TOKEN>
If you use the archive-storybook script to debug archives locally, set it there too:
"scripts": {
"archive-storybook": "CHROMATIC_ARCHIVE_LOCATION=path/to/test-results archive-storybook",
"build-archive-storybook": "CHROMATIC_ARCHIVE_LOCATION=path/to/test-results build-archive-storybook"
}
💡 For additional information on using Chromatic with a monorepo, see our monorepo documentation.