How to Run Cucumber Tests using Docker in parallel

2 min


651
2 comments, 651 points
Cucumber Tests using Docker in parallel
Cucumber Tests using Docker in parallel

How to Run Cucumber Tests using Docker

It is crucial once you have an automated test suite to run it often , get feedback as quick as possible and make the most of your tests to increase your team productivity and product quality. In our previous article we covered how to run selenium cucumber tests in chromedriver headless  but in order to have that done in a proper way we need to know how to run cucumber tests using docker in parallel .

Assuming we have docker setup already done in jenkins and your local machine if not here is how your docker file should look like we are going to use jenkins pipeline scripts to kick off our tests in parallel.

Create your jenkins job

Go to Jenkins top page, select “New Job“, then choose “Build a free-style softwareproject“. This job type consists of the following elements: optional SCM, such as CVS or Subversion where your source code resides. optional triggers to control when Jenkins will perform builds.

Go to configure tab job : https://jenkins.yourjenkinshostname.com/view/{ViewName}/job/{JobName}/configure

Paste your pipeline script

Lets try to understand some bits from this script:

This line is to push your test results to an external report system as in this case is reportportal .

Threads : thread1 , thread2 …threadn is a cucumber profile that sores one or more cucumber tags and should be added in your cucumber yaml file.

You need it only if you use a notification system for your build test results , Im going to cover it in a separate article how you can send slack notifications using jenkins pipeline. I will do it separated as is a big topic.

In test stage you can see I used a function getresults()

Basically is our way to set a threshold in jenkins when to fail the build based in the test results. We automatically pass the build if fail rate is less than 2 %. I will cover how to do that in a further article.

Your run tests sh script

Inside runjob() function you’ve seem ./run_tests.sh , bellow you can see the code from it.

 

Using this jenkins pipeline script you can customise your cucumber tests to run on whatever environment you like , browser , brand ( if you have a big framework that incorporates multiple internal projects.)

Now there might be voices to say that we are defining the number of threads and we don’t leave  jenkins to split the objects dynamically . You can run jobs in parallel using the pipeline script provided by Jenkins but the problem with this will run all your tests sequentially first and only on the second run will be running in parallel.

I found it a bit weird because as you are going to increase the number of tests this job will run again and again your tests sequentially in order to figure out how to split the time equally.

It’s up to you what solution you wanna choose , the top one works well for me.

If you have any queries please do not hesitate to add it in the comment bellow.

Happy testing!


Like it? Share with your friends!

651
2 comments, 651 points

What's Your Reaction?

cute cute
0
cute
scary scary
0
scary
wtf wtf
1
wtf
geek geek
0
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. I have created a jenkins pipeline where in one of the stages I am running the scripts which runs the maven test cases then I copy that to the workspace the complete cucumber folder ,some of the cases are failing still build are marked as sucess

    1. hi , it should not be the case

      In the example I have a notified.getRresults()

      My bad I didn’t published the code for the getResults method

      here we go
      @NonCPS
      def getResults(){
      AbstractTestResultAction testResultAction = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
      def failCount = null
      def failureDiffString = null
      def totalCount = null
      def passed = null
      def passrate = null
      if (testResultAction != null) {
      failCount = testResultAction.failCount
      totalCount = testResultAction.totalCount
      passed = totalCount - failCount
      passrate = (passed/totalCount*100).toInteger()
      }

      return passrate
      }

      also if you will have this code in a separate groovy file you need to create it

      and load it in your pipeline
      notifier = null

      and inside your build after you checkout your code :
      notifier = load 'jenkins/notify.groovy'

      I will update the article with this informations

Choose A Format
Trivia quiz
Story