You can ignore Behat Tests using tags. ~ symbol is used along with tags to ignore the scenario.
This works both for Scenario as well as Feature. You can skip a scenario, set of scenarios or all scenarios in a feature file. You can also use this with conjunction with AND or OR.
One way of ignoring tag is mention only tags which you want to run in tags value of Behat but this is not best practice. Consider, when out of 10 you have to executed 9 tags and ignore one. Then, there is no benefit of typing 9 tags. In that case we skip tags using ~ operator.
Consider below feature file
#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 @smoke @regression 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?"
Example #1: To execute all scenarios except @smoke.
bin/behat --tags '~@smoke'
This will execute 3rd scenario.
Example #2: Execute Scenario which are are tagged with regression and not with smoke.
bin/behat --tags '@regression&&~smoke'
This will execute nothing.
Example #3: Execute scenarios which are tagged with smoke but not with Regression.
bin/behat --tags '@smoke&&~@regression'
This will executed 1st scenario.
Example #4: Execute Scenario that are either tagged with Sanity or it does not contain @regression tag.
bin/behat --tags '@sanity,~@regression'
This will execute 1st and 3rd scenarios.