Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Compare snapshot with file outside test snapshot directory #30898

Closed
TadasV1 opened this issue May 19, 2024 · 4 comments
Closed

[Feature]: Compare snapshot with file outside test snapshot directory #30898

TadasV1 opened this issue May 19, 2024 · 4 comments

Comments

@TadasV1
Copy link

TadasV1 commented May 19, 2024

馃殌 Feature Request

Allow to pass outside test dir snapshot file to toHaveScreenshot function

Example

// tests/B/B.test.js

const path = /tests/A/A.test.js-snapshots/A-1-${project}-win32.png
await expect(page).toHaveScreenshot(path)

Motivation

  • some tests have screenshots that are the same as in another
  • these tests produce many screenshots + multiply by different projects

This creates an unnecessary files to review for these screenshots which are identical.

@pavelfeldman
Copy link
Member

You can control the way your expectations are matched with https://playwright.dev/docs/api/class-testproject#test-project-snapshot-path-template and the actual toHaveScreenshot name parameter. Do you think you can use these two to achieve your goal?

@TadasV1
Copy link
Author

TadasV1 commented May 20, 2024

Unfortunately not. Maybe some example will give more insights.

  • I need featureA1 to compare to featureA screenshot
  • featureA snapshots are located in its own snapshot directory
  • featureA(i) generate same screenshots
  • tests are seperate files:
    > featureA.test.js -- 5 screenshots [1, 2, 3, 4, 5]
    > featureA1.test.js -- 3 screenshots [2, 4, 5]
    > ...
    > featureA23.test.js -- 2 screenshots [1, 4]

For now I am keeping the redundant files.

@pavelfeldman
Copy link
Member

with the snapshot dir template set as this: {testDir}/__screenshots__/{arg}{ext}, you'll be able to use explicit names for your expectations across the files. Why does not it work for you? It does address the use case you provide above.

@pavelfeldman
Copy link
Member

Closing as per above, please feel free to open a new issue if this does not cover your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants