From a1b1da3425c18e31e7183146e835ea43703a7ba3 Mon Sep 17 00:00:00 2001 From: "Nir.Tal" Date: Fri, 28 Feb 2025 01:19:47 +0200 Subject: [PATCH 1/3] feat: added console bidi events --- tests/conftest.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index cf291d6be4..07da1a59c9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -134,7 +134,7 @@ def vrt_helper(): def pytest_runtest_setup(item: Item) -> None: - global browser, driver, chrome_options, wait + global browser, driver, chrome_options, wait, console_messages, javascript_errors browser = item.config.getoption("driver") base_url = item.config.getoption("base_url") if browser in ("chrome", "chrome_headless"): @@ -184,7 +184,9 @@ def pytest_runtest_setup(item: Item) -> None: chrome_options.add_argument(f"user-agent={Constants.AUTOMATION_USER_AGENT}") match browser: case "firefox": - driver = webdriver.Firefox() + firefox_options = webdriver.FirefoxOptions() + firefox_options.enable_bidi = True + driver = webdriver.Firefox(firefox_options) case "chrome_headless": chrome_options.add_argument("headless=new") chrome_options.add_argument("force-device-scale-factor=0.6") @@ -217,6 +219,11 @@ def pytest_runtest_setup(item: Item) -> None: driver.maximize_window() driver.get(base_url) wait = WebDriverWait(driver, 10) + if browser != "remote": + console_messages = [] + driver.script.add_console_message_handler(console_messages.append) + javascript_errors = [] + driver.script.add_javascript_error_handler(javascript_errors.append) item.cls.wait = wait item.cls.about_page = AboutPage(driver, wait) item.cls.login_page = LoginPage(driver, wait) @@ -336,12 +343,24 @@ def pytest_exception_interact(node: Item) -> None: name="Local Storage", attachment_type=allure.attachment_type.JSON, ) - allure.attach( - body=json.dumps(driver.get_log("browser"), indent=4), - name="Console Logs", - attachment_type=allure.attachment_type.JSON, - ) + if browser != "remote": + # https://github.com/lana-20/selenium-webdriver-bidi + if console_messages: + console_messages_text = "\n".join( + str(message) for message in console_messages + ) + allure.attach( + body=console_messages_text, + name="Console Logs", + attachment_type=allure.attachment_type.TEXT, + ) + if javascript_errors: + allure.attach( + body=javascript_errors, + name="JavaScript Errors", + attachment_type=allure.attachment_type.TEXT, + ) # looks like cdp not working with remote: https://github.com/SeleniumHQ/selenium/issues/8672 if window_count == 1: allure.attach( From f75fc3cc8b27a6912dfb557d3d76725f53cf4e66 Mon Sep 17 00:00:00 2001 From: Nir Tal Date: Fri, 28 Feb 2025 01:26:11 +0200 Subject: [PATCH 2/3] Update tests/conftest.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 07da1a59c9..56531ed723 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -357,7 +357,7 @@ def pytest_exception_interact(node: Item) -> None: ) if javascript_errors: allure.attach( - body=javascript_errors, + body="\n".join(str(error) for error in javascript_errors), name="JavaScript Errors", attachment_type=allure.attachment_type.TEXT, ) From 87ee815d2b8a1bee10c03b18a2d5ef705f9a1325 Mon Sep 17 00:00:00 2001 From: "Nir.Tal" Date: Fri, 28 Feb 2025 01:27:38 +0200 Subject: [PATCH 3/3] feat: added console bidi events --- tests/conftest.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 56531ed723..2eec018246 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -347,11 +347,8 @@ def pytest_exception_interact(node: Item) -> None: if browser != "remote": # https://github.com/lana-20/selenium-webdriver-bidi if console_messages: - console_messages_text = "\n".join( - str(message) for message in console_messages - ) allure.attach( - body=console_messages_text, + body="\n".join(str(message) for message in console_messages), name="Console Logs", attachment_type=allure.attachment_type.TEXT, )