Search code examples
javascriptplaywrightplaywright-test

Running specific test group in Playwright


I have grouped my tests in playwright. My test grouping looks as following

test.describe('API Test Suite', ()=> {
test("get users @smoke", async ({request}) => {
//Test here
})

test("get countries @integration", async ({request}) => {
//Test here
})
});

I can grep them using tags e.g. @smoke/@integration but I wonder how can I filter them out based on their test group i.e "API Test Suite" in this scenario and run them.


Solution

  • You may directly use tag inside describe title as well like @API mentioned below:

    test.describe('@API Test Suite', ()=> {
         test("get users @smoke", async ({request}) => {
        //Test here
         })
        
         test("get countries @integration", async ({request}) => {
        //Test here
         })
        
    });
    

    Or you can simply use grep:

    npx playwright test --grep "API Test Suite"
    

    Or you can combine both of them to create complex scenarios:

    //Run tests containing the @API Test Suite tag AND do not contain the @readonly tag
      npx playwright test --grep "@API Test Suite" --grep-invert "@readonly"