Integrating Jenkins With Testsigma for Continuous Integration
See how Testsigma's test automation tool can be integrated with your Jenkins pipeline to enable continuous testing as part of CI/CD.
Join the DZone community and get the full member experience.
Join For FreeIntroduction to Continous Integration
Continuous Integration (CI) is the practice of merging all developer working copies to a shared mainline several times a day, as per the wiki definition. CI was initially popularized by modern development strategies such as XP (Extreme Programming) and Agile. Presently, it is the de-facto standard for most of the Product based companies but not limited to them as it encourages testing and fixing issues at an earlier stage.
Testsigma provides built-in CI support among its suite of various plugins to facilitate the test automation process. We will take a look at setting up Jenkins pipeline to run automated tests on Testsigma in this article.
Jenkins - An Overview
As you may already know, Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software. It does this by following the principle of pipelining those tasks.
A pipeline is an automated expression of your process for getting software from version control right through to your users and customers. Every change to your software (committed to source control) goes through a complex process on its way to being released. This process involves building the software in a reliable and repeatable manner, as well as progressing the built software (called a "build") through multiple stages of testing and deployment.
Testsigma's Place in the CI/CD Pipeline
Testsigma comes into picture during the Testing stage. Using the Jenkins plugin for Testsigma, we can integrate the Testsigma Test Automation tool into the Jenkins pipeline so that whenever a successful build is made, Testsigma executes the tests and notifies whether the tests passed or failed. The test results help us determine whether the build is a release candidate (RC), i.e. whether it is deployable or not.
Integrating Testsigma Into a Jenkins Pipeline
If you are fairly new to Testsigma tool, please check out our previous article on Web Application Automated Testing with Testsigma for a quick overview of the tool.
We can use the Jenkins plugin in Testsigma to automate a Test Execution when a successful build is triggered in Jenkins automation server. This is done by adding a task to the Jenkins pipeline to execute a shell script. The script sends POST requests to Testsigma API using curl when a successful build is generated.
Adding the Test Execution Step to the Jenkins Pipeline
First, go to the Execution details page in Testsigma tool for the Execution that you want to include in your Jenkins Pipeline. The CURL request format for starting a Test Execution can be found on the Execution details page under the CI Integration Details as shown below:
Then, replace the <Username> and <Password> parts with your Testsigma login credentials to get the curl request format for the corresponding execution.
Once you get the required request format, you simply need to add a task to your Jenkins pipeline to execute a shell script that executes the above instruction.
Jenkins Script Formats
Simple Format
Add a step in the Jenkins pipeline to run the following bash script which starts the Test Execution remotely.
curl -X POST -H 'Content-type: application/json' \ -u : \ http://app.testsigma.com/rest/execution/229/run
This script simply starts the execution in Testsigma and you might need to add additional tasks to check for the result of the execution.
Advanced Format
This script starts the test execution and polls for the test execution completion every 120 secs until failure.
#https://github.com/trentm/json
#https://gist.github.com/maxcnunes/9f77afdc32df354883df
get_status(){
RUN_RESPONSE=$(curl -u <YOUR_USERNAME>:<YOUR_PASSWORD> --silent --write-out "HTTPSTATUS:%{http_code}" -X GET $URL/$HTTP_BODY/status)
# extract the body
RUN_BODY=$(echo $RUN_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
# extract the status
RUN_STATUS=$(echo $RUN_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
# print the body
echo "Run Status..."
echo "$RUN_BODY"
EXECUTION_STATUS=$(echo $RUN_BODY | json status)
echo "Execution Status $EXECUTION_STATUS"
echo $RUN_BODY | json status_text
if [ $EXECUTION_STATUS -eq 2 ]; then
sleep 120
get_status
else
echo "Automated Tests Execution completed..."
fi
}
echo "Start executing automated tests ... "
URL='<YOUR_EXECUTION_URL>'
#example: URL='http://app.testsigma.com/rest/execution/49/run'
# store the whole response with the status at the and
HTTP_RESPONSE=$(curl -u <YOUR_USERNAME>:<YOUR_PASSWORD> --silent --write-out "HTTPSTATUS:%{http_code}" -X POST $URL)
# extract the body
HTTP_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
#HTTP_BODY=$(echo '"$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS:.*//g'')
# extract the status
HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
# print the body
echo "$HTTP_BODY"
# example using the status
if [ ! $HTTP_STATUS -eq 200 ]; then
echo "Failed to executed automated tests!!"
echo "Error [HTTP status: $HTTP_STATUS]"
exit 1 #Exit with a failure.
else
#Poll to check the execution status
poll=true
while $poll
do
get_status
#sleep 120 #Wait for 120 seconds to check execution status again.
poll=false #Mark poll to false to stop polling and exit
done
fi
echo "Completed executing automated tests!!!"
You need to replace the <YOUR_USERNAME>, <YOUR_PASSWORD> with your Testsigma account username and password and <YOUR_EXECUTION_URL> with the URL of the corresponding Execution Details page. You may also modify the wait time of 120 seconds if needed.
Finally, add any of the two scripts (simple or advanced) to the shell script execution task into the Jenkins pipeline.
That's all we need to automate test execution when a successful build is triggered using the Jenkins CI server.
Welcome to the era of #SmartTestAutomation.
Opinions expressed by DZone contributors are their own.
Comments