Frank Ralf, Projektmanager und Site Builder

Using Behat with Drupal

Installing the Drupal Extension for Behat

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.

{
  "require": {
    "drupal/drupal-extension": "*"
  },
  "minimum-stability": "dev",
  "config": {
    "bin-dir": "bin/"
  }
}

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.

Installing Drupal Extension for Behat

Set up a Drupal project

  1. Create a Drupal project folder.
  2. Run behat --init
  3. Create a behat.yml file (see https://drupal.org/project/drupalextension point 3.)
  4. 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'

New Drupal step definitions

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.

Installing Drupal Extension for Behat
New Drupal step definitions

Kommentare

Abhiram - Tue, 09/24/2013 - 23:03
Hello Frank, I've been trying to install and run Behat with Mink extension on windows 7. The installation was smooth and i am able to run tests on goutte but when i add '@javascript' to one of the test scenarios and try to run it(it should automatically use selenium2), it just won't fire up the browser and i don't see any Behat error either on the command line. Were you able to run any test scenario successfully with the selenium2 extension? Thanks, Abhiram