Running Cross browser BDD scenarios in Parallel with ANT

Cross-Browser BDD Scenarios

Cross-Browser testing is a essential part of the automated test suite. While working with Behaviour Driven Development tools like Cucumber and Behat, we must have necessary setup to run BDD scenarios in parallel. Let’s consider, we have test suite which runs in Firefox, Safari and Google in parallel. What an awesome idea !

In this tutorial we will we will see how to run cross-browser BDD scenarios in parallel using apache-ANT

Apache ANT

Apache ANT is a java based build tool. You can use another  build tools like phing Or maven but I like ANT as it’s very simple to learn and so powerful.

Install ANT

There is complete installation guide on the apache ant website here. I think, you are smart enough to google it and get ANT installed on your machine

On my Mac OSX, ANT is pre-installed  if not then install it through Mac Port

sudo port install apache-ant

Test ANT Installation

If you have successfully installed ant you will get something like this if you run ‘ant’ command from your terminal.

$ ant
Buildfile: build.xml does not exist!
Build failed

Check ANT version and installation. You will see something like this.

ANT

 

Behat-Cross-Browser-Parallel

You need to setup Behat project as mentioned on my Github repository “Behat-CrossBrowser-Parallel” I will concentrate on main config in this tutorial.

Behat.yml

Create a separate profile for each browser as we have created in behat.yml as shown below

chrome:
  context:
    class:  'FeatureContext'
  extensions:
    Behat\MinkExtension\Extension:
      base_url:  'http://saucelabs.com/'
      javascript_session:  'selenium'
      browser_name: googlechrome
      goutte:              ~
      selenium:

safari:
  context:
    class:  'FeatureContext'
  extensions:
    Behat\MinkExtension\Extension:
      base_url:  'http://saucelabs.com/'
      javascript_session:  'selenium2'
      browser_name: safari
      goutte:              ~
      selenium2:

firefox:
  context:
    class:  'FeatureContext'
  extensions:
    Behat\MinkExtension\Extension:
      base_url:  'http://saucelabs.com/'
      javascript_session:  'selenium2'
      browser_name: firefox
      goutte:              ~
      selenium2:

 

Build.xml

This is a main config where we are creating separate targets for the each profile also generating nice looking html reports for each browsers. Try to understand config below

<project name="behat" basedir=".">
   <target name="run">
    <delete dir="${basedir}/report" />
      <mkdir dir="${basedir}/report"/>
      <parallel>
      <antcall target="chrome"></antcall>
      <antcall target="safari"></antcall>
       <antcall target="firefox"></antcall>
     </parallel>
  </target>
  <target name="chrome">
    <exec dir="${basedir}" executable="php" failonerror="true">
    <arg line= "bin/behat -f html --out report/chrome.html -p chrome"/>
    </exec>
  </target>
  <target name="safari">
    <exec dir="${basedir}" executable="php" failonerror="true">
    <arg line= "bin/behat -f html --out report/safari.html -p safari"/>
    </exec>
  </target>
  <target name="firefox">
    <exec dir="${basedir}" executable="php" failonerror="true">
    <arg line= "bin/behat -f html --out report/firefox.html -p firefox"/>
    </exec>
  </target>
</project>

Once you done with config, you need to run ANT with main target called “run”

ant run

Source-Code

Source-Code is available on GitHub. You can directly clone GitHub repository from here 

Don’t forget to start selenium-server before running tests. You should  run following commands..

$ java -jar selenium-server-standalone-2.30.0.jar
$ git clone git@github.com:Shashikant86/Behat-CrossBrowser-Parallel.git
$ cd Behat-CrossBrowser-Parallel
$ curl http://getcomposer.org/installer | php
$ php composer.phar install
$ ant run

Enjoy Cross-Browser BDD scenarios running in parallel. Watch Youtube video demo

Happy BDD !!

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>