|
8 | 8 | Author: Zeuz/AutomationSolutionz |
9 | 9 | """ |
10 | 10 |
|
11 | | -import subprocess |
12 | 11 | import os |
13 | | -import sys |
14 | 12 | from pathlib import Path |
15 | 13 | from Framework.Utilities import CommonUtil |
16 | | -from settings import ZEUZ_NODE_DOWNLOADS_DIR |
| 14 | +from Framework.Built_In_Automation.Web.Selenium.utils import ChromeForTesting |
17 | 15 |
|
18 | | -PW_BROWSERS_DIR = ZEUZ_NODE_DOWNLOADS_DIR / "pw-browsers" |
| 16 | +# Initialize Chrome for Testing instance |
| 17 | +chrome_for_testing = ChromeForTesting() |
19 | 18 |
|
20 | | -def check_playwright_browser_exists(): |
21 | | - if not PW_BROWSERS_DIR.exists(): |
22 | | - return False |
23 | 19 |
|
24 | | - # Check if a folder name exists that starts with "chromium-" |
25 | | - for folder in PW_BROWSERS_DIR.iterdir(): |
26 | | - if folder.name.startswith("chromium-"): |
27 | | - # Check if a file named "INSTALLATION_COMPLETE" exist |
28 | | - if (folder / "INSTALLATION_COMPLETE").exists(): |
29 | | - return True |
30 | | - return False |
31 | | - |
32 | | - |
33 | | -def download_playwright_browser(brand="chromium", download_path=PW_BROWSERS_DIR): |
| 20 | +def ensure_chromium_downloads(sModuleInfo): |
34 | 21 | """ |
35 | | - Download Playwright browser for the specified brand. |
| 22 | + Ensure Chrome for Testing is available for Playwright. |
36 | 23 | |
37 | 24 | Args: |
38 | | - brand (str): Browser brand to download (default: "chromium") |
39 | | - download_path (Path): Path to download the browser to (default: PW_BROWSERS_DIR) |
| 25 | + sModuleInfo: Module information for logging |
| 26 | + |
| 27 | + Returns: |
| 28 | + tuple: (chrome_binary_path, success_flag) where success_flag is True if successful |
40 | 29 | """ |
41 | | - |
42 | | - os.environ["PLAYWRIGHT_BROWSERS_PATH"] = str(download_path) |
43 | | - |
44 | | - CommonUtil.ExecLog("", f"Downloading Playwright browser: {brand} to {os.environ['PLAYWRIGHT_BROWSERS_PATH']}", 2) |
45 | | - # Execute the command with the current Python instance (venv) |
46 | | - python_path = sys.executable |
47 | | - install = subprocess.run([python_path, "-m", "playwright", "install", "--no-shell", brand]) |
48 | | - |
49 | | - if install.returncode == 0: |
50 | | - CommonUtil.ExecLog("", f"Playwright browser downloaded successfully: {brand}", 2) |
51 | | - return True |
52 | | - else: |
53 | | - CommonUtil.ExecLog("", f"Failed to download Playwright browser: {brand}", 2) |
54 | | - return False |
| 30 | + try: |
| 31 | + CommonUtil.ExecLog(sModuleInfo, "Setting up Chrome for Testing for Playwright...", 1) |
| 32 | + |
| 33 | + # Use Chrome for Testing to get Chrome binary |
| 34 | + chrome_bin, driver_bin = chrome_for_testing.setup_chrome_for_testing() |
| 35 | + |
| 36 | + if chrome_bin and chrome_bin.exists(): |
| 37 | + CommonUtil.ExecLog(sModuleInfo, f"Chrome for Testing ready: {chrome_bin}", 1) |
| 38 | + return str(chrome_bin), True |
| 39 | + else: |
| 40 | + CommonUtil.ExecLog(sModuleInfo, "Failed to setup Chrome for Testing", 3) |
| 41 | + return None, False |
| 42 | + |
| 43 | + except Exception as e: |
| 44 | + CommonUtil.ExecLog(sModuleInfo, f"Error setting up Chrome for Testing: {str(e)}", 3) |
| 45 | + return None, False |
0 commit comments