Rayrun
โ† Back to Discord Forum

Tag confusion

In the suite I've inherited tags have been implemented as so..

test('test name (@tag1 @tag2)')

But I've not seen putting two tags together like this in any examples anywhere & I question whether it works properly.

Has anyone ever seen this before? Does it generally work when you come to run them?

This thread is trying to answer question "Does using multiple tags in a test suite work properly and is it common to use different symbols before the tags?"

6 replies

Works well, dont really need ( ) unless you like it that way

Great, thank you. How about # instead of @ before the tag? Any idea?

timdeschryver
timdeschryver

@jhul_11 what do you mean with "works properly"

I find them useful, and you can use AND or OR expressions to filter tests with a tag.

For example: https://timdeschryver.dev/blog/create-and-run-playwright-test-sets-using-tags-and-grep#the-flexibility-of-test-tags

Good points about using @ or # or something meaningful. Might assert this is more up to individuals and conventions if people wanting to use them. The thing to be concerned with... Consider the environment(s) where or how you'll be running your tests. Might be using a bash or command/cmd or pwsh for running, consider your meta characters wisely and you can avoid a lot of hassles later ๐Ÿ™‚

Sorry that was a flippant use of language @timdeschryver . I'm finding there to be a lot of issues in the suite &/or with PW\VSCode so I may be sceptical about everything by extension! Thank you, you've made me think about it differently. I loved the article btw but the tags in my suite aren't standard, using # & then grepping. Excellent examples too! Definitely using this for inspiration moving forward!

Excellent points @d3333333 . I think that's likely why I'm finding it confusing! Feeling better for having changed them all now too ๐Ÿ˜Š

Personally i would drop the $#&^*# (oops possibly i'm swearing?) I find even including them annoying just use English or your native language. I love me my regex, as long as you are consistent with the tests naming like "Customer Order Create" , "Customer Order Delete", "Customer Order Update", "Customer Order ...."

A simply regex would be ".(Customer Order)." would get them all... Same but for Product Activity... ".((Customer Order|Product Activity|whatever else))."

Answer

Using Multiple Tags in Playwright Test Suite

Yes, you can use multiple tags in a Playwright test suite. You can run tests containing either tag (logical OR operator) using the --grep command line flag followed by the tags separated by a pipe symbol (|). Here's how you do it:

npx playwright test --grep "@fast|@slow"

This command will run tests with either the @fast or @slow tag.

The symbol before the tag is significant when using regular expressions to match multiple tags. You can use regex lookaheads to run tests containing both tags (logical AND operator). Here's the syntax:

npx playwright test --grep "(?=.*@fast)(?=.*@slow)"

In this case, both @fast and @slow tags must be present for a test to be included in the run.

Remember, these examples are specific to Playwright's testing framework. Other testing frameworks may have different conventions or syntax for tagging and filtering tests. Always consult the documentation or resources specific to the tools you're using.

For more information, check out our blog post on Organizing Playwright Tests using Tags.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.