skip to Main Content

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 }) => {});

2

Answers


  1. Chosen as BEST ANSWER

    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)"
    

  2. There are two ways I am using multi tags

    1. grouping my tests in test.describe block and using a tag at that level and then using tag at test level too as following
    test.describe("Sample test group @smoke @integrations", () => {
    
      test("Login Test case @regression", async ({
        page,
      }) => {
    
        // Arrange
        // Act
        
        // Assert
        
    
      }); // Test case closing
    
      }); // Test.describe block closing
    
    

    alternatively, the following

    1. Use multiple tags in test cases
      test("Login Test case @regression @smoke @integrations", async ({
        page,
      }) => {
    
        // Arrange
        // Act
        
        // Assert
        
    
      }); // Test case closing
    
    
    

    and then I use script to run them as following in package.json

        "smoke-tests": "npx playwright test --grep @smoke"
    

    if you don’t want to run it through scripts, you can use the following command in terminal

    npx playwright test --grep @smoke
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search