Skip to content

Commit 54c2bf6

Browse files
committed
Replace Playwright auto browser download with the Selenium CfT functions
1 parent f7a50ba commit 54c2bf6

2 files changed

Lines changed: 34 additions & 43 deletions

File tree

Framework/Built_In_Automation/Web/Playwright/BuiltInFunctions.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,10 @@ async def Open_Browser(step_data):
180180
# Handle Selenium-style capabilities where possible
181181
pass
182182

183-
# Set playwright browser path environment variable
184-
os.environ["PLAYWRIGHT_BROWSERS_PATH"] = str(PlaywrightUtils.PW_BROWSERS_DIR)
185-
186-
# Check if pw-browsers folder exists, download Chromium if needed
187-
if not PlaywrightUtils.check_playwright_browser_exists():
188-
CommonUtil.ExecLog(sModuleInfo, "Playwright browser not found, downloading Chromium...", 2)
189-
if not PlaywrightUtils.download_playwright_browser():
190-
CommonUtil.ExecLog(sModuleInfo, "Failed to download Playwright browser", 2)
191-
return "zeuz_failed"
183+
# Ensure Chrome for Testing is available
184+
chrome_binary_path, success = PlaywrightUtils.ensure_chromium_downloads(sModuleInfo)
185+
if not success:
186+
return "zeuz_failed"
192187

193188
# Launch Playwright
194189
CommonUtil.ExecLog(sModuleInfo, f"Launching Playwright with {browser_name} browser", 1)
@@ -204,6 +199,11 @@ async def Open_Browser(step_data):
204199
launch_options["args"] = args
205200
if downloads_path:
206201
launch_options["downloads_path"] = downloads_path
202+
203+
# Use Chrome for Testing binary if available
204+
if chrome_binary_path and browser_name in ("chrome", "chromium"):
205+
launch_options["executable_path"] = chrome_binary_path
206+
CommonUtil.ExecLog(sModuleInfo, f"Using Chrome for Testing binary: {chrome_binary_path}", 1)
207207

208208
# Select and launch browser
209209
if browser_name in ("chrome", "chromium"):

Framework/Built_In_Automation/Web/Playwright/utils.py

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,38 @@
88
Author: Zeuz/AutomationSolutionz
99
"""
1010

11-
import subprocess
1211
import os
13-
import sys
1412
from pathlib import Path
1513
from Framework.Utilities import CommonUtil
16-
from settings import ZEUZ_NODE_DOWNLOADS_DIR
14+
from Framework.Built_In_Automation.Web.Selenium.utils import ChromeForTesting
1715

18-
PW_BROWSERS_DIR = ZEUZ_NODE_DOWNLOADS_DIR / "pw-browsers"
16+
# Initialize Chrome for Testing instance
17+
chrome_for_testing = ChromeForTesting()
1918

20-
def check_playwright_browser_exists():
21-
if not PW_BROWSERS_DIR.exists():
22-
return False
2319

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):
3421
"""
35-
Download Playwright browser for the specified brand.
22+
Ensure Chrome for Testing is available for Playwright.
3623
3724
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
4029
"""
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

Comments
 (0)