Test Tags | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Advanced Tricks and Techniques
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore how to organize tests using tags in Playwright, allowing you to run specific groups of tests conveniently. Key Concepts Tagging Tests: You can mark tests with tags to run them based on certain criteria, even if they are located in different spec files or describe blocks. Running Tests by Tag: Use the command: npx playwright test --project=Chromium --grep="tag_name" to execute tests with a specific tag. Multiple Tags: You can assign multiple tags to a single test. For example, a test can have both smoke and regression tags. Custom Tags: Tags can be customized. For instance, adding a tag called blog to a describe block will allow you to run all tests within that block. Running Tests with Multiple Tags To run tests with multiple tags, modify your command to include a pipe (|) between tags: npx playwright test --grep="tag1|tag2" This will execute all tests associated with both tags. Platform-Specific Syntax Note that the command syntax varies by operating system: Mac: Use a pipe (|) to separate tags. Windows Command Line: Use a caret (^) instead of a pipe. PowerShell: Add -- and % for tag separation. Using tags in Playwright is a simple yet effective way to manage and execute your tests based on logical groupings. Practice incorporating tags into your testing strategy!
Video Transcript
And in this lesson, we will talk about additional option, how you can organize your test using a text. So very simple and very convenient way how to trigger a certain test that related to the certain groups. If sometimes your test located in different spec files or in different described blogs, but you want to run them at the same time based on the certain criteria, you can mark them with text. For example, let's say we want to run this navigate to form page test with a text. So we add into the description any tag that we want to run, for example, at smoke. And then inside of the command line to run this test based on the tag, we type npx playwright test, then project Chromium. This is a default project for our framework. And then dash dash grab and provide the name of the tag, which is smoke. And I run this test. You can see one test is successfully running. Test is completed. If I will add the same tag over here, smoke and run it. Now two tests are executed. You can add several tags inside of the test. For example, for the test number one, I want to add smoke and let's say regression. And if I run right now instead of smoke type regression, run it. And one test is executed. Additionally, you can add the tags to a different spec files and to the described blog sections as well. So scrolling up, for example, this described blog have two tests, radio buttons and input fields. And if I add the tag inside of the described blog, for example, blog. This will be my custom tag name and run it as blog. Then two tests are executed related to this described section. Test number one and test number two. And also you can run several tags at the same time. Let's say we want to run blog and we want to run, let's say, smoke test, something like that. So I just need to modify my command with double quotes and provide the pipe separating the tags smoke and double quotes. Run it. And right now four tests are executed. Two tests because we have two smoke tags and two tests because it's related to this blog. Keep in mind that if you run on Windows, the syntax will be a little bit different. So on Mac, you just put a pipe. If you run on Windows with a command line, you need to put here a caret sign. On the PowerShell, you will need additionally add dash dash and percentile. So this would be a command line for the PowerShell. So keep that in mind in case you are running on different systems. So that's pretty much it. Very easy and very convenient way of running different groups of tests or separating your tests by logic. If you are on your project, have a practice of using the test tags, you can also do this in the playwright. All right, that's it guys and see you in the next lesson.