1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

By Rafaela Azevedo
Hello guys !
I will explain a simple tutorial of “How can you use BDD with Selenium and PHP.”
– First thing you have to install Behat:
– Install Composer
– Create a composer.json file in your root directory



“require”: {

“behat/behat”: “2.4.*@stable”,

“behat/mink”: “1.5.*@stable”,

“behat/mink-goutte-driver”: “*”,

“behat/mink-extension”: “*”,

“behat/mink-selenium2-driver”: “*”


– Run composer install
– Create a behat.yml file




features: features

bootstrap: %behat.paths.features%/bootstrap



goutte: ~

selenium2: ~

– Initialize your Behat project with vendor/bin/behat –init. Note: bin directories are configurable in composer.json. If your composer file has a bin directory, use that path instead of vendor/bin.

– Create a feature file, e.g. test.feature


Feature: search

In order to find modules on
As a Drupal user
I need to be able to use search


Scenario: Searching for “behat”

Given I go to ““

When I search for “behat“

Then I should see “Behat Drupal Extension“

– Edit FeatureContext.php to extend from MinkContext. Note: You will need to add the use statement, use BehatMinkExtensionContextMinkContext. Run vendor/bin/behat
– Second Step: Adding Selenium as an optional driver
– Download Selenium Server
– Run java -jar /path/to/selenium-server-standalone-2.37.0.jar
– Add selenium2: ~ to your behat.yml
– Add a @javascript tag above your scenario
– Run vendor/bin/behat
– Third Step: Adding new step definitions
– Add the step you want to create in your scenario, e.g.
– When I search for “behat” Run vendor/bin/behat
– Copy the step definition template to FeatureContext.php and replace the PendingException with your code.


* @When /^I search for “([^”]*)”$/
public function iSearchFor($arg1)
$this->fillField(‘Search’, $arg1);



Category: Programming, QA, Test and Automation Stuffs, behat, mink, php with BDD, php with BDD and Selenium, selenium

Você também pode querer ler

Comments are off for this post.