Here's a sample Shell Script that can be added as a stage in your CI/CD Pipeline.


The Script triggers the executions and also waits until the Timeout for the execution to complete.

#!/bin/bash

#********START USER_INPUTS ************************************************
#UserID/E-mail with which you log-in to testsigma(https://app.testsigma.com/)
TESTSIGMA_USER_NAME=<Testsigma username>

#Testsigma user password
TESTSIGMA_PASSWORD=<Testsigma password>

# Testsigma URL to trigger a Test Plan. You can get this URL from Testsigma's Test Plan page. 
# For example, http://app.testsigma.com/rest/execution/49/run
TESTSIGMA_TEST_PLAN_RUN_URL=https://app.testsigma.com/rest/execution/<execution_id>/run

# Maximum time in minutes the script will wait for TEST Plan execution to complete. 
# The script will exit if the Maximum time is exceeded but the Test Plan will continue to run in Testsigma. 
# In that case, you can check test results later by logging to Testsigma.
MAX_WAIT_TIME_FOR_SCRIPT_TO_EXIT=180

# The JSON report data will be copied to a file under this directory. FileName: testsigma.json
JSON_OUTPUT_REPORTS_DIR=~/Documents/ts_reports
#********END USER_INPUTS*****************************************************

##########GLOBAL variables#########
# Time in minutes the script will wait between the polls Testsigma to check if the execution is complete.
POLL_INTERVAL_FOR_RUN_STATUS=3
NO_OF_POLLS=$((MAX_WAIT_TIME_FOR_SCRIPT_TO_EXIT/POLL_INTERVAL_FOR_RUN_STATUS))
SLEEP_TIME=$((POLL_INTERVAL_FOR_RUN_STATUS * 60))

# The generated Test Reports file name
JSON_FILE_NAME=testsigma.json
REPORT_FILE_NAME=$JSON_OUTPUT_REPORTS_DIR/$JSON_FILE_NAME
LOG_CONTENT=""
####################################

get_status(){

    RUN_RESPONSE=$(curl -u $TESTSIGMA_USER_NAME:$TESTSIGMA_PASSWORD --silent --write-out "HTTPSTATUS:%{http_code}" -X GET $TESTSIGMA_TEST_PLAN_RUN_URL/$HTTP_BODY/status)

    echo "Status_Response_Complete: $RUN_RESPONSE "
    # 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://')
    echo "Response_Status: $RUN_STATUS"
    # print the body
    echo "Run Status..."
    echo "$RUN_BODY"
    EXECUTION_STATUS=$(echo $RUN_BODY | getJsonValue status)

    echo "Execution Status: $EXECUTION_STATUS"


}

function checkTestPlanRunStatus(){
  IS_TEST_RUN_COMPLETED=0
  for((i=0; i<= NO_OF_POLLS;i++))
  do
    get_status
    if [ $EXECUTION_STATUS -eq 2 ]
     then
      echo "Sleep/Wait for $SLEEP_TIME seconds before next poll....."
      sleep $SLEEP_TIME

    else
      IS_TEST_RUN_COMPLETED=1
      echo "Automated Tests Execution completed...\n total script execution time:$(((i+1)*SLEEP_TIME/60)) minutes"
      break
    fi
  done


}

function saveFinalResponseToAFile(){
    if [ $IS_TEST_RUN_COMPLETED -eq 0 ]
     then
      LOG_CONTENT="Wait time exceeded specified maximum time(MAX_WAIT_TIME_FOR_SCRIPT_TO_EXIT). Please log-in to Testsigma to check Test Plan run status.
      You can visit the URL specified in \"app_url\" JSON param For landing in Test Plan run page directly.
      Ex: \"app_url\":\"https://dev.testsigma.com/#/projects/31/applications/53/version/72/report/executions/197/runs/819/environments\""

    fi
    echo "Reports dir::$REPORT_FILE_NAME"
    echo "$LOG_CONTENT \n $RUN_BODY"
    echo "$RUN_BODY" >> $REPORT_FILE_NAME
}

function getJsonValue() {
    json_key=$1
    awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/\042'$json_key'\042/){print $(i+1)}}}' | tr -d '"'
}

echo "************Testsigma:Start executing automated tests ... ************"

echo "NO of polls $NO_OF_POLLS"

# store the whole response with the status at the and
HTTP_RESPONSE=$(curl -u $TESTSIGMA_USER_NAME:$TESTSIGMA_PASSWORD --silent --write-out "HTTPSTATUS:%{http_code}" -X POST $TESTSIGMA_TEST_PLAN_RUN_URL)

# extract the body
echo "HTTP_RESPONSE:"
echo
echo $HTTP_RESPONSE
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 "Run_ID:$HTTP_BODY"

# example using the status
if [ ! $HTTP_STATUS -eq 200  ]; then
  echo "Failed to execute automated tests!!"
  echo "Error [HTTP status: $HTTP_STATUS]"
  exit 1 #Exit with a failure.
else
  checkTestPlanRunStatus
  saveFinalResponseToAFile
fi

echo "Final response: $RUN_BODY"
echo "************Testsigma:Completed executing automated tests ... ************"


Feel free to contact Support if you need more clarification.


Welcome to Testsigma!