Our documentation site has been updated to AIO Tests Knowledge Base
Postman via Newman report
AIO Tests provides integration with Postman tests by allowing users to import their Newman generated JSON report via REST calls or with a custom newman reporter. Results can be updated for existing AIO Tests Cases by mapping automated cases or by creating new ones from the Newman results json file.
Having the automated results reporting in AIO Tests, can help in having a holistic view of coverage of requirements (unit to manual to functional and end-to-end automated tests).
This article discusses how are API tests created and results of the tests uploaded to AIO Tests using Newman results.
- 1 Postman and Newman
- 2 Integration with AIO Tests
- 3 Reporting results
- 3.1 newman-reporter-aiotests
- 3.1.1 Install
- 3.1.2 Usage
- 3.1.3 CLI Options
- 3.1.3.1 With Newman CLI
- 3.1.3.2 With Newman as a Library
- 3.1 newman-reporter-aiotests
Postman and Newman
Postman is an API platform for building and using APIs. It is also an API client that makes it easy for developers to design, mock, create, share, test and document APIs. With Postman, you can send requests to connect to APIs you are working with. Requests can retrieve, add, delete, and update data. Requests can send parameters, authorization details, and any body data that is required.
Newman is an open source command-line Collection Runner for Postman. It enables you to run and test a Postman Collection directly from the command line, making it possible to run API tests in continuous integration servers and build systems.
Newman Setup
To run Newman, ensure that you have Node.js >= v10. Install Node.js via package manager.
npm install -g newman
orbrew install newman
Execute Postman Collection via Newman
Postman requests and examples can be grouped into collections to keep a workspace organized, to collaborate with teammates, to generate API documentation and API tests, and to automate request runs.
Create a Postman Collection. For details on creating Postman collections, please refer to Creating Collections and Adding Requests to Collections.
Export the collection (Steps to Export). Exporting creates a collection.json file.
Using the newman cli, run the collection
newman run sample-collection.json
Environments provide a set of variables that one can use within collections. If an environment file is required, then export the environment file and use it with newman run as follows:
newman run mycollection.json -e env.json
Sample collection
Generating Json report
The json reporter comes out of the box with newman. To generate a json report for a newman run, provide --reporters json
as a CLI option.
It takes the path to the file, where to write the report --reporter-json-export <path>
. If not specified, the file will be written to newman/
in the current working directory.
So, a complete command to run and generate json report will be as below:newman run mycollection.json -e env.json --reporters json --reporter-json-export <path>
Sample report
The json report is a comprehensive output of the run summary. It contains the details of all requests, their tests, the responses and much more. A sample report is as below:
Integration with AIO Tests
AIO Tests supports Postman API Tests via the BDD/Gherkin format of cases. Using the newman output of runs, AIO Tests allows users to
either report results against existing cases in AIO Tests
or create new cases on the fly.
A sample API case in AIO Tests looks like below. The next section shows how Postman data of request, tests and assertions are mapped to an AIO Test.
Field mapping (Postman → AIO Tests)
The below table summarizes how a Postman API Tests gets translated to an AIO Case.
Postman field | AIO Tests Field | Example |
---|---|---|
Name of request | Title | PublicApi - Get TestCase Priority |
Name of request | Automation key | PublicApi - Get TestCase Priority |
Request endpoint | First step in Given | GET {{SERVER_URL}}/project/{{JIRA_PROJECT_ID}}/config/testcase/priority |
Query Params | Data in first step | Query: startAt=0&maxResults=100&needDataInRTF=true |
Body params | Data in first step | {"testRunStatus": "Passed<b>NR</b>1", "effort": 180, "comments": ["Comment line1", "Comment line2"] } |
Form Data | Data in first step [FormData: key2=value2] | FormData: file = "/file.json" |
URL Encoded Body | Data in first step [ URLEncoded: key = value ] | URLEncoded: what = for |
Headers | No mapping |
|
First assertion (if any) | Step 2 with Then keyword |
|
Rest of the assertions | Step 3 and forth with And as keyword |
|
Reponse size, response code, response time | Actual result of first step |
|
Variable values [ Env, collection ] | Actual result of first step |
|
Request Error [ happens when server URL is invalid] | Actual result - against first step | RequestError{ errno=-3008, code='ENOTFOUND', syscall='getaddrinfo', hostname='{{cloud url}}'} |
Assertion Failures | Actual result |
|
Mapping Postman tests to existing AIO Tests
If cases have been created in AIO Tests, to uniquely map the AIO Case to the API Test, the case key can be added to the name of the API, as shown below:
Adding case key to API name is not mandatory. Even without a case key, the case would be identified using the automation key. However, in the event, where the API name changes, AIO would recognize it as a new case and create a new one. To avoid this situation, it is recommended to add case key, so that future changes to the name of the API still get written to the same case.
Creating Postman tests in AIO Tests
If no case key is added to the name of the API, then a new case is created in AIO Tests, with the field mappings as explained in the section : Field mapping (Postman → AIO Tests)
The automation key of this newly created case is set to the name of the API. The subsequent times when the API test is run, the cases are identified by the automation key.
In the above example, the first 2 cases will be reported to AT-TC-223 and AT-TC-224. However, the 3rd and the 4th request will be created as new cases. Below is an example of a newly created case
Reporting results
To report results of a collection run, AIO Tests provides 2 ways.
The newman-reporter-aiotests allows user to setup an AIO Tests config in their newman run if running newman as a library or via command line. The reporter gives additional capabilities to create cycles for each run or to reuse existing cycles.
Users may choose to import the json report (generated by the inbuilt json reporter), via the Import Result API or through the Cycle Import Results option or through the Jenkins plugin. To read more about these options, please refer to Importing Results in AIO Tests
newman-reporter-aiotests
AIO Tests has introduced a custom reporter for Newman. The newman-reporter-aiotests simplifies reporting results from Newman with an easy setup.
Install
The reporter works as a plugin with Newman so ensure that you have already installed that package globally, using
npm install -g newman
.
To globally
install the aiotests
package:
npm install -g newman-reporter-aiotests
To use aiotests
as a library, install the package as a dependency into a nodejs
project's package.json
file using:
npm install -S newman-reporter-aiotests
Usage
In order to enable this reporter, specify aiotests
in Newman's -r
or --reporters
option. The following command would run the reporter:
newman run collection.json -r aiotests
--reporter-aiotests-jiraProjectId=AUT --reporter-aiotests-aioApiToken=<yourAPIToken>
CLI Options
With Newman CLI
CLI Option | Description | Example |
---|---|---|
| To enable or disable reporter for a particular run. Defaults to true. |
|
| To enable or disable reporter for a particular run. Defaults to true. |
|
| Jira Project key - the Jira project to which the results need to be reported |
|
| Only for Jira Cloud |
|
| Only for Jira Server/DC |
|
| Only for Jira Server/DC |
|
| Set to true to create new cycle for run. |
|
| If createNewCycle is false, then the cycleKey identifies the existing AIO Tests Cycle to be updated |
|
| If createNewCycle is true, the newCycleTitle specifies the name of the cycle to create |
|
| Defaults to false. Set to true to create a new run for each execution. |
|
| Defaults to true. Set to false, if cases without case Key mapping should be reported as failures. |
|
| Defaults to true. Set to true to override data from report to overwrite the manual case in AIO Tests. Set to false, if case should not be updated. e.g If a new assertion is added in Postman, if bddForceUpdateCase is true, it would be added as a new step, else it would be reported as failure. |
|
With Newman as a Library
All the CLI functionality is available for programmatic use within a nodejs
script.
Install the required node modules using npm i -S newman newman-reporter-aiotests