---
title: Selenium testing with Behat and Mink | TestingBot Blog
description: |-
  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, ...
source_url:
  html: https://testingbot.com/blog/2012/02/10/selenium-testing-with-mink-and-behat
  md: https://testingbot.com/blog/2012/02/10/selenium-testing-with-mink-and-behat.md
---

# Behat and Mink webdriver testing

By [Jochen D.](https://testingbot.com/about/jochen-d)2012-02-10

 Share on Facebook 

 Share on Twitter 

 Post on Reddit 

 Share link 

If you haven't heard of [Behat](https://behat.org/) yet, it's a BDD framework which runs on PHP written by [Konstantin Kudryashov](http://about.me/everzet). 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](https://mink.behat.org/). 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](https://github.com/testingbot/Behat-Mink-TestingBot).

## Installing Behat and Mink

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

```bash
$ sudo pear channel-discover pear.behat.org
  $ sudo pear channel-discover pear.symfony.com
  $ sudo pear install behat/gherkin-beta
  $ sudo pear install behat/behat-beta
```

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:

```bash
$ sudo pear channel-discover testingbot.github.com/pear
  $ sudo pear install -a testingbot/TestingBot
```

## Set up a new project

Create a new directory and initialise Behat:

```bash
$ mkdir behat-demo
 $ cd behat-demo
 $ behat --init
```

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

```bash
$ cd features/bootstrap
```

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

```bash
$ vim bootstrap.php
```

Add the following in your bootstrap file:

```php
<?php
 date_default_timezone_set('Europe/London');
 require_once 'mink/autoload.php';
 require_once 'PHPUnit/Autoload.php';
 require_once 'PHPUnit/Framework/Assert/Functions.php';
 require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
 require_once 'PHPUnit/Extensions/TestingBotTestCase.php';
```

Specify the correct settings in your behat.yml file:

```yaml
default:
    context:
        parameters:
            javascript_session: selenium
            base_url: http://www.google.com
            browser: iexplore
            show_cmd: open %s
            selenium:
              host: hub.testingbot.com
              port: 4444
              browser: >
                {
                  "client_key" : "[KEY]",
                  "client_secret" : "[SECRET]",
                  "browserName" : "iexplore",
                  "version" : 8
                }
```

Don't forget to add your client\_key and client\_secret, which you can obtain from our [member area](https://testingbot.com/members).

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

```php
<?php

use Behat\Behat\Context\ClosuredContextInterface,
    Behat\Behat\Context\TranslatedContextInterface,
    Behat\Behat\Context\BehatContext,
    Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
    Behat\Gherkin\Node\TableNode;
use Behat\Mink\Behat\Context\MinkContext;
use Behat\Mink\Session;
use Behat\Mink\Driver\DriverInterface;

require_once 'bootstrap.php';

class FeatureContext extends MinkContext
```

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:

```bash
$ vim googleSearch

 Feature: googleSearch
  In order to search information on google
  As a user
  I want to get sensible results from site

 @javascript
  Scenario Outline: Search Keywords on Google
    Given I am on "/"
    And I fill in searchBox with "<input>"
    When I press submit button
    Then I should see "<output>" 

    Examples:
      | input | output |                                   
      | TestingBot | Selenium |
```

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

- A user navigates to the homepage of Google
- The user enters TestingBot in the search field
- The user clicks the submit button (search button)
- TestingBot should be included in the results

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:

```php
/**
     * @Given /^I fill in searchBox with "([^"]*)"$/
     */
    public function iFillInSearchboxWith($argument1)
    {
        throw new PendingException();
    }

    /**
     * @When /^I press submit button$/
     */
    public function iPressSubmitButton()
    {
        throw new PendingException();
    }
```

Add the following to your `FeatureContext.php` file:

```php
/**
     * @Given /^I fill in searchBox with "([^"]*)"$/
     */
    public function iFillInSearchboxWith($argument1)
    {
        $this->fillField("q",$argument1);
    }

    /**
     * @When /^I press submit button$/
     */
    public function iPressSubmitButton()
    {
        $this->getMink()->getSession()->getDriver()->click("//input[@type='submit'][1]"); //first submit button = search button on Google
        $this->getMink()->getSession()->wait("3000");
    }
```

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

The test should succeed and you will see:

```bash
1 scenario (1 passed)
4 steps (4 passed)
```

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](https://github.com/testingbot/Behat-Mink-TestingBot).

[← Previous post Selenium cloud testing with Jenkins](https://testingbot.com/blog/2012/02/09/selenium-cloud-testing-with-jenkins) [Next post → Selenium with Cucumber and Capybara](https://testingbot.com/blog/2012/02/19/selenium-cucumber-capybara)

## Sidebar

### TestingBot Cloud Testing

Run automated, manual and visual tests on remote browsers and devices. Sign up for a free trial.

[Free Trial](https://testingbot.com/users/sign_up)

### Latest articles

[![Announcing AI Test Insights](https://testingbot.com/assets/blog/2026/ai-insights.jpg)](https://testingbot.com/blog/ai-test-insights)

#### Announcing AI Test Insights

Use AI Insights to quickly discover why an automated test...

[Read: Announcing AI Test Insights](https://testingbot.com/blog/ai-test-insights)

[![Selenium vs Playwright 2026](https://testingbot.com/assets/blog/2026/selenium-vs-playwright-2026.jpg)](https://testingbot.com/blog/selenium-vs-playwright)

#### Selenium vs Playwright 2026

Comparing Selenium vs Playwright - which is the best test...

[Read: Selenium vs Playwright 2026](https://testingbot.com/blog/selenium-vs-playwright)

[![Maestro Physical Device Testing](https://testingbot.com/assets/blog/2026/maestro-physical.jpg)](https://testingbot.com/blog/maestro-physical-device-testing)

#### Maestro Physical Device Testing

Maestro testing in parallel on physical Android and iOS d...

[Read: Maestro Physical Device Testing](https://testingbot.com/blog/maestro-physical-device-testing)

## Related Articles

[![Selenium vs Playwright 2026](https://testingbot.com/assets/blog/2026/selenium-vs-playwright-2026.jpg)](https://testingbot.com/blog/selenium-vs-playwright "Selenium vs Playwright 2026")

### [Selenium vs Playwright 2026](https://testingbot.com/blog/selenium-vs-playwright)

Comparing Selenium vs Playwright - which is the best test framework for your usecase?

[Read article →](https://testingbot.com/blog/selenium-vs-playwright)

[![Playwright Testing on TestingBot](https://testingbot.com/assets/blog/2023/playwright-testing.jpg)](https://testingbot.com/blog/playwright-testing-introduction "Playwright Testing on TestingBot")

### [Playwright Testing on TestingBot](https://testingbot.com/blog/playwright-testing-introduction)

Learn how Playwright can run your automated tests on a variety of browsers, local or remote browsers on TestingBot.

[Read article →](https://testingbot.com/blog/playwright-testing-introduction)

[![Announcing AI Test Insights](https://testingbot.com/assets/blog/2026/ai-insights.jpg)](https://testingbot.com/blog/ai-test-insights "Announcing AI Test Insights")

### [Announcing AI Test Insights](https://testingbot.com/blog/ai-test-insights)

Use AI Insights to quickly discover why an automated test failed.

[Read article →](https://testingbot.com/blog/ai-test-insights)

[![tvOS Physical Device Testing](https://testingbot.com/assets/blog/2025/appletv.jpg)](https://testingbot.com/blog/tvos-automated-testing "tvOS Physical Device Testing")

### [tvOS Physical Device Testing](https://testingbot.com/blog/tvos-automated-testing)

Run automated tvOS tests on physical AppleTV devices.

[Read article →](https://testingbot.com/blog/tvos-automated-testing)

## More by Jochen D.

[![Announcing AI Test Insights](https://testingbot.com/assets/blog/2026/ai-insights.jpg)](https://testingbot.com/blog/ai-test-insights "Announcing AI Test Insights")
### [Announcing AI Test Insights](https://testingbot.com/blog/ai-test-insights)

Use AI Insights to quickly discover why an automated test failed.

[![Maestro Physical Device Testing](https://testingbot.com/assets/blog/2026/maestro-physical.jpg)](https://testingbot.com/blog/maestro-physical-device-testing "Maestro Physical Device Testing")
### [Maestro Physical Device Testing](https://testingbot.com/blog/maestro-physical-device-testing)

Maestro testing in parallel on physical Android and iOS devices.

[![tvOS Physical Device Testing](https://testingbot.com/assets/blog/2025/appletv.jpg)](https://testingbot.com/blog/tvos-automated-testing "tvOS Physical Device Testing")
### [tvOS Physical Device Testing](https://testingbot.com/blog/tvos-automated-testing)

Run automated tvOS tests on physical AppleTV devices.

[See all posts by Jochen D. →](https://testingbot.com/about/jochen-d)

## Ready to start testing?
[Start a free trial](https://testingbot.com/users/sign_up)
