CI Lifecycle Using Our API

In this example we start a test execution, wait for it to finish, and then save all results in CSV format.

Trigger an existing test configuration

It assumes you have already created a test configuration and scenario via the API or website first and have the trigger URL for the configuration available.

See the concepts, new configuration guide, new scenario guide, configuration API, and scenario API for more details.

Example:

curl -X POST --silent https://api.testable.io/public/$TESTABLE_TRIGGER | jq -r ".id"

Use Simple API to define all test parameters

Use the simple API to start a test passing all parameters. For example to run a Node.js script, test.js, in AWS N. Virginia on our shared grid use the following:

curl \
  -F "code=@/local/path/to/my/test.js" \
  -F "concurrent_users_per_region=5" \
  -F "duration_mins=2" \
  -F "rampup_mins=1" \
  -F "conf_testrunners[0].regions=aws-us-east-1" \
  https://api.testable.io/start?key=$TESTABLE_KEY

Monitor a running test and save results to CSV

The following script takes a test execution ID, waits for it to complete, prints out the success/failure status, and saves all results to a local CSV file.

testable-monitor.sh

#!/bin/bash

execution_id=$1
echo "[$(date)] Waiting for execution to complete (view online at https://a.testable.io/results/$execution_id)"
while [ $(curl -H "X-Testable-Key:$TESTABLE_KEY" --silent https://api.testable.io/executions/$execution_id | jq -r ".completed") = "false" ]; do
  echo -n "."
  sleep 5
done

if [ $(curl -H "X-Testable-Key:$TESTABLE_KEY" --silent https://api.testable.io/executions/$execution_id | jq -r ".success") = "false" ]; then
  echo -e "\n[$(date)] Test FAILED"
else 
  echo -e "\n[$(date)] Test SUCCESS"
fi

epoch=$(date +"%s")
echo "[$(date)] Storing CSV results at results-$epoch.csv"
curl -H "X-Testable-Key:$TESTABLE_KEY" --silent https://api.testable.io/executions/$execution_id/results.csv > results-$epoch.csv

Example usage with a trigger:

export TESTABLE_KEY=xxx
export TESTABLE_TRIGGER=yyy
./testable-monitor.sh $(curl -X POST --silent https://api.testable.io/public/$TESTABLE_TRIGGER | jq -r ".id")

Example usage with the Simple API:

export TESTABLE_KEY=xxx
./testable-monitor.sh $(curl \
  -F "code=@/local/path/to/my/test.js" \
  -F "concurrent_users_per_region=5" \
  -F "duration_mins=2" \
  -F "rampup_mins=1" \
  -F "conf_testrunners[0].regions=aws-us-east-1" \
  https://api.testable.io/start?key=$TESTABLE_KEY)