Sign inSign up

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:

playwright.config.ts
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
});

You can also override them for specific tests by adding the test.use() method in your test file and provide the required options:

HomePage.spec.js|ts
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.

OptionTypeDescription
disableAutoSnapshotbooleanWhen true, it will disable the snapshot that happens automatically at the end of a test when using the Chromatic test fixture.
resourceArchiveTimeoutnumberMaximum amount of time each test will wait for the network to be idle while archiving resources.
assetDomainsarray[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.

OptionTypeChromatic Docs
delaynumberDelay
diffIncludeAntiAliasingbooleanThreshold for changes
diffThresholdnumberThreshold for changes
ignoreSelectorsarray[string]Ignore elements
forcedColorsstringMedia Features
pauseAnimationAtEndbooleanAnimations
prefersReducedMotionstringMedia Features

Environment variables

Some options can be configured through environment variables.

Environment variableDescription
CHROMATIC_ARCHIVE_LOCATIONIf 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 Storybook and Chromatic configuration details live at the project’s root. In these cases, you will need to update the archive-storybook and build-archive-storybook scripts in your package.json by setting the -c flag and CHROMATIC_ARCHIVE_LOCATION environment variable. For example:

package.json
"scripts": {
  "archive-storybook": "CHROMATIC_ARCHIVE_LOCATION=path/to/test-results archive-storybook -c path/to/node_modules/@chromaui/archive-storybook/config",
  "build-archive-storybook": "CHROMATIC_ARCHIVE_LOCATION=path/to/test-results build-archive-storybook -c path/to/node_modules/@chromaui/archive-storybook/config"
}

💡 For additional information on using Chromatic with a monorepo, see our monorepo documentation.