-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_test.sh
executable file
·144 lines (140 loc) · 5 KB
/
run_test.sh
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
source test_list.sh
ENV_FILE=".env"
BROWSER="chromium" # Set the default browser value here
HEADLESS="false" # Set the default headless value here
run_registered_test() {
pytest "$1"
}
update_env_variable() {
awk -v key="$1" -v value="$2" 'BEGIN{FS=OFS="="} $1==key{$2=value} 1' "$ENV_FILE" > "$ENV_FILE.tmp" && mv "$ENV_FILE.tmp" "$ENV_FILE"
}
display_help() {
echo "Usage: ./run_test.sh [test_case] [--browser browser_name] [--headless true/false]"
echo
echo "Examples:"
echo " ./run_test.sh"
echo " ./run_test.sh login"
echo " ./run_test.sh login --browser firefox"
echo " ./run_test.sh login --browser chromium --headless true"
echo
echo "Browser Support:"
echo " chromium | firefox | webkit"
}
if [[ $# -eq 0 ]]; then
update_env_variable "BROWSER" "$BROWSER"
update_env_variable "HEADLESS" "$HEADLESS"
pytest
elif [[ $1 == "--help" ]]; then
display_help
exit 0
elif [[ $# -gt 0 && $# -lt 5 ]]; then
if [[ $# -eq 4 ]]; then
if [[ $1 == "--headless" && $3 == "--browser" ]]; then
update_env_variable "HEADLESS" "$2"
update_env_variable "BROWSER" "$4"
elif [[ $1 == "--browser" && $3 == "--headless" ]]; then
update_env_variable "BROWSER" "$2"
update_env_variable "HEADLESS" "$4"
fi
pytest
elif [[ $1 == "--headless" || $1 == "--browser" ]]; then
if [[ -n $2 ]]; then
variable=$1
if [[ $1 == "--headless" ]]; then
update_env_variable "BROWSER" "$BROWSER"
update_env_variable "HEADLESS" "$2"
elif [[ $1 == "--browser" ]]; then
update_env_variable "HEADLESS" "$HEADLESS"
update_env_variable "BROWSER" "$2"
fi
pytest
else
echo "Invalid arguments. Check './run_test.sh --help'"
exit 1
fi
else
if [[ -z $2 ]]; then
update_env_variable "BROWSER" "$BROWSER"
update_env_variable "HEADLESS" "$HEADLESS"
test_case=$1
if declare -p "$test_case"_tests &>/dev/null; then
test_files="${test_case}_tests[@]"
for test_file in "${!test_files}"; do
run_registered_test "$test_file"
done
else
echo "Invalid test case. Please provide a valid test case name."
exit 1
fi
elif [[ $2 == "--headless" || $2 == "--browser" ]]; then
if [[ $2 == "--browser" ]]; then
update_env_variable "BROWSER" "$3"
update_env_variable "HEADLESS" "$HEADLESS"
elif [[ $2 == "--headless" ]]; then
update_env_variable "HEADLESS" "$3"
update_env_variable "BROWSER" "$BROWSER"
else
echo "Invalid arguments. Check './run_test.sh --help'"
exit 1
fi
test_case=$1
if declare -p "$test_case"_tests &>/dev/null; then
test_files="${test_case}_tests[@]"
for test_file in "${!test_files}"; do
run_registered_test "$test_file"
done
else
echo "Invalid test case. Please provide a valid test case name."
exit 1
fi
else
echo "Invalid arguments. Check './run_test.sh --help'"
exit 1
fi
fi
elif [[ $# -gt 2 && $# -lt 6 ]]; then
if [[ $# -eq 5 ]]; then
if [[ $2 == "--headless" && $4 == "--browser" ]]; then
update_env_variable "HEADLESS" "$3"
update_env_variable "BROWSER" "$5"
elif [[ $2 == "--browser" && $4 == "--headless" ]]; then
update_env_variable "BROWSER" "$3"
update_env_variable "HEADLESS" "$5"
fi
test_case=$1
if declare -p "$test_case"_tests &>/dev/null; then
test_files="${test_case}_tests[@]"
for test_file in "${!test_files}"; do
run_registered_test "$test_file"
done
else
echo "Invalid test case. Please provide a valid test case name."
exit 1
fi
else
if [[ $2 == "--browser" ]]; then
update_env_variable "BROWSER" "$3"
update_env_variable "HEADLESS" "$HEADLESS"
elif [[ $2 == "--headless" ]]; then
update_env_variable "HEADLESS" "$3"
update_env_variable "BROWSER" "$BROWSER"
else
echo "Invalid arguments. Check './run_test.sh --help'"
exit 1
fi
test_case=$1
if declare -p "$test_case"_tests &>/dev/null; then
test_files="${test_case}_tests[@]"
for test_file in "${!test_files}"; do
run_registered_test "$test_file"
done
else
echo "Invalid test case. Please provide a valid test case name."
exit 1
fi
fi
else
echo "Invalid arguments. Check './run_test.sh --help'"
exit 1
fi