-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·304 lines (262 loc) · 7.05 KB
/
Copy pathrun-tests.sh
File metadata and controls
executable file
·304 lines (262 loc) · 7.05 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/bin/bash
# BackWPUp E2E Test Runner Script
# Supports multiple test execution modes
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_usage() {
echo "BackWPUp E2E Test Runner"
echo ""
echo "Usage: $0 [OPTIONS] [TEST_TYPE]"
echo ""
echo "TEST_TYPE:"
echo " playwright Run Playwright tests (default)"
echo " cucumber Run Cucumber BDD tests"
echo " backstop Run visual regression tests"
echo " all Run all test types"
echo ""
echo "OPTIONS:"
echo " -h, --help Show this help message"
echo " -e, --env ENV Set test environment (local, staging, prod)"
echo " -b, --browser Browser to use (chromium, firefox, webkit)"
echo " -d, --debug Run tests in debug mode"
echo " -u, --headed Run tests with visible browser"
echo " -p, --parallel Run tests in parallel"
echo " -r, --record Record test videos"
echo " -s, --screenshot Take screenshots on failure"
echo " -c, --clean Clean test results before running"
echo " --smoke Run only smoke tests"
echo " --regression Run only regression tests"
echo ""
echo "Examples:"
echo " $0 # Run default Playwright tests"
echo " $0 -e staging cucumber # Run Cucumber tests on staging"
echo " $0 -d -u playwright # Debug Playwright tests with browser"
echo " $0 -c all # Clean and run all test types"
echo " $0 --smoke playwright # Run only smoke tests"
}
# Default values
TEST_TYPE="playwright"
ENVIRONMENT="local"
BROWSER="chromium"
DEBUG_MODE=false
HEADED_MODE=false
PARALLEL_MODE=false
RECORD_VIDEO=false
TAKE_SCREENSHOTS=false
CLEAN_RESULTS=false
SMOKE_ONLY=false
REGRESSION_ONLY=false
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
print_usage
exit 0
;;
-e|--env)
ENVIRONMENT="$2"
shift 2
;;
-b|--browser)
BROWSER="$2"
shift 2
;;
-d|--debug)
DEBUG_MODE=true
shift
;;
-u|--headed)
HEADED_MODE=true
shift
;;
-p|--parallel)
PARALLEL_MODE=true
shift
;;
-r|--record)
RECORD_VIDEO=true
shift
;;
-s|--screenshot)
TAKE_SCREENSHOTS=true
shift
;;
-c|--clean)
CLEAN_RESULTS=true
shift
;;
--smoke)
SMOKE_ONLY=true
shift
;;
--regression)
REGRESSION_ONLY=true
shift
;;
playwright|cucumber|backstop|all)
TEST_TYPE="$1"
shift
;;
*)
echo "Unknown option: $1"
print_usage
exit 1
;;
esac
done
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Clean test results if requested
clean_results() {
if [ "$CLEAN_RESULTS" = true ]; then
print_status "Cleaning test results..."
rm -rf test-results/
rm -rf playwright-report/
rm -rf reports/
rm -rf backstop_data/bitmaps_test/
mkdir -p test-results
mkdir -p reports
print_success "Test results cleaned"
fi
}
# Build Playwright command
build_playwright_command() {
local cmd="npx playwright test"
if [ "$DEBUG_MODE" = true ]; then
cmd="$cmd --debug"
elif [ "$HEADED_MODE" = true ]; then
cmd="$cmd --headed"
fi
if [ "$BROWSER" != "chromium" ]; then
cmd="$cmd --project=$BROWSER"
fi
if [ "$PARALLEL_MODE" = true ]; then
cmd="$cmd --workers=4"
else
cmd="$cmd --workers=1"
fi
if [ "$RECORD_VIDEO" = true ]; then
cmd="$cmd --config playwright.config.ts"
fi
if [ "$SMOKE_ONLY" = true ]; then
cmd="$cmd --grep=\"@smoke\""
elif [ "$REGRESSION_ONLY" = true ]; then
cmd="$cmd --grep=\"@regression\""
fi
echo "$cmd"
}
# Build Cucumber command
build_cucumber_command() {
local cmd="npx cucumber-js"
if [ "$HEADED_MODE" = true ]; then
cmd="$cmd --config cucumber.headed.json"
fi
if [ "$SMOKE_ONLY" = true ]; then
cmd="$cmd --tags \"@smoke\""
elif [ "$REGRESSION_ONLY" = true ]; then
cmd="$cmd --tags \"@regression\""
fi
echo "$cmd"
}
# Run Playwright tests
run_playwright() {
print_status "Running Playwright tests..."
local cmd=$(build_playwright_command)
print_status "Command: $cmd"
export TEST_ENV="$ENVIRONMENT"
if eval "$cmd"; then
print_success "Playwright tests completed successfully"
return 0
else
print_error "Playwright tests failed"
return 1
fi
}
# Run Cucumber tests
run_cucumber() {
print_status "Running Cucumber tests..."
local cmd=$(build_cucumber_command)
print_status "Command: $cmd"
export TEST_ENV="$ENVIRONMENT"
if eval "$cmd"; then
print_success "Cucumber tests completed successfully"
return 0
else
print_error "Cucumber tests failed"
return 1
fi
}
# Run BackstopJS tests
run_backstop() {
print_status "Running visual regression tests..."
export TEST_ENV="$ENVIRONMENT"
if npx backstop test; then
print_success "Visual regression tests completed successfully"
return 0
else
print_error "Visual regression tests failed"
print_status "Run 'npm run test:backstop:approve' to approve new reference images"
return 1
fi
}
# Run all tests
run_all() {
print_status "Running all test types..."
local failed=0
run_playwright || failed=$((failed + 1))
run_cucumber || failed=$((failed + 1))
run_backstop || failed=$((failed + 1))
if [ $failed -eq 0 ]; then
print_success "All tests completed successfully"
else
print_error "$failed test type(s) failed"
exit 1
fi
}
# Main execution
main() {
echo ""
print_status "BackWPUp E2E Test Runner"
print_status "Environment: $ENVIRONMENT"
print_status "Test Type: $TEST_TYPE"
echo ""
# Set environment variable
export TEST_ENV="$ENVIRONMENT"
# Clean results if requested
clean_results
# Run tests based on type
case $TEST_TYPE in
playwright)
run_playwright
;;
cucumber)
run_cucumber
;;
backstop)
run_backstop
;;
all)
run_all
;;
*)
print_error "Unknown test type: $TEST_TYPE"
print_usage
exit 1
;;
esac
print_success "Test execution completed"
}
# Run main function
main "$@"