Description
🚀 Feature Request
In #21632 I don't see a big problem solved, which is the naming of toHaveScreenshot
:
[...] the name
toHaveScreenshot
is ambiguous, why is it named like that? Having a screenshot is something else than matching a screenshot 🤷
toHaveScreenshot
name is not clear, it should be updated to something liketoMatchScreenshot
My initial reaction when I saw the naming of toHaveScreenshot
was like, what is going on here? Playwright supports two kinds of snapshot assertions, one is based on screenshot, the other one can take other data types too, like just text. But they're still doing essentially the same thing: matching snapshots! Usually it makes no sense for webpages to be asserted literally to have a screenshot, because that's not the point of a typical web page! So the naming is a big confusion, it doesn't tell what the purpose of the function is, and it's hard to see quickly that there are two features doing the same thing but with different types of data.
This must change!
Example
Especially because some guides write something like this:
expect(await page.screenshot()).toMatchSnapshot('reference-screenshot.png');
For which, we practically got a shorthand assertion, but named weirdly:
expect(page).toHaveSnapshot('reference-screenshot.png');
This is not in line with the original code's intended meaning, and it will only make sense if it's renamed to toMatchScreenshot
.
Motivation
Understanding the differences between the two snapshot assertion methods are hard already as they are. The documentations I currently found did not make it very easy for me to compare the two. Especially because if someone has a Cypress background, they would expect a visual and a JSON-based snapshot matching technique, then you have to check 2 pages:
- https://playwright.dev/docs/test-snapshots is titled Visual comparisons, but it has a chapter called Non-image snapshots, which is weird, because the latter is not visual comparison anymore.
- https://playwright.dev/docs/aria-snapshots is called Snapshot testing, but it doesn't mention visual snapshot testing. Edit: Also, ARIA snapshots is just a subtitle, but the page URL includes
aria-snapshots
.
I would also merge the two guides into one page or structure them differently.