Skip to main content

Behat Selenium Testing: Running Behat Automation Scripts on Selenium Grid Cloud

Execute your automation test scripts with Selenium WebDriver instantly through LambdaTest which is a cloud-based, cross browser testing tool offering a Selenium Grid consisting 2000+ browsers and browser versions running on real operating systems to pace up automation testing of your web-app or website. In this topic, you will learn how to automate Behat tests with Selenium on LambdaTest cloud.

  1. Run a sample Selenium with Behat automation script on LambdaTest.
  2. Set up an environment for testing your locally hosted web pages using Behat automation testing.
  3. Understand & configure Behat desired capabilities for executing a Behat Selenium test.
  4. Explore advanced features of LambdaTest.

Prerequisites For Running Behat Selenium Scripts#

All the code samples in this documentation can be found in the Behat LambdaTest Repository on Image GitHub. You can either download or clone the repository to quickly run your tests.

Before you begin automation testing with Selenium and Behat, be ready with the below essentials:

  • Make sure that you have the latest PHP installed on your system. If you are using a Mac then PHP would be installed by default. For Linux you would need to enter the below command in terminal:
sudo apt-get install curl libcurl3 libcurl3-dev php

For Windows, you can download PHP from here. Also, refer to this documentation for ensuring the accessibility of PHP through Command Prompt(cmd).

  • Set up Behat automation for your OS using composer.
php composer.phar require behat/behat

If you don’t have composer installed in your system then click here.

  • Once you have composer installed, you can leverage Composer to download and install Selenium dependencies. For that first create a composer.json file in your directory and add the following code to the json.
{  "require": {      "behat/behat": "2.5.*@stable",       "facebook/webdriver": "dev-master",      "symfony/yaml": "*"  },  "config": {      "bin-dir": "bin/"  },  "scripts": {    "test": "composer single  && composer parallel",    "single": "./bin/behat --config=config/single.conf.yml",    "parallel": "CONFIG_FILE=config/parallel.conf.yml /usr/bin/env php lib/parallel.php"  },  "autoload": {    "classmap": ["lib/"]  }}
  • Check out our GitHub repository for finding all the code references that will be discussed in this topic.

Getting Started With Behat Automation Framework and LambdaTest#

Let us have a look at an example which will validate your LambdaTest credentials for authentication purpose. Later, the code will select the basic capabilities such as OS, browser, browser version and so on. This code is also available on our Behat GitHub repository for you to clone and play around.

Feature: Google's Search Functionality Scenario: Can find search results     Given I am on ""     When I search for "LambdaTest"     Then I get title as "LambdaTest - Google Search"
default:   paths:       features: '../features/single'       bootstrap:  '../features/bootstrap'   context:       parameters:           lambdatest:               server: ""               user: "YOUR_LAMBDATEST_USERNAME"               key: "YOUR_LAMBDATEST_ACCESS_KEY"                capabilities:                   build: "behat-selenium-sample"                   name: "single-behat-test"                   video: true                   visual: true                   network: true                   console: true                 environments:                   -                       browserName: chrome                       version: 71.0                       platform: Win10

Execute The Test Using Behat Selenium Automation Framework#

You would need to execute the below command in your terminal/cmd.

composer single
Last updated on