Testsigma provides a robust API to manage and trigger the Executions using RESTful API Calls. These can be used to integrate with any of the third-party CI tools available in the industry such as GitLab, Codeship, CircleCI e.t.c.


Note: You need to authenticate each of these requests with your Testsigma Account login credentials before executing these requests.

Start Execution

We can start/trigger the execution remotely in Testsigma easily using the following API request:

http://app.testsigma.com/rest/execution/<execution-id>/run

Replace the <execution-id> part with actual execution-id.


For a particular Execution, you can get the complete API request(that uses cURL command) to trigger the execution from the Executions page as shown below:

curl -X POST -H 'Content-type: application/json' -u <Username>:<Password> https://app.testsigma.com/rest/execution/1247/run

As you can see, the execution ID in the above case is '1247'. Replace <Username> & <Password> with real credentials and also replace the <Execution-ID> that you get from the Execution Details page.


The Environment Run Id is returned in the response for the request if the execution was started successfully.


Check Execution Status

We can check the execution status in Testsigma easily using the following API request:

https://app.testsigma.com/rest/execution/<execution-id>/run/<run-id>/status

Replace the <execution-id> part with actual execution-id and <run-id> with actual run-id for the individual execution run whose status we are checking.


The run ID can be obtained in two ways:
1. For a successful execution started/triggered using 'Start Execution REST API Call', the response returns the run ID of the Execution run that has started.
2. The Run ID of the execution can be found from the Run Results page for the specified Execution in Testsigma tool.


The response of the Execution Status API is as given below:

{
    "result": 0,
    "summary": {
        "SUCCESS": 4,
        "PRE_REQUISITE_FAILURE": 0,
        "QUEUED": 0,
        "NOT_EXECUTED": 0,
        "STOPPED": 0,
        "Total": 4,
        "ABORTED": 0,
        "FAILURE": 0
    },
    "status_text": "Completed",
    "message": "Execution completed",
    "status": 0
}


Advanced Topic: CI/CD - Wait for Passed Execution to trigger deployment

We are only interested in the keys named 'status' and 'result' in the above response.

For 'status', the value '0' corresponds to a completed execution(irrespective of a passed or failed test)

For 'result', the value '0' corresponds to a passing execution.


Therefore, we need to poll the API at regular intervals until the 'status' becomes '0'. Once the 'status' becomes '0' i.e COMPLETED, check whether the 'result' is '0' i.e PASSED. Else, return an error condition in the tool that you are using.

Here's the steps for use in your CI/CD tool:

1. Obtain the execution ID from Execution details page in Testsigma.

2. Trigger the execution using the endpoint /rest/execution/<execution-id>/run

3. Store the run-id from response to variable <run-id>

4. Check status of execution using the endpoint rest/execution/<execution-id>/run/<run-id>/status

5. If the value of <status> is 0:

    5a. If value of <result> is 0: test passed - deploy

    5b. Else: test failed, debug the test failure

6. Else, go to step 5 again.


And Here's the bash Script:

cd #!/bin/bash

echo "Triggering Execution!"
currentrunid=$(curl -sS -X POST -H 'Content-type: application/json' -u renju@testsigma.com:testsigma https://app.testsigma.com/rest/execution/1940/run)
echo "Started Execution. Waiting for tests to complete..."
currentstatus=1
while [ $currentstatus -ne 0 ]
do
    currentstatus=$(curl -sS -X GET -H 'Content-type: application/json' -u renju@testsigma.com:testsigma https://app.testsigma.com/rest/execution/1940/run/$currentrunid/status | jq '.status')
    sleep 5
done
echo "Test Execution Completed. Checking results..."
currentresult=$(curl -sS -X GET -H 'Content-type: application/json' -u renju@testsigma.com:testsigma https://app.testsigma.com/rest/execution/1940/run/$currentrunid/status | jq '.result')
if [ $currentresult -ne 0 ]
then
    echo "Test Failed. Please check Testsigma to know the reason for failure."
fi