Cucumber parallel testing

2 comments, 625 points
cucumber parallel testing
cucumber parallel testing

Cucumber parallel testing

In a previous article we’ve discussed about how to run cucumber tests in parallel using docker there everything was relying on the jenkins pipeline and I wasn’t talking about selenium grid, so lets have a look into cucumber parallel testing using docker and selenium grid.

Test automation and continuous integration its a very important step in our software development life cycle  and we need to look into finding reliable tools that can help us to get a quick feedback , to be real , and reduce the number of flaky tests.



Feature: Tests

  Scenario: Visit
    Given visit
    Then verify page title is Automation

  Scenario Outline: Visit some articles
    Given visit
    Then verify page title is <page_title>
      | page_title |
      | Testing    |
      | solution   |
      | Testing    |

  Scenario: Visit contact
    Given visit

Let’s run the tests in parallel

In order to run the tests in parallel Im going to use a ruby gem in this case parallel_tests .

bundle exec parallel_cucumber features/feature_file.feature -n 6 –group-by scenarios

“-n” defines processes and it provides parallel sessions with -n separate sessions.

Create a docker image to run parallel Cucumber Scenarios

Lets create our docker image with the following content and chunk our entry point that is gonna be called when we do docker run.

  • Dockerfile
FROM ruby:2.4.0
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs && chmod +x /;
WORKDIR /myapp
#CMD ["/bin/bash"]

In Entrypoint file we are just installing the gems and starting to run our tests in parallel using our grid services that we are going to discuss down in this article.

mkdir -p /code/output
bundle install
bundle exec parallel_cucumber features/feature_file.feature -n 6 --group-by scenarios

To build Docker image run below command:

“docker build -t parallel_cucumber .”

Docker Compose

Basically, if we run “docker-compose up” command, the file will download the “selenium/hub”, “selenium/node-chrome”, “selenium/node-firefox” images (if they have not downloaded yet) and create a containers of them.

version: "3"
 image: selenium/hub
 - "4444:4444"
 image: selenium/node-chrome
 - HUB_PORT_4444_TCP_ADDR=selenium
 - HUB_PORT_4444_TCP_PORT=4444
 - "5555"
 - selenium

To start selenium server and chrome node run below command:

“docker-compose up”

After that you can scale ‘chrome’ nodes as you want. To increase nodes use that command:

“docker-compose scale chromenode=5”

And here is how your selenium grid console will look like :

To start the parallel execution you can use below command:

“docker run parallel_cucumber”

If you want to use other browser to test your scenarios on, just add related image information into compose file like firefox.

If you want to read about docker and headless chrome just have a look at our article here .

Happy testing!

Like it? Share with your friends!

2 comments, 625 points
Test engineer


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

seven + six =

  1. Hi, thanks for this tutorial, but it’s hard to follow for newbies like me, for example what is this code under the title Docker Compose , do you have the code in github ? Thanks,