Stand-alone installationΒΆ

A stand-alone installation is recommended when you want your tests and testing environment to be portable, from local development to CI server, to client infrastructure. It also makes documentation consistent and reliable.

  1. Create a folder for your BDD tests:

    mkdir projectfolder
    cd projectfolder
    
All the commands that follow are written to install from the root of your project folder.
  1. Install Composer, a php package manager:

    curl -s https://getcomposer.org/installer | php
    
  2. Create a composer.json file to tell Composer what to install. To do that, paste the following code into your editor and save as composer.json. The Drupal Extension requires Behat, Mink, and the Mink Extension. They will all be set up because they’re dependencies of the Drupal Extension, so you don’t have to specify them directly in the composer.json file:

1
2
3
4
5
6
7
8
{
  "require": {
    "drupal/drupal-extension": "~3.0"
},
  "config": {
    "bin-dir": "bin/"
  }
}

For Drupal 8, you’ll need to specify the correct version of Guzzle:

1
2
3
4
5
6
7
8
9
{
  "require": {
    "drupal/drupal-extension": "~3.0",
    "guzzlehttp/guzzle" : "^6.0@dev"
},
  "config": {
    "bin-dir": "bin/"
  }
}
  1. Run the following command to install the Drupal Extension and all those dependencies. This takes a while before you start to see output:

    php composer.phar install
    
  2. Configure your testing environment by creating a file called behat.yml with the following. Be sure that you point the base_url at the web site YOU intend to test. Do not include a trailing slash:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
  extensions:
    Behat\MinkExtension:
      goutte: ~
      selenium2: ~
      base_url: http://seven.l
    Drupal\DrupalExtension:
      blackbox: ~
  1. Initialize behat. This creates the features folder with some basic things to get you started, including your own FeatureContext.php file:

    bin/behat --init
    
  2. This will generate a FeatureContext.php file that looks like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php

use Behat\Behat\Tester\Exception\PendingException;
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {

  /**
   * Initializes context.
   *
   * Every scenario gets its own context instance.
   * You can also pass arbitrary arguments to the
   * context constructor through behat.yml.
   */
  public function __construct() {
  }
}

This FeatureContext.php will be aware of both the Drupal Extension and the Mink Extension, so you’ll be able to take advantage of their drivers add your own custom step definitions as well.

  1. To ensure everything is set up appropriately, type:

    bin/behat -dl
    

    You’ll see a list of steps like the following, but longer, if you’ve installed everything successfully:

1
2
3
4
 default | Given I am an anonymous user
 default | Given I am not logged in
 default | Given I am logged in as a user with the :role role(s)
 default | Given I am logged in as :name