Testsigma provides a robust API to manage the Executions and Execution Data using RESTful API Calls. Below given are some of the utilities provided by Testsigma API.

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


Start Execution

We can start an execution in Testsigma easily using the following API request and replacing the <execution-id> part with actual execution-id

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


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

As you can see, the execution ID in the above case is '1247'.

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


Making the API Call - Using cURL

Now, if you would prefer a curl command, that is even more simple. Send a cURL request of the form using your preferred application:

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


Replace <Username> & <Password> with real credentials and also replace the <Execution-ID> that you get from the Execution Details page.


REST API Response

A successful execution trigger Call returns the Run ID of the Execution in response as shown below:


Check Execution Status

We can check the execution status in Testsigma easily using the following API request. 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.

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


The run ID can be obtained in two ways:
1. For a successful execution trigger 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.


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'.

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 passed execution.


Therefore, we need to continuously poll the API in 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:testsigma123 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:testsigma123 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:testsigma123 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