playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Add possibility to compare screenshots not only in scope of PW test() function

Open RockMinsk opened this issue 3 years ago • 10 comments

Use case

In our project we're using gherkin scenarios (Cucumber as test runner) without defined PlaywrightTestConfig All expect methods work fine except expect(page).toHaveScreenshot() and expect(page).toMatchSnapshot(). I got the following issue: Error: toHaveScreenshot() must be called during the test:

2022_06_30_PW_Snapshots_comparison

Limitation

For now using expect(page).toHaveScreenshot() and expect(page).toMatchSnapshot() methods is possible only in scope of PW test() function since the matcher checks testInfo and takes a snapshot dir path from there: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/matchers/toMatchSnapshot.ts#L292-L298

Feature

It will be great to have possibility to use expect(page).toHaveScreenshot() and expect(page).toMatchSnapshot() methods without defined PlaywrightTestConfig and out of the PW test() scope (e.g. if some other test runner is using) - to define absolute path to reference snapshot directly in methods (e.g. like optional parameter expect(page).toHaveScreenshot({ path: PATH_TO_REFERENCE_SCREENSHOT }) or expect(page).toHaveScreenshot(REFERENCE_SCREENSHOT_NAME, { snapshotDir: PATH_TO_CUSTOM_REFERENCE_SCREENSHOT_DIRECTORY })) without using snapshot dir path from testInfo if this optional parameter is using.

RockMinsk avatar Jun 30 '22 15:06 RockMinsk

Having the exact same problem right now where all other tests work as expected, only the one for comparing screenshots does not: https://gitlab.com/mvanremmerden/gitdock/-/merge_requests/108/diffs#ac6e7587d6b6d54c7b14db36e902be005c853c71_16_17

MvRemmerden avatar Jul 01 '22 09:07 MvRemmerden

Relates to https://github.com/microsoft/playwright/issues/11975 & #14539

lthurr avatar Jul 11 '22 15:07 lthurr

Having the same issue too. Did anyone found an alternative solution ?

AuroreLlinares avatar Nov 25 '22 14:11 AuroreLlinares

I am facing the same issue and raised the problem in a different #15800 . Is there any solution to use screen comparison with cucumber runner?

karthick27august avatar May 02 '23 09:05 karthick27august

Still no fix or workaround?

cchantep avatar Aug 12 '23 21:08 cchantep

I am facing the same issue.

vnpradhan avatar Aug 20 '23 17:08 vnpradhan

Still have this issue now.

nils-e avatar Aug 22 '24 03:08 nils-e

like to have it as well

Octopus134 avatar Nov 19 '24 22:11 Octopus134

In general not sure if such comments are more helpful or annoying. But I would also really like to have this feature. It is possible to use Playwright almost completely with a different test runner. Unfortunately not screenshots.

weilbith avatar Nov 20 '24 08:11 weilbith

I am having the same issue

yaineriSedeno avatar Dec 02 '24 14:12 yaineriSedeno

having the same issue

Taamallah-Nefaa avatar Mar 03 '25 15:03 Taamallah-Nefaa

We would love to have this feature !

PLEASE !

bskottke avatar Jun 04 '25 12:06 bskottke

This feature will be very helpful for the projects with cucumber framework. Please add this feature

VishnuPrasath10 avatar Jul 02 '25 07:07 VishnuPrasath10