Integrating Tests To Your Development Pipeline. Quickstart Guide To Loadero API.

Why you should use API to launch test runs

Sometimes using a graphical user interface isn’t enough to fulfill your daily tasks, especially when you start automating your testing routines. Imagine a scenario, when you perform a regression test on a piece of functionality every time you push a new release or merge your code to a particular branch. It would be a nightmare to manually run those tests every time, especially if your team is rather large and you’re practicing continuous delivery. It gets even worse when you don’t have a dedicated QA team and developers do all the testing. Loadero allows you to solve this by triggering test runs using API. Today we will take a look at how you can use it.

Loadero API allows you to programmatically interact with Loadero functionality by integrating it into the workflows, pipelines and testing solutions. Setting test automation in your pipeline instead of launching tests manually or testing manually yourself, which is even worse, saves quite a lot of time for your QАs or developers, especially if you launch tests often. 

There are many use cases when API can improve development workflows. Let’s imagine that your web application handles a lot of traffic and it’s very crucial that it stays performant after adding new features. To ensure that you don’t get any regressions after adding new functionality, you may want to run a load test on every feature release. Setting test automation for this by integrating Loadero into your build pipelines is quite easy. For example, load tests can be run every time you push the code into production, so you will always be sure that the web application is ready to handle a known number of users. 

There are also other cases where the Loadero API can be used such as WebRTC application testing, test automation across different browsers, locations and network conditions, that help to make sure that users will get the best experience. 
With Loadero API you can create new tests and edit existing ones, make changes to participant and group settings, set asserts and preconditions for them. All this can be done without the need to interact with the user interface. To start doing that we advise you to first take a look at the  API documentation that can be found here.

Preparation to use the Loadero API

There are some actions you have to take before actually starting to use the API. Access to it is available for all projects that are not on trial, so make sure to choose a paid plan that suits your needs

First you have to request an access token for your project. To do that contact Loadero support via email or a webchat. In the request, you will need to specify:

  • Project ID this access token will be used for
  • Access token expiration time, if you would like to make its lifetime limited
  • Mention if you want to restrict this token to have only some of the scopes available

Important: The project access token provides direct API access in the scope of a single project it was specifically created for. In other words, the project access token will be limited to a single project. 

Once you’ve got your project access token handy, you can start working on test automation for your testing routines!

API use example

In the following example, we will take a look at how we can run a load test using the Loadero API. To keep things simple, I have manually created a simple test called ‘load test’’ beforehand. I have noted my project ID, test ID and my access token, as they will be necessary later. The test also has participants and participant groups already configured according to my needs. If you don’t have a test created in Loadero yet, follow this step-by-step guide to create your first one. You can use the API not only to launch any of the previously created tests in your Loadero project, but also the tests can be created and configured programmatically using API endpoints. 

Now let’s move to the steps you have to take for launching a test with API. Our example will use Javascript, but you can use other languages to achieve the same as well.

1) To begin with, we define constants for the API base URL(you will have the same URL for your implementation), project ID, test ID and request options. In the request options object, we add the Authorization header with the value consisting of a LoaderoAuth token type and provided access token. 

2) Next, we create an asynchronous function that accepts URL string as a parameter. Within this function, we use the Fetch API to create a request by passing a URL value and the options object. 

3) To run a test, we simply call the runTest function by passing a constructed test run endpoint URL that contains project and test IDs. 

4) After we called the runTest function, in the response, we can confirm that the execution of our test has been made.

// Loadero API base URL
const BASE_URL = "https://api.loadero.com/v2/projects";
// The ID of the project we are working with
const PROJECT_ID = 12345;
// The ID of the test we want to run
const TEST_ID = 12345;
const runTest = async url => {
   // Request options with authorization header and access token
   const OPTIONS = {
       headers: {
               "LoaderoAuth <WRITE YOUR TOKEN HERE>"
       method: "POST"
   const response = await fetch(url, OPTIONS);
   return response.json();
// Run test
runTest(`${BASE_URL}/${PROJECT_ID}/tests/${TEST_ID}/runs/`).then((data) => {
 // created: "2021-04-15T06:26:01Z"
 // execution_finished: "0001-01-01T00:00:00Z"
 // execution_started: "0001-01-01T00:00:00Z"
 // ...

That is it! We have successfully run a test by using the Loadero API. That’s all you have to do to successfully launch a test from your CI pipeline. In practice, you would like to poll test run status to see when it completes and check if it was successful, and maybe add some other steps.

Of course, there are many other things you can automate with Loadero API. The API integration plays an important role in testing web applications. Loadero API provides all the necessary tools to automate all your manual tasks and run your development pipelines and workflows smoothly.

You can start preparing to integrate tests into your CI pipeline today by signing up for a Loadero free trial, creating and launching your first free tests. Once you are ready, upgrade to any of our paid plans, you will be able to use API for integration as well. If you have any questions about Loadero API use, feel free to contact our support for that.