-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathpostman-tests.sh
More file actions
executable file
·79 lines (65 loc) · 2.6 KB
/
postman-tests.sh
File metadata and controls
executable file
·79 lines (65 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/zsh
# ------------------- Constants & Config ---------------------------------------------------
COLLECTION="./src/test/postman/petclinic-nonregressiontests.postman_collection.json"
ENVIRONMENT="./src/test/postman/petclinic-env.postman_environment.json"
REPORT_DIR="./src/test/postman/reports"
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m'
REQUIRED_CMDS=("node" "jq")
mkdir -p "$REPORT_DIR"
# --------------------------- Checking required dependecies ------------------------------
for CMD in "${REQUIRED_CMDS[@]}"; do
if ! command -v "$CMD" &>/dev/null; then
echo -e "${RED}❌ Error: '$CMD' is required but not installed.${NC}"
echo -e "${YELLOW}💡 Try installing it with one of the following:${NC}"
echo -e "${YELLOW} • brew install $CMD # macOS${NC}"
echo -e "${YELLOW} • sudo apt install $CMD # Debian/Ubuntu${NC}"
echo -e "${YELLOW} • sudo dnf install $CMD # Fedora${NC}"
echo -e "${YELLOW} • sudo pacman -S $CMD # Arch Linux${NC}"
exit 1
fi
done
# -------------- Getting folder (scenarios) names from collection ---------------------------
SCENARIOS=""
while IFS= read -r name; do
SCENARIOS="${SCENARIOS}
${name}"
done <<EOF
$(jq -r '.item[].name' "$COLLECTION")
EOF
# ----------- Checking if there's folders (scenarios) in collection -------------------------
if [ ${#SCENARIOS[@]} -eq 0 ]; then
echo -e "${RED}❌ Error: No folders (scenarios) found in collection.${NC}"
exit 1
fi
# ---------------- Announce & list scenarios ---------------------------------------------
echo ""
echo -e "${GREEN}🐾 Starting Petclinic API tests with Newman...${NC}"
sleep 1
echo ""
echo "$SCENARIOS" | while IFS= read -r SCENARIO; do
[ -z "$SCENARIO" ] && continue
echo "${YELLOW}🔎 Will execute scenario: $SCENARIO${NC}"
sleep 0.7
done
# ---------------- Running tests with Newman ------------------------------------
echo ""
echo -e "${GREEN}Running tests...${NC}"
echo ""
npx -p newman -p newman-reporter-htmlextra newman run "$COLLECTION" \
-e "$ENVIRONMENT" \
--reporters cli,htmlextra \
--reporter-htmlextra-export "$REPORT_DIR/report.html" \
--timeout-request 5000 \
EXIT_CODE=$?
# --------------- Checking if the test failed ----------------------------------------------------
if [ $EXIT_CODE -ne 0 ]; then
echo -e "${RED}❌ Newman tests failed. See the HTML report at: $REPORT_DIR/report.html${NC}"
exit 1
fi
# -------------- Done when is success --------------------------------------------------------------------
echo ""
echo -e "${YELLOW}📄 HTML report generated at: $REPORT_DIR/report.html${NC}"
echo ""