Testsigma offers Web hooks for triggering Testsigma Executions remotely from any third-party tool that provides a Command Line Interface(CLI). In this guide, let us see how we can integrate Testsigma in CircleCI for automatically triggering Test Executions with code change on your Code Repository and wait for the tests to pass before proceeding with deployment.

 

TABLE OF CONTENTS


Prerequisite

- A CircleCI Account with connected Source Code Management(SCM) tool(Github, Azure e.t.c)

- A CI/CD pipeline already set up in CircleCI (Please check with your DevOps team if you need help with this)


Obtain API and Test Plan ID from Testsigma App

1. If you have not created a Testsigma API key already, please create one by navigating to Settings > API Keys and clicking on Create an API Key button on the top right corner.

We will be using this API Key to authenticate our remote Test Plan trigger requests from CircleCI(explained in next article section - Set up Code Repository)


2. Create a Test Plan in Testsigma that you would like to execute as part of the CircleCI Pipeline. Obtain the Test Plan ID for the Test Plan from the CI/CD Integrations tab within Test Plan details as shown below:

We will be using this Test Plan ID to specify which Test Plan to trigger from CircleCI(explained in next article section - Set up Code Repository)


So, we have noted down the Testsigma API Key and the Test Plan ID now. We will be adding those to a Shell script and add the shell script file to your Code Repository in the next section.


Add the Shell Script to Code Repository

You need to add a script file in your Code Repository stored on Github, Bitbucket, Azure, or any such platform.

This script file contains commands to trigger the Testsigma Test Plan remotely.


1. Copy the shell script from the article:  Generic Shell Script for Integrating with CI/CD Tools and customize the script.

#********START USER_INPUTS ********

TESTSIGMA_API_KEY= <Give in an API Key Generated in the Configuration-> API Keys tab in Testsigma>

TESTSIGMA_TEST_PLAN_ID= <Test Plan ID for the run which you need to trigger>
MAX_WAIT_TIME_FOR_SCRIPT_TO_EXIT=180
REPORT_FILE_PATH=./junit-report.xml
RUNTIME_DATA_INPUT="buildurl=http://test.testsigma.com,data1=testdata"

#********END USER_INPUTS***********

2 Update your Testsigma API Key and Test Plan ID in the above script.


3. Now upload the script file to your Code Repository(preferably, root folder) and commit.


Configure the CircleCI Pipeline

1. In CircleCI, create a new Project or select the Project that you want to integrate with Testsigma.


2. Clicking on Set up Project takes us to the Set Up page as shown below:


3. Modify the config.yml file and include a job to run the specified bash script file that initiates Testsigma Execution and waits for its completion before deployment. Here's a sample entry for config.yml file:

# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 1.0
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk
- image: debian:stretch
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: mvn dependency:go-offline
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}
# run tests!
# Trigger test on Testsigma and wait until completion or timeout!
- run: chmod a+x ./trigger_testsigma_tests_and_wait.sh
- run: ./trigger_testsigma_tests_and_wait.sh

# deploy!
- run: ./deploy_to_cloud.sh

Check the section that starts with the comment #run tests!


The below line sets executable permission for the script file that triggers test run on Testsigma

run: chmod a+x ./trigger_testsigma_tests_and_wait.sh

The next line actually runs the shell script and this triggers the test plan on Testsigma

run: ./trigger_testsigma_tests_and_wait.sh


4. Now, click on Start Building button on the top right to start a test build. You will be greeted with a dialog stating that the config.yml will be added to the selected Repo by CircleCI.


5. Click on Add Config button to Add the Config and start building. It will take you to the Pipelines page.


That's it.

With the above settings, the build will be triggered whenever there is a change in the repository and as soon as the build is triggered, the tests will begin in Testsigma. The script will wait until the test completes and checks that the result of the tests is passed.


Happy Test Automation!