Cucumber parallel testing


625
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.

Example:

 

Feature: Tests Scenario: Visit Testingrepository.com Given visit testingrepository.com Then verify page title is Automation Scenario Outline: Visit some articles Given visit mail.yahoo.com Then verify page title is <page_title> Examples: | page_title | | Testing | | solution | | Testing | Scenario: Visit contact Given visit testingrepository.com/contact-us/

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
ADD entrypoint.sh /entrypoint.sh
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs && chmod +x /entrypoint.sh;
WORKDIR /myapp
ENTRYPOINT ["/entrypoint.sh"]
#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.

  • Entrypoint.sh
#!/bin/bash
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"
services:
selenium:
image: selenium/hub
ports:
- "4444:4444"
chromenode:
image: selenium/node-chrome
environment:
- HUB_PORT_4444_TCP_ADDR=selenium
- HUB_PORT_4444_TCP_PORT=4444
ports:
- "5555"
depends_on:
- selenium
networks:
default:

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!

625
2 comments, 625 points

What's Your Reaction?

cute cute
0
cute
scary scary
0
scary
wtf wtf
0
wtf
geek geek
1
geek
WIN WIN
0
WIN
Love Love
0
Love
OMG OMG
0
OMG
Angry Angry
0
Angry
Lol Lol
0
Lol
Test engineer

2 Comments

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

  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,

Choose A Format
Trivia quiz
Story