Skip to content

Commit f21ea13

Browse files
Nir.TalNir.Tal
authored andcommitted
feat: added console bidi events
1 parent dc32e62 commit f21ea13

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tests/conftest.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,13 @@ def pytest_runtest_setup(item: Item) -> None:
221221
wait = WebDriverWait(driver, 10)
222222
if browser != "remote":
223223
console_messages = []
224-
driver.script.add_console_message_handler(console_messages.append)
224+
driver.script.add_console_message_handler(
225+
lambda log_entry: console_messages.append(log_entry.__dict__)
226+
)
225227
javascript_errors = []
226-
driver.script.add_javascript_error_handler(javascript_errors.append)
228+
driver.script.add_javascript_error_handler(
229+
lambda log_entry: javascript_errors.append(log_entry.__dict__)
230+
)
227231
item.cls.wait = wait
228232
item.cls.about_page = AboutPage(driver, wait)
229233
item.cls.login_page = LoginPage(driver, wait)
@@ -348,15 +352,15 @@ def pytest_exception_interact(node: Item) -> None:
348352
# https://github.com/lana-20/selenium-webdriver-bidi
349353
if console_messages:
350354
allure.attach(
351-
body="\n".join(str(message) for message in console_messages),
355+
body=json.dumps(console_messages, indent=4),
352356
name="Console Logs",
353-
attachment_type=allure.attachment_type.TEXT,
357+
attachment_type=allure.attachment_type.JSON,
354358
)
355359
if javascript_errors:
356360
allure.attach(
357-
body="\n".join(str(error) for error in javascript_errors),
361+
body=json.dumps(javascript_errors, indent=4),
358362
name="JavaScript Errors",
359-
attachment_type=allure.attachment_type.TEXT,
363+
attachment_type=allure.attachment_type.JSON,
360364
)
361365
# looks like cdp not working with remote: https://github.com/SeleniumHQ/selenium/issues/8672
362366
if window_count == 1:

0 commit comments

Comments
 (0)