This project focuses on testing a local server API using Postman and Newman. It is integrated with GitHub Actions to automate the execution of API tests, and the test results are published to GitHub Pages.
-
Install Nodejs:
-
Clone the repository:
git clone https://github.com/haite4/postman-newman-task
-
Navigate to the project directory:
cd postman-newman-task
-
Install dependencies:
npm install
- Run the local server:
npm run tern-on-api
This section provides an overview of the available API endpoints for interacting with the local server. The server supports routes for managing products
, orders
, and users
. The table below details the operations for the products
resource, which are similarly available for orders
and users
.
VERB | Route | Input | Output |
---|---|---|---|
GET | /products | None | Array |
GET | /products/:id | e.g 3 | Object |
POST | /products | object | Created object |
PUT | /products | object | Updated object |
DELETE | /products/:id | e.g 3 | Deleted object |
-
Open Postman: Launch the Postman application on your computer.
-
Import Collection: Import the
store.collection.json
file into Postman. This file contains the API requests and tests. -
Run Tests:
- Single Test: To run a specific test, select the request from the collection and click "Send" to execute it.
- All Tests:
- Right-click on the collection name in the sidebar.
- Select "Run Collection" from the context menu.
- The Collection Runner will open. In the Runner, click the "Run " button to start executing all tests.
Newman is a command-line utility that enables you to run Postman collections directly from your terminal. Follow these steps to execute your tests locally and view the results:
-
Install Newman:
- To add Newman as a local development tool, run the following command:
npm install newman --save-dev
- To add Newman as a local development tool, run the following command:
-
Execute the Tests and Create a Report:
- Run your Postman collection and generate a test report by executing:
npm run test:api
- Run your Postman collection and generate a test report by executing:
-
View the Report:
-
For macOS Users: Open the report file in your default web browser by using:
open testResults/index.html
-
For Windows Users: Launch the report file in your default web browser with:
start testResults/index.html
-
For Linux Users: Open the report file in your default web browser with:
xdg-open testResults/index.html
-
We have set up a GitHub Actions workflow to automatically run the petstore.collection.json
Postman collection. The workflow executes the API tests and publishes the results to GitHub Pages. You can review the test results at the following link:
- GitHub Actions Workflow: The workflow is configured to run the Postman collection and generate test reports.
- Result Publication: Test results are automatically published to GitHub Pages, providing a convenient way to access and review the results online.