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.
Syntax:
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.
Example:
test('CSS Selector @pb', async ({page})=>
{
await page.goto("https://www.programsbuzz.com/");
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})=>
{
test.info().annotations.push({ type: 'issue', description: 'Check Alert Popup' })
await page.goto("http://autopract.com/selenium/alert2/#");
//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.