by your friend:
!
Ryan Weaver
@weaverryan
Behavioral Driven Development
with Behat
GrPhpDev FTW Meetup
KnpUniversity.com

github.com/weaverryan
• Lead for the Symfony documentation

!
• KnpLabs US - Symfony consulting, traini...
Plan, Work, Miscommunicate,
Panic, Put out Fires, Repeat!
Intro
(aka Project Work)
The Typical Project
How the customer explained it
http://www.projectcartoon.com
How the project leader understood it
http://www.projectcartoon.com
How the programmer wrote it
http://www.projectcartoon.com
What the customer really needed
http://www.projectcartoon.com
... and my personal favorite
What the beta testers received
http://www.projectcartoon.com
Computer Science?
https://www.flickr.com/photos/diueine/3604050776
Where it breaks down...
womp womp
Different roles,
different languages,
miscommunication
@weaverryan
One
@weaverryan
Two
Your code and business
values may not align
I've just dreamt up this
cool new feature that we
should implement!
!
Why? Because it's cool!
@weaverryan
Three
Over-planning, under-planning,
planning...?
https://www.flickr.com/photos/tambako/4175456498
Act 1
!
Getting down with BDD
Evolution of Test-Driven
Development
@weaverryan
“Behaviour” is a more
useful word, than “test”
© Dan North, 2003
@weaverryan
Evolution of Test-Driven
Development
≈ Unit Tests
≈ Functional
Tests
@weaverryan
Specification BDD
http://www.phpspec.net
Scenario-oriented BDD
(Story BDD)
@weaverryan
Let’s create a single
vocabulary and process
product
owners
business
analysts
project
managers
developers
QA
@weaverryan
product
owners
business
analysts
project
managers
developers
QA
... for planning, implementing,
and testing a ...
@weaverryan
product
owners
business
analysts
project
managers
developers
QA
... with a focus on the
*behavior* of the feat...
@weaverryan
Solution
1. Define business value for the features

2. Prioritize features by their business value

3. Describ...
Act 2
!
Gherkin
A project consists of
many features
@weaverryan
These need to be planned,
written and shared
@weaverryan
@weaverryan
Gherkin
==
a structured language to
describe a feature
Feature: {custom_title}	
In order to {A}	
As a {B}	
I need to {C}
• {A} - the benefit or value of the feature
• {B} - the ...
@weaverryan
Solution
1. Define
!
2. Prioritize
!
3. Describe
!
4. And only then -
1. Define business value for the features
Feature: I18n	
In order to read news in french	
As a french user	
I need to be able to switch locale
read news in French
@...
Feature: I18n	
In order to read news in french	
As a french user	
I need to be able to switch locale
read news in French
T...
Feature: I18n	
In order to read news in french	
As a french user	
I need to be able to switch locale
read news in French
T...
Feature: I18n	
In order to read news in french	
As a french user	
I need to be able to switch locale
read news in French
D...
@weaverryan
Solution
1. Define
!
2. Prioritize
!
3. Describe
!
4. And only then -
2. Prioritize features by their business...
Prioritize...
1) Feature: News admin panel	
!
2) Feature: I18n	
!
3) Feature: News list API
@weaverryan
1. Define
!
2. Prioritize
!
3. Describe
!
4. And only then -
Solution
3. Describe them with readable scenarios
Feature: News admin panel	
In order to maintain a list of news	
As a site administrator	
I need to be able to edit news
Sc...
Scenarios
Given
!
Defines the initial state of the system for the
scenario
Scenario: Add new article	
Given I am on the "/...
Scenarios
When
!
Describes the action taken by the person/role
Scenario: Add new article	
Given I am on the "/admin/news" ...
Scenarios
Then
!
Describes the observable system state after
the action has been performed
Scenario: Add new article	
Give...
Scenarios
And/But
!
Can be added to create multiple
Given/When/Then lines
Scenario: Add new article	
Given I am on the "/a...
Example #2
Scenario: List available articles	
Given there are 5 news articles	
And I am on the "/admin" page	
When I click...
Gherkin
gives us a consistent language
for describing features and
their scenarios
... now let’s turn them into
tests!
http://bit.ly/behatch-t
Act 3
Having a standard way of
describing features is cool...
... executing those sentences
as functional tests is just
*AWESOME*
@weaverryan
What is Behat?
Behat does one simple thing:
** each line in a scenario is called a “step”
Behat “executes” you...
Installing Behat
Behat is just a library that
can be installed easily in any
project via Composer
New to Composer? Free sc...
In your project directory...
1) Download Composer
$> curl -s http://getcomposer.org/installer | php
2) Create (or update) ...
{	
"require": {	
"behat/behat": "~3.0"	
}	
}
bit.ly/behat3-composer
In your project directory...
1) Download Composer
$> curl -s http://getcomposer.org/installer | php
2) Create (or update) ...
o/ Woo!
The most important product
of the installation is an
executable vendor/bin/behat
file
@weaverryan
To use Behat in a project you need:
!
!
1) Actual *.feature files to be executed

2) A FeatureContext.php file...
$> php vendor/bin/behat --init
<?php	
// features/bootstrap/FeatureContext.php



use BehatBehatContextSnippetAcceptingContext;

use BehatGherkinNodePySt...
<?php	
// features/bootstrap/FeatureContext.php



use BehatBehatContextSnippetAcceptingContext;

use BehatGherkinNodePySt...
Pretend you’re testing the
“ls” program
1) Describe your Feature
Feature: ls
features/ls.feature
In order to see the directory structure
As a UNIX user
I need to ...
2) Your First Scenario
“If you have two files in a directory,
and you're running the command -
you should see them listed.”
Scenario: List 2 files in a directory
Write in the natural voice of “a UNIX user”
Given I have a file named "foo"
And I ha...
3) Run Behat
$> php vendor/bin/behat
Behat tries
to find a
method in
FeatureContext
for each step
Matching is
done with
simple wildcards
For each step that
doesn’t have a matching
method, Behat prints
code to copy into
F...
class FeatureContext extends BehatContext	
{	
/** @Given I have a file named :file */

public function iHaveAFileNamed($fi...
5) Make the definitions do
what they need to
/**	
* @Given I have a file named :file	
*/	
public function iHaveAFileNamed($file) {	
touch($file);	
}	
!
/**	
* @Given I...
/**	
* @When I run :command	
*/	
public function iRun($command) {	
exec($command, $output);	
$this->output = trim(implode(...
See the full FeatureContext
class:
!
http://bit.ly/behat-ls-feature
Scenario Step
Definition
Given I have a file named “foo”
pattern
public function iHaveAFileNamed($file) {
do work
Pass/Fai...
Creating files and directories in
FeatureContext is nice...
but wouldn’t it be really cool
to command a browser, fill out
forms and check the output?
Act 4
!
Mink
https://www.flickr.com/photos/15016964@N02/5696367600
Mink!
http://mink.behat.org/
• A standalone library to use PHP to 

command a “browser”

• One easy API that can be used t...
A sample of Mink
use BehatMinkDriverGoutteDriver;	
use BehatMinkSession;	
!
// change *only* this line to run	
// in Selenium, etc	
$driver...
// visit a page	
$session->visit('http://behat.org');
echo 'URL : '.$session->getCurrentUrl();
echo 'Status: '.$session->g...
$page = $session->getPage();
// drill down into the page	
$ele = $page->find('css', 'li:nth-child(4) a');
echo 'Link text ...
Mink inside FeatureContext
=>
Dangerous Combo for
Functional Testing
http://mink.behat.org/@weaverryan
Behat Mink
Integration
MinkExtension
• An “Extension” is like a Behat plugin

• The Mink...
@weaverryan
Install Mink & MinkExtension
$> php composer.phar update
• Update composer.json to include
> Mink
> MinkExtens...
{	
"require": {	
"behat/behat": "~3.0",	
"behat/mink-extension": "~2.0@dev",	
"behat/mink-goutte-driver": "~1.0",	
"behat/...
Goal:
!
To easily use Mink inside
FeatureContext
@weaverryan
Bootstrap MinkExtension
behat.yml is the Behat configuration file and
can contain much more than you see here
...
@weaverryan
Extend MinkContext
use BehatMinkExtensionContextRawMinkContext;



/**

* Behat context class.

*/

class Feat...
Access to a Mink Session
class FeatureContext extends RawMinkContext	
{	
public function doSomething()	
{	
$session = $thi...
@weaverryan
More! Add MinkContext
# behat.yml

default:

extensions:	
# ...	
suites:

default:

contexts:

- FeatureContex...
We inherit a pile of great
definitions
the -dl option prints all current definitions
Before adding MinkContext:
After adding MinkContext:
In other words:
We can write some tests for
our app without writing any
PHP code
Suppose we’re testing
Wikipedia.org
# features/wikipedia.feature	
Feature: Search	
In order to see a word definition	
As a website user	
I need to be able to ...
Celebration!
Act 5
!
JavaScript
https://www.flickr.com/photos/yoanngd/10669976224
Let’s try another scenario
!
Auto-Completion!
# features/wikipedia.feature
Scenario: Searching for a page with autocompletion	
Given I am on "/wiki/Main_Page"	
When I f...
http://en.wikipedia.org/wiki/The_Scream
Can we run this so that
JavaScript works?
Add @javascript
# ...	
!
@javascript	
Scenario: Searching for a page with autocompletion	
Given I am on "/wiki/Main_Page"	...
Add @javascript
# ...	
!
@javascript	
Scenario: Searching for a page with autocompletion	
Given I am on "/wiki/Main_Page"	...
Download and start Selenium
$> wget http://selenium-
release.storage.googleapis.com/2.42/selenium-
server-standalone-2.42....
Re-run the tests
Yes, add only 1 line of code
to run a test in Selenium
(you can also use phantomjs)
Your Turn!
https://www.flickr.com/photos/dtelegraph/5907116936
0) Decide Behat 2 or 3
* Behat 3 is stable, and documentation

is decent (install + config are the big

differences)
!
* B...
1) Install Behat (v2)
http://knpuniversity.com/screencast/behat
... and learn more about what you can do
with Mink: http://mink.behat.org/
2) Write features for your app!
3) high-five your teammates
https://www.flickr.com/photos/nickwebb/3904325807
GrPhpDev FTW Meetup
Thanks!
Ryan Weaver
@weaverryan
KnpUniversity.com
PHP, Behat, Twig, OO, etc Tutorial Screencasts
Ryan Weaver
@weaverryan
... and we love west MI!
@weaverryan
KnpUniversity.com
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Upcoming SlideShare
Loading in...5
×

Grand Rapids PHP Meetup: Behavioral Driven Development with Behat

866

Published on

Testing our applications is something we all do. Ahem, rather, it's something we all *wish* we did. In this chat, I'll introduce you to Behat (behat.org) (version 3!!!!): a behavior-driven-development (BDD) library that allows you to write functional tests against your application just by writing human-readable sentences/scenarios. To sweeten the deal these tests can be run in a real browser (via Selenium2) with just the flip of a switch. If you asked me to develop without Behat, I'd just retire. It's that sweet. By the end, you'll have everything you need to start functionally-testing with Behat in your new, or very old and ugly project.

Published in: Technology

Grand Rapids PHP Meetup: Behavioral Driven Development with Behat

  1. 1. by your friend: ! Ryan Weaver @weaverryan Behavioral Driven Development with Behat GrPhpDev FTW Meetup
  2. 2. KnpUniversity.com github.com/weaverryan • Lead for the Symfony documentation ! • KnpLabs US - Symfony consulting, training, 
 Kumbaya ! • Writer for KnpUniversity.com screencasts Who is this Hipster? ! ! ! ! ! ! • Husband of the much more talented @leannapelham
  3. 3. Plan, Work, Miscommunicate, Panic, Put out Fires, Repeat! Intro (aka Project Work)
  4. 4. The Typical Project
  5. 5. How the customer explained it http://www.projectcartoon.com
  6. 6. How the project leader understood it http://www.projectcartoon.com
  7. 7. How the programmer wrote it http://www.projectcartoon.com
  8. 8. What the customer really needed http://www.projectcartoon.com
  9. 9. ... and my personal favorite
  10. 10. What the beta testers received http://www.projectcartoon.com
  11. 11. Computer Science? https://www.flickr.com/photos/diueine/3604050776
  12. 12. Where it breaks down... womp womp
  13. 13. Different roles, different languages, miscommunication @weaverryan One
  14. 14. @weaverryan Two Your code and business values may not align
  15. 15. I've just dreamt up this cool new feature that we should implement! ! Why? Because it's cool!
  16. 16. @weaverryan Three Over-planning, under-planning, planning...?
  17. 17. https://www.flickr.com/photos/tambako/4175456498 Act 1 ! Getting down with BDD
  18. 18. Evolution of Test-Driven Development @weaverryan
  19. 19. “Behaviour” is a more useful word, than “test” © Dan North, 2003
  20. 20. @weaverryan Evolution of Test-Driven Development ≈ Unit Tests ≈ Functional Tests
  21. 21. @weaverryan Specification BDD http://www.phpspec.net
  22. 22. Scenario-oriented BDD (Story BDD)
  23. 23. @weaverryan Let’s create a single vocabulary and process product owners business analysts project managers developers QA
  24. 24. @weaverryan product owners business analysts project managers developers QA ... for planning, implementing, and testing a feature
  25. 25. @weaverryan product owners business analysts project managers developers QA ... with a focus on the *behavior* of the feature
  26. 26. @weaverryan Solution 1. Define business value for the features
 2. Prioritize features by their business value
 3. Describe them with readable scenarios
 4. And only then - implement them
  27. 27. Act 2 ! Gherkin
  28. 28. A project consists of many features @weaverryan
  29. 29. These need to be planned, written and shared @weaverryan
  30. 30. @weaverryan Gherkin == a structured language to describe a feature
  31. 31. Feature: {custom_title} In order to {A} As a {B} I need to {C} • {A} - the benefit or value of the feature • {B} - the role (or person) who will benefit • {C} - short feature description | The person “writing” this feature - the “I”
  32. 32. @weaverryan Solution 1. Define ! 2. Prioritize ! 3. Describe ! 4. And only then - 1. Define business value for the features
  33. 33. Feature: I18n In order to read news in french As a french user I need to be able to switch locale read news in French @weaverryan
  34. 34. Feature: I18n In order to read news in french As a french user I need to be able to switch locale read news in French The business value @weaverryan
  35. 35. Feature: I18n In order to read news in french As a french user I need to be able to switch locale read news in French The person who benefits + The “author” of this feature @weaverryan
  36. 36. Feature: I18n In order to read news in french As a french user I need to be able to switch locale read news in French Description of the feature, the action the person will take @weaverryan
  37. 37. @weaverryan Solution 1. Define ! 2. Prioritize ! 3. Describe ! 4. And only then - 2. Prioritize features by their business value
  38. 38. Prioritize... 1) Feature: News admin panel ! 2) Feature: I18n ! 3) Feature: News list API
  39. 39. @weaverryan 1. Define ! 2. Prioritize ! 3. Describe ! 4. And only then - Solution 3. Describe them with readable scenarios
  40. 40. Feature: News admin panel In order to maintain a list of news As a site administrator I need to be able to edit news Scenario: Add new article Given I am on the "/admin/news" page When I click "New Article" And I fill in "Title" with "Learned BDD" And I press "Save" Then I should see "A new article was added"
  41. 41. Scenarios Given ! Defines the initial state of the system for the scenario Scenario: Add new article Given I am on the "/admin/news" page When I click "New Article" And I fill in "Title" with "Learned BDD" And I press "Save" Then I should see "A new article was added"
  42. 42. Scenarios When ! Describes the action taken by the person/role Scenario: Add new article Given I am on the "/admin/news" page When I click "New Article" And I fill in "Title" with "Learned BDD" And I press "Save" Then I should see "A new article was added"
  43. 43. Scenarios Then ! Describes the observable system state after the action has been performed Scenario: Add new article Given I am on the "/admin/news" page When I click "New Article" And I fill in "Title" with "Learned BDD" And I press "Save" Then I should see "A new article was added"
  44. 44. Scenarios And/But ! Can be added to create multiple Given/When/Then lines Scenario: Add new article Given I am on the "/admin/news" page When I click "New Article" And I fill in "Title" with "Learned BDD" And I press "Save" Then I should see "A new article was added"
  45. 45. Example #2 Scenario: List available articles Given there are 5 news articles And I am on the "/admin" page When I click "News Administration" Then I should see 5 news articles
  46. 46. Gherkin gives us a consistent language for describing features and their scenarios
  47. 47. ... now let’s turn them into tests!
  48. 48. http://bit.ly/behatch-t Act 3
  49. 49. Having a standard way of describing features is cool...
  50. 50. ... executing those sentences as functional tests is just *AWESOME*
  51. 51. @weaverryan What is Behat? Behat does one simple thing: ** each line in a scenario is called a “step” Behat “executes” your scenarios, reading each step and calling the function associated with it It Maps Each step** to a PHP Callback
  52. 52. Installing Behat Behat is just a library that can be installed easily in any project via Composer New to Composer? Free screencast cures it! KnpUniversity.com/screencast/composer
  53. 53. In your project directory... 1) Download Composer $> curl -s http://getcomposer.org/installer | php 2) Create (or update) composer.json for Behat bit.ly/behat3-composer!
  54. 54. { "require": { "behat/behat": "~3.0" } } bit.ly/behat3-composer
  55. 55. In your project directory... 1) Download Composer $> curl -s http://getcomposer.org/installer | php 2) Create (or update) composer.json for Behat http://bit.ly/behat3-composer 3) Download Behat libraries $> php composer.phar update
  56. 56. o/ Woo!
  57. 57. The most important product of the installation is an executable vendor/bin/behat file
  58. 58. @weaverryan To use Behat in a project you need: ! ! 1) Actual *.feature files to be executed
 2) A FeatureContext.php file that holds the PHP callbacks for each step
 3) (optional) A behat.yml configuration file
  59. 59. $> php vendor/bin/behat --init
  60. 60. <?php // features/bootstrap/FeatureContext.php
 
 use BehatBehatContextSnippetAcceptingContext;
 use BehatGherkinNodePyStringNode;
 use BehatGherkinNodeTableNode;
 
 /**
 * Behat context class.
 */
 class FeatureContext implements SnippetAcceptingContext
 {
 }

  61. 61. <?php // features/bootstrap/FeatureContext.php
 
 use BehatBehatContextSnippetAcceptingContext;
 use BehatGherkinNodePyStringNode;
 use BehatGherkinNodeTableNode;
 
 /**
 * Behat context class.
 */
 class FeatureContext implements SnippetAcceptingContext
 {
 }
 Nothing Interesting here yet...
  62. 62. Pretend you’re testing the “ls” program
  63. 63. 1) Describe your Feature Feature: ls features/ls.feature In order to see the directory structure As a UNIX user I need to be able to list the current directory's contents
  64. 64. 2) Your First Scenario “If you have two files in a directory, and you're running the command - you should see them listed.”
  65. 65. Scenario: List 2 files in a directory Write in the natural voice of “a UNIX user” Given I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should see "foo" in the output And I should see "bar" in the output features/ls.feature
  66. 66. 3) Run Behat $> php vendor/bin/behat
  67. 67. Behat tries to find a method in FeatureContext for each step
  68. 68. Matching is done with simple wildcards For each step that doesn’t have a matching method, Behat prints code to copy into FeatureContext
  69. 69. class FeatureContext extends BehatContext { /** @Given I have a file named :file */
 public function iHaveAFileNamed($file)
 {
 throw new PendingException();
 }
 
 /** @When I run :command */
 public function iRun($command)
 {
 throw new PendingException();
 } // ... } 4) Copy in the new Definitions Quoted text maps to a method argument
  70. 70. 5) Make the definitions do what they need to
  71. 71. /** * @Given I have a file named :file */ public function iHaveAFileNamed($file) { touch($file); } ! /** * @Given I have a directory named :dir */ public function iHaveADirectoryNamed($dir) { mkdir($dir); }
  72. 72. /** * @When I run :command */ public function iRun($command) { exec($command, $output); $this->output = trim(implode("n", $output)); } ! /** * @Then I should see :string in the output */ public function iShouldSeeInTheOutput($string) { if (strpos($this->output, $string) === false) { throw new Exception(‘Did not see’.$string); ); }
  73. 73. See the full FeatureContext class: ! http://bit.ly/behat-ls-feature
  74. 74. Scenario Step Definition Given I have a file named “foo” pattern public function iHaveAFileNamed($file) { do work Pass/Fail: Each step is a “test”, which passes *unless* an exception is thrown touch($file); @Given I have a file named :file What Behat *does*
  75. 75. Creating files and directories in FeatureContext is nice...
  76. 76. but wouldn’t it be really cool to command a browser, fill out forms and check the output?
  77. 77. Act 4 ! Mink https://www.flickr.com/photos/15016964@N02/5696367600
  78. 78. Mink! http://mink.behat.org/ • A standalone library to use PHP to 
 command a “browser”
 • One easy API that can be used to 
 command Selenium, Goutte, ZombieJS, etc @weaverryan
  79. 79. A sample of Mink
  80. 80. use BehatMinkDriverGoutteDriver; use BehatMinkSession; ! // change *only* this line to run // in Selenium, etc $driver = new GoutteDriver(); $session = new Session($driver);
  81. 81. // visit a page $session->visit('http://behat.org'); echo 'URL : '.$session->getCurrentUrl(); echo 'Status: '.$session->getStatusCode();
  82. 82. $page = $session->getPage(); // drill down into the page $ele = $page->find('css', 'li:nth-child(4) a'); echo 'Link text is: '.$ele->getText(); echo 'href is: '.$ele->getAttribute('href'); // click the link // (you can also fill out forms) $ele->click();
  83. 83. Mink inside FeatureContext => Dangerous Combo for Functional Testing
  84. 84. http://mink.behat.org/@weaverryan Behat Mink Integration MinkExtension • An “Extension” is like a Behat plugin
 • The MinkExtension makes using Mink 
 inside Behat a matter of configuration
  85. 85. @weaverryan Install Mink & MinkExtension $> php composer.phar update • Update composer.json to include > Mink > MinkExtension > Goutte and Selenium2 Drivers for Mink http://bit.ly/behat-mink-composer
 • Update the vendor libraries
  86. 86. { "require": { "behat/behat": "~3.0", "behat/mink-extension": "~2.0@dev", "behat/mink-goutte-driver": "~1.0", "behat/mink-selenium2-driver": "~1.1" } } http://bit.ly/behat-mink-composer
  87. 87. Goal: ! To easily use Mink inside FeatureContext
  88. 88. @weaverryan Bootstrap MinkExtension behat.yml is the Behat configuration file and can contain much more than you see here # behat.yml
 default:
 extensions:
 BehatMinkExtension:
 goutte: ~
 selenium2: ~
 # The base URL you're testing
 base_url: http://en.wikipedia.org/ http://bit.ly/behat-yml
  89. 89. @weaverryan Extend MinkContext use BehatMinkExtensionContextRawMinkContext;
 
 /**
 * Behat context class.
 */
 class FeatureContext extends RawMinkContext Extending RawMinkContext gives us...
  90. 90. Access to a Mink Session class FeatureContext extends RawMinkContext { public function doSomething() { $session = $this->getSession(); $session->visit('http://behat.org'); } ! // ... } Our custom definitions can now command a browser!
  91. 91. @weaverryan More! Add MinkContext # behat.yml
 default:
 extensions: # ... suites:
 default:
 contexts:
 - FeatureContext
 - BehatMinkExtensionContextMinkContext
 Behat now parses definitions from *our* class *and* this MinkContext class
  92. 92. We inherit a pile of great definitions the -dl option prints all current definitions Before adding MinkContext:
  93. 93. After adding MinkContext:
  94. 94. In other words: We can write some tests for our app without writing any PHP code
  95. 95. Suppose we’re testing Wikipedia.org
  96. 96. # features/wikipedia.feature Feature: Search In order to see a word definition As a website user I need to be able to search for a word These 4 definitions all come packaged with MinkContext Scenario: Searching for a page that does exist Given I am on "/wiki/Main_Page" When I fill in "search" with "Behavior Driven Development" And I press "searchButton" Then I should see "agile software development"
  97. 97. Celebration!
  98. 98. Act 5 ! JavaScript https://www.flickr.com/photos/yoanngd/10669976224
  99. 99. Let’s try another scenario ! Auto-Completion!
  100. 100. # features/wikipedia.feature Scenario: Searching for a page with autocompletion Given I am on "/wiki/Main_Page" When I fill in "search" with "Behavior Driv" Then I should see "Behavior Driven Development"
  101. 101. http://en.wikipedia.org/wiki/The_Scream
  102. 102. Can we run this so that JavaScript works?
  103. 103. Add @javascript # ... ! @javascript Scenario: Searching for a page with autocompletion Given I am on "/wiki/Main_Page" When I fill in "search" with "Behavior Driv" Then I should see "Behavior Driven Development” ! ! !
  104. 104. Add @javascript # ... ! @javascript Scenario: Searching for a page with autocompletion Given I am on "/wiki/Main_Page" When I fill in "search" with "Behavior Driv" Then I should see "Behavior Driven Development” ! ! ! Yep, that’s all you do!
  105. 105. Download and start Selenium $> wget http://selenium- release.storage.googleapis.com/2.42/selenium- server-standalone-2.42.2.jar ! ! $> java -jar selenium-server-standalone-2.42.2.jar
  106. 106. Re-run the tests
  107. 107. Yes, add only 1 line of code to run a test in Selenium
  108. 108. (you can also use phantomjs)
  109. 109. Your Turn! https://www.flickr.com/photos/dtelegraph/5907116936
  110. 110. 0) Decide Behat 2 or 3 * Behat 3 is stable, and documentation
 is decent (install + config are the big
 differences) ! * Behat 2 is stable, long-term supported and not too different from 3
  111. 111. 1) Install Behat (v2) http://knpuniversity.com/screencast/behat
  112. 112. ... and learn more about what you can do with Mink: http://mink.behat.org/ 2) Write features for your app!
  113. 113. 3) high-five your teammates https://www.flickr.com/photos/nickwebb/3904325807
  114. 114. GrPhpDev FTW Meetup Thanks! Ryan Weaver @weaverryan KnpUniversity.com PHP, Behat, Twig, OO, etc Tutorial Screencasts
  115. 115. Ryan Weaver @weaverryan ... and we love west MI!
  116. 116. @weaverryan KnpUniversity.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×