Playwright Tag Tests

In playwright, we can tag tests as uniquely to fetch them with the grep keyword and mainly run that test alone. This can be done by tagging our test steps as '@tagname' and only running the tests with this tag.

Grep and grep invert command line flags are used for that.


test('Test1 @pb', async ({ page }) => {
 // ...
test('Test2 @auto', async ({ page }) => {
 // ...
npx playwright test --grep '@pb'
  • Only test with @pb tag runs.
npx playwright test --grep-invert '@auto'
  • Skips @auto and runs @pb.


test('CSS Selector @pb', async ({page})=> 
await page.goto("");
await page.locator('.gv-icon-52').click()
await page.locator('#edit-keys').type('Playwright')
await page.locator('#edit-submit').click()
test('Alert Handling @auto', async ({page})=> 
{{ type: 'issue', description: 'Check Alert Popup' })
await page.goto("");
//await page.locator('#callConfirm').click()
//await page.locator("div[class='ui-dialog-buttonpane ui-widget-content ui-helper-clearfix'] button:nth-child(1) span:nth-child(1)").click()
await page.locator("tbody tr:nth-child(2) td:nth-child(3) a:nth-child(1)").click()
await page.on('dialog',dialog => dialog.accept())

  • Consider this test. Let us use grep and run @auto.
npx playwright test tests/skip.spec.js --headed --project='chromium' --reporter=html --grep '@auto'
  • Let us run invert grep.
npx playwright test tests/skip.spec.js --headed --project='chromium' --reporter=html --grep-invert '@pb'
  • Here @pb test step has been skipped, and the other test step is run.
Fri, 02/03/2023 - 11:47
Ashwin possesses over five years of experience in the Quality Assurance industry and is currently serving as a Technical Lead at iVagus. His expertise encompasses a broad range of technologies, including Cypress, Rest Assured, Selenium, Cucumber, JavaScript and TypeScript.