Web Acceptance Testing Framework for PHP
A Web acceptance testing framework for PHP is now available on GitHub. It can be used for web acceptance testing of the PHP projects. This framework is build around Behat, Mink, Sauce Labs and ANT. You can configure it with a continuous integration server like Jenkins.
Behat is a BDD framework for PHP. Behat comes up with Mink which is used for browser emulation (functional testing) where browser interaction takes place. Behat and Mink combination is used for web acceptance testing.
Key features of web acceptance testing framework
- Selenium and Sahi servers are plugged into build file, user doesn’t need to download or launch Selenium or Sahi server while running features with ANT or Jenkins.
- Test reports are generated in HTML and xml format in “/report” directory.
- Easy switching over to another driver. You can run tests using any available drivers, just by specifying name of them.
- Framework is integrated with cloud testing service called “Sauce Labs”. You can run your features in cloud with selenium driver.
- Testers can get started easily without any hassles.
- With little changes in config file, it is ready for your project.
Behat for Testers
Testers might have tried Cucumber & Selenium or Cucumber & capybara combination for Ruby projects. BDD for testers could be very interesting topic to discuss. Testers can now use BDD framework for PHP project as well. Thanks to Behat !
Behat has provided lot of driver options for testers. Its not limited to selenium. It has following mink drivers.
Tester can pick one of these and start implementing features. Goutte can be used for tests which doesn’t need browser interaction. Tester can always switch to another driver if feature is failing for one of the driver. There are some pro’s and con’s of each driver
|Hidden Link Access||Yes||Yes||No|
|Sauce Lab Support||No||Yes||No|
|Https sites testing||Hectic, need to add certificate exception||Accepts certificated automatically||Accepts certificated automatically|
It is very important to choose right driver for your testing. It depends on your application and requirement. This framework makes it easy to switch over to another driver.
What you need to use framework?
- Create Your Project
$ behat --init
- Clone Web Acceptance testing Framework from GitHub
- Clone test framework from Github into your local machine.
- Make sure you have initialized Behat in your root directory, currently its “Behat”.
- Now you are ready to use the framework for adding features and running them with different drivers like Selenium, Sahi or webdriver.
- How to use framework?
- Change “base_url” “browser” parameter in all config files like ‘behat.yml’, ‘sahi.yml’, ‘selenium.yml’, and ‘webdriver.yml’ as per your project requirement. eg change in sahi.yml file as shown below
Run features locally
To run feature locally, you need to start Selenium or Sahi server before executing them.
You need to download selenium server jar file and execute following command:
$ cd /path/to/selenium-server $java -jar selenium-server-standalone-2.15.0.jar
Download sahi zip file from SourceForge
Now launch Sahi Server using command below:
$ cd /path/to/sahi $ cd userdata/bin $bash start_sahi.sh
Now you can run behat command to run feature locally
$ cd /path/to/behat $behat --name wikiSearch (your feature)
You can see feature running on your local host.
- How to run features using ANT
You need to install Apache Ant on your localhost. You can download and install Ant from Apache Ant website.
No need install or download selenium or Sahi. It is configured inside this framework. Ant will automatically launch selenium or Sahi server still you need to update version of selenium server frequently.
Now you got three drivers options to run your features
- Sahi Driver
- Selenium Driver
- Selenium 2 Driver (webdriver)
- Run feature with selenium driver
$ cd /path/to/my/project $ant runSelenium
- Run feature with Sahi driver.
$ cd /path/to/my/project $ant runSahi
- Run feature with webdriver
$ cd /path/to/my/project $ant runWebdriver
- Run feature on Sauce Labs
$ cd /path/to/my/project $ant sauceTests
If you are using selenium driver, then you have to implement wait in your step definitions every time there is new page is loaded like this:
Sahi driver waits automatically for element to be appear on page or page to load. You don’t have to implement wait if you would like to use Sahi driver.
Once you run ‘ant’ command from terminal you will see your feature running in browser, you configured.You will see reports generated in “/report” directory. There will be HTML reports as well.
Configure Jenkins to run features
- Download & Launch Jenkins by executing below command:
$ java -jar jenkins.war
Visit url : http://localhost:8080 to access Jenkins in browser. You can specify different port to launch Jenkins.
- Create new Build a free-style software project and name it “Behat”
- Configure job by specifying your repository.(Git, SVN, CSV)
- You need to Invoke Ant as shown below
If you wish to run tests using Sahi driver then specify target as “runSahi”
You can see reports generated once you run your feature.
Using web acceptance test framework for PHP, you can write features and run them easily on ANT, Jenkins and Sauce labs with choice of available drivers.
Happy BDD for testers !! Any questions or comment mention me @Shashikant86 on Twitter.