@@ -601,7 +601,7 @@ check-manifest: ## 📦 Verify MANIFEST.in completeness
601
601
@echo " 📦 Verifying MANIFEST.in completeness..."
602
602
@$(VENV_DIR ) /bin/check-manifest
603
603
604
- unimport : # # 📦 Unused import detection
604
+ unimport : # # 📦 Unused import detection
605
605
@echo " 📦 unimport …" && $(VENV_DIR ) /bin/unimport --check --diff mcpgateway
606
606
607
607
vulture : # # 🧹 Dead code detection
@@ -2364,3 +2364,148 @@ db-history:
2364
2364
2365
2365
db-revision-id :
2366
2366
@$(ALEMBIC ) current --verbose | awk ' /Current revision/ {print $$3}'
2367
+
2368
+
2369
+ # =============================================================================
2370
+ # 🎭 UI TESTING (PLAYWRIGHT)
2371
+ # =============================================================================
2372
+ # help: 🎭 UI TESTING (PLAYWRIGHT)
2373
+ # help: playwright-install - Install Playwright browsers (chromium by default)
2374
+ # help: playwright-install-all - Install all Playwright browsers (chromium, firefox, webkit)
2375
+ # help: test-ui - Run Playwright UI tests with visible browser
2376
+ # help: test-ui-headless - Run Playwright UI tests in headless mode
2377
+ # help: test-ui-debug - Run Playwright UI tests with Playwright Inspector
2378
+ # help: test-ui-smoke - Run UI smoke tests only (fast subset)
2379
+ # help: test-ui-parallel - Run UI tests in parallel using pytest-xdist
2380
+ # help: test-ui-report - Run UI tests and generate HTML report
2381
+ # help: test-ui-coverage - Run UI tests with coverage for admin endpoints
2382
+ # help: test-ui-record - Run UI tests and record videos (headless)
2383
+ # help: test-ui-update-snapshots - Update visual regression snapshots
2384
+ # help: test-ui-clean - Clean up Playwright test artifacts
2385
+
2386
+ .PHONY : playwright-install playwright-install-all test-ui test-ui-headless test-ui-debug test-ui-smoke test-ui-parallel test-ui-report test-ui-coverage test-ui-record test-ui-update-snapshots test-ui-clean
2387
+
2388
+ # Playwright test variables
2389
+ PLAYWRIGHT_DIR := tests/playwright
2390
+ PLAYWRIGHT_REPORTS := $(PLAYWRIGHT_DIR ) /reports
2391
+ PLAYWRIGHT_SCREENSHOTS := $(PLAYWRIGHT_DIR ) /screenshots
2392
+ PLAYWRIGHT_VIDEOS := $(PLAYWRIGHT_DIR ) /videos
2393
+
2394
+ # # --- Playwright Setup -------------------------------------------------------
2395
+ playwright-install :
2396
+ @echo " 🎭 Installing Playwright browsers (chromium)..."
2397
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2398
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2399
+ pip install -e ' .[playwright]' 2> /dev/null || pip install playwright pytest-playwright && \
2400
+ playwright install chromium"
2401
+ @echo " ✅ Playwright chromium browser installed!"
2402
+
2403
+ playwright-install-all :
2404
+ @echo " 🎭 Installing all Playwright browsers..."
2405
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2406
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2407
+ pip install -e ' .[playwright]' 2> /dev/null || pip install playwright pytest-playwright && \
2408
+ playwright install"
2409
+ @echo " ✅ All Playwright browsers installed!"
2410
+
2411
+ # # --- UI Test Execution ------------------------------------------------------
2412
+ test-ui : playwright-install
2413
+ @echo " 🎭 Running UI tests with visible browser..."
2414
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2415
+ @mkdir -p $(PLAYWRIGHT_SCREENSHOTS ) $(PLAYWRIGHT_REPORTS )
2416
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2417
+ pytest $(PLAYWRIGHT_DIR ) / -v --headed --screenshot=only-on-failure \
2418
+ --browser chromium || { echo ' ❌ UI tests failed!' ; exit 1; }"
2419
+ @echo " ✅ UI tests completed!"
2420
+
2421
+ test-ui-headless : playwright-install
2422
+ @echo " 🎭 Running UI tests in headless mode..."
2423
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2424
+ @mkdir -p $(PLAYWRIGHT_SCREENSHOTS ) $(PLAYWRIGHT_REPORTS )
2425
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2426
+ pytest $(PLAYWRIGHT_DIR ) / -v --screenshot=only-on-failure \
2427
+ --browser chromium || { echo ' ❌ UI tests failed!' ; exit 1; }"
2428
+ @echo " ✅ UI tests completed!"
2429
+
2430
+ test-ui-debug : playwright-install
2431
+ @echo " 🎭 Running UI tests with Playwright Inspector..."
2432
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2433
+ @mkdir -p $(PLAYWRIGHT_SCREENSHOTS ) $(PLAYWRIGHT_REPORTS )
2434
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2435
+ PWDEBUG=1 pytest $(PLAYWRIGHT_DIR ) / -v -s --headed \
2436
+ --browser chromium"
2437
+
2438
+ test-ui-smoke : playwright-install
2439
+ @echo " 🎭 Running UI smoke tests..."
2440
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2441
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2442
+ pytest $(PLAYWRIGHT_DIR ) / -v -m smoke --headed \
2443
+ --browser chromium || { echo ' ❌ UI smoke tests failed!' ; exit 1; }"
2444
+ @echo " ✅ UI smoke tests passed!"
2445
+
2446
+ test-ui-parallel : playwright-install
2447
+ @echo " 🎭 Running UI tests in parallel..."
2448
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2449
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2450
+ pip install -q pytest-xdist && \
2451
+ pytest $(PLAYWRIGHT_DIR ) / -v -n auto --dist loadscope \
2452
+ --browser chromium || { echo ' ❌ UI tests failed!' ; exit 1; }"
2453
+ @echo " ✅ UI parallel tests completed!"
2454
+
2455
+ # # --- UI Test Reporting ------------------------------------------------------
2456
+ test-ui-report : playwright-install
2457
+ @echo " 🎭 Running UI tests with HTML report..."
2458
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2459
+ @mkdir -p $(PLAYWRIGHT_REPORTS )
2460
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2461
+ pip install -q pytest-html && \
2462
+ pytest $(PLAYWRIGHT_DIR ) / -v --screenshot=only-on-failure \
2463
+ --html=$(PLAYWRIGHT_REPORTS ) /report.html --self-contained-html \
2464
+ --browser chromium || true"
2465
+ @echo " ✅ UI test report generated: $( PLAYWRIGHT_REPORTS) /report.html"
2466
+ @echo " Open with: open $( PLAYWRIGHT_REPORTS) /report.html"
2467
+
2468
+ test-ui-coverage : playwright-install
2469
+ @echo " 🎭 Running UI tests with coverage..."
2470
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2471
+ @mkdir -p $(PLAYWRIGHT_REPORTS )
2472
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2473
+ pytest $(PLAYWRIGHT_DIR ) / -v --cov=mcpgateway.admin \
2474
+ --cov-report=html:$(PLAYWRIGHT_REPORTS ) /coverage \
2475
+ --cov-report=term --browser chromium || true"
2476
+ @echo " ✅ UI coverage report: $( PLAYWRIGHT_REPORTS) /coverage/index.html"
2477
+
2478
+ test-ui-record : playwright-install
2479
+ @echo " 🎭 Running UI tests with video recording..."
2480
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2481
+ @mkdir -p $(PLAYWRIGHT_VIDEOS )
2482
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2483
+ pytest $(PLAYWRIGHT_DIR ) / -v --video=on \
2484
+ --browser chromium || true"
2485
+ @echo " ✅ Test videos saved in: $( PLAYWRIGHT_VIDEOS) /"
2486
+
2487
+ # # --- UI Test Utilities ------------------------------------------------------
2488
+ test-ui-update-snapshots : playwright-install
2489
+ @echo " 🎭 Updating visual regression snapshots..."
2490
+ @test -d " $( VENV_DIR) " || $(MAKE ) venv
2491
+ @/bin/bash -c " source $( VENV_DIR) /bin/activate && \
2492
+ pytest $(PLAYWRIGHT_DIR ) / -v --update-snapshots \
2493
+ --browser chromium"
2494
+ @echo " ✅ Snapshots updated!"
2495
+
2496
+ test-ui-clean :
2497
+ @echo " 🧹 Cleaning Playwright test artifacts..."
2498
+ @rm -rf $(PLAYWRIGHT_SCREENSHOTS ) /* .png
2499
+ @rm -rf $(PLAYWRIGHT_VIDEOS ) /* .webm
2500
+ @rm -rf $(PLAYWRIGHT_REPORTS ) /*
2501
+ @rm -rf test-results/
2502
+ @rm -f playwright-report-* .html test-results-* .xml
2503
+ @echo " ✅ Playwright artifacts cleaned!"
2504
+
2505
+ # # --- Combined Testing -------------------------------------------------------
2506
+ test-all : test test-ui-headless
2507
+ @echo " ✅ All tests completed (unit + UI)!"
2508
+
2509
+ # Add UI tests to your existing test suite if needed
2510
+ test-full : coverage test-ui-report
2511
+ @echo " 📊 Full test suite completed with coverage and UI tests!"
0 commit comments