Skip to content

[Feature]: Allow tags to be added using fixtures #35796

@nicojs

Description

@nicojs

🚀 Feature Request

We have a custom screenshotTest fixture which does some basic setup for screenshot tests. We also have a updateSnaps pipeline for updating the reference screenshots. We only want to run the screenshot tests that pipeline. We focus the screenshot test using --grep @screenshot.

I.e. we would love something like this:

 import { test as base } from '@playwright/test';

+ export const screenshotTest = base.extend<{ screenshotSetup: void, tags: void }>({
- export const screenshotTest = base.extend<{ screenshotSetup: void }>({
+  tags: ['@screenshot'],
   screenshotSetup: [
     async ({ }, use, testInfo) => {
       const isCI =
         process.env.CI === '1' ||
         (process.env.CI && process.env.CI.toLowerCase() === 'true');
       testInfo.skip(
         !isCI,
         "Test is skipped because it's not running in CI.\nIf this happens in CI, please verify that the CI environment variable is set correctly.",
       );
       await use();
     },
     { auto: true },
   ],
});

Example

screenshotTest(
      'review card should contain the star rating',
-      { tag: '@screenshot' },
      async () => {
        const starRating = reviewsPage.getFirstReviewDetails().starRating;
        await expect(starRating).toHaveScreenshot();
      },
    );

Motivation

We currently need to tag each screenshotTest with the tag @screenshot, because we don't know of a way to add tags statically using a fixture so --grep supports them.

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