I put on my mink and wizard behat (talk)
-
Upload
xsist10 -
Category
Technology
-
view
147 -
download
4
Transcript of I put on my mink and wizard behat (talk)
![Page 1: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/1.jpg)
I put on my mink and
wizard behatQuesting in the world of
front end testing
![Page 2: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/2.jpg)
Booking.com@thomas_shone
WE ARE HIRING
![Page 3: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/3.jpg)
Hoare Logic{P} C {Q}
![Page 4: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/4.jpg)
Hodor Logic{P} C {Q}
![Page 5: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/5.jpg)
Why?What's the benefit?
![Page 6: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/6.jpg)
Meet The PartyDon’t feed the druid after midnight
![Page 7: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/7.jpg)
TaskEach test has a different approach
![Page 8: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/8.jpg)
BarbarianQuality Assurance
![Page 9: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/9.jpg)
RangerUnit Test
![Page 10: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/10.jpg)
ClericContinuous Integration
![Page 11: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/11.jpg)
WizardFront End Test
![Page 12: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/12.jpg)
![Page 13: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/13.jpg)
Dreaded Bugbear
![Page 14: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/14.jpg)
Teamwork Wizards are squishy
![Page 15: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/15.jpg)
The glue
Behat(cucumber syntax)
Mink(browser emulation)
Goutte(web driver)
Selenium(web driver)
Zombie(web driver)
Guzzle(curl)
Selenium RC(java)
Zombie.js(node.js)
![Page 16: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/16.jpg)
Feature: Party harmonyAs a leader, I want to ensure harmony and mutual trust, so that we work as a team
Scenario: Teach members to respect others’ property Given that the Wizard has 10 cookies And the Bard eats 1 cookie Then the Bard is mysteriously on fire
Cucumber SyntaxReadable testing language
![Page 17: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/17.jpg)
class FeatureContext … {/** * @Given that the wizard has :num cookies */public function wizardHasCookies($num) {
// $this->wizard is a pre-existing condition... like syphilis$this->wizard->setNumberOfCookies($num);
}}
and converts it intoFeatureContext.php
![Page 18: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/18.jpg)
Feature: Party harmonyAs a leader, I want to ensure harmony and mutual trust, so that we work as a team
Scenario: Teach members to respect others’ property Given that the Wizard has 10 cookies And the Bard eats 1 cookie Then the Bard is mysteriously on fire
Cucumber SyntaxWhat’s missing?
![Page 19: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/19.jpg)
Scenario:Given that the wizard has 10 cookiesAnd the Bard eats 1 cookie
# The triggered fire spell fizzled due to OutOfManaExceptionThen the Bard is mysteriously on fire
1 scenario (1 failed)3 steps (2 passed, 1 failed)0m0.03s (14.19Mb)
Remember {P} C {Q}Set your starting states
![Page 20: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/20.jpg)
Feature: Party harmonyAs a leader, I want to ensure harmony and mutual trust, so that we work as a team
Background:The Wizard’s fire spell is fully chargedAnd the Bard is currently not on fire
Scenario: Teach members to respect others’ property Given that the Wizard has 10 cookies And the Bard eats 1 cookie Then the Bard is mysteriously on fire
Remember {P} C {Q}Set your starting states
![Page 21: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/21.jpg)
???As a leader, I want to ensure harmony and
mutual trust, so that we work as a team
![Page 22: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/22.jpg)
User storiesAs a <role>, I want to <desire> so that
<benefit>
![Page 23: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/23.jpg)
Features are your contract with the stakeholders
User storiesFeatures
Backgrounds are your restrictions or global constraints
Background
Scenarios are the use cases that outline the user story
Scenarios
![Page 24: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/24.jpg)
Front end testing is “code coverage” for
your user stories
![Page 25: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/25.jpg)
Legend has it...… that someone once convinced their PO to
write all their front end tests.
![Page 26: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/26.jpg)
class MinkContext … {/** * Clicks link with specified id|title|alt|text. *
* @When /^(?:|I )follow "(?P<link>(?:[^"]|\\")*)"$/ */public function clickLink($link) {
$link = $this->fixStepArgument($link); $this->getSession()->getPage()->clickLink($link); }}
Mink provides...MinkContext.php
![Page 27: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/27.jpg)
OK...Dropping the party
![Page 28: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/28.jpg)
https://github.com/opencfp/opencfp
![Page 29: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/29.jpg)
$ composer require behat/behat="~3.0,>=3.0.5"
Getting started
$ composer require behat/mink-extension="~2.0"
Behat (cucumber syntax)
Mink (browser emulator)
Web drivers$ composer require behat/mink-goutte-driver="~1.0"$ composer require behat/mink-selenium2-driver="~1.2"
![Page 30: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/30.jpg)
$ ./vendor/bin/behat --init
+d features - place your *.feature files here+d features/bootstrap - place your context classes here+f features/bootstrap/FeatureContext.php - place your definitions, transformations and hooks here
InitializeCreate a new test suite
![Page 31: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/31.jpg)
use Behat\MinkExtension\Context\MinkContext;
class FeatureContext extends MinkContext … {…
}
ContextFeatureContext.php
![Page 32: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/32.jpg)
$ ./vendor/bin/behat -dl
Given /^(?:|I )am on "(?P<page>[^"]+)"$/ When /^(?:|I )reload the page$/ When /^(?:|I )move backward one page$/ When /^(?:|I )move forward one page$/ When /^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/ When /^(?:|I )follow "(?P<link>(?:[^"]|\\")*)"$/ When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/
ContextWhat does Mink bring to the table?
![Page 33: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/33.jpg)
default: suites: default: paths: [ %paths.base%/features/ ] contexts: [ FeatureContext ] extensions: Behat\MinkExtension: base_url: "[your website]" sessions: default: goutte: ~
Configurationbehat.yml
![Page 34: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/34.jpg)
Feature: Authentication and authorisationAs a security conscious developer I wish to ensure that only valid users can access our website.
Scenario: Attempt to login with invalid details Given I am on "/login"
When I fill in "email" with "[email protected]" And I fill in "password" with "invalid" And I press "Login" Then I should see "Invalid Email or Password"
Our first featureauth.feature
![Page 35: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/35.jpg)
$ ./vendor/bin/behat --config behat.yml features/auth.feature
Scenario: Attempt to login with an invalid accountGiven I am on "/login"When I fill in "email" with "[email protected]"And I fill in "password" with "invalid"And I press "Login"Then I should see "Invalid Email or Password"
1 scenarios (1 passed)5 steps (5 passed)
Victoryoutput
![Page 36: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/36.jpg)
Feature: Authentication and authorisationAs a security conscious developer I wish to ensure that only valid users can access our website.
Scenario: Attempt to login with invalid details Given I login as "[email protected]" with password "invalid" Then I should see "Invalid Email or Password"
Simplifyauth.feature
![Page 37: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/37.jpg)
Scenario: Attempt to login with an invalid accountGiven I login as "[email protected]" with password "invalid"Then I should see "Invalid Email or Password"
1 scenario (1 undefined) /** * @Given I login as :arg1 with password :arg2 */
public function iLoginAsWithPassword($arg1, $arg2) { throw new PendingException();
}
Simplifyoutput
![Page 38: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/38.jpg)
class FeatureContext … {/**
* @Given I login as :username with password :password */
public function iLoginAsWithPassword($username, $password) {$this->visit("/login");$this->fillField("email", $username);$this->fillField("password", $password);$this->pressButton("Login");
}}
SimplifyFeatureContext.php
![Page 39: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/39.jpg)
Scenario: Attempt to login with an invalid accountGiven I login as "[email protected]" with password "invalid"Then I should see "Invalid Email or Password"
1 scenarios (1 passed)2 steps (2 passed)
Simplifyoutput
![Page 40: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/40.jpg)
Feature: Authentication and authorisationAs a security conscious developer I wish to ensure that only valid users can access our website.
Scenario: Attempt to register a new user Given I am on "/signup"
When I fill in "email" with "[email protected]" And I fill in "password" with "valid" And I fill in "password2" with "valid" And I fill in "first_name" with "some"
And I fill in "last_name" with "guy" And I press "Create my speaker profile" Then I should see "You’ve successfully created your account"
Our first hurdleThis ones easy, you do…. oh….
![Page 41: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/41.jpg)
Migration and seedingDoctrine, Propel, Laravel, Phinx
![Page 42: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/42.jpg)
Phinx to the rescue
SIDE NOTE
![Page 43: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/43.jpg)
$ composer require robmorgan/phinx="~0.4"
Phinx to the rescueInstall
$ php vendor/bin/phinx initPhinx by Rob Morgan - https://phinx.org. version 0.4.3Created ./phinx.xml
Configuration
$ php vendor/bin/phinx create InitialMigration
Creating
SIDE NOTE
![Page 44: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/44.jpg)
#!/usr/bin/env bashDATABASE="opencfp"mysql -e "DROP DATABASE IF EXISTS $DATABASE" -uroot -p123mysql -e "CREATE DATABASE $DATABASE" -uroot -p123vendor/bin/phinx migratevendor/bin/behat
A bit extreme?run-behat-tests.sh
![Page 45: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/45.jpg)
SAVEPOINT identifier;
# Run tests
ROLLBACK TO SAVEPOINT identifier;RELEASE SAVEPOINT identifier;
Transaction/RollbackRoll your own solution
![Page 46: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/46.jpg)
Activation emails?smtp-sink, FakeSMTP, etc
![Page 47: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/47.jpg)
# Stop the currently running servicesudo service postfix stop# Dumps outgoing emails to file as "day.hour.minute.second"smtp-sink -d "%d.%H.%M.%S" localhost:2500 1000 &
vendor/bin/behat
smtp-sinkrun-behat-test.sh
![Page 48: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/48.jpg)
Or….actually send the email and read it via SMTP
![Page 49: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/49.jpg)
Or….you could just read the activation code from
the database directly
![Page 50: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/50.jpg)
class DatabaseContext {public function __construct($dsn, $user, $pass) {
$this->dbh = new PDO($dsn, $user, $pass);}/** * @When /^there is no user called :user$/ */public function removeUser($user) {
$this->dbh->prepare("DELETE FROM `users` WHERE username=?")->query([$user]);
}}
A new contextDatabaseContext.php
SIDE NOTE
![Page 51: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/51.jpg)
default: suites: default: paths: [ %paths.base%/features/ ] contexts:
- FeatureContext- DatabaseContext:
- mysql:host=localhost;dbname=opencfp- root- 123
Configurationbehat.yml
SIDE NOTE
![Page 52: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/52.jpg)
How far is too far?What are your priorities?
![Page 53: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/53.jpg)
Taking it too farThis one is actually a true story
![Page 54: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/54.jpg)
// Make sure your server and your behat client have the same time set// Share the secret key between the two. The code should be valid for// 30 second periods$code = sha1($secret_key . floor(time() / 30));if ($request->get("code") === $code) {
// Bypass captcha}
Easier waySimple but safe bypass
![Page 55: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/55.jpg)
Our first talkSet the stage
Feature: Manage paper submissionsIn order to ensure that speakers can submit their papersAs an speaker I need to be able to manage my own submissions
Background:There is a speaker registered as "[email protected]" with a
password "secrets"I login as "[email protected]" with password "secrets"
Scenario: Add a new talk to our submissions...
![Page 56: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/56.jpg)
Our first talkTalk submission in 3, 2, 1...
Scenario: Add a new talk to our submissionsGiven I am on "talk/create"And I fill in the following: | title | Behat Talk | | description | Awesome | | type | regular | | category | testing |
| level | mid |And I check "desired"And I press "Submit my talk!"Then I should see "Success: Successfully added talk."
![Page 57: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/57.jpg)
Tyranny of JavaScriptDeleting a talk
![Page 58: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/58.jpg)
Well that won’t worktalks.feature
Feature: Manage paper submissions In order to ensure that speakers can submit their papers As an speaker I need to be able to manage my own submissions
Scenario: Delete a talkGiven create a talk called "Behat Talk"And I am on "/dashboard"When I follow "Delete"And I should not see "Behat Talk Changed"
The text "Behat Talk Changed" appears in the text of this page, but it should not. (Behat\Mink\Exception\ResponseTextException)
![Page 59: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/59.jpg)
// Guzzle using web scraperbehat/mink-goutte-driver
// Java-based distributed browser workers (support JavaScript)behat/mink-selenium2-driverbehat/mink-sahi-driver
// node.js headless browser proxy (support JavaScript)behat/mink-zombie-driver
DriversSome take the scenic route
![Page 60: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/60.jpg)
default: # … extensions: Behat\MinkExtension: base_url: "[your website]" sessions: default: goutte: ~ javascript: selenium2: ~
ConfigurationSetting up for Selenium
![Page 61: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/61.jpg)
$ java -jar selenium-server-standalone-2.*.jar
Selenium
@javascriptFeature: Manage paper submissions In order to ensure that speakers can submit their papers As an speaker I need to be able to manage my own submissions
Start Selenium Server
Specify javascript requirement
![Page 62: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/62.jpg)
$ ./vendor/bin/behat --tags speaker,talk
TagsRun specific tags
@speakerFeature: Manage paper submissions In order to ensure that speakers can submit their papers As an speaker I need to be able to manage my own submissions
@talk Scenario: Create a new talk Given I am logged in as a speaker ...
SIDE NOTE
![Page 63: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/63.jpg)
Feature: Submitting and managing talks As a speaker I wish be able to submit talks so I can get a chance to talk at a conference.
@javascript Scenario: Delete a talk
Given create a talk called "Behat Talk"And I am on "/dashboard"When I fill "Delete"And I accept alertsAnd I should not see "Behat Talk"
Enable JavaScripttalks.feature
![Page 64: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/64.jpg)
Run as JavaScripttalks.feature
Feature: Submitting and managing talks As a speaker I wish be able to submit talks so I can get a chance to talk at a conference.
Scenario: Delete a talkGiven create a talk called "Behat Talk"And I am on "/dashboard"When I follow "Delete"And I accept alertsAnd I should not see "Behat Talk"
![Page 65: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/65.jpg)
Advanced Usagewith extra bells and whistles
![Page 66: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/66.jpg)
class MemoryContext {/**
* @Transform /^memory:(.*)$/ */
public function fromMemory($key) { if (!isset($this->memory[$key])) { throw new LogicException("Entry $key does not exist"); }
return $this->memory[$key];}
}
TransformationsMemoryContext.php
![Page 67: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/67.jpg)
class FeatureContext … {public function takeAScreenshotCalled($filename) { $driver = get_class($this->getSession()->getDriver());
if ($driver == 'Behat\Mink\Driver\Selenium2Driver') {$ss = $this->getSession()
->getDriver()->getScreenshot();
file_put_contents($filename, $ss);}
}}
ScreenshotFeatureContext.php
![Page 68: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/68.jpg)
use Behat\Behat\Hook\Scope\AfterFeatureScope; // @AfterFeature \AfterScenarioScope; // @AfterScenario \AfterStepScope; // @AfterStep \BeforeFeatureScope; // @BeforeFeature \BeforeScenarioScope; // @BeforeScenario \BeforeStepScope; // @BeforeStep \FeatureScope; // @Feature \ScenarioScope; // @Scenario \StepScope; // @Step
HooksListen in close
![Page 69: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/69.jpg)
class FeatureContext … {/** * @AfterScenarioScope */public function afterScenario(AfterScenarioScope $scope) {
$scenario = $scope->getScenario()->getTitle();$filename = make_safe_filename($scenario);// Take a screenshot and put it on a dashboard// where people can see it
}}
HooksFeatureContext.php
![Page 70: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/70.jpg)
class FeatureContext … {/** * @AfterStep */public function afterStep(AfterStepScope $scope) {
$code = $event->getTestResult()->getResultCode();if ($code == TestResult::FAILED) {
// Take a screenshot}
}}
HooksFeatureContext.php
![Page 71: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/71.jpg)
Some days everything is made of glass
Common Gotchas
![Page 72: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/72.jpg)
Expect breakagesAnd that’s a good thing
![Page 73: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/73.jpg)
Speed vs CoverageFind the right balance
![Page 74: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/74.jpg)
Keep Selenium updatedBrowsers change faster than fashion trends
![Page 75: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/75.jpg)
Behat documentshttp://docs.behat.org points to v2.5 docs but
doesn’t tell you.Use http://docs.behat.org/en/v3.0/
![Page 76: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/76.jpg)
Questions?or ask me later via @thomas_shone
![Page 77: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/77.jpg)
Thank youPhoto from Flickr by John Morey, TrojanRat, Gerry Machen, USFS Region 5,
Peregrina Tyss and Thomas Hawk
![Page 78: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/78.jpg)
PermutationsThe reason why testing is painful
![Page 79: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/79.jpg)
default: suites: web: paths: [ %paths.base%/features/web ] contexts: [ BaseContext, WebContext ] api: paths: [ %paths.base%/features/api ] contexts: [ BaseContext, ApiContext ]
ConfigurationMultiple contexts
![Page 80: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/80.jpg)
default: suites: admin: paths: [ %paths.base%/features/web ] contexts: [ BaseContext, AdminContext ] filters: role: admin speaker: paths: [ %paths.base%/features/web ] contexts: [ BaseContext, SpeakerContext ] filters: tags: @speaker
ConfigurationGrouping and filtering
![Page 81: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/81.jpg)
$ ./vendor/bin/behat --suite admin
SuitesRun a specific suite
Feature: Managing the CFP In order to ensure that speakers can submit their papers As an admin I need to be able to open the call for papers
![Page 82: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/82.jpg)
$ ./vendor/bin/behat --suite speaker
SuitesRun a specific suite
@speakerFeature: Submitting to the CFP In order to ensure that the conference has papers As an speaker I need to be able to submit papers
![Page 83: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/83.jpg)
$ java -jar selenium-server-standalone-2.*.jar -role hub
Selenium Grid
$ java -jar selenium-server-standalone-2.*.jar -role node -hub http://[gridserver]:4444/grid/register
Start the grid
Add a node
![Page 84: I put on my mink and wizard behat (talk)](https://reader033.fdocuments.net/reader033/viewer/2022042608/55c097b4bb61ebef1c8b45ea/html5/thumbnails/84.jpg)
default: extensions: Behat\MinkExtension: sessions: javascript: selenium2: wd_host: "http://127.0.0.1:4444/wb/hub" capabilities: version: ""
ConfigurationBecause magic...