Skip to content

[Feature]: Improve the usage of snapshotPathTemplate to screenshot() method. #35882

Open
@samixchoumi

Description

@samixchoumi

🚀 Feature Request

Actually snapshotPathTemplate config value seem not to work for .screenshot() method while it works fine for .toHaveScreenshot()

Example

For example, in my project I've this config :
snapshotPathTemplate: './fixtures/__screenshots__/${ environment }/{testFilePath}/{arg}{ext}',
On my test I just do

await expect(page, `Expected '${ pageWanted }' page to be compliant with '${ screenshotName }' screenshot`).toHaveScreenshot(screenshotName, { mask: locatorToExclude });

And I just need to put a screenshot name to make it works.
But if I want to generate a new screenshot for my test, do some action, and then assert screenshot, then I need to do like this :

const screenshotPath = './fixtures/__screenshots__/${environment}/tests/TestScenario.feature.spec.js/';
const screenshotName = 'temp-${ pageName.toLowerCase().replaceAll(' ', '-') }-screenshot.png';
await page.screenshot({
    path: screenshotPath + screenshotName,
    mask: locatorToExclude
  });

Instead of this current behavior, it could become something like that :

const screenshotName = 'temp-${ pageName }-screenshot.png';
await page.screenshot({ path: screenshotName, mask: locatorToExclude });

Motivation

It could be better to just use the snapshotPathTemplate for the .screenshot() method too so It will just need to set the screenshot name has we did for .toHaveScreenshot() method.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions