hi,
I created a new collection that uses packages instead of using eval=>…
Locally in Postman, it’s working just fine but when I tried to run it via Newman all the scripts were failing.
This is my Job: I am triggering collection sanity_RF this is the only collection that use packages
name: Test API collection
on:
workflow_dispatch:
inputs:
Projects:
description: 'Projects'
required: true
default: ''
type: choice
options:
- "Select a project"
- All Booking tests
- Sanity dev integration
- Sanity_RF
- Price_calculation_baggage
- Schema_BELLTRAV_via_12G0
- Schema_NOKNARAR_via_12G0
- Sanity prod
- Search
- Compare_Search_TC_vs_BAW
environments:
description: 'Environments'
required: true
default: 'integration'
type: choice
options:
- integration
- dev
- production
- production_bookaway
jobs:
newman:
name: "Collection: ${{ inputs.Projects }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
run-tests:
runs-on: ubuntu-latest
name: "Environment: ${{ inputs.environments }}"
steps:
- name: Clear cache
run: |
rm -rf ~/.npm
rm -rf ~/.cache
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: "20.x"
- run: npm i npm@latest
- run: npm i
- name: Install newman
run: |
npm install -g newman
npm install -g newman-reporter-htmlextra
- name: Run POSTMAN collection
id: newman
run: |
if [ -n "${{ inputs.environments }}" ]; then
envFile="${{ inputs.environments }}"
case $envFile in
integration)
envFilePath="integration.postman_environment.json"
;;
dev)
envFilePath="dev.postman_environment.json"
;;
production)
envFilePath="production.postman_environment.json"
;;
production_bookaway)
envFilePath="production_bookaway.postman_environment.json"
;;
*)
echo "Invalid environment selection: $envFile"
exit 1
;;
esac
else
envFilePath="integration.postman_environment.json"
fi
# Handle project selection
project="${{ inputs.Projects }}"
case $project in
"Sanity dev integration")
collections=("./Sanity/Sanity.postman_collection.json")
;;
"Sanity_RF")
collections=("./Sanity/Sanity_RF.postman_collection.json")
;;
"Sanity prod")
collections=("./Sanity_denaly/Sanity_Daneli_proxy.postman_collection.json")
;;
"Search")
collections=("./Search/Search.postman_collection.json")
;;
"Price_calculation_baggage")
collections=("./Price_calculation_baggage/Price_calculation_NOKNARAR_via_12G0.postman_collection.json")
;;
"Schema_BELLTRAV_via_12G0")
collections=("./Schema_BELLTRAV_via_12G0/Schema_BELLTRAV_via_12G0.postman_collection.json")
;;
"Schema_NOKNARAR_via_12G0")
collections=("./Schema_NOKNARAR_via_12G0/Schema_NOKNARAR_via_12G0.postman_collection.json")
;;
"Compare_Search_TC_vs_BAW")
collections=("./Compare_Search_TC_vs_BAW/Compare_Search_TC_vs_BAW.postman_collection.json")
;;
"All Booking tests")
if [ "$envFile" == "integration" ]; then
collections=(
"./Sanity/Sanity.postman_collection.json"
"./Schema_BELLTRAV_via_12G0/Schema_BELLTRAV_via_12G0.postman_collection.json"
"./Schema_NOKNARAR_via_12G0/Schema_NOKNARAR_via_12G0.postman_collection.json"
)
else
collections=(
"./Sanity/Sanity.postman_collection.json"
"./Price_calculation_baggage/Price_calculation_NOKNARAR_via_12G0.postman_collection.json"
"./Schema_BELLTRAV_via_12G0/Schema_BELLTRAV_via_12G0.postman_collection.json"
"./Schema_NOKNARAR_via_12G0/Schema_NOKNARAR_via_12G0.postman_collection.json"
)
fi
;;
"Select a project")
echo "Please select a valid project."
exit 1
;;
*)
echo "No valid project selected for $project. Skipping..."
exit 0
;;
esac
for collectionPath in "${collections[@]}"; do
if [ -n "$collectionPath" ]; then
# Run the collection
newman run "$collectionPath" -e "./Environments/$envFilePath" --reporters cli,htmlextra --reporter-htmlextra-export "docs/index-$(basename "$collectionPath" .postman_collection.json).html"
status=$? # Save the exit code in a variable
echo "Newman exit code for $(basename "$collectionPath" .postman_collection.json): $status"
fi
done
- name: Upload HTML reports as artifacts
if: ${{ success() || failure() }} # Upload artifact regardless of previous step outcome
uses: actions/upload-artifact@v4
with:
name: HTML-Reports
path: docs/*.html
# Post to a Slack channel if the Newman run fails
- name: Post to a Slack channel
if: ${{ failure() }} # Only run if the Newman run fails
uses: slackapi/[email protected]
with:
channel-id: 'C06Q6007SMT'
slack-message: |
GitHub build result: *Failed* ❌
*Collection: ${{ inputs.Projects }}*
*Environment: ${{ inputs.environments }}*
${{ github.event.pull_request.html_url || github.event.head_commit.url }}
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Build triggered for branch: *main*
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
# Post to a Slack channel if the Newman run passes
- name: Post to a Slack channel
if: ${{ success() }} # Only run if the Newman run passes
uses: slackapi/[email protected]
with:
channel-id: 'C06Q6007SMT'
slack-message: |
GitHub build result: *Passed* ✅
*Collection: ${{ inputs.Projects }}*
*Environment ${{ inputs.environments }}*
${{ github.event.pull_request.html_url || github.event.head_commit.url }}
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Build triggered for branch: *main*
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}