behat sauce
DESCRIPTION
TRANSCRIPT
![Page 1: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/1.jpg)
Automated Web Acceptance Testing
with Behat Shashikant Jagtap
Twitter : @Shashikant86
![Page 2: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/2.jpg)
Overview
Behat : BDD for PHP Mink: Web Acceptance Testing Framework Behat with Sauce Labs for cloud testing Relish for living documentation Building feature with Jenkins Useful Links
![Page 3: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/3.jpg)
Behat : BDD for PHP
Behat is a BDD framework for PHP applications. http://behat.org/
BDD approach
Feature is defined in story format. Domain Specific Language used is 'Gherkin'.
Behat is developed by Konstantin Kudryashov (@everzet)
![Page 4: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/4.jpg)
Mink
Mink is a acceptance test framework for PHP applications http://mink.behat.org/ Mink has different drivers for browser emulation. Bowser emulation can be headless or with browser controllers. Mink supports both selenium1 driver as well as webdriver. Mink has various API's that can used to control browser actions. Full list of Mink API's can found here http://mink.behat.org/api/
![Page 6: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/6.jpg)
Installations
Behat Installation: Run following commands from your pear channel
$ sudo pear channel-discover pear.behat.org
$ sudo pear channel-discover pear.symfony.com
$ sudo pear install behat/gherkin-beta
$ sudo pear install behat/behat-beta Mink Installation$ pear channel-discover pear.symfony.com
$ pear channel-discover pear.behat.org
$ pear install behat/mink Check Installations$ behat –version
Behat version 2.2.0
Mink can be used by including following file in PHP classes. require_once 'mink/autoload.php';
![Page 7: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/7.jpg)
Start Your Project
Navigate to the project root directory and initialize Behat by running these commands:
![Page 8: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/8.jpg)
FeatureContext.php
![Page 9: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/9.jpg)
Bootstrap.php Create 'features->bootstrap->bootstrap.php' and include mink and all
other third party libraries in it. Include bootstrap.php into 'FeatureContext.php'.
![Page 10: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/10.jpg)
Behat.yml Create 'behat.yml'. This is configuration file to run
features You can specify mink driver, base url and browser of your
choice. This file uses 'selenium' driver to run feature.
![Page 11: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/11.jpg)
wikiSearch.feature Now, write sample feature file. This feature file good example of data-
driven tests.
![Page 12: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/12.jpg)
Get code for Step Definitions Now, you are ready to run 'behat' command again. This will give you example
code for undefined steps
![Page 13: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/13.jpg)
Implement Step definitions
Now, copy example code and paste it in 'FeatureContext.php' Use Mink API's to implement steps like this
![Page 14: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/14.jpg)
Start your engine Download Selenium from http://seleniumhq.org/download/ Run Selenium server using command
$java -jar selenium-server-standalone-2.15.0.jar
![Page 15: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/15.jpg)
Watch your Test running Now run 'behat' again and watch your test running in
browser.
![Page 16: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/16.jpg)
Watch Your Test Passed
![Page 17: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/17.jpg)
Behat with Sauce Labs Sauce Labs is a cloud testing service which allows tests to run in
cloud machine with specified browser. http://saucelabs.com/ Behat features can be run on sauce labs by simple configuration We need to create another configuration file to run features on
Sauce Labs.
![Page 18: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/18.jpg)
Create 'sauce.yml' In order to run feature on Sauce Labs, we need to create
'sauce.yml' as a config file. You need Sauce labs 'username' and 'API key'.
![Page 19: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/19.jpg)
Run Feature on Sauce Labs You need to tell behat to pick 'sauce.yml' as config file $behat -c sauce.yml You can watch video this job here:
http://snipurl.com/21y5lb6
![Page 20: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/20.jpg)
Relish: Living Documentation
Relish is cool tool to manage Gherkins feature files online. https://www.relishapp.com/relish/relish/docs
Install Relish You need to have Ruby gems installed on your system. $gem install relish Create Project $relish projects:add projectName
# or, if you want a private project: $relish projects:add my-secret-project:private Push your files online
$relish push my-best-projectmoonstar:NewBehat sjagtap$ relish push sjagtap/acnesent:features/wikiSearch.feature
![Page 21: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/21.jpg)
Relish
You can find our feature on Relish here https://www.relishapp.com/sjagtap/acne/docs/wikisearch
![Page 22: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/22.jpg)
Source Code from GitHub
Get Sample Source Code available on GitHub https://github.com/Shashi-ibuildings/Behat-SauceClone the repository $ git clone [email protected]:Shashi-ibuildings/Behat-Sauce.git
$ cd /path to/Behat-SauceEdit ‘Sauce.yml’ file in order to specify your username and API key. Now, Run ANT command to execute feature on sauce Labs $ ant runSauceSee the reports generated in 'report/report.html' file.
![Page 23: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/23.jpg)
Directory Structure
Once you cloned project, You will have following files in the project, directory structure looks like this
![Page 24: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/24.jpg)
Running Features on Jenkins
Jenkins is continuous integration server To configure Behat with CI server, we need 'build.xml '
file You need to have Jenkins installed on server or localhost- We will Run Jenkins- moonstar:~ sjagtap$ java -jar jenkins-1.war Visit http://localhost:8080/ to see Jenkins Dashboard Create new job called “BehatSauce”. Specify it as 'Build
a free-style software project. Specify Git repository as SCM. Select ‘Invoke Ant’ from ‘Build’ and specify ‘runSauce’
target Specify HTML report path. (You need to have HTML report
plugin installed on Jenkins)
![Page 25: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/25.jpg)
Jenkins Configuration
![Page 26: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/26.jpg)
Jenkins Configuration Contd..
![Page 27: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/27.jpg)
Jenkins Project
![Page 28: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/28.jpg)
Jenkins Test Report
![Page 29: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/29.jpg)
Links
Blogpost 'Adding Sauce To behat'http://saucelabs.com/blog/index.php/2012/01/adding-sauce-to-behat/ Video Demohttp://www.youtube.com/watch?v=Zu9mWuVvsUQ Source Code on GitHub https://github.com/Shashi-ibuildings/Behat-Sauce Relish Documentationhttps://www.relishapp.com/sjagtap/acne My Blogshttp://lestbddphp.wordpress.com/ About Me http://about.me/shashikantjagtap
![Page 30: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/30.jpg)
Questions
![Page 31: Behat sauce](https://reader034.vdocuments.us/reader034/viewer/2022050720/53f9c4658d7f72b82e8b4ba1/html5/thumbnails/31.jpg)
Thank You