API Automation Testing ProjectΒΆ
A comprehensive API testing automation project using Newman (Postman CLI) with CI/CD integration and performance reporting hosted on GitHub Pages.
π OverviewΒΆ
This project provides automated API testing for a Node.js CRUD application with the following features:
- Local Testing: Run Newman tests locally using batch scripts
- CI/CD Integration: Automated testing on every push to master branch
- Performance Reporting: Test results hosted on GitHub Pages
- Multiple Environments: Support for development and production environments
- Comprehensive Test Coverage: Full CRUD operations testing (Create, Read, Update, Delete)
π Project StructureΒΆ
βββ .github/workflows/
β βββ ci-cd.yml # GitHub Actions CI/CD pipeline
βββ performance/
β βββ performance-report.html # Performance report from Postman GUI
β βββ performance-report.pdf # Performance report from POstman GUI
βββ postman/
β βββ NODE-E2E.postman_collection.json # Postman test collection
β βββ dev-env.postman_environment.json # Development environment
β βββ prod-env.postman_environment.json # Production environment
βββ script/
β βββ collection-runner.bat # Local Newman runner script
βββ reports/ # Local test reports (gitignored)
βββ README.md
π οΈ PrerequisitesΒΆ
Local DevelopmentΒΆ
InstallationΒΆ
# Install Newman globally
npm install -g newman
# Install Newman reporters
npm install -g newman-reporter-html
npm install -g newman-reporter-htmlextra
πββοΈ Running TestsΒΆ
Using Postman Collection Runner (GUI)ΒΆ
The Postman Collection Runner provides a powerful GUI interface for executing your test collection with detailed performance metrics and HTML report generation.
1. Import Collection and EnvironmentΒΆ
Option A: Import Files
- Open Postman Desktop or navigate to Postman Web
- Click Import button in the top left
- Drag and drop or select these files:
postman/NODE-E2E.postman_collection.jsonpostman/prod-env.postman_environment.json(for production)postman/dev-env.postman_environment.json(for development)
Option B: Import via URL (if hosted on GitHub)
- Click Import β Link
- Paste the raw GitHub URLs for each file
2. Configure Collection RunnerΒΆ
- Click Collections in the sidebar
- Find your NODE-E2E collection
- Click Performance Tab
-
Set up your performance test:
Performance Basic Setup:
- Load profile: Select
Fixed,Ramp up,SpikeorPeak - Virtual users: Set to
5(or desired number) - Test duration: Set to
1(in minutes)
Performance Metric (Pass test if):
- Metric: Response Time, Error, Requests per second
- Condition: is greater than, is less than, is less than equal to, is greater than equal to
- Value: desired number
- Load profile: Select
Documentation
3. Execute Performance RunΒΆ
- Click Run NODE-E2E button
- Monitor real-time execution in the runner interface
- View detailed request/response data, test results, and timing metrics
- Watch the progress bar and individual test status
4. Download HTML Performance ReportΒΆ
After the collection run completes:
-
View Results Summary:
- Total requests executed
- Pass/fail test counts
- Average response time
- Individual request performance metrics
-
Export HTML Report:
- Click Export Results button (top right of runner results)
- Select Export as HTML
- Choose download location
-
The HTML report includes:
- β Complete test execution summary
- β Request/response details with timing
- β Test assertions results
- β Performance metrics and charts
- β Environment variables used
- β Console logs and error details
-
Report Features:
- Interactive charts showing response times
- Detailed request/response inspection
- Color-coded test results (pass/fail)
- Performance trends across iterations
- Export-friendly format for sharing
5. Performance AnalysisΒΆ
The HTML report provides comprehensive performance insights:
- Response Time Analysis: Min/max/average response times per endpoint
- Throughput Metrics: Requests per second calculations
- Error Rate Tracking: Success/failure ratios
- Test Coverage: Assertion results across all test scenarios
- Timeline View: Chronological execution flow
- Performance Trends: Multi-iteration comparison
Using Batch Script (Windows)ΒΆ
- Update the
BASE_DIRpath inscript/collection-runner.batto match your project location - Run the script:
Using Newman Command LineΒΆ
# Run with production environment
newman run postman/NODE-E2E.postman_collection.json \
--environment postman/prod-env.postman_environment.json \
--iteration-count 5 \
--reporters cli,html,json,junit \
--reporter-html-export reports/newman-report.html \
--reporter-json-export reports/newman-report.json \
--reporter-junit-export reports/newman-report.xml \
--delay-request 1000 \
--timeout-request 30000
# Run with development environment
newman run postman/NODE-E2E.postman_collection.json \
--environment postman/dev-env.postman_environment.json \
--iteration-count 1
π CI/CD PipelineΒΆ
The project includes a comprehensive GitHub Actions workflow (.github/workflows/ci-cd.yml) that:
Test JobΒΆ
- β Runs Newman tests automatically on push to master
- β Uses production environment configuration
- β Executes 5 iterations with request delays
- β Generates multiple report formats (CLI, JSON, JUnit)
- β Uploads test artifacts for 30 days retention
Deploy JobΒΆ
- β Deploys test results to GitHub Pages
- β Creates performance reports dashboard
- β Runs only after test completion
- β Updates on every master branch push
Workflow FeaturesΒΆ
- Concurrent Control: Cancels previous deployments
- Error Handling: Continues pipeline even if tests fail
- Artifact Management: Unique naming with run numbers
- Environment Flexibility: Easy switching between dev/prod
π Test CoverageΒΆ
The E2E test collection covers complete CRUD operations:
π Create ProductΒΆ
- Endpoint:
POST /api/products - Validation: Schema validation, field types, MongoDB ObjectId format
- Environment: Stores created product ID for subsequent tests
π Read ProductΒΆ
- Endpoint:
GET /api/products/{id} - Validation: Response structure, data integrity, field validation
βοΈ Update ProductΒΆ
- Endpoint:
PUT /api/products/{id} - Validation: Updated fields, schema compliance, timestamp validation
ποΈ Delete ProductΒΆ
- Endpoint:
DELETE /api/products/{id} - Validation: Deletion confirmation, proper response format
Test Validations Include:ΒΆ
- JSON Schema validation
- Field type checking (string, integer, ObjectId)
- ISO8601 timestamp format validation
- MongoDB ObjectId pattern matching
- Response key existence verification
- Business logic validation (positive values, non-empty strings)
π EnvironmentsΒΆ
Development EnvironmentΒΆ
- Base URL:
http://localhost:3000 - Test Data: Bakpia (Indonesian traditional food)
- Use Case: Local development and testing
Production EnvironmentΒΆ
- Base URL:
https://simple-crud-apps.vercel.app - Test Data: Ketoprak (Indonesian traditional food)
- Use Case: Production API testing and CI/CD
π Performance ReportingΒΆ
GitHub Pages IntegrationΒΆ
Test results are automatically published to GitHub Pages:
- URL:
https://[username].github.io/[repository-name] - Content: Performance reports and test summaries
- Updates: Automatic on every master branch push
Report TypesΒΆ
- HTML Reports: Visual test execution results
- JSON Reports: Machine-readable test data
- JUnit Reports: CI/CD integration compatible
- Performance Dashboard: Hosted on GitHub Pages
βοΈ ConfigurationΒΆ
Customizing Test ParametersΒΆ
Edit the CI/CD workflow parameters in .github/workflows/ci-cd.yml:
newman run "$COLLECTION" \
--environment "$ENVIRONMENT" \
--iteration-count 5 # Number of test iterations
--timeout-request 30000 # Request timeout (30 seconds)
--delay-request 1000 # Delay between requests (1 second)
Environment VariablesΒΆ
Update environment files in the postman/ directory:
- Modify
baseUrlfor different API endpoints - Adjust test data values (
productName,productPrice, etc.) - Configure environment-specific settings
Local Script ConfigurationΒΆ
Update paths in script/collection-runner.bat:
π§ TroubleshootingΒΆ
Common IssuesΒΆ
-
Collection/Environment Not Found
- Verify file paths in the script
- Check file names match exactly
- Ensure files are in the correct directories
-
Newman Command Not Found
- Install Newman globally:
npm install -g newman - Verify Node.js installation
- Check PATH environment variable
- Install Newman globally:
-
API Connection Issues
- Verify API endpoint availability
- Check network connectivity
- Validate environment configuration
-
GitHub Actions Failures
- Check workflow logs in Actions tab
- Verify repository permissions
- Ensure GitHub Pages is enabled
π ContributingΒΆ
- Fork the repository
- Create a feature branch
- Add or modify test cases in the Postman collection
- Update environment files if needed
- Test locally using the batch script
- Submit a pull request
π LicenseΒΆ
This project is open source and available under the MIT License.
Happy Testing! π





