This document discusses automated web acceptance testing using Behat and Mink. It provides an overview of Behat, a behavior-driven development framework for PHP, and Mink, a web acceptance testing framework. It then covers setting up a Behat project with Mink, writing feature files, implementing step definitions, running tests locally and on Sauce Labs. It also discusses using Relish for living documentation and integrating tests with Jenkins.
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. 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)
4. 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/
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. 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. wikiSearch.feature
ďŹ
Now, write sample feature file. This feature file good example of data-driven tests.
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. Implement Step definitions
ďŹ
Now, copy example code and paste it in 'FeatureContext.php'
ďŹ
Use Mink API's to implement steps like this
14. Start your engine
ďŹ
Download Selenium from http://seleniumhq.org/download/
ďŹ
Run Selenium server using command
$java -jar selenium-server-standalone-2.15.0.jar
15. Watch your Test running
ďŹ
Now run 'behat' again and watch your test running in browser.
17. 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.
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. 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
20. 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-project
moonstar:NewBehat sjagtap$ relish push sjagtap/acne
sent:
features/wikiSearch.feature
21. Relish
ďŹ
You can find our feature on Relish here
https://www.relishapp.com/sjagtap/acne/docs/wikisearch
22. Source Code from GitHub
Get Sample Source Code available on GitHub
ďŽ
https://github.com/Shashi-ibuildings/Behat-Sauce
Clone the repository
ďŽ
$ git clone git@github.com:Shashi-ibuildings/Behat-Sauce.git
$ cd /path to/Behat-Sauce
Edit âSauce.ymlâ file in order to specify your username and API key. Now, Run
ďŽ
ANT command to execute feature on sauce Labs
$ ant runSauce
See the reports generated in 'report/report.html' file.
ďŽ
23. Directory Structure
ďŽ
Once you cloned project, You will have following files in the project,
directory structure looks like this
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)