There are lots of situations when we need to run only some of our automated tests instead of the whole test suite (e.g. run only the smoke tests instead of the full regression suite; the entire suite grows and you might want to run only subsets of your tests, and so on).
This thing is possible in Playwright using the grep functionality (a filter to only run tests with a title matching one of the patterns).
How do we apply this approach?
Step 1 – Include a custom @tag in your test title (it can by anything, e.g. @smoke @regression)
In the following test file, I included @smoke tag in the title of test2 and test3.

Step 2 – Run the tests from CLI, using the -g “@smoke” flag. The test execution will include only the tests that contain this tag in their title (e.g. test2 and test3).

Considering the above example, we could use a similar approach to EXCLUDE the tests with a specific tag,
using --grep-invert "@smoke"
In the following test execution, will be executed only the tests that DO NOT contain the @smoke tag (e.g. test 1)

If you liked this article, then please subscribe to my YouTube Channel for Test Automation video tutorials. You can also find me on LinkedIn and Twitter.