Running specific test group in Playwright

215 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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"