Skip to content

Commit

Permalink
[py] Add example of logging console errors
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed Jun 8, 2024
1 parent 23b81a7 commit eadb710
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions py/test/selenium/webdriver/common/bidi_script_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

@pytest.mark.xfail_safari
def test_logs_console_messages(driver, pages):
log_entries = []
pages.load("bidi/LogEntryAdded.html")

log_entries = []
driver.script.add_console_message_handler(log_entries.append)

driver.find_element(By.ID, "jsException").click()
Expand All @@ -39,9 +40,35 @@ def test_logs_console_messages(driver, pages):


@pytest.mark.xfail_safari
def test_logs_multiple_console_messages(driver, pages):
def test_logs_console_errors(driver, pages):
pages.load("bidi/LogEntryAdded.html")

log_entries = []
def log_error(entry):
if entry.level == "error":
log_entries.append(entry)

driver.script.add_console_message_handler(log_error)

driver.find_element(By.ID, "consoleLog").click()
driver.find_element(By.ID, "consoleError").click()

WebDriverWait(driver, 5).until(lambda _: log_entries)

assert len(log_entries) == 1

log_entry = log_entries[0]
assert log_entry.level == "error"
assert log_entry.method == "error"
assert log_entry.text == "I am console error"
assert log_entry.type_ == "console"


@pytest.mark.xfail_safari
def test_logs_multiple_console_messages(driver, pages):
pages.load("bidi/LogEntryAdded.html")

log_entries = []
driver.script.add_console_message_handler(log_entries.append)
driver.script.add_console_message_handler(log_entries.append)

Expand All @@ -54,9 +81,10 @@ def test_logs_multiple_console_messages(driver, pages):

@pytest.mark.xfail_safari
def test_removes_console_message_handler(driver, pages):
pages.load("bidi/LogEntryAdded.html")

log_entries1 = []
log_entries2 = []
pages.load("bidi/LogEntryAdded.html")

id = driver.script.add_console_message_handler(log_entries1.append)
driver.script.add_console_message_handler(log_entries2.append)
Expand Down

0 comments on commit eadb710

Please sign in to comment.