-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
385 lines (347 loc) Β· 16.4 KB
/
Copy pathjustfile
File metadata and controls
385 lines (347 loc) Β· 16.4 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# Justfile for TunService Test Automation Project
#
# DEVICE TESTING
# ==============
# ΠΡΠΎΠ΅ΠΊΡ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅Ρ Π·Π°ΠΏΡΡΠΊ ΡΠ΅ΡΡΠΎΠ² Π½Π° ΡΠ°Π·Π½ΡΡ
ΡΡΡΡΠΎΠΉΡΡΠ²Π°Ρ
.
# ΠΠ½ΡΠΎΡΠΌΠ°ΡΠΈΡ ΠΎ device Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈ Π΄ΠΎΠ±Π°Π²Π»ΡΠ΅ΡΡΡ Π²ΠΎ Π²ΡΠ΅ ΠΎΡΡΠ΅ΡΡ:
# - Allure ΠΎΡΡΠ΅ΡΡ: labels Π΄Π»Ρ ΡΠΈΠ»ΡΡΡΠ°ΡΠΈΠΈ (device, viewport)
# - HTML ΠΎΡΡΠ΅ΡΡ: Environment ΡΠ°Π±Π»ΠΈΡΠ° + ΠΊΠ°ΡΡΠΎΠΌΠ½ΡΠ΅ ΠΊΠΎΠ»ΠΎΠ½ΠΊΠΈ (Device, Viewport)
# - JUnit XML: properties Π΄Π»Ρ GitHub Actions (device, viewport)
# - Playwright Trace: title, HTTP headers, metadata tab
#
# ΠΠΠ‘Π’Π£ΠΠΠ«Π Π£Π‘Π’Π ΠΠΠ‘Π’ΠΠ:
# - desktop: Desktop Chrome (1280x720)
# - mobile: iPhone 15 Pro Max (430x739)
# - tablet: iPad Pro 11 (834x1194)
# - ΠΡΠ±ΠΎΠ΅ ΡΡΡΡΠΎΠΉΡΡΠ²ΠΎ ΠΈΠ· Playwright: DEVICE="iPhone 14 Pro"
#
# ΠΠ ΠΠΠΠ Π«:
# just test-desktop # Desktop + Chromium
# just test-mobile # Mobile + Chromium
# just test-device "iPhone 14 Pro"
# ============================================================================
# CONFIGURATION
# ============================================================================
VENV := ".venv"
PYTEST := VENV + "/bin/pytest"
PYTHON := VENV + "/bin/python"
# Common pytest options
PYTEST_OPTS := "-v --tb=short"
PYTEST_BROWSER := "chromium"
PYTEST_BASE := PYTEST + " tests/ " + PYTEST_OPTS + " --browser " + PYTEST_BROWSER
# Paths
TESTS_DIR := "tests/"
PIXEL_TESTS_DIR := "tests/pixels-tests/"
REPORTS_DIR := "reports/"
ALLURE_RESULTS := REPORTS_DIR + "allure-results"
ALLURE_REPORT := REPORTS_DIR + "allure-report"
# ============================================================================
# VALIDATION
# ============================================================================
_check-root:
#!/usr/bin/env bash
if [ ! -f "justfile" ] || [ ! -f "pytest.ini" ]; then
echo "β Error: Must run from project root directory"
echo "Current directory: $(pwd)"
echo "Please run 'cd' to project root first"
exit 1
fi
if [ ! -f "{{PYTEST}}" ]; then
echo "β Error: Virtual environment not found at {{VENV}}"
echo "Please run: python -m venv {{VENV}} && source {{VENV}}/bin/activate && pip install -r requirements.txt"
exit 1
fi
# ============================================================================
# HELP
# ============================================================================
default: _check-root
@echo "π TunService Test Automation - Available Commands"
@echo ""
@echo "π§ͺ Functional Tests:"
@echo " just test - Run all functional tests (Chromium)"
@echo " just smoke - Run smoke tests (supports browser/device)"
@echo " just regression - Run regression tests (supports browser/device)"
@echo " just validation - Run validation tests (supports browser/device)"
@echo ""
@echo "π‘ Smoke/Regression/Validation Examples:"
@echo " just smoke # Smoke tests (Chromium, default)"
@echo " just smoke browser=firefox # Smoke tests on Firefox"
@echo " just smoke device=mobile # Smoke tests on mobile"
@echo " just smoke browser=webkit device=tablet # Smoke tests on WebKit tablet"
@echo " just regression # Regression tests (Chromium, default)"
@echo " just regression browser=firefox device=mobile # Regression on Firefox mobile"
@echo " just validation # Validation tests (Chromium, default)"
@echo " just validation browser=firefox device=mobile # Validation on Firefox mobile"
@echo ""
@echo "πΈ Visual Regression Tests (format: {browser}-{viewport}-{title}.png):"
@echo " just test-pixels - Run pixel tests (chromium-desktop)"
@echo " just test-pixels browser=webkit - Run pixel tests for WebKit"
@echo " just test-pixels-all - Run pixel tests for all browsers"
@echo " just test-pixels-update - Update snapshots (chromium-desktop)"
@echo " just test-pixels-update browser=webkit - Update WebKit snapshots"
@echo " just test-pixels-update-all - Update snapshots for all browsers"
@echo " just snapshots-clean - Clean snapshot failure artifacts"
@echo ""
@echo "π Pixel Tests Examples:"
@echo " just test-pixels # Run all Chromium pixel tests"
@echo " just test-pixels webkit # Run WebKit pixel tests"
@echo " just test-pixels chromium desktop tests/pixels-tests/test_login_page_pixels.py # Run specific test"
@echo " just test-pixels-update chromium desktop tests/pixels-tests/test_login_page_pixels.py # Update specific test"
@echo " Download reference snapshots from GitHub Actions artifacts (first time setup)"
@echo ""
@echo "π± Device-specific tests (device info added to all reports):"
@echo " test-desktop - Desktop Chrome (1280x720)"
@echo " test-mobile - iPhone 15 Pro Max (430x739)"
@echo " test-tablet - iPad Pro 11 (834x1194)"
@echo " test-device <device> - Any Playwright device"
@echo " test-all-devices - All devices (desktop, mobile, tablet)"
@echo ""
@echo "π§ Other commands:"
@echo " lint - Run linting (ruff)"
@echo " format - Format code (black + isort)"
@echo " clean - Clean test artifacts"
@echo " allure - Serve Allure results ({{ALLURE_RESULTS}})"
@echo ""
@echo "π Debug & Development:"
@echo " test-debug - Run tests in headed mode (visible browser)"
@echo " test-upload - Run tests with upload marker"
@echo " test-authorization - Run tests with authorization marker"
@echo " test-marker <marker> - Run tests by marker"
help: default
# ============================================================================
# SETUP
# ============================================================================
setup: _check-root
@echo "π§ Setting up project dependencies..."
pip install -r requirements.txt
@echo "π Installing Playwright browsers..."
playwright install
@echo "β
Setup completed successfully!"
# ============================================================================
# FUNCTIONAL TESTS
# ============================================================================
test browser="chromium" device="": _check-root
#!/usr/bin/env bash
BROWSER_ARG="--browser {{browser}}"
if [ -n "{{device}}" ]; then
DEVICE={{device}} {{PYTEST}} {{TESTS_DIR}} {{PYTEST_OPTS}} $BROWSER_ARG
else
{{PYTEST}} {{TESTS_DIR}} {{PYTEST_OPTS}} $BROWSER_ARG
fi
smoke browser="chromium" device="": _check-root
#!/usr/bin/env bash
BROWSER_ARG="--browser {{browser}}"
if [ -n "{{device}}" ]; then
DEVICE={{device}} {{PYTEST}} {{TESTS_DIR}} {{PYTEST_OPTS}} -m smoke $BROWSER_ARG
else
{{PYTEST}} {{TESTS_DIR}} {{PYTEST_OPTS}} -m smoke $BROWSER_ARG
fi
regression browser="chromium" device="": _check-root
#!/usr/bin/env bash
BROWSER_ARG="--browser {{browser}}"
if [ -n "{{device}}" ]; then
DEVICE={{device}} {{PYTEST}} {{TESTS_DIR}} {{PYTEST_OPTS}} -m "smoke or regression" $BROWSER_ARG
else
{{PYTEST}} {{TESTS_DIR}} {{PYTEST_OPTS}} -m "smoke or regression" $BROWSER_ARG
fi
validation browser="chromium" device="": _check-root
#!/usr/bin/env bash
BROWSER_ARG="--browser {{browser}}"
if [ -n "{{device}}" ]; then
DEVICE={{device}} {{PYTEST}} {{TESTS_DIR}} {{PYTEST_OPTS}} -m validation $BROWSER_ARG
else
{{PYTEST}} {{TESTS_DIR}} {{PYTEST_OPTS}} -m validation $BROWSER_ARG
fi
# Marker-based tests
test-upload: _check-root
@echo "π€ Running tests with upload marker..."
{{PYTEST_BASE}} -m upload
test-authorization: _check-root
@echo "π Running tests with authorization marker..."
{{PYTEST_BASE}} -m authorization
test-marker marker: _check-root
@echo "π·οΈ Running tests with marker: {{marker}}"
{{PYTEST_BASE}} -m {{marker}}
# Sequential execution (for Docker)
tests: _check-root
@echo "π’ Running tests sequentially (for Docker)..."
{{PYTEST_BASE}} -n 1
# ============================================================================
# VISUAL REGRESSION TESTS
# ============================================================================
# Snapshot naming format: {browser}-{viewport}-{title}.png
# Examples: chromium-desktop-test_header.png, webkit-desktop-test_footer.png
#
# CI Workflow:
# 1. First run creates snapshots in CI (Chrome/WebKit differ from local)
# 2. Download snapshots from CI artifacts: just snapshots-download
# 3. Commit to repo: git add references/ && git commit
# 4. Subsequent runs compare against committed snapshots
test-pixels browser="chromium" device="desktop" *args: _check-root
#!/usr/bin/env bash
echo "πΈ Running visual regression tests ({{browser}} on {{device}})..."
if [ "$#" -gt 0 ]; then
HEADLESS=true BROWSER={{browser}} DEVICE={{device}} \
{{PYTEST}} "$@" {{PYTEST_OPTS}} -m pixel_test --browser {{browser}} --color=yes
else
HEADLESS=true BROWSER={{browser}} DEVICE={{device}} \
{{PYTEST}} {{PIXEL_TESTS_DIR}} {{PYTEST_OPTS}} -m pixel_test --browser {{browser}} --color=yes
fi
test-pixels-all: _check-root
#!/usr/bin/env bash
echo "πΈ Running pixel tests for all browsers..."
echo "π Testing Chromium..."
HEADLESS=true BROWSER=chromium DEVICE=desktop \
{{PYTEST}} {{PIXEL_TESTS_DIR}} {{PYTEST_OPTS}} -m pixel_test --browser chromium --color=yes
echo ""
echo "π Testing WebKit..."
HEADLESS=true BROWSER=webkit DEVICE=desktop \
{{PYTEST}} {{PIXEL_TESTS_DIR}} {{PYTEST_OPTS}} -m pixel_test --browser webkit --color=yes
echo ""
echo "β
All browsers tested!"
test-pixels-update browser="chromium" device="desktop" *args: _check-root
#!/usr/bin/env bash
echo "πΈ Updating visual snapshots ({{browser}} on {{device}})..."
if [ "$#" -gt 0 ]; then
HEADLESS=true BROWSER={{browser}} DEVICE={{device}} \
{{PYTEST}} "$@" --update-snapshots {{PYTEST_OPTS}} --browser {{browser}} --color=yes
else
HEADLESS=true BROWSER={{browser}} DEVICE={{device}} \
{{PYTEST}} {{PIXEL_TESTS_DIR}} --update-snapshots {{PYTEST_OPTS}} --browser {{browser}} --color=yes
fi
echo ""
echo "β
Snapshots updated for {{browser}}-{{device}}!"
echo "π Review changes in: references/"
echo "β οΈ Don't forget to commit: git add references/"
echo "π§Ή Cleaning Allure reports..."
rm -rf {{ALLURE_RESULTS}}/ {{ALLURE_REPORT}}/
test-pixels-update-all: _check-root
#!/usr/bin/env bash
echo "πΈ Updating snapshots for all browsers..."
echo "π Updating Chromium snapshots..."
HEADLESS=true BROWSER=chromium DEVICE=desktop \
{{PYTEST}} {{PIXEL_TESTS_DIR}} --update-snapshots {{PYTEST_OPTS}} --browser chromium
echo ""
echo "π Updating WebKit snapshots..."
HEADLESS=true BROWSER=webkit DEVICE=desktop \
{{PYTEST}} {{PIXEL_TESTS_DIR}} --update-snapshots {{PYTEST_OPTS}} --browser webkit
echo ""
echo "β
All snapshots updated!"
echo "π Review changes in: references/"
echo "β οΈ Don't forget to commit: git add references/"
echo "π§Ή Cleaning Allure reports..."
rm -rf {{ALLURE_RESULTS}}/ {{ALLURE_REPORT}}/
# Download snapshots from GitHub Actions UI (simplified workflow)
# 1. Go to GitHub Actions > Pixel Tests workflow run
# 2. Download "references" artifact (contains combined snapshots from all browsers)
# 3. Extract ZIP to project root
# 4. Review and commit: git add references/ && git commit -m 'Update pixel test snapshots'
snapshots-clean: _check-root
#!/usr/bin/env bash
echo "ποΈ Cleaning snapshot failure artifacts..."
rm -rf snapshot_failures/
echo "β
Cleaned successfully"
snapshots-clean-all: _check-root
#!/usr/bin/env bash
echo "ποΈ Cleaning ALL snapshots (failures + references)..."
rm -rf snapshot_failures/ references/
echo "β
Cleaned successfully"
# ============================================================================
# DEVICE-SPECIFIC TEST COMMANDS
# ============================================================================
# ΠΡΠ΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈ Π΄ΠΎΠ±Π°Π²Π»ΡΡΡ device ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΡ Π² ΠΎΡΡΠ΅ΡΡ:
# - Allure: labels (device, viewport)
# - HTML: Environment ΡΠ°Π±Π»ΠΈΡΠ° + ΠΊΠΎΠ»ΠΎΠ½ΠΊΠΈ (Device, Viewport)
# - JUnit XML: properties (device, viewport) Π΄Π»Ρ GitHub Actions
# - Trace: title, HTTP headers, metadata
test-desktop: _check-root
@echo "π₯οΈ Running tests on desktop..."
DEVICE=desktop {{PYTEST_BASE}}
test-mobile: _check-root
@echo "π± Running tests on mobile..."
DEVICE=mobile {{PYTEST_BASE}}
test-tablet: _check-root
@echo "π± Running tests on tablet..."
DEVICE=tablet {{PYTEST_BASE}}
test-device device: _check-root
@echo "π± Running tests on device: {{device}}"
DEVICE="{{device}}" {{PYTEST_BASE}}
test-all-devices: _check-root
#!/usr/bin/env bash
echo "π± Running all devices on Chromium..."
echo "π₯οΈ Testing desktop..."
DEVICE=desktop {{PYTEST_BASE}} && \
echo "π± Testing mobile..." && \
DEVICE=mobile {{PYTEST_BASE}} && \
echo "π± Testing tablet..." && \
DEVICE=tablet {{PYTEST_BASE}} && \
echo "β
All devices tested successfully!"
# ============================================================================
# DEBUG & DEVELOPMENT
# ============================================================================
test-debug: _check-root
@echo "π Running tests in debug mode (headed browser)..."
{{PYTEST_BASE}} --headed
tracing device test_file: _check-root
#!/usr/bin/env bash
echo "π Running test with tracing enabled..."
ENABLE_TRACING=true DEVICE={{device}} {{PYTEST}} {{test_file}} {{PYTEST_OPTS}} --browser {{PYTEST_BROWSER}}
echo "β
Trace saved. Check trace.zip file"
# ============================================================================
# CODE QUALITY
# ============================================================================
lint:
@echo "π Running linter (ruff)..."
ruff check .
@echo "β
Linting completed"
format:
@echo "β¨ Formatting code with black and isort..."
black .
isort .
@echo "β
Code formatting completed"
clean:
#!/usr/bin/env bash
echo "π§Ή Cleaning test artifacts..."
find {{REPORTS_DIR}} -type f -delete 2>/dev/null || true
rm -rf .ruff_cache/ .pytest_cache/
rm -f trace.zip trace-*.zip
rm -rf {{ALLURE_RESULTS}}/ {{ALLURE_REPORT}}/
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f \( -name "*.pyc" -o -name ".DS_Store" -o -name "*.pyo" -o -name "*.pyd" \) -delete 2>/dev/null || true
echo "β
Cleanup completed"
# ============================================================================
# ALLURE REPORTS
# ============================================================================
allure: _check-root
#!/usr/bin/env bash
echo "π Opening Allure report..."
allure serve {{ALLURE_RESULTS}}
allure-clean: _check-root
#!/usr/bin/env bash
echo "π§Ή Cleaning Allure reports..."
rm -rf {{ALLURE_RESULTS}}/ {{ALLURE_REPORT}}/ {{REPORTS_DIR}}junit.xml {{REPORTS_DIR}}failed_screenshots/*.png
echo "β
Allure reports cleaned"
allure-open: _check-root
#!/usr/bin/env bash
echo "π Opening Allure report..."
if [ -d "{{ALLURE_REPORT}}" ]; then
allure open {{ALLURE_REPORT}}
else
echo "β οΈ Allure report not found. Generating from results..."
allure generate {{ALLURE_RESULTS}} -o {{ALLURE_REPORT}} --clean
allure open {{ALLURE_REPORT}}
fi
# ============================================================================
# UTILITIES
# ============================================================================
health-check: _check-root
@echo "π₯ Health Check - Environment Status"
@echo "ββββββββββββββββββββββββββββββββββββββββ"
@echo "π Python version:"
@{{PYTHON}} --version
@echo "π§ͺ Pytest version:"
@{{PYTEST}} --version
@echo "π Playwright version:"
@{{VENV}}/bin/playwright --version
@echo "ββββββββββββββββββββββββββββββββββββββββ"
@echo "β
Health check completed"