36

I'm trying to run a specific Behat scenario from the command line, here's what I'm doing:

$ bin/behat features/features/baseline.feature:3

However this isn't picking up the scenario.

If I run

bin/behat features/features/baseline.feature

I can get the entire feature file to run.

Here's what the file looks like -- the scenario I'm trying to run is on line 3 in my text editor:

Feature:
  @api
  Scenario: Clear cache
    Given the cache has been cleared
    When I am on the homepage
    Then I should get a "200" HTTP response

  Scenario:
    Given I am not logged in
    When I am on the homepage
    Then I should see the text "We love our users"
JeremyKirkham
  • 935
  • 2
  • 10
  • 18

3 Answers3

49

First of all you should add the whole description of the feature file, like:

Feature: Home page functionality
  In order to use application functionality
  As a website user
  I need to be able see the home page

And Scenario should also has a description.

You can run behat scenarios using tags:

bin/behat --tags @api

Basically every Scenario could has own tag. Behat command will try to find all scenarios with that @api tag.

Also you can specify tag for the whole Feature file:

@whole-feature-file
Feature: Home page functionality

Run Scenario using part of the name:

bin/behat --name="element of feature"

Or according to the @greggles comment:

Specify the feature file name and line number, e.g.

bin/behat features/file.feature:123 

where 123 is the line number of the line like Scenario: Clear cache

For more details see behat docs

Igor Lantushenko
  • 1,633
  • 9
  • 18
  • 5
    Not sure if this is a newly available option, but it is also possible to specify the feature file name and line number, e.g. `bin/behat features/file.feature:123` where 123 is the line number of the line like `Scenario: Clear cache`. – greggles Dec 30 '16 at 21:32
  • 2
    You can even lauch tests on a range of lines, as explained in `bin/behat --help`: `*.feature:10-*`, `*.feature:10-20` – Gregoire Oct 26 '17 at 15:21
4

Found out you can simply tag a scenario with any custom tag, for example @foobar.

Feature:
  @api @foobar
  Scenario: Clear cache
    Given the cache has been cleared
    When I am on the homepage
    Then I should get a "200" HTTP response

  Scenario:
    Given I am not logged in
    When I am on the homepage
    Then I should see the text "We love our users"

And then have only this scenarios run with:

behat --tags foobar
leymannx
  • 4,420
  • 4
  • 35
  • 42
1

I find that I have to use the full path to the feature file only when executing a specific scenario. For example, if your feature file was in /var/www/html/tests/features/features, and your in /var/www/html/tests then try this command:

bin/behat /var/www/html/tests/features/features/baseline.feature:3
Evil E
  • 553
  • 1
  • 3
  • 9