Interact With QAComplete REST API

Applies to QAComplete 14.3, last modified on February 19, 2024

You can interaсt with QAComplete REST API using various tools, including those provided by SmartBear. In this section, we offer a selection of ordinary tasks, which you can achieve with a tool of your choice.

Basics

QAComplete REST API provides an extensive functionality on creating, updating, and working with all items within your QAComplete projects. Basically, it means you can create an automated or semi-automated scenario for your preferred testing tool, and this allows you to reflect all changes you make to your application in QAComplete without any action from your side.

For interacting with QAComplete REST API, your selected tool must support the following functionality:

For a complete list of QAComplete REST API specifics and requirements, see About QAComplete REST API.

ReadyAPI and SoapUI

ReadyAPI and SoapUI are automated testing tools that you can use to create functional and security tests for web service APIs.

The internal structure of projects in these tools implies that you will use the REST Request test step to access QAComplete. Try to create a simple project in ReadyAPI to see how it works:

  1. Create a new functional test in ReadyAPI or SoapUI.

  2. Select URL as a tested resource.

  3. Use the following address of the REST API service:

    • For SaaS users:https://rest.qacomplete.smartbear.com/rest-api/service
    • For on-premises users:http://[your server name]/rest-api/service
  4. After the service URL, add the path to the REST resource you want to access.

    In this example, we use the /projects GET operation, which returns the list of all available projects in your QAComplete instance. To use it, complete the path with the following:

    /api/v1/projects
  5. When the request is ready, use the request editor to add an authorization header to it.

  6. Try out the request – it will return a list of projects from your QAComplete instance.

With ReadyAPI and SoapUI, you can create a multitude of requests in the same way to access various endpoints of QAComplete instance to use the information you retrieve in your tests or add new data to the QAComplete database.

Wishing to learn more about ReadyAPI and SoapUI and functionality they provide? Feel free to take a look at the free trial.

Scripts and testing applications

When you work with your preferred testing framework, it may be helpful to access QAComplete REST API to retrieve some data or post the results of your tests. Of course, you can always pack up your testing project and manually upload it to QAComplete, or use the integration plugin if it is available, but there are cases that can manage with simple interaction solutions.

You can access QAComplete REST API directly using scripts in any testing tool you find suitable – for example, TestComplete or Selenium.

Check the example below to see how it works – you can use it in any Python interpreter, including those provided by various testing tools.

Example

The following example demonstrates how to create a test run in the QAComplete instance using the ../testruns POST operation and retrieve the ID of the test run you have created.

The sample scripts in this section use the third-party Requests library. Make sure to download and install it before trying to implement these scripts yourself.

Python

import requests, json

def createNewRun(projectId):

    # Use the following URL for the SaaS edition of &product-name;, or replace it with the URL of your server
    url = "https://rest.qacomplete.smartbear.com/rest-api/service/api/v2/projects/" + str(projectId) + "/testruns"

    # Describe your test in the testrun object
    testrun = {"TestId": 5130960}

    response = requests.post(url, data=json.dumps(testrun), headers = {"Content-Type": "application/json"}, auth=("[email protected]", "p@ssw0rd"))

    # Print the result
    print(response.text)

    # Convert the response to a Python dictionary
    responseData = json.loads(response.text)

    # Retrieve values from response fields
    testrunId = responseData.get("id")
    status = responseData.get("status_code")

    # Print the ID of the test run
    print(testrunId)

Now, you can retrieve the ID of the test run item to use it in subsequent requests – for example, to update this item. For that purpose, use the ../testruns/{TestRunId}/items GET operation.

Python

import requests, json

def getTestRunInfo(projectId, testrunId):

    # Use the following URL for the SaaS edition of &product-name;, or replace it with the URL of your server
    url = "https://rest.qacomplete.smartbear.com/rest-api/service/api/v2/projects/" + str(projectId) + "/testruns/" + str(testrunId) + "/items"

    response = requests.get(url, auth=("[email protected]", "p@ssw0rd"))

    # Parse the result
    responseData = json.loads(response.text)

    # Retrieve the ID of the first test run item
    
    testrunitemId = responseData.get("results",{})[0].get("id")

    # Print the ID
    print(testrunitemId)

Knowing the ID, you can update the test run item (a step) in the QAComplete instance using the ../testruns/{TestRunId}/items/{ItemId} PATCH operation.

Python

import requests, json

def updateRunInfo(projectId, testrunId, testrunitemId):
    
    # Use the following URL for the SaaS edition of &product-name;, or replace it with the URL of your server
    url = "https://rest.qacomplete.smartbear.com/rest-api/service/api/v2/projects/" + str(projectId) + "/testruns/" + str(testrunId) + "/items/" + str(testrunitemId)

    # Describe which fields you want to update in the test run item
    updateFields = {"Critical": True, "StatusCode": "Passed"}

    response = requests.patch(url, data=json.dumps(updateFields), headers = {"Content-Type": "application/json"}, auth=("[email protected]", "p@ssw0rd"))
  
    # Print the result
    print(response.text)

Windows PowerShell

You can use Windows PowerShell to make calls to the QAComplete REST API. With its functionality, you can perform any necessary tasks.

The following code demonstrates how to create a new test run in the QAComplete database:

# Create variables for credentials

$user = '[email protected]'
$pass = 'p@ssw0rd'

# Encoding credentials

$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"

# Creating an authorization header

$header = @{
Authorization = $basicAuthValue
}

# Specifying an endpoint and HTTP method

$url = "https://rest.qacomplete.smartbear.com/rest-api/service/api/v2/projects/86763/testruns"
$verb = "POST"

# Describing a test run object

$body = @{
"TestSetId"="254767"
}

# Sending the request

Invoke-WebRequest -Method $verb -Uri $url -Body ($body|ConvertTo-Json) -ContentType "application/json" -Headers $header

See Also

QAComplete REST API

Highlight search results