logo logo

Scheduling API Automation Flows and CI/CD Execution

CI/CD flow - Scheduling API Automation Flows and CI/CD Execution

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

  1. Overview – Automating End to End API Testing Flows
  2. Chapter 1 – Basic API Test Automation
  3. Chapter 2 – API Test Automation Flows Combined with Mobile Functional Test
  4. Chapter 3 – API Test Automation Flows Combined with Database Flows
  5. Chapter 4 – API Test Automation with Combination of Shell Commands and Local Files
  6. Chapter 5Advanced API Test Automation and Validation Flows
  7. 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:

Scheduling Recurrent RESTful API Tests

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.

Schedule Job Execution using TestProject

Schedule Job Execution using TestProject

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:

Create an API Key - TestProject

Then, in order to get your project and job ID, simply copy them from each section respectively:

TestProject Project ID

TestProject Job ID

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:

Happy Testing! 🎯

David Goichman

About the author

David Goichman

Automation has been a great passion of mine from day one. Software Engineer at TestProject.

Join TestProject Community

Get full access to the world's first cloud-based, open source friendly testing community. Enjoy TestProject's end-to-end test automation Platform, Forum, Blog and Docs - All for FREE.

Join Us Now  

Leave a Reply

popup image

A new world for test automation

Join 150,000 testing & dev teams taking their web & mobile testing to new heights, using #1 FREE test automation platform, designed to help deliver quality at speed.
Get Started
FacebookLinkedInTwitterEmail