playwright/packages/playwright-core/src/utils
Andrey Lushnikov c18077c0de
feat(toHaveScreenshot): align screenshot generation & comparison (#12812)
This patch aligns the strategies that are used to generate new
screnshot expectations and to compare screenshot expectations against
baseline.

With this patch, `toHaveScreenshot` will:
- when generating a new expectation: will wait for 2 consecutive
  screenshots to match and accept the last one as expectation.
- when given an expectation:
  * will compare first screenshot against expectation. If matches,
    resolve successfully
  * if first screenshot doesn't match, then wait for 2 consecutive
    screenshots to match and then compare last screenshot with the
    expectation.

An example of a new detailed call log:

```
  1) a.spec.ts:3:1 › should work ===================================================================

    Error: Screenshot comparison failed:

      20000 pixels (ratio 0.03 of all image pixels) are different

    Call log:
      - expect.toHaveScreenshot with timeout 5000ms
      -   verifying given screenshot expectation
      - fast-path: checking first screenshot to match expectation
      - taking page screenshot
      -   disabled all CSS animations
      -   waiting for fonts to load...
      -   fonts in all frames are loaded
      - fast-path failed: first screenshot did not match expectation - 20000 pixels (ratio 0.03 of all image pixels) are different
      - waiting for 2 consecutive screenshots to match
      - waiting 100ms before taking screenshot
      - taking page screenshot
      -   disabled all CSS animations
      -   waiting for fonts to load...
      -   fonts in all frames are loaded
      - 2 consecutive screenshots matched
      - final screenshot did not match expectation - 20000 pixels (ratio 0.03 of all image pixels) are different
      - 20000 pixels (ratio 0.03 of all image pixels) are different

    Expected: /Users/andreylushnikov/tmp/test-results/a-should-work/should-work-1-expected.png
    Received: /Users/andreylushnikov/tmp/test-results/a-should-work/should-work-1-actual.png
        Diff: /Users/andreylushnikov/tmp/test-results/a-should-work/should-work-1-diff.png

      3 | test('should work', async ({ page }) => {
      4 |   await page.goto('file:///Users/andreylushnikov/prog/playwright/tests/assets/rotate-z.html');
    > 5 |   await expect(page).toHaveScreenshot();
        |                      ^
      6 | });
      7 |
```
2022-03-21 15:10:33 -07:00
..
async.ts reland(hooks): separate test timeout from beforeAll/afterAll timeouts (#12609) 2022-03-08 19:05:23 -08:00
browserFetcher.ts chore: add browser like UA to browser fetcher (#11006) 2022-01-14 02:46:17 -08:00
comparators.ts feat(toHaveScreenshot): align screenshot generation & comparison (#12812) 2022-03-21 15:10:33 -07:00
debugLogger.ts chore: migrate to monorepo (#9421) 2021-10-11 16:52:17 +02:00
dependencies.ts chore: print error if install-deps is used != ubuntu (#12877) 2022-03-18 19:13:11 +01:00
errors.ts chore: migrate to monorepo (#9421) 2021-10-11 16:52:17 +02:00
eventsHelper.ts chore: migrate to monorepo (#9421) 2021-10-11 16:52:17 +02:00
httpServer.ts chore: don't write into stdout from the test runner, use reporters instead (#11367) 2022-01-12 19:52:40 -08:00
multimap.ts chore: migrate to monorepo (#9421) 2021-10-11 16:52:17 +02:00
nativeDeps.ts fix(firefox): add missing dependency on Ubuntu 18.04 (#12625) 2022-03-09 11:21:15 -08:00
netUtils.ts chore: migrate to monorepo (#9421) 2021-10-11 16:52:17 +02:00
processLauncher.ts fix: do not show taskkill.exe output (#10244) 2021-11-11 18:32:22 +01:00
registry.ts feat(webkit): bump to 1617, freeze macOS 10.15 (#12790) 2022-03-15 16:09:56 -07:00
socksProxy.ts chore: intercept socks proxy in the driver (#12021) 2022-02-13 14:03:47 -08:00
stackTrace.ts fix: properly define apiName for web-first assertions (#12706) 2022-03-14 18:01:13 -07:00
stringUtils.ts feat(locator.withText): allow narrowing locators to those with text (#10688) 2021-12-03 09:27:06 -08:00
timeoutSettings.ts chore: do not stall on actions when test timeout is 0 (#12418) 2022-03-01 13:43:38 -08:00
ubuntuVersion.ts chore: add browser like UA to browser fetcher (#11006) 2022-01-14 02:46:17 -08:00
utils.ts Revert "chore: best-effort cleanup for output folders that are mounted (#12300)" (#12321) 2022-02-23 14:10:11 -08:00
verifyNodeJsVersion.ts chore: don't write into stdout from the test runner, use reporters instead (#11367) 2022-01-12 19:52:40 -08:00
vfs.ts chore: migrate to monorepo (#9421) 2021-10-11 16:52:17 +02:00
zones.ts chore(zones): prepare to remove wrapApiCall, introduce zones (#10427) 2021-11-18 22:30:09 -08:00