Skip to main content

Utilities for Behat 3.x "tips & tricks"

 Key commands list for behat

Run the tests with the configuration have given by the yml file

behat --config [path/to/yml]

Example: behat --config sites/default/default.behat.yml

 

Initialize the feature suite structure inside your project, 

behat --config [path/to/yml] --init

Behat will automatically add all missing pass methods to your FeatureContext class

behat --config [patt/to/yml] --dry-run --append-snippets

We generate a template of a Yml file by default with its specifications, if we also export it, we will quickly have a predefined configuration file.

behat --config-reference
# Example
behat --config-reference > default.behat.yml

 

Multitag

We can use the tags that give us Behat to manage which Scenarios we want to execute and which omit
To understand it, here is what is evaluated as Boolean expression in the different cases:

~test,test2: (NOT test) OR test2

~@test,~@test2: (NOT test) OR (NOT test2) which is equivalent to NOT (test AND test2)

~@test&&~@test2: (NOT test) AND (NOT test2)

* The @ in the tag name is optional in all cases: @ `is replaced by an empty string.