If you want one or more scenarios to do something different compared to others then you can use behat tagged hooks.


Feature


Although all the scenarios are same, the last one where we see @do-something-special tag will do something different compared to others.


Feature: Listing countries
In order to list countries
As a user
I should be able to navigate to country page

Scenario: Listing all countries
Given I am on "/country"
Then I should see "Turkey"

Scenario: Listing all countries
Given I am on "/country"
Then I should see "Germany"

@do-something-special
Scenario: Listing all countries
Given I am on "/country"
Then I should see "United Kingdom"

FeatureContext


namespace AppBundle\Features\Context;

use Behat\MinkExtension\Context\MinkContext;
use Behat\Symfony2Extension\Context\KernelAwareContext;
use Symfony\Component\HttpKernel\KernelInterface;

class FeatureContext extends MinkContext implements KernelAwareContext
{
/** @var KernelInterface */
private $kernel;

public function setKernel(KernelInterface $kernel)
{
$this->kernel = $kernel;
}

/**
* @BeforeScenario @do-something-special
*/
public function doSomethingSpecial()
{
echo 'I did something special...';
}
}

Test


Feature: Listing countries
In order to list countries
As a user
I should be able to navigate to country page

Scenario: Listing all countries # src/AppBundle/Features/Country.feature:6
Given I am on "/country" # AppBundle\Features\Context\FeatureContext::visit()
Then I should see "Turkey" # AppBundle\Features\Context\FeatureContext::assertPageContainsText()

Scenario: Listing all countries # src/AppBundle/Features/Country.feature:10
Given I am on "/country" # AppBundle\Features\Context\FeatureContext::visit()
Then I should see "Germany" # AppBundle\Features\Context\FeatureContext::assertPageContainsText()

┌─ @BeforeScenario @do-something-special # AppBundle\Features\Context\FeatureContext::doSomethingSpecial()

│ I did something special...

@do-something-special
Scenario: Listing all countries # src/AppBundle/Features/Country.feature:15
Given I am on "/country" # AppBundle\Features\Context\FeatureContext::visit()
Then I should see "United Kingdom" # AppBundle\Features\Context\FeatureContext::assertPageContainsText()

3 scenarios (3 passed)
6 steps (6 passed)
0m0.68s (31.55Mb)