Rayrun
← Back to Discord Forum

undo grepInvert

If I want to by-default ignore some tags, how can I force-call them? https://playwright.dev/docs/api/class-testconfig#test-config-grep-invert

import { defineConfig } from '@playwright/test';

export default defineConfig({
  grepInvert: /manual/,
});

and

npx playwright test --grep @manual

This thread is trying to answer question "How can I force-call tags that I have set to be ignored by default using 'grepInvert' in Playwright, particularly if the tag is per-project rather than global?"

4 replies

... how about if it is a per-project tag (instead of a global one)?

Not sure if I get what you are asking, but in our GH pipeline we use the command line for tagging so we can allow the caller of the workflow specify the tags for there run. So the input is excluded or included tags the command line gets used if in the following fashion.

npx playwright test --grep @flaky npx playwright test --grep-invert @flay

You can add tags at the project level as well, but I haven't tested it. I would be careful that if you go with project tags that the global tagging is removed to not conflict or confuse the users.

CI should never run @flaky - so it is marked in-config (instead of changing the CI command line).

I would like to be able to "force-ignore" that, if I so choose, by providing a command-line argument (e.g. --grep-invert '').

=== My scenario is more complicated that this. Otherwise, the annoying env.CI ? /@manual/ : undefined would've worked

You can achieve it with automatic fixture like this: export const test = base.extend<{ filterManualTags: void }>({ filterManualTags: [async({}, use, testInfo) => { if (testInfo.title.includes('@manual')) testInfo.skip(); await use(); },{ auto: true }] });

Answer

Sure, you can force-call ignored tags in Playwright using the grepInvert option in your test project configuration. Here's how:

First, you need to set up your test project configuration file, typically named playwright.config.ts. This is where you define your test project settings.

// playwright.config.ts

import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  // Other configuration options...
};
export default config;

Next, within this file, find the testProject object. Add a grepInvert property to it. Set its value to an array of regular expressions or a single regular expression pattern. These patterns represent the tags you want to ignore.

// playwright.config.ts

const config: PlaywrightTestConfig = {
  // Other configuration options...

  testProject: {
    // Other project settings...

    grepInvert: [/tag1/, /tag2/], // Specify the tags to be ignored
  },
};

In this example, tests with titles containing "tag1" or "tag2" will be ignored by default. This configuration is per-project and won't affect global configurations or other projects.

Remember, if no patterns are specified for exclusion using grepInvert, all tests will run, regardless of their tags.

For more details on organizing Playwright tests using tags, check out this blog post.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].