https://github.com/ghoshasish99/postman-newman
API testing with Postman
https://github.com/ghoshasish99/postman-newman
apitesting newman newman-reporter postman postman-collection postman-test
Last synced: 12 days ago
JSON representation
API testing with Postman
- Host: GitHub
- URL: https://github.com/ghoshasish99/postman-newman
- Owner: ghoshasish99
- Created: 2021-02-25T01:41:19.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-25T17:31:08.000Z (over 5 years ago)
- Last Synced: 2025-01-15T14:35:20.440Z (over 1 year ago)
- Topics: apitesting, newman, newman-reporter, postman, postman-collection, postman-test
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# API testing with Postman and Newman
[](https://dev.azure.com/AutomationsTools/Execution/_build/latest?definitionId=8&branchName=main)
* *Postman* is a lightweight API testing solution. Its predominantly used for Testing but can be used for API developments too.
* *Newman* is the commandline collection runner for Postman which facilitates execution via CICD
Postman supports REST, SOAP, or plain HTTP. One can download Postman from here : https://www.postman.com/downloads/
In Postman, one can create individual requests and add them to a *Collection*. Inorder to run a *Collection* from commandline, we need **Newman**.
### To download and install Newman , run this command on the terminal :
```shell
npm install -g newman
```
This will install newman globally.
### Some basic Newman commands are :
Operations | Commands
---- | ----
Simple collection run | `newman run MyCollection.json`
Run a collection with environment details | `newman run MyCollection.json -e Env.json`
Run a collection with an external data source | `newman run MyCollection.json -d UserData.csv`
Generate Junit report | `newman run MyCollection.json --reporters junit --reporter-junit-export junit.xml`
### Chaining API requests :
Sometimes we may require to fire a chain of APIs passing data from one API response to another API request. Lets take the following example :
- Create a user
- Extract the User ID from the response
- Use the User ID to Delete the user
Here we will use the `Tests` section of a Request in Postman.
If the response of the Create User is :
```json
{
"first_name": "Ashish",
"last_name": "Ghosh",
"email": "Ashish.Ghosh@jsonserver.com",
"id": 3
}
```
To extract the `id` value and store it in a variable `UserID` defined in Postman, in the Test section add this :
```javascript
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("UserID", jsonData.id);
```
Now this `UserID` variable can be used in the next Postman request.
For XML responses, the approach will be similar, but syntax will be different :
If the XML response is :
```xml
```
To extract the `id` value and store it in a variable `UserID` defined in Postman, in the Test section add this :
```javascript
var jsonObject = xml2Json(responseBody);
var user_id = jsonObject['soapenv:Envelope']['soapenv:Body']['soapenv:Result']['CreateUser']['user'].$.id;
pm.environment.set ("UserID", user_id);
```
To view a document generated by Postman click here : https://documenter.getpostman.com/view/5085233/TWDcEDxP