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.
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
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.
#!/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 .”
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:
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 .