Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Behat sauce


Published on

Published in: Lifestyle, Technology
  • Be the first to comment

Behat sauce

  1. 1. Automated WebAcceptance Testing with Behat Shashikant Jagtap Twitter : @Shashikant86
  2. 2. 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
  3. 3. Behat : BDD for PHP Behat is a BDD framework for PHP applications. BDD approach Feature is defined in story format. Domain Specific Language used is Gherkin. Behat is developed by Konstantin Kudryashov (@everzet)
  4. 4. Mink Mink is a acceptance test framework for PHP applications Mink has different drivers for browser emulation. Bowser emulationcan be headless or with browser controllers.Mink supports both selenium1 driver as well as webdriver. Mink has various APIs that can used to control browser actions.Full list of Mink APIs can found here
  5. 5. Basic Browser InteractionsSource:
  6. 6. Installations Behat Installation: Run following commands from your pear channel$ sudo pear channel-discover$ sudo pear channel-discover$ sudo pear install behat/gherkin-beta$ sudo pear install behat/behat-beta Mink Installation$ pear channel-discover$ pear channel-discover$ pear install behat/mink Check Installations$ behat –version Behat version 2.2.0Mink can be used by including following file in PHP classes. require_once mink/autoload.php;
  7. 7. Start Your ProjectNavigate to the project root directory and initialize Behat by running these commands:
  8. 8. FeatureContext.php
  9. 9. Bootstrap.php Create features->bootstrap->bootstrap.php and include mink and all other third party libraries in it. Include bootstrap.php into FeatureContext.php.
  10. 10. 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.
  11. 11. wikiSearch.feature Now, write sample feature file. This feature file good example of data-driven tests.
  12. 12. Get code for Step Definitions Now, you are ready to run behat command again. This will give you example code for undefined steps
  13. 13. Implement Step definitions Now, copy example code and paste it in FeatureContext.php Use Mink APIs to implement steps like this
  14. 14. Start your engine Download Selenium from Run Selenium server using command $java -jar selenium-server-standalone-2.15.0.jar
  15. 15. Watch your Test running Now run behat again and watch your test running in browser.
  16. 16. Watch Your Test Passed
  17. 17. Behat with Sauce Labs Sauce Labs is a cloud testing service which allows tests to run in cloud machine with specified browser. Behat features can be run on sauce labs by simple configuration We need to create another configuration file to run features on Sauce Labs.
  18. 18. 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.
  19. 19. 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:
  20. 20. Relish: Living Documentation Relish is cool tool to manage Gherkins feature files online. Install RelishYou 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-project moonstar:NewBehat sjagtap$ relish push sjagtap/acne sent: features/wikiSearch.feature
  21. 21. Relish You can find our feature on Relish here
  22. 22. Source Code from GitHubGet Sample Source Code available on GitHub the repository $ git clone $ 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.
  23. 23. Directory Structure Once you cloned project, You will have following files in the project, directory structure looks like this
  24. 24. 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)
  25. 25. Jenkins Configuration
  26. 26. Jenkins Configuration Contd..
  27. 27. Jenkins Project
  28. 28. Jenkins Test Report
  29. 29. Links Blogpost Adding Sauce To behat Video Demo Source Code on GitHub Relish Documentation My Blogs About Me
  30. 30. Questions
  31. 31. Thank You