Skip to content

Playwright: Accept uses the GUI host platform for snapshots from Linux CI #807

Open

Description

@dimazollo

I'm trying to accept screenshots from Linux CI on my Mac, without rerunning the tests locally. CI already has the images I want to commit, but Accept writes example-darwin.png instead of updating example-linux.png.

getScreenshotPath uses the GUI host's process.platform for {platform} and the default {snapshotSuffix}.

Reproduction

With Playwright 1.59.1 and a template like:

snapshotPathTemplate: '{testDir}/__screenshots__/{arg}-{platform}{ext}'
  1. On Linux, generate a baseline for expect(page).toHaveScreenshot('example.png') using npx playwright test --update-snapshots.
  2. Change the page appearance and run npx playwright test --reporter=blob on Linux.
  3. Download the blob into a macOS checkout of the same revision, keeping the original Linux baseline.
  4. Run npx playwright merge-reports --reporter=html-reporter/playwright ./blob-report, then npx html-reporter gui --tool playwright.
  5. Click Accept and check the changed files. The target should be the Linux baseline, not a new Darwin file. Undo should restore that same file.

I investigated this on a 11.16.1-based fork with Node 20.19.6. The path resolver still produces the Darwin filename on upstream 11.16.2; I haven't rerun the full GUI flow on that release.

Small resolver-only repro on macOS

Run from an installed source checkout of html-reporter:

node -r ./test/setup/ts-node <<'NODE'
const path = require('node:path');
const {PlaywrightConfigAdapter} = require('./lib/adapters/config/playwright.ts');
const config = {
    testDir: process.cwd(),
    snapshotPathTemplate: '{testDir}/__screenshots__/{arg}-{platform}{ext}',
    projects: []
};
const test = {file: 'visual.spec.ts', browserId: 'chromium', titlePath: ['visual']};
console.log(path.basename(new PlaywrightConfigAdapter(config).getScreenshotPath(test, 'example')));
NODE

Prints example-darwin.png: the resolver has no input for the source run's platform.

Possible fix

I have a prototype that saves the source platform per result. Direct runs use their process platform; blob merges read onBlobReportMetadata.params.userAgent through the internal V2 onReportConfigure hook. Accept/Undo worked with a Linux report on macOS even after removing the blobs, and Undo restored the original checksum.

I'd like to avoid requiring a platform flag for every downloaded report. The concern with this implementation is its reliance on private Playwright hooks and user-agent parsing. Older blobs need a fallback, and arbitrary custom snapshotSuffix values aren't recovered. The prototype also contains a separate error-classification fix, which I would leave out of the platform PR.

Would you accept per-result platform metadata, or prefer preserving the resolved snapshot path? Is there a supported way to get this during blob merging that I've missed? I'd appreciate guidance on that and on the fallback for old reports before preparing the PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions