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
1 2 3 4 5 6 7 8 9 |
{
“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
1 2 3 4 5 6 7 8 |
default:
paths:
features: features
bootstrap: %behat.paths.features%/bootstrap
extensions:
Behat\MinkExtension\Extension:
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.
1 2 3 4 5 6 7 8 9 10 |
Feature: Drupal.org search
In order to find modules on Drupal.org
As a Drupal user
I need to be able to use Drupal.org search
@javascript
Scenario: Searching for “behat”
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 Behat\MinkExtension\Context\MinkContext. 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.
1 2 3 4 5 6 7 8 |
/**
* @When /^I search for “([^”]*)”$/
*/
public function iSearchFor($arg1)
{
$this->fillField(‘Search Drupal.org’, $arg1);
$this->pressButton(‘Search’);
}
|
Resources: http://lin-clark.com/blog/2013/11/26/quickstart-testing-with-behat-mink-selenium/
One thought on “Behat, Mink and Selenium”