javascriptannotationstagsplaywright

How to use multi tags/annotations in tests using Playwright


According to Playwright Tag-Tests Docs

Tagging test looks like this:

test('My test @foo', async ({ page }) => {
  // ...
});

But there is no mention of multi tagging.

I'm looking for something like:

test('My test @foo, bar', async ({ page }) => {});
or
test('My test @foo bar', async ({ page }) => {});

Solution

  • I've found a solution, and it's very simple and straight-forward, simply separate tags with space:

    test('My test @foo @bar', async ({ page }) => {
      // ...
    });
    

    Execution:

    // foo OR bar
    npx playwright test --grep "@foo|@bar"
    
    // foo AND bar
    npx playwright test --grep "(?=.*@foo)(?=.*@bar)"
    

    v1.42 Update:

    Since v1.42 it can be achived using a new tags object too:

    test('multi tags example', {
        tag: ['@foo', '@bar'],
      }, async ({ page }) => {
        // ...
      });