How to execute only desired BDD scenarios

How to execute only desired BDD scenarios

When doing BDD testing sometimes there is a need to execute only certain scenarios instead of all the scenarios of the feature file.

Tags are a great way to organize/group your Scenarios. One can use squishrunner’s  --tags option to execute just those BDD secnarios which match a given tag filter.

Setting a tag filter for BDD scenarios:

In the example below @foo and @bar tags are used to tag scenarios.

Feature: Filling of addressbook
As a user I want to fill the addressbook with entries

    @foo
    Scenario: Initial state of created address book
        Given addressbook application is running
        When I create a new addressbook
        Then addressbook should have zero entries

    @bar
    Scenario: State after adding one entry
        Given addressbook application is running
        When I create a new addressbook
        And I add a new person 'John','Doe','john@m.com','500600700' to address book
        Then '1' entries should be present

    @foo @bar
    Scenario: State after adding two entries
        Given addressbook application is running
        When I create a new addressbook
        And I add new persons to address book
        | forename  | surname  | email      | phone  |
        | John      | Smith    | john@m.com| 123123  |
        | Alice     | Thomson  | alice@m.com/ 234234 |
        Then '2' entries should be present

    @bar
    Scenario: Forename and surname is added to table
        Given addressbook application is running
        When I create a new addressbook
        When I add a new person 'Bob','Doe','Bob@m.com','123321231' to address book
        Then previously entered forename and surname shall be at the top

Now, when we want to execute only the scenarios tagged @foo, we can use squishrunner with tags option as shown below:
squishrunner –testsuite C:\Users\suite_BDD_Delte –testcase tst_case7 –tags @foo

Syntax for different use-cases:

– -tags foo
Executes all scenarios or test scripts with the tag foo

– -tags ~foo
Executes all scenarios or test scripts not tagged foo

– -tags foo,bar
Executes all scenarios or test scripts tagged either foo or bar (or both).

– -tags foo – -tags bar
Executes all scenarios or test scripts tagged both foo and bar.

– -tags foo,bar – -tags yoyo
Execute all scenarios or test scripts with the tag yoyo and one (or both) of foo and bar.

Neha was born in Kashmir, India and grew up in Kashmir and New Delhi. She did her diploma in computer science at C-DAC (Center of Diploma in Advance Computing), New Delhi, and worked for IBM India as a software developer until she moved to Germany in 2006.

1 Comment

Pingbacks

  1. […] out a past blog on this topic: How to execute only desired BDD scenarios. And read more about tags in our documentation: Playback option […]

Leave a reply

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

*