Tags in Behave BDD

Tutorial​​ 15​​ ​​ ​​ Tags in​​ Behave BDD

Welcome to the 15th article in Behave BDD series!

What you will Learn :

  • Importance of​​ Tags

  • Execute​​ @Smoke test

  • Execute 2 tags seperated by comma (logical OR)

  • Execute 2 tags seperated by several --tags (logical AND)

  • Use ~ to ignore scenario execution​​ 

Importance of​​ Tags

We can do some excellent things​​ when we execute our test cases with Behave BDD. We can tag sanity based test cases, smoke test cases, regression test cases​​ etc.​​ 

To further understand the tags,​​ let us create a new feature file having 3 scenarios

So far, we haven’t added any tags to our feature file.

Let us create the corresponding step definition file for the above feature file
​​ 

Save the file.

Let us run the feature file to ensure there are no errors
​​ 

So there are no errors in execution.

We will now create​​ 3​​ tags​​ in our feature file for​​ all the 3 scenarios, see below​​ 

Save the file​​ and execute the feature file once again. Notice below that all the scenarios get executed as expected


Execute​​ @Smoke test

We will now​​ see how to​​ run only ‘smoke’ based test case/scenario. The syntax is as mentioned below:

behave filename.feature --tags=tagname

 

Notice​​ above​​ that​​ only​​ @smoke scenario got executed​​ (the summary result says 2 skipped and we see # None against the 6 steps).

Let us now change the tag​​ to @Integration. Notice below that this time only @integration scenario got executed



Execute​​ 2 tags​​ seperated by comma (logical OR)

You can execute​​ 2 tags​​ together​​ as well​​ by​​ separating the tagnames by comma (logical​​ ‘OR’). So below we are executing those test cases which are tagged with @Smoke or @Regression

 ​​​​ 

Similarly, see below. We do not have @Unit test case and hence only @Integration gets executed



Similarly you can try executing more than 2 tags as well.


Execute​​ 2 tags seperated by​​ several --tags​​ (logical AND)

Let us represent the second scenario using 2 tags: @Regression @Production (see below)​​ 

Save the file.

Now how we run a scenario that has 2 tags attached to it?​​ 

See below and notice that only one scenario gets executed that has both the tags


Use​​ ~ to​​ ignore scenario​​ execution

Let us remove the @Production tag from second scenario

Save the file

Let us say we want to execute all the scenarios except @Smoke. We can do that using​​ ~​​ (tilde), see below


Notice above that @Smoke did not execute
.​​ 

So this is how we can use tags in our feature files.

Thank you​​ for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 31st DEC 2024