These are the slides of the talk given at London Selenium Meetup on 29 may 2012. This talk was on Behat, MinkExtension and Selenium. http://www.meetup.com/seleniumlondon/events/61732192/
Pic : http://www.meetup.com/seleniumlondon/photos/8638912/#124419342
6. Overview
ATDD
Behat from Scratch
Composer & MinkExtension
Speeding up BDD with Sublime Text2
Browser Automation with Selenium
ATDD with Behat and Selenium
ANT & HTML Report Generation
Video/Live Demo
8. ATDD
Acceptance Test Driven Development
Specification Workshop
Discuss Distill
Stor Stor
y2 Stor y3 Tester Develope
y1 PM/S
rs M
9. ATDD
Acceptance Test Driven Development
Specification Workshop
Discuss Distill
Stor Stor
y2 Stor y3 Tester PM/S
Develope
y1 M
rs
Acceptance Tests
Implement
Test
Devel
er
oper
10. ATDD
Acceptance Test Driven Development
Specification Workshop
Discuss Distill
Stor Stor
y2 Stor y3 Tester PM/S
Develope
y1 M
rs
Acceptance Tests
Executable Spec Implement
Automat Demo
ion Test
Automat Devel
er
ion oper
14. ATDD
Get Acceptance Criteria
Write Acceptance Test Collaboratively
[Failing/Undefined]
Implement Step Definition to make it Pass
Test Pass !! Automation Achieved.
16. Behat
Behat is a BDD tool for PHP Applications
http://behat.org/
Mink is a web Acceptance Testing
Framework for PHP
http://mink.behat.org/
Combination of Behat/Mink can be used
for web acceptance Testing.
Mink has Selenium1 & Selenium2 Drivers
for browser automation
22. If Not Then
$ pear channel-discover pear.symfony.com
$ pear channel-discover pear.behat.org
$ pear install behat/behat
pear install behat/mink
23. If Not Then
$ pear channel-discover pear.symfony.com
$ pear channel-discover pear.behat.org
$ pear install behat/behat
pear install behat/mink
You Ready to use Behat/Mink,
24. If Not Then
$ pear channel-discover pear.symfony.com
$ pear channel-discover pear.behat.org
$ pear install behat/behat
pear install behat/mink
You Ready to use Behat/Mink,
WAIT.... We got EASIER OPTION !!!!!
26. We Got Composer !!!!!!
Composer is dependency manager for PHP
Composer allow you to declare libraries
you needed and install it for you
Just define all dependencies in
'composer.json' file and you are done !!
So, Let's do that
27. Create Project
Make New Directory
$ mkdir BehatDemo
$ cd BehatDemo
31. Download Composer
Download composer using command
$curl http://getcomposer.org/installer | php
Shashi-MacBook-Pro:BehatDemo user$ curl http://getcomposer.org/installer |
php
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7606 100 7606 0 0 59636 0 --:--:-- --:--:-- --:--:-- 165k
#!/usr/bin/env php
All settings correct for using Composer
Downloading...
Composer successfully installed to: /Users/user/BehatDemo/composer.phar
Use it: php composer.phar
35. Start Behat
$ ./bin/behat --init
Shashi-MacBook-Pro:BehatDemo user$ ./bin/behat --init
+d features - place your *.feature files here
+d features/bootstrap - place bootstrap scripts and static files here
+f features/bootstrap/FeatureContext.php - place your feature related code
here
[You will See Behat created 'features' and 'bootstrap' directory for you]
36. Behat Did Something ?
Created 'features' directory
Created 'bootstrap' directory and
'FeatureContext.php' file where we will
implement step definitions.
37. Mink Extension
We need 'FeatureContext' class to'Behat
MinkExtensionContextMinkContext
So, We are using 'MinkExtension' which
automatically create Mink instance.
We used Mink API's to automated
Browser actions.
(http://mink.behat.org/api/)
38. Now, We are ready to use
Behat, Mink, Selenium and
stuff. Run Behat with
$ ./bin/behat
40. How it Looks Like?
Feature: feature
In order to [ add feature]
As a [role]
I want [featute]
Scenario: First Scenario
Given [Context]
When [Action]
Then [OutCome]
41. BlogSearch.feature
Feature: Blog Search
In order to search blogs
As a sauce user
I need see blogs
@javascript
Scenario: Search Behat Blogs
Given I am on "/blog"
When I fill in "s" with "behat"
And I press "Search"
Then I should see "Adding Sauce To Behat"
[This file should be in /features directory. ]
42. What will Help to write
feature?
Behat Cheat Sheet
http://blog.lepine.pro/php/ressources-tutos-
Mink Api's
http://mink.behat.org/api/
46. Who Wrote Awesome Snippets
Willemsen Christophe
GitHub : kwattro
- Intranet appz developer for the Belgian
Defense, BDD practitioner. [ Symfony]
Twitter : @ikwattro
GitHub:
https://github.com/kwattro/sublime-
behat-snippets
47. Don't forget
To tag Scenarios with “@javascript” tag
&
Launch our Lovely Selenium Server
$ java -jar selenium-server-standalone-2.21.0.jar
48. Now Run
$./bin/behat
Watch Test Running in a Browser
50. ATDD with Behat & Selenium
How should I find locators before
Implementation?
51. ATDD with Behat & Selenium
How should I find locators before
Implementation?
Don't worry, Write high level tests and
Behat & Mink API's will help you to
implement Step def later (after
implementation)
52. atdd.feature
Feature: ATDD
In order to implement ATDD
As a QA
I need to write acceptance tests first
@javascript @atdd
Scenario: Searching
Given I am on blogs page
When I search for "chips"
Then I should see "No Posts"
53. Implement Steps
/**
* @When /^I search for "([^"]*)"$/
*/
public function iSearchFor($key)
{ $this->fillField("s", $key);
$this->pressButton("Search");
}
/**
* @Given /^I am on blogs page$/
*/
public function iAmOnBlogsPage()
{
$this->visit("/blog");
}
56. Generate Report
To Generate HTML reports
$ ./bin/behat -f html --out report.html
You will see 'report.html' generated which looks
awesome in browser !!
58. Get Code
$git clone git@github.com:Shashikant86/BehatDemo.git
$cd BehatDemo
$curl http://getcomposer.org/installer | php
$php composer.phar install
Download Selenium Server and launch server
$ java -jar selenium-server-standalone-2.21.0.jar
$./bin/behat
59. Run ANT build
Shashi-MacBook-Pro:BehatDemo user$ ant run
Buildfile: /Users/user/BehatDemo/build.xml
run:
[delete] Deleting directory
/Users/user/BehatDemo/report
[mkdir] Created dir:
/Users/user/BehatDemo/report
behat:
BUILD SUCCESSFUL
60. Reports
We have created 'report' directory to save
test report of the latest build
Report will generate in html format in the
'report/report.html' file.
61. Video Demo
How To clone Repo and use
http://youtu.be/Apt-1_94zCE
Things We did
http://tinyurl.com/d79s4oy