Installing the Drupal Extension for Behat
Using Behat with Drupal
By Frank Ralf
To use Behat for Drupal testing you should install the Drupal Extension (https://drupal.org/project/drupalextension) which provides Drupal specific step definitions and drivers.
Installing using Composer
Just follow the instructions at https://drupal.org/project/drupalextension.
You have to create a new composer.json file in your Behat directory. If there is already one from your initial Behat installation just rename it. (You should not add the following code to an existing composer.json file. The Drupal Extension will care for all dependencies itself.) You might also have to rename (or delete) the composer.lock file to be able to run Composer.
{<br> "require": {<br> "drupal/drupal-extension": "*"<br> },<br> "minimum-stability": "dev",<br> "config": {<br> "bin-dir": "bin/"<br> }<br>}
Now just run Composer from the command line (here Windows PowerShell):
composer install
Composer will update some already installed components and then install the Drupal Extension.
Set up a Drupal project
- Create a Drupal project folder.
- Run behat --init
- Create a behat.yml file (see https://drupal.org/project/drupalextension point 3.)
- Then at least modify the FeatureContext.php file according to point 10.
Check your installation
To check if everything went fine run
behat -dl
to get the definition list of all available steps. There should be some new Drupal specific entries.
As the list might be a bit overwhelming try filtering the list by some Drupal specific term like "node":
behat -d 'node'
What's next?
The Drupal Extension comes with three different drivers for interacting with a Drupal site (http://www.dspeak.com/drupalextension/drivers.html). The distribution contains some example settings and feature files for these drivers. I'll show how to run these example files in my next blog post on the Drupal Extension for Behat. So stay tuned.