-
Notifications
You must be signed in to change notification settings - Fork 50
Automating Postman Tests with GitHub Actions
This documentation outlines the steps taken to set up an automated testing workflow for the hng_boilerplate_golang_web repository using GitHub Actions. The workflow is designed to run Postman tests every 15 minutes and upload the test results to a specified API endpoint.
- Set up a GitHub Actions workflow that runs Postman tests using Newman.
- Schedule the workflow to run every 15 minutes.
- Upload the test results to an API endpoint.
- GitHub repository: hng_boilerplate_golang_web
- A Postman collection to be tested: KimikoGolangSwagger.postman_collection.json
- GitHub Actions enabled for the repository
- An API endpoint to receive the test results
Go to the hng_boilerplate_golang_web repository on GitHub.
In the GitHub repository, click on the branch dropdown (usually shows main or master). Type a new branch name, such as setup-postman-tests, and press Enter to create the branch.
- Create a New File: In the new branch, navigate to the .github/workflows directory. If it does not exist, create it.
- Add a New File: Click on "Add file" > "Create new file".
- File Naming: Name the file run-postman-tests.yaml.
- Edit the File: Copy and paste the following content into the editor:
name: Run Postman Tests Every 15 Minutes
on:
workflow_dispatch:
schedule:
- cron: '*/15 * * * *' # Every 15 minutes
jobs:
run-postman-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Newman
run: npm install -g newman
- name: Run Newman tests
id: newman
run: |
newman run status/postman/KimikoGolangSwagger.postman_collection.json --reporters cli,json --reporter-json-export report.json
continue-on-error: true
- name: Upload Newman Report to API
run: |
curl -X POST ${{ vars.API_URL }}/api/v1/api-status \
-H "Content-Type: multipart/form-data" \
-F "[email protected]"
- Commit Changes: Scroll down, provide a commit message like "Add GitHub Actions workflow for Postman tests", and commit the file directly to the new branch.
- Open a PR: Once the file is committed, GitHub will prompt you to open a pull request. Click "Compare & pull request".
- Review PR: Review the changes, ensure everything looks good, and add a description.
- Create PR: Click "Create pull request" to submit the PR for review.
After the PR is reviewed and approved (or if you are the only maintainer), merge the PR into the main branch. This will make the workflow active, and it will start running as scheduled.
Navigate to the "Actions" tab in the repository. You can see the workflow runs, their statuses, and logs to debug if necessary.
- Check Workflow Run: The workflow should run every 15 minutes as scheduled. You can also manually trigger it using workflow_dispatch.
- Validate Results: After each run, ensure the tests pass and the results are correctly uploaded to the API endpoint.
- Debugging: If tests fail or the report upload does not work, review the logs available in the "Actions" tab for troubleshooting.
By setting up this GitHub Actions workflow, you have automated the process of running Postman tests and uploading the results at regular intervals. This helps in maintaining the reliability of the API by ensuring that it is continuously tested, and any issues are detected early.
This setup provides a robust CI/CD pipeline for API testing, ensuring that the system remains reliable and errors are identified promptly.