Most of the time, changes are made to many functionalities at the same time; so testers require to test all those functionalities. Sometimes we have to run all the Scenarios marked as @regression or sometime all scenarios with @smoke and sometimes; we want to run all Scenarios for search feature or login feature or both.
Logic of AND and OR work similar to logical operator exist in other programming language. There is also logical NOT in Behat if you want to skip or ignore particular scenario. Which we will discuss later.
Consider below example:
#language: en @login Feature: Login Functionality Background: Given I am on homepage When I follow "Sign in" And I wait 3 seconds @smoke Scenario: Verify user Login And I fill in "email" with "firstname.lastname@example.org" And I fill in "passwd" with "Test1234" And I press "SubmitLogin" And I wait 10 seconds @regression @smoke Scenario: Create New User And I fill in "email_create" with "email@example.com" Then I press "SubmitCreate" @sanity Scenario: Forgot password And I follow "Forgot your password?"
ANDing: When you want to execute scenarios tagged with @regression and @smoke. Use below command:
$ bin/behat --tags '@regression&&@smoke'
This will execute second scenario, since that is the only scenario with both tags.
ORing: When we want to run the Scenarios with either of the mentioned Tags. For example when you want to execute the scenario tagged with @smoke or @sanity. Use below command:
$ bin/behat --tags '@smoke,@sanity'
this is same as:
$ bin/behat --tags 'smoke,sanity'
This will execute all 3 scenarios. We have used single feature file for demo but Anding Oring is not limited for single feature file. It is applicable to complete project.