This project demonstrates API testing using Postman, providing a collection of tests to validate various endpoints of the API.
- Tests for GET, POST, PUT, DELETE requests
- Collection of tests covering different API endpoints
- Environment setup for easy switching between environments
- Pre-request scripts for data setup
- Test scripts for assertions and validations
- Postman
- Newman
- Node Js
- Newman
- Newman Html Report Library
- Postman: If you haven't already, download and install Postman.
- Clone the repository:
[git clone https://github.com/rashadkhan97/Automated-Testing-of-Rest-Booking-API-with-Newman-Report.git]
- Import the Postman collection:
- Open Postman.
- Click on the Import button.
- Select the file from the repository.
- Import the Postman environment:
- In Postman, click on the gear icon in the top right corner.
- Select Import and choose the file.
- Newman and Report Installation Process:
- Newman Install Command:
npm install -g newman
- Newman Html Report Install Command:
npm install -g newman-reporter-htmlextra
- Select Environment:
- In Postman, select the appropriate environment (e.g., Development, Production) from the top-right dropdown.
- Run Collection:
- Select the imported collection from the Collections sidebar.
- Click on the Runner button to open the collection runner.
- Select the desired environment.
- Click Start Test to run the collection.
- View Results:
- View the results in the Runner tab once the tests are complete.
- Detailed test results can be viewed for each request.
Request URL: https://restful-booker.herokuapp.com/booking/
//DYNAMIC CREATION LIST FOR ALL VARIABLES
//First Name
var firstname = pm.variables.replaceIn("{{$randomFirstName}}");
pm.environment.set("firstname", firstname)
//Last Name
var lastname = pm.variables.replaceIn("{{$randomLastName}}");
pm.environment.set("lastname", lastname); //calling enivorment to get lastname in enviroment
//totalprice
var totalprice = pm.variables.replaceIn("{{$randomInt}}");
pm.environment.set("totalprice", totalprice)
//depositpaid
var depositpaid = pm.variables.replaceIn("{{$randomBoolean}}");
pm.environment.set("depositpaid", depositpaid)
//calling moment library for Checkin & Check out
const moment = require("moment");
// moment is a library for date and time
const today = moment();
//for checking
pm.environment.set("checkin", today.add(0,'d').format("YYYY-MM-DD"));
pm.environment.set("checkout", today.add(5, 'd').format("YYYY-MM-DD"));
//additional needs
var additionalneeds = pm.variables.replaceIn("{{$randomProduct}}");
pm.environment.set("additionalneeds", additionalneeds)
Request Body:
{
"firstname" : "{{firstName}}",
"lastname" : "{{lastName}}",
"totalprice" : {{totalPrice}},
"depositpaid" : {{depositPaid}},
"bookingdates" : {
"checkin" : "{{checkin}}",
"checkout" : "{{checkout}}"
},
"additionalneeds" : "{{additionalNeeds}}"
}
Response Body:
{
"bookingid": 1394,
"booking": {
"firstname": "Brianne",
"lastname": "Jacobson",
"totalprice": 605,
"depositpaid": false,
"bookingdates": {
"checkin": "2024-03-25",
"checkout": "2024-03-30"
},
"additionalneeds": "Pants"
}
}
{
"firstname": "Brianne",
"lastname": "Jacobson",
"totalprice": 605,
"depositpaid": false,
"bookingdates": {
"checkin": "2024-03-25",
"checkout": "2024-03-30"
},
"additionalneeds": "Pants"
}
Request URL: https://restful-booker.herokuapp.com/auth
{
"username": "admin",
"password": "password123"
}
Response Body:
{
"token": "0d1b2ff4d291883"
}
//DYNAMIC CREATION LIST FOR ALL VARIABLES
//First Name
var updated_firstname = pm.variables.replaceIn("{{$randomFirstName}}");
pm.environment.set("updated_firstname", updated_firstname)
//Last Name
var updated_lastname = pm.variables.replaceIn("{{$randomLastName}}");
pm.environment.set("updated_lastname", updated_lastname); //calling enivorment to get lastname in enviroment
//totalprice
var updated_totalprice = pm.variables.replaceIn("{{$randomInt}}");
pm.environment.set("updated_totalprice", updated_totalprice)
//depositpaid
var updated_depositpaid = pm.variables.replaceIn("{{$randomBoolean}}");
pm.environment.set("updated_depositpaid", updated_depositpaid)
//calling moment library for Checkin & Check out
const moment = require("moment");
// moment is a library for date and time
const today = moment();
//for checking
pm.environment.set("updated_checkin", today.add(1,'d').format("YYYY-MM-DD"));
pm.environment.set("updated_checkout", today.add(5, 'd').format("YYYY-MM-DD"));
//additional needs
var updated_additionalneeds = pm.variables.replaceIn("{{$randomProduct}}");
pm.environment.set("updated_additionalneeds", updated_additionalneeds)
Request Body:
{
"firstname" : "{{updated_firstname}}",
"lastname" : "{{updated_lastname}}",
"totalprice" : "{{updated_totalprice}}",
"depositpaid" : {{updated_depositpaid}},
"bookingdates" : {
"checkin" : "{{updated_checkin}}",
"checkout" : "{{updated_checkout}}"
},
"additionalneeds" : "{{updated_additionalneeds}}"
}
Response Body:
{
"firstname": "Justen",
"lastname": "Marvin",
"totalprice": 620,
"depositpaid": true,
"bookingdates": {
"checkin": "2024-03-26",
"checkout": "2024-03-31"
},
"additionalneeds": "Bike"
}
- Run Command for Console:
newman run Rashadul_Islam_SQA_API_Testing.postman_collection.json -e Rashadul_Islam_SQA_API_Testing.postman_environment.json
- Run Command for Report:
newman run Rashadul_Islam_SQA_API_Testing.postman_collection.json -e Rashadul_Islam_SQA_API_Testing.postman_environment.json -r cli,htmlextra