|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Standalone EdgeDriver integration test for issues #1312 and BOM bug. |
| 3 | +
|
| 4 | +Verifies that: |
| 5 | + 1. Microsoft's LATEST_RELEASE endpoint BOM is stripped before building the |
| 6 | + download URL — without the fix, the URL contains %EF%BB%BF and returns 404 |
| 7 | + 2. EdgeDriver binary can be downloaded (tests azureedge.net -> microsoft.com |
| 8 | + redirect fix from PR #1227) — this is the primary test |
| 9 | + 3. A headless Edge session can be started (end-to-end, requires Edge browser installed) |
| 10 | +
|
| 11 | +Expected to FAIL without the BOM-strip fix (webdriver-manager 4.0.2 bug). |
| 12 | +Expected to PASS after fix: EdgeChromiumDriver.get_latest_release_version() strips \\ufeff. |
| 13 | +
|
| 14 | +Exit codes: |
| 15 | + 0 — download succeeded (session also started if Edge browser is installed) |
| 16 | + 1 — download or session failed unexpectedly |
| 17 | +
|
| 18 | +Usage: |
| 19 | + python test_edge_driver.py |
| 20 | + # or from packages/core directory: |
| 21 | + uv run python tests/python/test_edge_driver.py |
| 22 | +""" |
| 23 | +import shutil |
| 24 | +import sys |
| 25 | +from pathlib import Path |
| 26 | + |
| 27 | + |
| 28 | +def main() -> int: |
| 29 | + import importlib.metadata |
| 30 | + |
| 31 | + selenium_ver = importlib.metadata.version("selenium") |
| 32 | + print(f"Selenium version: {selenium_ver}") |
| 33 | + |
| 34 | + # Step 0: verify BOM-strip fix in EdgeChromiumDriver |
| 35 | + print("Checking BOM strip in EdgeChromiumDriver...") |
| 36 | + try: |
| 37 | + from RPA.core.webdriver import EdgeChromiumDriver |
| 38 | + bom_version = "\ufeff145.0.3800.97" |
| 39 | + stripped = EdgeChromiumDriver._strip_bom(bom_version) |
| 40 | + assert stripped == "145.0.3800.97", f"BOM not stripped: {stripped!r}" |
| 41 | + print(f" BOM strip OK: {bom_version!r} -> {stripped!r}") |
| 42 | + except Exception as exc: |
| 43 | + print(f"\nFAIL (BOM strip check): {type(exc).__name__}: {exc}") |
| 44 | + return 1 |
| 45 | + |
| 46 | + # Step 1: download EdgeDriver — exercises the azureedge.net redirect patch |
| 47 | + try: |
| 48 | + from RPA.core import webdriver |
| 49 | + |
| 50 | + results_dir = Path(__file__).parent / "results" |
| 51 | + results_dir.mkdir(exist_ok=True) |
| 52 | + print("Downloading EdgeDriver...") |
| 53 | + driver_path = webdriver.download("Edge", root=results_dir) |
| 54 | + print(f" Driver downloaded: {driver_path}") |
| 55 | + except Exception as exc: |
| 56 | + print(f"\nFAIL (download): {type(exc).__name__}: {exc}") |
| 57 | + return 1 |
| 58 | + |
| 59 | + # Step 2: start a headless Edge session — requires Edge browser to be installed |
| 60 | + edge_binary = shutil.which("msedge") or shutil.which("microsoft-edge") |
| 61 | + if not edge_binary: |
| 62 | + # Check standard macOS application path |
| 63 | + macos_edge = Path("/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge") |
| 64 | + if macos_edge.exists(): |
| 65 | + edge_binary = str(macos_edge) |
| 66 | + if not edge_binary: |
| 67 | + # Check standard Windows installation paths (msedge.exe is not on PATH by default) |
| 68 | + import os |
| 69 | + windows_paths = [ |
| 70 | + Path(os.environ.get("PROGRAMFILES(X86)", "")) / "Microsoft/Edge/Application/msedge.exe", |
| 71 | + Path(os.environ.get("PROGRAMFILES", "")) / "Microsoft/Edge/Application/msedge.exe", |
| 72 | + Path(os.environ.get("LOCALAPPDATA", "")) / "Microsoft/Edge/Application/msedge.exe", |
| 73 | + ] |
| 74 | + for p in windows_paths: |
| 75 | + if p.exists(): |
| 76 | + edge_binary = str(p) |
| 77 | + break |
| 78 | + |
| 79 | + if not edge_binary: |
| 80 | + print( |
| 81 | + "\nPASS (download only): EdgeDriver downloaded successfully. " |
| 82 | + "Edge browser not installed — skipping session test." |
| 83 | + ) |
| 84 | + return 0 |
| 85 | + |
| 86 | + try: |
| 87 | + from selenium import webdriver as selenium_webdriver |
| 88 | + from selenium.webdriver import EdgeOptions |
| 89 | + from selenium.webdriver.edge.service import Service |
| 90 | + |
| 91 | + options = EdgeOptions() |
| 92 | + options.add_argument("--headless=new") |
| 93 | + options.add_argument("--no-sandbox") |
| 94 | + options.add_argument("--disable-dev-shm-usage") |
| 95 | + options.binary_location = edge_binary |
| 96 | + service = Service(driver_path) |
| 97 | + print(f"Starting headless Edge session (binary: {edge_binary})...") |
| 98 | + driver = selenium_webdriver.Edge(service=service, options=options) |
| 99 | + try: |
| 100 | + driver.get("about:blank") |
| 101 | + title = driver.title |
| 102 | + finally: |
| 103 | + driver.quit() |
| 104 | + print(f" Session OK, page title: '{title}'") |
| 105 | + except Exception as exc: |
| 106 | + print(f"\nFAIL (session): {type(exc).__name__}: {exc}") |
| 107 | + return 1 |
| 108 | + |
| 109 | + print("\nPASS: EdgeDriver download and session both work correctly.") |
| 110 | + return 0 |
| 111 | + |
| 112 | + |
| 113 | +if __name__ == "__main__": |
| 114 | + sys.exit(main()) |
0 commit comments