Docker Compose Cucumber for Cross-Browser Testing

Docker-Compose

Docker is the trending tool in the recent days which allows us to run multiple lightweight containers to perform various task. Just in case, you haven’t got docker please refer my previous post ‘Guide to Docker ToolBox‘ to start Docker from scratch.

Docker-compose is a way of managing multiple containers to perform specific tasks. It allows us to create ‘docker-compose.yml’ file with our container requirements. You can install docker-compose in with PIP with single command.

$ pip install docker-compose

In this short post, we will setup Ruby-Cucumber to run scenarios in the multiple browses. We will execute it in PhantomJS based Poltergeist driver.

Docker-Compose Cucumber

We will consider two basic scenarios here.

  • You have existing cucumber framework setup
  • You have to start from scratch

Existing Cucumber Framework

Assuming, you have created Dockerfile & profile for those browsers and registered drivers. This also assumes that you have docker image provisioned with specific webdriver drivers e.g firefox-driver, chrome-driver etc

You can create a docker-compose.yml fie which looks like this :

cucumber-phantomjs:
  build: .
  command: bundle exec cucumber -p phantomjs
  volumes:
    - .:/myapp
  ports:
    - "4777:4777"

cucumber-chome:
  build: .
  command: bundle exec cucumber -p chrome
  volumes:
    - .:/myapp

This will allow us to setup multiple browsers in our cucumber.

 Start from Scratch

I have created little project on Github to start with Docker-Compose with Cucumber.

https://github.com/Shashikant86/docker-compose-cucumber

You can clone this repo and use it directly.

$ git clone https://github.com/Shashikant86/docker-compose-cucumber

$ cd docker-compose-cucumber

You have all the setup ready.

Configuring Docker-Compose File

Now have a look at ‘docker-compose.yml’ file. It has phantomjs and chrome profile. You can update file according to the browser and cloud testing services you use like Saucelabs, Testingbot and Browserstack.

  • Using With PhantomJS

You can use headless browser PhantomJS with Poltergeist driver.

cucumber-phantomjs:
  build: .
  command: bundle exec rake parallel_cucumber
  volumes:
    - .:/myapp
  ports:
    - "4777:4777"

 

  • Using with Chrome

You have to make sure, Docker image has chrome and chrome-driver installed.

cucumber-chome:
  build: .
  command: bundle exec rake chrome
  volumes:
    - .:/myapp

You can also use other drivers as well if you have Saucelabs, Browserstack Key setup in the ‘features/support/env.rb’ file.

Now run Docker Compose

 $ docker-compose up

This will build and run cucumber scenarios in the different containers with different browsers.

docker-compose-cucumber-

You can see above two containers has been launched, one for phantomJS and other for chrome.

Video Demo

  • Installing Docker Toolbox

  • Docker-Compose Cucumber Cross Browser