API testing is an essential part of software development to ensure that your application's APIs (Application Programming Interfaces) are functioning correctly. Postman, Newman, and newman-reporter-htmlextra are powerful tools that work together to streamline API testing, automate test execution, and generate detailed HTML reports for test results.
Postman: Postman is a popular API testing tool that allows you to create, manage, and execute API requests and collections. It provides a user-friendly interface for designing requests, setting up test scripts, and organizing tests into collections. Postman also enables manual testing, which is valuable during initial API development and exploration.
Newman: Newman is a command-line collection runner for Postman. It allows to automate the execution of Postman collections, making it suitable for continuous integration and continuous deployment (CI/CD) pipelines.
newman-reporter-htmlextra: newman-reporter-htmlextra is a custom Newman reporter that extends the default HTML reporter. It generates comprehensive HTML reports that provide a detailed summary of the API test runs. These reports include information such as request-response details, test script results, environment variables, and even screenshots. This reporter enhances the visibility of the test results, making it easier to identify issues and communicate test outcomes.
-
Install Node.js: Node.js is required for both Newman and the newman-reporter-htmlextra reporter. Visit the official Node.js website: Node.js Downloads. Download the LTS (Long Term Support) version and install.
-
Verify Node.js and npm Installation: After installing Node.js, open terminal or command prompt and run the following commands to verify the installation:
node -v
npm -v
These commands should display the installed Node.js and npm versions.
-
Install Postman: Visit the official Postman website: Postman Download. Download the appropriate version and install postman.
-
Install Newman: Newman is a command-line tool for running Postman collections. It is installed using npm (Node Package Manager). Open terminal or command prompt and run the following command:
npm install -g newman
This command installs Newman globally on the system.
- Install newman-reporter-htmlextra: The newman-reporter-htmlextra reporter provides detailed HTML reports for Newman test runs. Open terminal or command prompt and run the following command to install it globally using npm:
npm install -g newman-reporter-htmlextra
- Verify Newman and newman-reporter-htmlextra Installation: To verify that Newman and the HTML Extra reporter are installed, run the following commands:
newman -v
newman-reporter-htmlextra -v
These commands should display the installed versions of Newman and the HTML Extra reporter.
Application: Reqres project
Reqres is a popular public API that provides a mock server for testing purposes. It's an excellent resource for practicing and learning API testing with tools like Postman and Newman. Reqres can be used to simulate various HTTP request-response scenarios.
Here are some of the common Reqres endpoints used for testing:
-
List of Users:
Endpoint: GET /api/users
Description: Retrieve a list of users
Example: https://reqres.in/api/users?page=2 -
Single User:
Endpoint: GET /api/users/:id
Description: Retrieve information about a single user, identified by their id.
Example: https://reqres.in/api/users/2 -
Create User:
Endpoint: POST /api/users
Description: Create a new user by sending a POST request with user data in the request body.
Example: https://reqres.in/api/users -
Update User:
Endpoint: PUT /api/users/:id
Description: Update user information for the user identified by their id. Send user data in the request body.
Example: https://reqres.in/api/users/2 -
Delete User:
Endpoint: DELETE /api/users/:id
Description: Delete a user based on their id.
Example: https://reqres.in/api/users/2 -
List Resources:
Endpoint: GET /api/unknown
Description: Retrieve a list of resources. This endpoint has a delay in the response to simulate real-world conditions.
Example: https://reqres.in/api/unknown -
Single Resource:
Endpoint: GET /api/unknown/:id Description: Retrieve information about a single resource, identified by its id. This endpoint also has a delay in the response.
Example: https://reqres.in/api/unknown/2 -
Register:
Endpoint: POST /api/register
Description: Simulate user registration by sending a POST request with user registration data in the request body. This endpoint does not perform actual user registration.
Example: https://reqres.in/api/register
-
Create and Organize API Tests in Postman:
Used Postman to design the API requests and organized them into collections.
Added test scripts to validate the responses and ensure the correctness of the APIs. -
Export the Postman Collection/Enviornment/Global as json file:
Export the Postman Collection/Enviornment/Global as a JSON file. These files will be used by Newman for test execution.
Collection file : (Reqres project.postman_collection.json)
Environment file: (Env_QA.postman_environment.json) -
Run API Tests with Newman and Generate HTML Reports:
Executed the API tests using Newman from the command line. Specified the Postman collection and used the newman-reporter-htmlextra reporter.newman run your-collection.json -r htmlextraThis command will rund tests and generates HTML reports using newman-reporter-htmlextra.
Report: (Reqres project-2023-09-17-21-07-33-017-0.html) -
Review and Share HTML Reports:
Open the generated HTML reports in your web browser to review the test results.
Report Image: (Postman-Reqres-Project-newman-Summary-Report.png)
Report Image: (Postman-Reqres-Project-newman-All-Report-2.png)

