Skip to main content

Execute Behat Feature or Scenario using Partial title match

If you want to run only part of your suite, or some scenarios, you can also do it using --name filter. You can use name option to match part of Feature or Scenario title.

For Example:

$ behat --name="element of feature"

Here you don't need to specify your complete feature or scenario title. You can give only Only part of the given name or regex. One point to note here that value is case sensitive. Here word Test is different from test.

Consider This feature file:

#language: en
Feature:Test Login Functionality

    Given I am on homepage
    When I follow "Sign in"
    And I wait 3 seconds

  Scenario: Verify user Login
    And I fill in "email" with ""
    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 ""
    Then I press "SubmitCreate"
    Then I should see "test"

  Scenario: Forgot password
    And I follow "Forgot your password?"

Example 1: Below command will execute Scenario #1 because Scenario #1 contains Verify user.

$ bin/behat --name 'Verify user'

Example 2: Below command will execute scenario #1 and #2 because Scenario #1 and #2 contains user.

$ bin/behat --name 'user'

Example 3: This command will execute Scenario #2 because that scenario ends with user.

$ bin/behat --name '/user$/'

Example 4: Below command will execute complete feature file because feature title consist of Test Login

$ bin/behat --name 'Test Login'

Example 5: This command will execute nothing because value is case sensitive.

$ bin/behat --name 'test Login' 

Submitted by tgoswami on October 19, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.