ATDD with Behat and Selenium (LDNSE6)
-
Upload
shashikant-jagtap -
Category
Technology
-
view
6.792 -
download
5
Transcript of ATDD with Behat and Selenium (LDNSE6)
ATDD with Behat and Selenium
About Me
Shashikant Jagtap [Shashi] Twitter: @Shashikant86 London Behat Users [#LDNBU] BDD Enthusiastic Tester
Overview
ATDD
Overview
ATDD
Behat from Scratch
Overview
ATDD
Behat from Scratch
Composer & Mink Extension
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
ATDD
Acceptance Test Driven Development
DiscussStory 2Story 1Story 3
ATDD
Acceptance Test Driven Development
DiscussStory 2Story 1Story 3
Specification Workshop
Distill
TesterDevelopersPM/SM
ATDD
Acceptance Test Driven Development
DiscussStory 2Story 1Story 3
Specification Workshop
Distill
TesterDevelopersPM/SM
ImplementAcceptance Tests
TesterDeveloper
ATDD
Acceptance Test Driven Development
DiscussStory 2Story 1Story 3
Specification Workshop
Distill
TesterDevelopersPM/SM
ImplementAcceptance Tests
TesterDeveloperDemo
Executable Spec
AutomationAutomation
ATDD
Get Acceptance Criteria
ATDD
Get Acceptance Criteria
Write Acceptance Test Collaboratively [Failing/Undefined]
ATDD
Get Acceptance Criteria
Write Acceptance Test Collaboratively [Failing/Undefined]
Implement Step Definition to make it Pass
ATDD
Get Acceptance Criteria
Write Acceptance Test Collaboratively [Failing/Undefined]
Implement Step Definition to make it Pass
Test Pass !! Automation Achieved.
Behat
It's cousin of
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
Who is Doing/Maintaining?
Konstantin Kudryashov - Knplabs, France
Twitter : @everzet
GitHub : Everzet
+ Some Awesome Contributors
Let's Get Started With Behat
Pre-requisiteLaptop/Computer
PHP Stacks (LAMP, WAMP, MAMP)
Selenium Server
Curl or wget
GitHub (optional)
Behat Installation
Could you Live Without
If Not Then
If Not Then
$ pear channel-discover pear.symfony.com$ pear channel-discover pear.behat.org
$ pear install behat/behat
pear install behat/mink
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,
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 !!!!!
We Got Composer !!!!!!
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
Create Project
Make New Directory
$ mkdir BehatDemo
$ cd BehatDemo
Create composer.json
{"require": { "behat/behat": "2.4@stable", "behat/mink-extension": "dev-master", "fabpot/goutte": "*", "alexandresalome/php-selenium": "*", "instaclick/php-webdriver": "*" }, "config": { "bin-dir": "bin" }}
Create 'behat.yml'
default: context: class: 'FeatureContext' extensions: Behat\MinkExtension\Extension: base_url: 'http://saucelabs.com/' javascript_session: 'selenium2' goutte: ~ selenium2:
Download Composer
Download composer using command $curl http://getcomposer.org/installer | php
Download Composer
Download composer using command $curl http://getcomposer.org/installer | phpShashi-MacBook-Pro:BehatDemo user$ curl http://getcomposer.org/installer | php % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed100 7606 100 7606 0 0 59636 0 --:--:-- --:--:-- --:--:-- 165k#!/usr/bin/env phpAll settings correct for using ComposerDownloading...Composer successfully installed to: /Users/user/BehatDemo/composer.pharUse it: php composer.phar
Install composer.phar
$php composer.phar install
You can also use
$php composer.phar update
Install composer.phar
$php composer.phar installShashi-MacBook-Pro:BehatDemo user$ php composer.phar update Updating dependencies - Installing guzzle/guzzle (v2.6.3) Downloading: 100%
- Installing symfony/yaml (dev-master) Cloning 49ad500448c17a4b515c8f567dbb540af3cf41ef
- Installing symfony/translation (dev-master) [So on ...........]
Start Behat
$ ./bin/behat --init
Start Behat
$ ./bin/behat --initShashi-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]
Behat Did Something ?
Created 'features' directory
Created 'bootstrap' directory and 'FeatureContext.php' file where we will implement step definitions.
Mink Extension
We need 'FeatureContext' class to'Behat\MinkExtension\Context\MinkContext
So, We are using 'MinkExtension' which automatically create Mink instance.
We used Mink API's to automated Browser actions. (http://mink.behat.org/api/)
Now, We are ready to use Behat, Mink, Selenium and stuff. Run Behat with $ ./bin/behat
Feature File
How it Looks Like?
Feature: featureIn order to [ add feature]As a [role]I want [featute]Scenario: First ScenarioGiven [Context]When [Action]Then [OutCome]
BlogSearch.feature
Feature: Blog SearchIn order to search blogsAs a sauce userI need see blogs
@javascriptScenario: 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. ]
What will Help to write feature?
Behat Cheat Sheethttp://blog.lepine.pro/php/ressources-tutos-php/cheat-sheet-behat
Mink Api's http://mink.behat.org/api/
I know, Too Boring to type ?
I know, Too Boring to type ?
Let Me Show You Something Which Will do this in a Minute
Sublime Text2 : Behat- Mink Snippets.
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
Don't forget To tag Scenarios with @javascript tag &
Launch our Lovely Selenium Server$ java -jar selenium-server-standalone-2.21.0.jar
Now Run $./bin/behatWatch Test Running in a Browser
ATDD with Behat & Selenium
How should I find locators before Implementation?
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)
atdd.feature
Feature: ATDDIn order to implement ATDDAs a QAI 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"
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");}
Run Scenarios with 'atdd' tags
$ ./bin/behat --tags="atdd"
Generate Report
To Generate HTML reports
$ ./bin/behat -f html --out report.html
You will see 'report.html' generated which looks awesome in browser !!
report.html
Get Code
$git clone [email protected]: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
Run ANT build
Shashi-MacBook-Pro:BehatDemo user$ ant runBuildfile: /Users/user/BehatDemo/build.xml
run: [delete] Deleting directory /Users/user/BehatDemo/report [mkdir] Created dir: /Users/user/BehatDemo/report
behat:
BUILD SUCCESSFULTotal time: 21 seconds
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.
Video Demo
How To clone Repo and use http://youtu.be/Apt-1_94zCE
Things We did
http://tinyurl.com/d79s4oy
Links
http://behat.org/
http://mink.behat.org/
https://github.com/Shashikant86/BehatDemo
https://github.com/kwattro/sublime-behat-snippets
http://everzet.com/
Questions?
Thank You