@@ -50,19 +50,33 @@ def launch_browser(cls):
5050 break
5151
5252 if not browser_path :
53- print ("Brave 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 Brave..." )
79+ print ("Stopping Brave Browser ..." )
6680 try :
6781 # First try graceful shutdown using AppleScript
6882 subprocess .run ([
@@ -78,24 +92,50 @@ def stop_browser(cls):
7892 # Still running, force kill
7993 subprocess .run (["pkill" , "-f" , "Brave Browser" ],
8094 check = False , capture_output = True )
95+ print ("Killed Brave Browser processes" )
8196
82- print ("All Brave processes have been closed." )
97+ print ("Brave Browser has been closed." )
8398 except Exception as e :
84- print ("Brave might not be running." )
99+ print ("Brave Browser might not be running." )
85100
86101 time .sleep (3 )
87- print ("Stopped Brave" )
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" )
95- # Connect to the existing Chrome instance
96- cls .seleniumdriver = webdriver .Chrome (options = chrome_options )
97110
98- print ("Open a window on Chrome" )
111+ # Explicitly specify ChromeDriver path and Chrome browser path for macOS
112+ from selenium .webdriver .chrome .service import Service
113+ chromedriver_path = "/usr/local/bin/chromedriver"
114+
115+ # Use Brave Browser only for macOS automation
116+ brave_path = "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
117+
118+ import os
119+ browser_path = None
120+ if os .path .exists (brave_path ):
121+ browser_path = brave_path
122+ print (f"Found Brave at: { browser_path } " )
123+ else :
124+ print ("Brave Browser not found - required for macOS tests" )
125+ raise FileNotFoundError ("Brave Browser is required for macOS CI tests" )
126+
127+ # Set Brave as the browser binary if found
128+ if browser_path :
129+ chrome_options .binary_location = browser_path
130+
131+ # Create service with explicit ChromeDriver path and bypass version checking
132+ service_args = ["--whitelisted-ips=" , "--disable-build-check" ]
133+ service = Service (executable_path = chromedriver_path , service_args = service_args )
134+
135+ # Connect to the existing Brave instance
136+ cls .seleniumdriver = webdriver .Chrome (service = service , options = chrome_options )
137+
138+ print ("Open a window on Brave" )
99139
100140 wait = WebDriverWait (cls .seleniumdriver , 60 )
101141
0 commit comments