Web Acceptance Testing Framework for PHP

9 Jan

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

Sahi Selenium Webdriver

Implicit Wait Yes No Yes
Hidden Link Access Yes Yes No
Sauce Lab Support No Yes No
Speed Medium Medium Fast
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?

Install Behat using Behat documentation which explained all these methods in simple way. Similarly install mink using Mink documentation.

  • Create Your Project

Initiate Behat:

$ behat --init
  • Clone Web Acceptance testing  Framework from GitHub

  1. Clone test framework from Github into your local machine.
  2. Make sure you have initialized Behat in your root directory, currently its “Behat”.
  3. 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?
  1. 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
javascript_session: sahi
base_url: http://{your url}
browser: {your browser}
show_cmd: open %s 

Run features locally

To run feature locally, you need to start Selenium or Sahi server before executing them.

Download Selenium or Sahi and launch Selenium or Sahi server as shown below

Selenium Server

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 

Sahi Server

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

  1. Sahi Driver
  2. Selenium Driver
  3. 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
$ 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

Jenkins Configuration

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.


One Response to “Web Acceptance Testing Framework for PHP”


  1. Web Acceptance Testing Framework for PHP - June 22, 2012

    […] Read more via Web Acceptance Testing Framework for PHP […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: