Skip to content

Commit acb626c

Browse files
committed
fix: mac os tests use brave
1 parent 57d7ad7 commit acb626c

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

sample/Tests/test/test_mac.py

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def tearDownClass(cls):
4040
def launch_browser(cls):
4141
print("Starting Browser...")
4242
browser_paths = [
43-
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
43+
"/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
4444
]
4545

4646
browser_path = None
@@ -50,76 +50,92 @@ def launch_browser(cls):
5050
break
5151

5252
if not browser_path:
53-
print("Chrome executable not found.")
53+
print("Brave Browser executable not found.")
5454
exit(1)
5555

5656
subprocess.Popen([
5757
browser_path,
58-
"--remote-debugging-port=9222"
58+
"--remote-debugging-port=9222",
59+
"--no-first-run",
60+
"--no-default-browser-check"
5961
])
6062

61-
time.sleep(5)
63+
# Give Brave more time to fully initialize remote debugging
64+
print("Waiting for Brave to fully initialize...")
65+
time.sleep(10)
66+
67+
# Verify remote debugging is accessible
68+
try:
69+
import urllib.request
70+
with urllib.request.urlopen("http://127.0.0.1:9222/json", timeout=5) as response:
71+
tabs = response.read()
72+
print(f"Remote debugging verified - found {len(eval(tabs))} tabs")
73+
except Exception as e:
74+
print(f"Remote debugging check failed: {e}")
75+
print("Continuing anyway...")
6276

6377
@classmethod
6478
def stop_browser(cls):
65-
print("Stopping Chrome...")
79+
print("Stopping Brave Browser...")
6680
try:
6781
# First try graceful shutdown using AppleScript
6882
subprocess.run([
6983
"osascript", "-e",
70-
'tell application "Google Chrome" to quit'
84+
'tell application "Brave Browser" to quit'
7185
], check=False, capture_output=True)
7286
time.sleep(2)
7387

7488
# Check if still running, then force kill
75-
result = subprocess.run(["pgrep", "-f", "Google Chrome"],
89+
result = subprocess.run(["pgrep", "-f", "Brave Browser"],
7690
capture_output=True, text=True)
7791
if result.returncode == 0:
7892
# Still running, force kill
79-
subprocess.run(["pkill", "-f", "Google Chrome"],
93+
subprocess.run(["pkill", "-f", "Brave Browser"],
8094
check=False, capture_output=True)
95+
print("Killed Brave Browser processes")
8196

82-
print("All Chrome processes have been closed.")
97+
print("Brave Browser has been closed.")
8398
except Exception as e:
84-
print("Chrome might not be running.")
99+
print("Brave Browser might not be running.")
85100

86101
time.sleep(3)
87-
print("Stopped Chrome")
102+
print("Stopped Brave Browser")
88103

89104
@classmethod
90105
def login(cls):
91-
print("Connect to Chrome")
92-
# Set up Chrome options to connect to the existing Chrome instance
106+
print("Connect to Brave Browser")
107+
# Set up Chrome options to connect to the existing Brave instance (Brave uses Chromium engine)
93108
chrome_options = Options()
94109
chrome_options.add_experimental_option("debuggerAddress", "localhost:9222")
95110

96111
# Explicitly specify ChromeDriver path and Chrome browser path for macOS
97112
from selenium.webdriver.chrome.service import Service
98113
chromedriver_path = "/usr/local/bin/chromedriver"
99114

100-
# Use Chrome browser (company software ensures it's installed)
101-
chrome_path = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
115+
# Use Brave Browser only for macOS automation
116+
brave_path = "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
102117

103118
import os
104119
browser_path = None
105-
if os.path.exists(chrome_path):
106-
browser_path = chrome_path
107-
print(f"Found Chrome at: {browser_path}")
120+
if os.path.exists(brave_path):
121+
browser_path = brave_path
122+
print(f"Found Brave at: {browser_path}")
108123
else:
109-
print("Chrome not found, letting Selenium auto-detect")
124+
print("Brave Browser not found - required for macOS tests")
125+
raise FileNotFoundError("Brave Browser is required for macOS CI tests")
110126

111-
# Set Chrome as the browser binary if found
127+
# Set Brave as the browser binary if found
112128
if browser_path:
113129
chrome_options.binary_location = browser_path
114130

115131
# Create service with explicit ChromeDriver path and bypass version checking
116132
service_args = ["--whitelisted-ips=", "--disable-build-check"]
117133
service = Service(executable_path=chromedriver_path, service_args=service_args)
118134

119-
# Connect to the existing Chrome instance
135+
# Connect to the existing Brave instance
120136
cls.seleniumdriver = webdriver.Chrome(service=service, options=chrome_options)
121137

122-
print("Open a window on Chrome")
138+
print("Open a window on Brave")
123139

124140
wait = WebDriverWait(cls.seleniumdriver, 60)
125141

0 commit comments

Comments
 (0)