auto-psgen-cli
Version:
A CLI tool to automate project structure setup for API test
126 lines (84 loc) β’ 3.62 kB
Markdown
# API Testing Automation
This project automates API testing using **Newman** (Postman CLI) with Data-Driven Testing to execute test cases efficiently and generate reports.
## π Prerequisites
Ensure you have the following installed on your system:
- [Node.js](https://nodejs.org/) (version 14 or later recommended)
- [Newman](https://www.npmjs.com/package/newman) (Postman CLI for running collections)
- [Newman Reporter](https://www.npmjs.com/package/newman-reporter-html) (for generating reports)
- A valid **Postman Collection** exported as a JSON file
- A **Data File** (CSV/JSON) containing test cases
## π¦ Installation
To install the required dependencies, run the following command:
```sh
npm install -g newman newman-reporter-html
```
## π Running API Tests
### 1οΈβ£ Basic Test Execution
To execute a Postman Collection without data-driven testing:
```sh
newman run <your-collection.json>
```
### 2οΈβ£ Running with Environment Variables
If your API requires an environment file:
```sh
newman run <your-collection.json> -e <your-environment.json>
```
### 3οΈβ£ Running Tests with Data File (Data-Driven Testing)
To execute tests with dynamic data from a CSV or JSON file:
```sh
newman run <your-collection.json> -d <test-data.csv>
```
### 4οΈβ£ Generating an HTML Report
To generate a detailed HTML report of test results:
```sh
newman run <your-collection.json> -d <test-data.csv> -r html --reporter-html-export report.html
```
## π Test Reporting
Newman provides various reporting formats:
- **CLI Report:** Default console output
- **HTML Report:** A visually detailed summary (`report.html`)
- **JSON Report:** Structured report output (`report.json`)
- **JUnit Report:** XML-based test results (`report.xml`)
To specify a different report format:
```sh
newman run <your-collection.json> -r cli,json,junit --reporter-json-export report.json --reporter-junit-export report.xml
```
## π Automating API Testing with CI/CD
To integrate Newman into your CI/CD pipeline (Jenkins, GitHub Actions, GitLab CI, etc.), add a command in your pipeline script:
### **Example for GitHub Actions**
```yaml
jobs:
api-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Install Newman
run: npm install -g newman
- name: Run API Tests
run: newman run <your-collection.json> -d <test-data.csv> -r html --reporter-html-export report.html
- name: Upload Report
uses: actions/upload-artifact@v3
with:
name: API Test Report
path: report.html
```
## π Troubleshooting
**Issue:** `newman: command not found`
- Ensure you have installed Newman globally (`npm install -g newman`).
- Run `newman -v` to check if it's installed correctly.
**Issue:** API requests failing due to authentication
- Verify that your environment variables are set correctly.
- Check API keys and authentication headers.
**Issue:** CSV data not being used
- Ensure your CSV file is formatted correctly (headers must match Postman variables).
- Use JSON format if CSV parsing issues occur.
## π€ Author
- **Mike EJ Redondo**
π Passionate about automation and API testing!
π§ [redondomikej@gmail.com
π Mobile: 09169045914
π ]()[LinkedIn Profile](https://www.linkedin.com/in/mike-e-j-redondo-735977209/)
π Location: Philippines
---
Now youβre ready to automate and streamline your API testing process! π