Search code examples
behatgherkin

How to exclude beforeFeature for specific tag in behat


I have a behat feature with specific tag and I have two beforeFeature function. One of them runs for every scenario and one of them runs only for specific tagged scenarios. The problem is that the beforeFeature with no tag also runs before those features that have the tag. I want to make this beforeFeature to not runs on those feature with specific tag. For example I have a following feature:

@taggedFeature
Feature: This feature runs tagged beforeFeature

And In my FeatureContect I have the following beforeFeature functions

/** @BeforeFeature */
public static function beforeFeatureDefault()
{ 
 // Do something
}

and

 /** @BeforeFeature @taggedFeature*/
public static function beforeFeatureTagged()
{ 
 // Do something
}

What I want is from behat is to not run the beforeFeatureDefault() function before my tagged feature.


Solution

  • You can exclude the tagged features with ~:

    /** @BeforeFeature ~@taggedFeature */
    public static function beforeFeatureDefault() {
         echo 'beforeFeatureDefault()';
    }
    
    /** @BeforeFeature @taggedFeature */
    public static function beforeFeatureTagged() {
         echo 'beforeFeatureTagged()';
    }