playwright: [BUG] very slow screenshot comparison

System info

  • Playwright Version: v1.37.1
  • Operating System: macOS 12.3
  • Browser: Chromium

Source code

Config file

// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'], },
    },
  ]
});

Test file (self-contained)

import { test, expect } from '@playwright/test';

test('test long page', async ({page}) => {
    await page.setViewportSize({
        width: 1280,
        height: 1024,
    });

    await page.goto('https://bank.yandex.ru');

    await expect(page).toHaveScreenshot('foo.png', {fullPage: true, animations: 'disabled'});
});

Steps

  • Run the test (screenshot accepted
  • Change viewport width to 1075 (for example) in order to get screenshot difference
  • Run the test again -> screenshot comparison takes more than 5000 ms in most cases

Expected

[Describe expected behavior]

Comparing screenshots takes less than 5 seconds and no unnecessary comparisons are made under the hood

[Describe actual behavior]

Test fails when taking a screenshot (timeout).

I looked at the code sources and found that when the reference and the current image do not match, a comparison is made between the two screenshots just taken (previous actual and new actual). It takes a lot of time (more than 5 sec). For what purpose is this done? Is it possible not to do this?

What takes the most time:

  • screenshot page - ~1-2 sec (x2, for actual and previous actual)
  • compare with pixelmatch - ~2-3 sec (x2, compare actual with reference and actual with previous actual)

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Reactions: 1
  • Comments: 15 (11 by maintainers)

Most upvoted comments

Discussed this in a meeting today, things that we can implement:

  • do buffer comparison as a fast check before parsing png
  • introduce separate timeout config for toHaveScreenshot (currently it is the same as TestConfig.expect: { timeout: 100 })
  • supporttimeout: 1 for one-shot snapshots without waiting for stable images