Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playwright: Can I run a subset of tests based on a tag?

I'm used to using Cucumber where I can tag my feature files with annotations like @prodSafe and run only tests with that tag on my production environment.

Is there a way I can do that with Playwright? I want to run all my tests on dev but then on production, there are tests I'd like to skip for things like deleting users, etc.

like image 819
Doctor Who Avatar asked Jan 29 '26 17:01

Doctor Who


1 Answers

To tag a test in playwright, we just add the tag, for example @smokeDev to the test definition:

test('@smokeDev - Login to dev with valid credentials', async ({ page }) 
      ...  
});

To run all tests having a tag you can use

npx playwright test --grep '@smokeDev'

This command will run all tests having @smokeDev tag. It is also possible to pick multiple tags by simply combining them with |

For instance:

npx playwright test --grep '@smokeDev|smokeProd'

This command will run all tests having either the tag

  • @smokeDev or
  • @smokeProd
like image 55
Mustafa SDET Avatar answered Feb 01 '26 13:02

Mustafa SDET



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!