behavioral driven development with behatdrupalnights.org/sites/default/files/events... ·...
TRANSCRIPT
![Page 1: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/1.jpg)
by your friend:
Ryan Weaver@weaverryan
Behavioral Driven Development with Behat
Thursday, May 23, 13
![Page 2: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/2.jpg)
Who is this Hipster?
• The Symfony “Docs” guy
• KnpLabs US - Symfony consulting, training, Kumbaya
• Writer for KnpUniversity.comscreencasts
knplabs.comgithub.com/weaverryan@weaverryan
Thursday, May 23, 13
![Page 3: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/3.jpg)
Who is this Hipster?
• The Symfony “Docs” guy
• KnpLabs US - Symfony consulting, training, Kumbaya
• Writer for KnpUniversity.comscreencasts
• Husband of the much more talented @leannapelham
knplabs.comgithub.com/weaverryan@weaverryan
Thursday, May 23, 13
![Page 4: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/4.jpg)
Plan, Work, Miscommunicate, Panic, Put out Fires, Repeat!
Intro
http://www.flickr.com/photos/lifeontheedge/416514144/
(aka Project Work)
Thursday, May 23, 13
![Page 5: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/5.jpg)
The Typical Project
Thursday, May 23, 13
![Page 6: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/6.jpg)
How the customer explained it
http://www.projectcartoon.comThursday, May 23, 13
![Page 7: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/7.jpg)
How the project leader understood it
http://www.projectcartoon.comThursday, May 23, 13
![Page 8: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/8.jpg)
How the programmer wrote it
http://www.projectcartoon.comThursday, May 23, 13
![Page 9: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/9.jpg)
What the customer really needed
http://www.projectcartoon.comThursday, May 23, 13
![Page 10: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/10.jpg)
... and my personal favorite
Thursday, May 23, 13
![Page 11: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/11.jpg)
What the beta testers received
http://www.projectcartoon.comThursday, May 23, 13
![Page 12: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/12.jpg)
Computer Science?
Thursday, May 23, 13
![Page 13: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/13.jpg)
Where it breaks down...
Thursday, May 23, 13
![Page 14: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/14.jpg)
Different roles, different languages, miscommunication
@weaverryan
1
Thursday, May 23, 13
![Page 15: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/15.jpg)
2
Your code and businessvalues may not align
@weaverryanThursday, May 23, 13
![Page 16: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/16.jpg)
I've just dreamt up this cool new feature that we should implement!
Why? Because it's cool!
Thursday, May 23, 13
![Page 17: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/17.jpg)
3
Over-planning, under-planning,planning...?
@weaverryanThursday, May 23, 13
![Page 18: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/18.jpg)
Act 1
Getting down with BDD
Thursday, May 23, 13
![Page 19: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/19.jpg)
@weaverryan
Evolution of Test-Driven Development
Thursday, May 23, 13
![Page 20: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/20.jpg)
“Behaviour” is a more useful word, than “test”
© Dan North, 2003Thursday, May 23, 13
![Page 21: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/21.jpg)
@weaverryan
Evolution of Test-Driven Development
≈ Unit Tests
≈ Functional Tests
Thursday, May 23, 13
![Page 22: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/22.jpg)
@weaverryan
Specification BDD
http://www.phpspec.netThursday, May 23, 13
![Page 23: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/23.jpg)
Scenario-oriented BDD(Story BDD)
Thursday, May 23, 13
![Page 24: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/24.jpg)
Let’s create a single vocabulary and process
product owners
business analysts
project managers
developers QA
Thursday, May 23, 13
![Page 25: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/25.jpg)
... for planning, implementing, and testing a feature
product owners
business analysts
project managers
developers QA
Thursday, May 23, 13
![Page 26: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/26.jpg)
... with a focus on the *behavior* of the feature
product owners
business analysts
project managers
developers QA
Thursday, May 23, 13
![Page 27: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/27.jpg)
@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
Thursday, May 23, 13
![Page 28: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/28.jpg)
Act 2
Gherkin
Thursday, May 23, 13
![Page 29: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/29.jpg)
A project consists of many features
Thursday, May 23, 13
![Page 30: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/30.jpg)
These need to be planned, written and shared
Thursday, May 23, 13
![Page 31: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/31.jpg)
Gherkin==
a structured language to describe a feature
Thursday, May 23, 13
![Page 32: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/32.jpg)
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”
Thursday, May 23, 13
![Page 33: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/33.jpg)
@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
1. Define business value for the features
Thursday, May 23, 13
![Page 34: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/34.jpg)
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
Thursday, May 23, 13
![Page 35: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/35.jpg)
Feature: I18n In order to read news in french As a french user I need to be able to switch locale
read news in FrenchThe business value
Thursday, May 23, 13
![Page 36: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/36.jpg)
Feature: I18n In order to read news in french As a french user I need to be able to switch locale
read news in FrenchThe person who benefits
+The “author” of this feature
Thursday, May 23, 13
![Page 37: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/37.jpg)
Feature: I18n In order to read news in french As a french user I need to be able to switch locale
read news in FrenchDescription of the feature, the
action the person will take
Thursday, May 23, 13
![Page 38: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/38.jpg)
@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
2. Prioritize features by their business value
Thursday, May 23, 13
![Page 39: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/39.jpg)
prioritize...
1) Feature: News admin panel
2) Feature: I18n
3) Feature: News list API
Thursday, May 23, 13
![Page 40: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/40.jpg)
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
@weaverryan
Solution
3. Describe them with readable scenarios
Thursday, May 23, 13
![Page 41: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/41.jpg)
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"
Thursday, May 23, 13
![Page 42: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/42.jpg)
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"
Thursday, May 23, 13
![Page 43: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/43.jpg)
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"
Thursday, May 23, 13
![Page 44: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/44.jpg)
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"
Thursday, May 23, 13
![Page 45: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/45.jpg)
Scenarios
And/But
Can be added to create multipleGiven/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"
Thursday, May 23, 13
![Page 46: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/46.jpg)
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
Thursday, May 23, 13
![Page 47: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/47.jpg)
Gherkingives us a consistent language
for describing features and their scenarios
Thursday, May 23, 13
![Page 48: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/48.jpg)
... now let’s turn them into tests!
Thursday, May 23, 13
![Page 49: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/49.jpg)
Act 3
t-shirt: http://bit.ly/behatch-tThursday, May 23, 13
![Page 50: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/50.jpg)
Having a standard way of describing features is cool...
Thursday, May 23, 13
![Page 51: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/51.jpg)
... executing those sentences as functional tests is just
awesome
Thursday, May 23, 13
![Page 52: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/52.jpg)
@weaverryan
What is Behat?
Behat does one simple thing:
It Maps Each step** to a PHP Callback
** each line in a scenario is called a “step”
Behat “executes” your scenarios, reading each step and calling the function associated with it
Thursday, May 23, 13
![Page 53: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/53.jpg)
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
Thursday, May 23, 13
![Page 54: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/54.jpg)
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/behat-composer
Thursday, May 23, 13
![Page 55: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/55.jpg)
{ "require": { "behat/behat": "2.4.*@stable" }, "minimum-stability": "dev", "config": { "bin-dir": "bin/" }}
http://bit.ly/behat-composerThursday, May 23, 13
![Page 56: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/56.jpg)
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/behat-composer
3) Download Behat libraries
$> php composer.phar install
Thursday, May 23, 13
![Page 57: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/57.jpg)
\o/ Woo!
Thursday, May 23, 13
![Page 58: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/58.jpg)
The most important product of the installation is an
executable bin/behat file
Thursday, May 23, 13
![Page 59: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/59.jpg)
Thursday, May 23, 13
![Page 60: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/60.jpg)
@weaverryan
Behat in a project
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
Thursday, May 23, 13
![Page 61: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/61.jpg)
$> php bin/behat --init
Thursday, May 23, 13
![Page 62: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/62.jpg)
<?php// features/bootstrap/FeatureContext.php
use Behat\Behat\Context\BehatContext, Behat\Behat\Exception\PendingException;
class FeatureContext extends BehatContext{}
Thursday, May 23, 13
![Page 63: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/63.jpg)
<?php// features/bootstrap/FeatureContext.php
use Behat\Behat\Context\BehatContext, Behat\Behat\Exception\PendingException;
class FeatureContext extends BehatContext{}
Nothing Interesting here yet...
Thursday, May 23, 13
![Page 64: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/64.jpg)
Pretend you’re testing the “ls” program
Thursday, May 23, 13
![Page 65: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/65.jpg)
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
Thursday, May 23, 13
![Page 66: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/66.jpg)
2) Your First Scenario
“If you have two files in a directory, and you're running the command -
you should see them listed.”
Thursday, May 23, 13
![Page 67: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/67.jpg)
2) Write Your First Scenario
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
Thursday, May 23, 13
![Page 68: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/68.jpg)
3) Run Behat
$> php bin/behat
Thursday, May 23, 13
![Page 69: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/69.jpg)
Behat triesto find a
method in FeatureContext for each step
Thursday, May 23, 13
![Page 70: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/70.jpg)
Matching is done via regex
For each step that doesn’t have a matching
method, Behat prints code to copy into FeatureContext
Thursday, May 23, 13
![Page 71: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/71.jpg)
class FeatureContext extends BehatContext{ /** @Given /^I have a file named "([^"]*)"$/ */ public function iHaveAFileNamed($arg1) { throw new PendingException(); }
/** @When /^I run "([^"]*)"$/ */ public function iRun($arg1) { throw new PendingException(); } // ...}
4) Copy in the new Definitions
Quoted text maps to a method
argument
Thursday, May 23, 13
![Page 72: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/72.jpg)
5) Make the definitions do what they need to
Thursday, May 23, 13
![Page 73: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/73.jpg)
/** * @Given /^I have a file named "([^"]*)"$/ */public function iHaveAFileNamed($file) { touch($file);}
/** * @Given /^I have a directory named "([^"]*)"$/ */public function iHaveADirectoryNamed($dir) { mkdir($dir);}
Thursday, May 23, 13
![Page 74: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/74.jpg)
/** * @When /^I run "([^"]*)"$/ */public function iRun($command) { exec($command, $output); $this->output = trim(implode("\n", $output));}
/** * @Then /^I should see "([^"]*)" in the output$/ */public function iShouldSeeInTheOutput($string) { assertContains( $string, explode("\n", $this->output) );}
Thursday, May 23, 13
![Page 75: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/75.jpg)
Thursday, May 23, 13
![Page 76: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/76.jpg)
Thursday, May 23, 13
![Page 77: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/77.jpg)
Thursday, May 23, 13
![Page 78: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/78.jpg)
Thursday, May 23, 13
![Page 79: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/79.jpg)
See the full FeatureContext class:
http://bit.ly/behat-ls-feature
Thursday, May 23, 13
![Page 80: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/80.jpg)
Scenario Step
Definition
Given I have a file named “foo”
regex
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 "([^"]*)"$/
What Behat *does*
Thursday, May 23, 13
![Page 81: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/81.jpg)
Creating files and directories in FeatureContext is nice...
Thursday, May 23, 13
![Page 82: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/82.jpg)
but wouldn’t it be really cool to command a browser, fill out forms and check the output?
Thursday, May 23, 13
![Page 83: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/83.jpg)
Act 4
Mink
Thursday, May 23, 13
![Page 84: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/84.jpg)
@weaverryan
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
Thursday, May 23, 13
![Page 85: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/85.jpg)
A sample of Mink
Thursday, May 23, 13
![Page 86: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/86.jpg)
use Behat\Mink\Driver\GoutteDriver;use Behat\Mink\Session;
// change *only* this line to run// in Selenium, etc$driver = new GoutteDriver();$session = new Session($driver);
Thursday, May 23, 13
![Page 87: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/87.jpg)
// visit a page$session->visit('http://behat.org');
echo 'URL : '.$session->getCurrentUrl();
echo 'Status: '.$session->getStatusCode();
Thursday, May 23, 13
![Page 88: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/88.jpg)
$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();
Thursday, May 23, 13
![Page 89: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/89.jpg)
Mink inside FeatureContext=>
Dangerous Combo for Functional Testing
Thursday, May 23, 13
![Page 90: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/90.jpg)
@weaverryan
Behat
http://mink.behat.org/
Mink
Integration
MinkExtension
• An “Extension” is like a Behat plugin
• The MinkExtension makes using Mink inside Behat a matter of configuration
Thursday, May 23, 13
![Page 91: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/91.jpg)
@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
Thursday, May 23, 13
![Page 92: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/92.jpg)
{ "require": { "behat/mink": "1.4@stable", "behat/mink-goutte-driver": "*", "behat/mink-selenium2-driver": "*", "behat/behat": "2.4@stable", "behat/mink-extension": "*" }, "minimum-stability": "dev", "config": { "bin-dir": "bin/" }} http://bit.ly/behat-mink-composer
Thursday, May 23, 13
![Page 93: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/93.jpg)
Goal: To easily use Mink inside FeatureContext
Thursday, May 23, 13
![Page 94: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/94.jpg)
@weaverryan
Bootstrap MinkExtension
behat.yml is the Behat configuration file and can contain much more than you see here
# behat.ymldefault: extensions: Behat\MinkExtension\Extension: goutte: ~ selenium2: ~ # The base URL to app you're testing base_url: http://en.wikipedia.org/
http://bit.ly/behat-ymlThursday, May 23, 13
![Page 95: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/95.jpg)
@weaverryan
Extend MinkContext
use Behat\MinkExtension\Context\MinkContext;
class FeatureContext extends MinkContext
Extending MinkContext gives us 2 things...
Thursday, May 23, 13
![Page 96: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/96.jpg)
1) Access to a Mink Sessionclass FeatureContext extends MinkContext{ public function doSomething() { $session = $this->getSession(); $session->visit('http://behat.org'); }
// ...}
Our custom definitions can nowcommand a browser!
Thursday, May 23, 13
![Page 97: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/97.jpg)
2) We inherit a pile of great definitions
the -dl option prints all current definitions
Before extending MinkContext:
Thursday, May 23, 13
![Page 98: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/98.jpg)
After extending MinkContext:
Thursday, May 23, 13
![Page 99: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/99.jpg)
In other words:We can write some tests for our app without writing any
PHP code
Thursday, May 23, 13
![Page 100: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/100.jpg)
Suppose we’re testing Wikipedia.org
Thursday, May 23, 13
![Page 101: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/101.jpg)
# features/wikipedia.featureFeature: 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"
Thursday, May 23, 13
![Page 102: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/102.jpg)
Celebration!
Thursday, May 23, 13
![Page 103: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/103.jpg)
Act 5
Behat in your application
Thursday, May 23, 13
![Page 104: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/104.jpg)
@weaverryan
Getting “under the hood”
• So far, we can do true “black-box” testing - using Mink to test any website (e.g. wikipedia)
• But if we’re testing our app, we don’t have access to it, we can’t:
a) access/clear/prepare the database b) use any code in our application
Thursday, May 23, 13
![Page 105: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/105.jpg)
When testing: you should guarantee the starting
condition of your environment
Thursday, May 23, 13
![Page 106: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/106.jpg)
How can we add nodes, add users, and configure
permissions from inside Behat?
Thursday, May 23, 13
![Page 107: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/107.jpg)
@weaverryan
Behat in your app
1) Install Behat, Mink, MinkExtension http://bit.ly/behat-mink-composer
2) ??? Gain access to Drupal in Behat ???
3) Create nodes, users, etc so that you’re testing against a predictable dataset
Thursday, May 23, 13
![Page 108: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/108.jpg)
Introducing...
Thursday, May 23, 13
![Page 109: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/109.jpg)
... a library made by the Drupal community ...
Thursday, May 23, 13
![Page 110: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/110.jpg)
... which I did not help with ...
Thursday, May 23, 13
![Page 111: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/111.jpg)
DrupalExtension!
http://bit.ly/drupal-extension
A plugin (extension) for Behat and Drupal
Thursday, May 23, 13
![Page 112: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/112.jpg)
@weaverryan
DrupalExtension
2) Build nodes, add users, manage permissions inside Behat
3) Operating within Regions
4) Hooks to load more sentences/definitions from contrib modules
1) Even more built-in sentences/definitions
Thursday, May 23, 13
![Page 113: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/113.jpg)
Background: Given I am logged in as a user with the "administrator" role
Scenario: Edit Node Given I am viewing a "page" node with the title "Cool beans!" When I click "Edit" in the "Body" region And I fill in the following: | Body | Ipsumm | And I press "Save" Then I should see "Ipsumm" in the "Body" region
# features/node_manage.feature
Thursday, May 23, 13
![Page 114: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/114.jpg)
Background: Given I am logged in as a user with the "administrator" role
Scenario: Edit Node Given I am viewing a "page" node with the title "Cool beans!" When I click "Edit" in the "Body" region And I fill in the following: | Body | Ipsumm | And I press "Save" Then I should see "Ipsumm" in the "Body" region
Creates a user and adds a role to it
Thursday, May 23, 13
![Page 115: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/115.jpg)
Background: Given I am logged in as a user with the "administrator" role
Scenario: Edit Node Given I am viewing a "page" node with the title "Cool beans!" When I click "Edit" in the "Body" region And I fill in the following: | Body | Ipsumm | And I press "Save" Then I should see "Ipsumm" in the "Body" region
Creates a “page” node in the database
Thursday, May 23, 13
![Page 116: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/116.jpg)
Background: Given I am logged in as a user with the "administrator" role
Scenario: Edit Node Given I am viewing a "page" node with the title "Cool beans!" When I click "Edit" in the "Body" region And I fill in the following: | Body | Ipsumm | And I press "Save" Then I should see "Ipsumm" in the "Body" region
Looks for the text in a CSS region you’ve defined as “Body”
Thursday, May 23, 13
![Page 117: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/117.jpg)
And it’s alive!
Thursday, May 23, 13
![Page 118: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/118.jpg)
The 3 Modes of the DrupalExtension
1) blackbox: test an external server, no access to the database2) drupal: Bootstraps Drupal’s code and calls functions3) drush: Interacts with Drupal via drush
Thursday, May 23, 13
![Page 119: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/119.jpg)
and all of this works right now, in Drupal 7... 6... and 8!
Thursday, May 23, 13
![Page 120: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/120.jpg)
@weaverryan
Contrib Modules
• Every module brings its own screens and user-flows
• What if every module brought its own Behat definitions?
✴ Given I have a view....✴ Given I upload an image and crop it...
Thursday, May 23, 13
![Page 121: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/121.jpg)
The DrupalExtension has a hook to automatically load
these
Thursday, May 23, 13
![Page 122: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/122.jpg)
... We just need to add these definitions into contrib :)
Thursday, May 23, 13
![Page 123: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/123.jpg)
Want the test to run in Selenium?
Thursday, May 23, 13
![Page 124: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/124.jpg)
Add @javascript
# ...
@javascriptScenario: Edit Node Given I am viewing a "page" node with the title "Cool beans!" When I click "Edit" in the "Body" region And I fill in the following: | Body | Ipsumm | And I press "Save" Then I should see "Ipsumm" in the "Body" region
Thursday, May 23, 13
![Page 125: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/125.jpg)
Add @javascript
# ...
@javascriptScenario: Edit Node Given I am viewing a "page" node with the title "Cool beans!" When I click "Edit" in the "Body" region And I fill in the following: | Body | Ipsumm | And I press "Save" Then I should see "Ipsumm" in the "Body" region
Yep, that’s all you do!
Thursday, May 23, 13
![Page 126: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/126.jpg)
Download and start Selenium
$> wget http://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar
$> java -jar selenium-server-standalone-2.31.0.jar
Thursday, May 23, 13
![Page 127: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/127.jpg)
Re-run the tests
Thursday, May 23, 13
![Page 128: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/128.jpg)
Yes, add only 1 line of code to run a test in Selenium
Thursday, May 23, 13
![Page 129: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/129.jpg)
Epilogue
You’re Turn!
Thursday, May 23, 13
![Page 130: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/130.jpg)
1) Install DrupalExtension
This will also install Behat, Mink andMinkContext in your project
http://bit.ly/drupal-extension
Thursday, May 23, 13
![Page 131: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/131.jpg)
2) Write features for your app!
... and learn more about what you can do with Mink: http://mink.behat.org/
Thursday, May 23, 13
![Page 132: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/132.jpg)
3) high-five your teammates
Thursday, May 23, 13
![Page 133: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/133.jpg)
... and do your homework
1) Behat & Mink Screencast:KnpUniversity.com/screencast/behatCoupon: HIPSTER
2) Talk with OpenSourcery, read their blogs, give them jumping high-fives
3) Chat with Melissa Anderson (eliza411) - she’ll make you think of the testing process holistically: from geek to biz person
Thursday, May 23, 13
![Page 134: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/134.jpg)
Thanks...
Ryan Weaver@weaverryan
KnpUniversity.comPHP, Behat, Twig, OO, etc Tutorial Screencasts
SPECIAL thanks toJonathan Hedstrom
(jhedstrom)
Thursday, May 23, 13
![Page 135: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/135.jpg)
... and we love you!
Ryan Weaver@weaverryan
Ryan Weaver@weaverryan
Thursday, May 23, 13
![Page 136: Behavioral Driven Development with Behatdrupalnights.org/sites/default/files/events... · Behavioral Driven Development with Behat Thursday, May 23, 13. ... Your code and business](https://reader034.vdocument.in/reader034/viewer/2022052004/6017f8ac9a3644111e0a4ce4/html5/thumbnails/136.jpg)
Coupon: HIPSTER
KnpUniversity.com@weaveryan
@KnpUniversityThursday, May 23, 13