On Github rodrigoaguilera / talk_behat
A talk by Rodrigo Aguilera / @marinero
Thank you to the organization. I'm excited about behat.https://www.drupal.org/u/rodrigoaguilera
I'm from Madrid, now I live in Barcelona. I'm 29. I work as a drupal developer at Ymbra, Citilab. I have a curiosity to improve process. Previously on: servers, multilingual, community tools, code review development quality...
Aka BDD
It's a bit philosophical. Around the concept of behaviour.We all use different languages.
Clients don't care about scope or budget so better speak bussines language. A solution for miscomunication. Get everyone together.It's not just a cool thing to have it really adds bussines value.
You can check your application continously.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
Structured language to describe features. keywords highlighted. .feature file multilingual.composer require behat/behat
composer require drupal/drupal-extension='~3.1'Little demo with a D8 standard install. I'm not going into composer details.
vendor/bin/behat --initThen we can write some features.
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: ~Later you will add css selectors as regions to this file.
vendor/bin/behat -di
vendor/bin/behatSimple! You can introduce in your task runner and receive a nice report.
Translates each step in a PHP callback
When I run the banana example I get the code that I should write in the FeatureContext.phpuse 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; } ... }Regular expresions. Don't create phrases that are not meaningful to the user role.
/** * @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();Session: just a tab. Page: the DOM. e: element
/** * @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'); }Not only command the browser, execute js.
Stops the test.
Very good documentation.
One download and one command. Don't go full BDD. The most important pages. Use only the steps available.
Thank you. - http://docs.behat.org