A talk by Rodrigo Aguilera / @marinero
https://www.drupal.org/u/rodrigoaguilera
Aka BDD
We all use different languages.
It's not just a cool thing to have it really adds bussines value.
BDD framework written in PHP.
Feature: Banana Calculator
In order to keep a stock of bananas
As Bob the Banana merchant,
I want a calculator that can add the amount of bananas so that I can know how many bananas I currently have
Scenario: Add 2 banana amounts
Given I have 3 Bananas
When I add 5 Bananas
Then I should have 8 Bananas
composer require behat/behat
composer require drupal/drupal-extension='~3.1'
vendor/bin/behat --init
default:
suites:
default:
contexts:
- Drupal\DrupalExtension\Context\DrupalContext
extensions:
Behat\MinkExtension:
goutte: ~
base_url: http://example.org/ # Replace with your site's URL
Drupal\DrupalExtension:
blackbox: ~
vendor/bin/behat -di
vendor/bin/behat
Translates each step in a PHP callback
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Context\SnippetAcceptingContext;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {
private $bananas
/**
* @Given /^I have (\d+) bananas$/
*/
public function iHaveBananas($b) {
$this->bananas = $b;
}
...
}
/**
* @When /^I add (\d+) bananas$/
*/
public function iAddBananas($b) {
$this->bananas += $b;
}
/**
* @Then /^I should have (\d+) bananas$/
*/
public function iShouldHaveBananas($b) {
assertEquals($b, $this->bananas);
}
$session = $this->getSession();
$session->visit('http://drupal.org');
$session->getStatusCode();
$session->getCurrentUrl();
$page = $session->getPage();
$e = $page->find('css', li:nth-child(4) a);
$e->getText();
$e->getAttribute('href');
$e->click();
/**
* @Given /^I switch to the first iframe$/
*/
public function iSwitchToTheFirstIframe() {
$javascript = <<<JS
(function(){
var iframes = document.getElementsByTagName('iframe');
var f = iframes[0];
f.id = "no_name_iframe";
})()
JS;
$this->getSession()->executeScript($javascript);
$this->getSession()->switchToIFrame('no_name_iframe');
}
Very good documentation.
Thank you.
- http://docs.behat.org