Post

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

123456789

{

“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

12345678

default:

paths:

features: features

bootstrap: %behat.paths.features%/bootstrap

extensions:

BehatMinkExtensionExtension:

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

12345678910

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”

Given I go to “http://drupal.org“

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.

12345678

/**
* @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/

Source: http://azevedorafaela.wordpress.com/2014/04/09/behat-mink-and-selenium/

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.