playwright: [BUG] Same test, different runs causes different heights with a weird compression effect

Context:

  • Playwright Version: 1.27.1
  • Operating System: MacOS 13.0
  • Node.js version: 16.15.0
  • Browser: All
  • Extra: Also CI using MacOS 12 (Github Actions)

Describe the bug

Subsequent screenshots (on different test runs) of the same page are coming out with different heights. This is mainly due to a weird “compression” (like smashing) effect on one of the screenshots.

These two example come from the same code, same server (NextJS locally) running, just yarn test two times in a row:

full-page-actual full-page-expected

I’m sorry for the long image, but that may be part of the problem (although short pages sometimes have this problem too).

If you compare the images using something like https://www.diffchecker.com/image-diff/ you can see the weird effect.

Is this a known bug? The differences are even greater once we run the tests on CI (more screenshots are different), but it’s flaky, so sometimes it happens and sometimes everything is good.

EDIT: Just to clarify, by compression I mean that the pixels themselves are smashed, so everything is shorter, which in turn causes the heights of the screenshots to differ, like on of them was “smashed”, which is wrong, e.g. causes the square logo to turn into a rectangle, etc

Thanks in advance!

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 41
  • Comments: 52 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Any update on this issue?

Any update on this please? It will be a good option to allow for dimension error tolerance. My tests are failing and none of the options here is giving me any alternative.

Expected an image 208px by 31px, received 207px by 31px. 

To make easier to vote on this issue (because what count are 👍 for first comment) @filipesmedeiros pls edit your comment and add folding for this huge image

<details>
  <summary>Hello</summary>
  World!
</details>

Demo:

Hello World!

That is something we might be able to fix!

Unfortunately this issue is limiting our ability to write and run concise tests. Our Bamboo test runs fail with this 1px issue. We have been able to work around the issue by specifying locators that capture a broader area which is not always ideal.

Error: Screenshot comparison failed:

  Expected an image 816px by 96px, received 817px by 96px. 

Wanted to report in that this happens on my team’s MacBooks as well. We run both M1 and Intel chips. Our CI runs the official image. Locally generated, fullPage screenshots differ in 1px height from the CI screenshots. image

We can mitigate this by generating screenshots in a docker image, but a fix for this would be awesome. If I can help anyhow, let me know 😃

Playwright Version: 1.29.2 Playwright config: https://gist.github.com/thraizz/0b2ab81f31925265a467e75fec58935f macOS 13.1

There has been a PR submitted above that allows you to provide a tolerance on this check. I’m hoping someone will graciously review it.

Link to PR posted for this: https://github.com/microsoft/playwright/pull/27513

We had this issue as well (in https://github.com/widgetti/solara/pull/67), we had a screenshot that had a different width sometimes. Based on https://github.com/microsoft/playwright/issues/20015#issuecomment-1427285592, we had the idea of printing out the bounding box.

  • On failure we got: {‘x’: 416.765625, ‘y’: 611, ‘width’: 134.5, ‘height’: 36}, and our resulting image was 136x36
  • On success we got: {‘x’: 398, ‘y’: 611, ‘width’: 134.5, ‘height’: 36}, and our resulting image was 135x36

So I think it is a combination of something else on the page pushing an element to a non-integer pixel position (but not stable every time) that can cause an image to change by 1-pixel width or height.

Hopefully, this is useful for others and also the cause of this issue.

Any update on this?

We are also experiencing the same problem. When we run the test using ‘run test button’ and save screenshots we don’t get any problems. But when we try to run test using command line we get the error. This only applies to Google Chrome. Mac OS 13.2.1, M1 Pro Screenshot 2023-04-03 at 9 38 31 AM

Screenshot 2022-11-16 at 10 19 18

Same thing happens 😞 e.g. in the above image you can see a 1 pixel height different between screenshots

any updated? i still have the same problem (1.42 + 1.50)

I had also a problem with random position on the y-axis. I make my test with a ugly hack stable. Get the bounding box and move the clipped area based on the current position:

const panel = page.getByRole("dialog");
  const headingBox = await page
    .getByRole("heading")
    .boundingBox();
  const panelBox = await panel.boundingBox();
  if (panelBox == null) {
    throw new Error("PanelBox was null");
  }
  panelBox.height -= 1;
  if (headingBox?.y == 26) {
    panelBox.y += 1;
  }
  await expect(page).toHaveScreenshot({ clip: panelBox });

@dgozman I noticed you tagged this, I’m pretty sure that means someone is aware of it, and potentially considering adding it. Can someone give us an update when you have one.

Much appreciate your consideration on this.

Link to PR posted for this: https://github.com/microsoft/playwright/pull/27513

Hello, we are also having this issue. Tests are always running inside the same environement (GitHub Action Linux Chrome headless)

Expected an image 344px by 335px, received 344px by 333px.
Expected an image 704px by 580px, received 702px by 580px.
Expected an image 1058px by 330px, received 1058px by 329px.
...

Using the latest playwright 1.38.1

I really think the issue is not with playwright: https://github.com/microsoft/playwright/issues/18827#issuecomment-1513345600 but having a bounding box with non-integer values (e.g 3.5) in combination with a non-stable page (e.g. fonts still loading).

Hello, I’m curious if there are any plans to look at this issue. I posted last month and never heard from anyone.

This is happening for us as well… It’s driving me crazy. Would be nice to be able to specify some tolerance for this

Expected an image 161px by 161px, received 161px by 160px

I think I’m seeing something similar, except it’s the width, not the height.

If I generate the screenshot using a headless Chromium (either from pnpm run playwright test or using the VSCode extension with “Reuse Browser” set to false) it generates a different width screenshot from the one generated by using the VSCode extension with “Reuse Browser” set to true:

Expected an image 1280px by 1108px, received 1265px by 1108px.

Additionally, if I use the mask option, the mask is placed in the wrong place if generating the screenshot with “Reuse Browser” set to true. In these examples, the second year (2023) should have been masked.

Reuse Browser is false (correct positioning)

image

Reuse Browser is true (offset positioning)

image

(I was going to raise a separate issue for this, but it feels like it might be related to this one. Let me know if you want it raised separately!)

This is with Playwright 1.37.1, Playwright Test for VSCode version v1.0.15, macOS macOS 13.5 (22G74) on Apple M1 Max, and whatever Playwright browsers were current at 09:00 (Europe/London) on 2023-08-30 😃