@@ -134,7 +134,7 @@ def vrt_helper():
134134
135135
136136def pytest_runtest_setup (item : Item ) -> None :
137- global browser , driver , chrome_options , wait
137+ global browser , driver , chrome_options , wait , console_messages , javascript_errors
138138 browser = item .config .getoption ("driver" )
139139 base_url = item .config .getoption ("base_url" )
140140 if browser in ("chrome" , "chrome_headless" ):
@@ -184,7 +184,9 @@ def pytest_runtest_setup(item: Item) -> None:
184184 chrome_options .add_argument (f"user-agent={ Constants .AUTOMATION_USER_AGENT } " )
185185 match browser :
186186 case "firefox" :
187- driver = webdriver .Firefox ()
187+ firefox_options = webdriver .FirefoxOptions ()
188+ firefox_options .enable_bidi = True
189+ driver = webdriver .Firefox (firefox_options )
188190 case "chrome_headless" :
189191 chrome_options .add_argument ("headless=new" )
190192 chrome_options .add_argument ("force-device-scale-factor=0.6" )
@@ -217,6 +219,11 @@ def pytest_runtest_setup(item: Item) -> None:
217219 driver .maximize_window ()
218220 driver .get (base_url )
219221 wait = WebDriverWait (driver , 10 )
222+ if browser != "remote" :
223+ console_messages = []
224+ driver .script .add_console_message_handler (console_messages .append )
225+ javascript_errors = []
226+ driver .script .add_javascript_error_handler (javascript_errors .append )
220227 item .cls .wait = wait
221228 item .cls .about_page = AboutPage (driver , wait )
222229 item .cls .login_page = LoginPage (driver , wait )
@@ -336,12 +343,24 @@ def pytest_exception_interact(node: Item) -> None:
336343 name = "Local Storage" ,
337344 attachment_type = allure .attachment_type .JSON ,
338345 )
339- allure .attach (
340- body = json .dumps (driver .get_log ("browser" ), indent = 4 ),
341- name = "Console Logs" ,
342- attachment_type = allure .attachment_type .JSON ,
343- )
346+
344347 if browser != "remote" :
348+ # https://github.com/lana-20/selenium-webdriver-bidi
349+ if console_messages :
350+ console_messages_text = "\n " .join (
351+ str (message ) for message in console_messages
352+ )
353+ allure .attach (
354+ body = console_messages_text ,
355+ name = "Console Logs" ,
356+ attachment_type = allure .attachment_type .TEXT ,
357+ )
358+ if javascript_errors :
359+ allure .attach (
360+ body = javascript_errors ,
361+ name = "JavaScript Errors" ,
362+ attachment_type = allure .attachment_type .TEXT ,
363+ )
345364 # looks like cdp not working with remote: https://github.com/SeleniumHQ/selenium/issues/8672
346365 if window_count == 1 :
347366 allure .attach (
0 commit comments