TestingBot Blog

TestingBot provides a cloud of browsers and devices, ready to run your Automated, Live and Visual tests.

< Back to Blog Overview

Behat and Mink webdriver testing

2012-02-10

If you haven't heard of Behat yet, it's a BDD framework which runs on PHP written by Konstantin Kudryashov. Behat is similar to Cucumber for Ruby, Lettuce for Python and SpecFlow for .NET.


You'll use Behat for functional testing, data-driven testing and API testing. With Behat you can easily write Gherkin stories (which are human readable test cases).


To start using Selenium together with Behat, you'll need Mink. Mink is perfect for functional testing together with Behat. It includes Selenium drivers which will run on our Selenium grid.


We've added a demo project which is ready to be used in our Github repo.

Installing Behat and Mink

Make sure you have PEAR installed. You need PEAR to install Behat and its dependencies.

Verify your installation: $ behat --version


Now we need to install Mink: $ pear install behat/mink


In order to use our TestingBot.com grid, we need to install the PHP TestingBot connector:

Set up a new project

Create a new directory and initialise Behat:

This will create a directory features in the behat-demo directory.

Now create a bootstrap file which will include all the necessities for our test.

Add the following in your bootstrap file:

Specify the correct settings in your behat.yml file:

Don't forget to add your client_key and client_secret, which you can obtain from our member area.


Next, make sure the FeatureContext.php file contains the following: $ vim features/bootstrap/FeatureContext.php

Make sure FeatureContext extends from MinkContext.

Write a feature

We'll now write a feature which will perform a basic test. The feature we'll use:

This feature is written in Gherkin DSL (DSL meaning Domain Specific Language). This feature will have the following steps:

You can run this test by executing the following command: $ behat --name googleSearch


After executing the command, Behat will return some step suggestions which we'll need to add to the FeatureContext.php file. The suggestions will be:

Add the following to your FeatureContext.php file:

Now run your feature again: $ behat --name googleSearch


The test should succeed and you will see:

We hope this was a helpful post and helped you as an introduction in using Behat and Mink together with our Selenium grid. You can download this demo project from our Github repo.

< Back to Blog Overview

Sign up for a Free Trial

Start testing your apps with TestingBot.

No credit card required.