|
1 | | -name: Automated API tests using Postman CLI |
| 1 | +name: Automated API tests using Postman (via Newman) |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
|
15 | 15 | jobs: |
16 | 16 | automated-api-tests: |
17 | 17 | runs-on: ubuntu-latest |
18 | | - env: |
19 | | - POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} |
20 | 18 | steps: |
21 | 19 | - uses: actions/checkout@v4 |
22 | 20 |
|
23 | | - - name: Install Postman CLI |
24 | | - run: | |
25 | | - # Fixed: removed trailing space in URL |
26 | | - curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh |
| 21 | + - name: Set up Node.js |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: '20' |
27 | 25 |
|
28 | | - - name: Login to Postman CLI |
29 | | - run: postman login --with-api-key "$POSTMAN_API_KEY" |
| 26 | + - name: Install Newman |
| 27 | + run: npm install -g newman |
30 | 28 |
|
31 | | - - name: Pull and Verify Postman Collection |
| 29 | + - name: Download Postman Collection (via API or direct link) |
| 30 | + env: |
| 31 | + POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} |
32 | 32 | run: | |
33 | 33 | mkdir -p collections |
34 | | - echo "⬇️ Attempting to pull collection: Feedlink" |
35 | | - postman pull "Feedlink" --output collections/feedlink.json |
36 | | -
|
37 | | - # Verify the file exists and is not empty |
38 | | - if [ ! -f collections/feedlink.json ] || [ ! -s collections/feedlink.json ]; then |
39 | | - echo "❌ ERROR: Failed to pull collection 'Feedlink'." |
40 | | - echo "📋 Available collections in your workspaces:" |
41 | | - postman list collections |
42 | | - echo "" |
43 | | - echo "💡 Make sure the name matches EXACTLY (case, spaces, symbols)." |
44 | | - echo "✅ Recommendation: Use the collection UID instead of name." |
| 34 | + # Replace COLLECTION_UID with your actual Postman Collection UID |
| 35 | + # Find it in Postman: Collection > ... > Share > Copy UID |
| 36 | + COLLECTION_UID="YOUR_COLLECTION_UID_HERE" |
| 37 | + |
| 38 | + curl -s "https://api.getpostman.com/collections/$COLLECTION_UID" \ |
| 39 | + -H "X-API-Key: $POSTMAN_API_KEY" \ |
| 40 | + -o collections/feedlink.json |
| 41 | +
|
| 42 | + if [ ! -f collections/feedlink.json ] || grep -q "error" collections/feedlink.json; then |
| 43 | + echo "❌ Failed to fetch collection. Check UID and API key." |
| 44 | + cat collections/feedlink.json || echo "No response received." |
45 | 45 | exit 1 |
46 | 46 | fi |
47 | 47 |
|
48 | | - echo "✅ Collection successfully pulled: collections/feedlink.json" |
| 48 | + echo "✅ Collection successfully downloaded: collections/feedlink.json" |
49 | 49 | echo "📄 Size: $(wc -c < collections/feedlink.json) bytes" |
50 | 50 |
|
51 | | - - name: Run API tests |
| 51 | + - name: Run API tests with Newman |
52 | 52 | run: | |
53 | 53 | mkdir -p reports |
54 | | - postman collection run collections/feedlink.json \ |
| 54 | + newman run collections/feedlink.json \ |
55 | 55 | --reporters cli,junit \ |
56 | 56 | --reporter-junit-export reports/junit.xml |
57 | 57 |
|
|
0 commit comments