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!
The post How to Run Cucumber Tests using Docker in parallel appeared first on TestingRepository.
This post first appeared on Testing Repository - Creating Testing, please read the originial post: here