End-to-end API testing flows can involve multiple input sources, such as HTML, Databases, Telnet/SSH, Mobile, Shell, Data files, other RESTful APIs and more. TestProject‘s test automation platform allows not only testing your APIs manually, but also to complete end-to-end API based test automation flows, schedule and run them periodically as part of your CI/CD execution, get execution reports and all of that without any third party tools and without a single line of code 🚀
This hands-on tutorial consists of step-by-step examples and real automated test flows, shared here for you to use and practice while automating your APIs. In this chapter (Chapter #6), we will walk through scheduling API automation flows and CI/CD execution.
Table of Contents – Automating End to End API Testing Flows
- Overview – Automating End to End API Testing Flows
- Chapter 1 – Basic API Test Automation
- Chapter 2 – API Test Automation Flows Combined with Mobile Functional Test
- Chapter 3 – API Test Automation Flows Combined with Database Flows
- Chapter 4 – API Test Automation with Combination of Shell Commands and Local Files
- Chapter 5 – Advanced API Test Automation and Validation Flows
- You’re here → Chapter 6 – Scheduling API Automation Flows and CI/CD Execution
Scheduling Recurrent RESTful API Tests
In order to schedule your API tests and have them repeat at certain time frames/dates, simply aggregate your tests into jobs:
Afterward, schedule the jobs to execute on your preferred time and date. The tests will automatically be executed at the selected time and date on the Agent selected while creating the job.
Running RESTful API Tests by Rest/Curl/CMD Command
TestProject offers a fully RESTful API you can use to trigger your API tests via curl commands from your local CMD. To trigger the API tests, you will need to place them in a job and run the following command from your terminal:
curl -X POST "https://api.testproject.io/v2/projects/YOUR_PROJECT_ID/jobs/YOUR_JOB_ID/run" -H "accept: application/json" -H "Authorization: YOUR_API_KEY" -H "Content-Type: application/json" -d "{ \"agentId\": \"string\", \"browsers\": [ \"Chrome\" ], \"devices\": [ \"string\" ], \"queue\": true, \"restartDriver\": true, \"projectParameters\": { \"additionalProp1\": {}, \"additionalProp2\": {}, \"additionalProp3\": {} }, \"testParameters\": [ { \"testId\": \"string\", \"testPosition\": 0, \"dataSourceId\": \"string\", \"reinstallApp\": true, \"data\": [ { \"additionalProp1\": {}, \"additionalProp2\": {}, \"additionalProp3\": {} } ] } ]}"
Notice you’ll need to place your correct TestProject API key, project and job ID where the API tests are located.
To create your TestProject API key, you can head over to the Integrations section, and then navigate to the API section on the TestProject platform:
Then, in order to get your project and job ID, simply copy them from each section respectively:
Executing RESTful API Tests as Part of a CI/CD Execution
To ensure testing coverage of your application, you can integrate API testing using TestProject into your CI/CD pipeline along with your functional tests. TestProject provides Jenkins and TeamCity built-in integrations that provide an easy way to execute TestProject jobs, update applications, data sources, project parameters and more. You can also use any other CI/CD tools of your choice, simply by using our RESTful API.
You can use these to easily trigger and run your TestProject API tests during your CI/CD Flow. The following pipeline will trigger a job containing API tests using the TestProject Jenkins plugin:
pipeline {   agent any   stages {      stage('Run API Test') {         steps {            tpJobRun agentId: '', executionParameters: '', jobId: 'MY_JOB_ID', junitResultsFile: '', projectId: 'MY_PROJECT_ID', waitJobFinishSeconds: 30         }      }   } }
If the CI/CD tool you are using does not have a built-in integration to TestProject, you can execute your API tests via curl commands through your pipeline, such as:
bat 'curl -X POST "https://api.testproject.io/v2/projects/YOUR_PROJECT_ID/jobs/YOUR_JOB_ID/run" -H "accept: application/json" -H "Authorization: YOUR_API_KEY" -H "Content-Type: application/json" -d "{ \"agentId\": \"string\", \"browsers\": [ \"Chrome\" ], \"devices\": [ \"string\" ], \"queue\": true, \"restartDriver\": true, \"projectParameters\": { \"additionalProp1\": {}, \"additionalProp2\": {}, \"additionalProp3\": {} }, \"testParameters\": [ { \"testId\": \"string\", \"testPosition\": 0, \"dataSourceId\": \"string\", \"reinstallApp\": true, \"data\": [ { \"additionalProp1\": {}, \"additionalProp2\": {}, \"additionalProp3\": {} } ] } ]}" '
Executing Restful API Tests as Part of CI/CD Execution from Docker Container
To execute your TestProject API tests on Docker as part of your CI/CD flow, you’ll need to setup a TestProject Agent on a Docker container and use it to execute the jobs containing your API tests.
The following CI/CD flow will start a job on an ephemeral instance, which will self-terminate once the job execution has finished. Notice the usage of the –rm flag, which will cause the container to be deleted once the TestProject agent finishes the job’s execution and exits.
pipeline {    agent any    stages {        stage('RunJob') {            steps {                bat 'docker run --rm -e TP_API_KEY="MY_API_KEY" -e TP_JOB_ID="MY_JOB_ID" testproject/agent:latest'            }        }    } }
That’s a Wrap!
You have completed our full step-by-step guide to automating end-to-end API testing flows using TestProject -we hope you enjoyed it! 😉 If you haven’t already, go ahead and explore the shared tests from these detailed examples and start your API testing journey:
- API HTML and Dynamic API Endpoint Test (Chapter 1)
- Android and Restful API Test Example (Chapter 2)
- iOS and Restful API Test Example (Chapter 2)
- API Database Test (Chapter 3)
- CMD Shell Commands and Restful API Test Example (Chapter 4)
- SSH Connection and Restful API Test Example (Chapter 4)
- CSV Operations and Restful API Test Example (Chapter 4)
- File Operations and Restful API Test Example (Chapter 4)
- RESTful API GET Call and JSON Schema Validation Test Example (Chapter 5)
- RESTful API GET Call with Extracting Multiple Values from JSON Response Test Example (Chapter 5)
- Basic Authorization Within RESTful API Call Test Example (Chapter 5)
- RESTful API Urlencoded Format Requests Example (Chapter 5)
- Executing API Tests with  Dynamic Parameters and Predefined Data Set (Chapter 5)