Code Sample- Python

This article will show simplified code samples to invoke AIO Tests REST APIs in Python to report automated test results in the AIO Tests execution.
The AIO Tests REST APIs use a mix of GET, POST and Multipart-form data requests to get details on execution cycles and create them, report results against individual cases or import results into AIO Tests with the results file for all cases.

In this documentation, you’ll understand:

Setup

For the purpose of this sample, we are going to use a Python library for making API calls- requests.py. Please refer to Installation instructions to add it to your project.

Sample

The Authorization header as shown in the AIO Tests API Token.

headers = {'Authorization': 'AioAuth <Your API Token>'}

1. Get Cycle Details [Swagger]

Get Cycle Details and other Cycle information APIs can be used to get details of existing cycles details, run summary and cycle folder structures.

import requests def _url(path): return 'https://tcms.aiojiraapps.com/aio-tcms/api/v1' + path projectKey = "ATSMPL" cycleKey = "ATSMPL-CY-Adhoc" headers = {'Authorization': 'AioAuth <Your API Token>'} response = requests.get(_url('/project/{}/testcycle/{}/detail'.format(projectKey, cycleKey)), headers=headers) print(response.text)

2. Create Cycle [Swagger]

Depending on your organization’s process/needs, automation execution results can be captured in AIO Tests in two ways.

  • By creating a new cycle for each execution [e.g. Regression Release 1_Day 1, Regression Release 1_Day 2 are individual cycles and only one execution is captured as part of each of these cycles]
    Or

  • By creating a new run in an existing cycle for each execution [e.g. Regression Release 1 is a cycle and daily executions are captured as multiple runs in the same cycle]

Below code sample (code is in #3) shows both creating a cycle, adding cases to it and reporting results.

3. Mark Execution Results [Swagger]

The below sample creates a new cycle and reports the execution results and duration of the run of your test cases.
The sample methods can be added to your test framework’s listeners or hooks which execute either after a case finishes or after execution finishes. [e.g. IInvokedMethodListener in TestNG / TestCaseFinished event in Cucumber / RunListener/TestExecutionListener in JUnit]
These case runs show up with Execution Mode as Automated in AIO Tests.

import requests def _url(path): return 'https://tcms.aiojiraapps.com/aio-tcms/api/v1' + path projectKey = "ATSMPL" headers = {'Authorization': 'AioAuth <Your API Token>'} #Create New cycle newCycleDetailsJson = {'title': 'v1.0 Regression Cycle 1', 'objective': 'Regression cycle for release v1.0', 'folder': {'ID': 212}} response = requests.post(_url('/project/{}/testcycle/detail'.format(projectKey)), headers=headers, json=newCycleDetailsJson) newCycleKey = response.json().get('key') #Mark case as passed caseKey = "ATSMPL-TC-7" results = {'testRunStatus':'Passed', 'effort':120} response = requests.post(_url('/project/{}/testcycle/{}/testcase/{}/testrun?createNewRun={}'.format(projectKey, newCycleKey,caseKey, 'true')), headers=headers, json=results) print(response.text)

4. Import Execution Results from JUnit/TestNG XML files [Swagger]

As a post-execution step, AIO Tests currently supports the JUnit XML Report format and the TestNG report format.
To import results from either of these formats to AIO Tests, the Import Results API can be used in post-execution listeners/hooks.

5. Uploading attachment to a case [Swagger]

Attachments can be added to cases via API calls.

For further queries and suggestions, please feel free to reach out to our customer support service via help@aiotests.com.