Code: Select all
def test_capture_console_logs(driver, capture_browser_logs):
driver.get("https://www.google.com")
# Execute JavaScript to log information in the browser console
script = """
console.log('Info: This is a test log.');
console.warn('Warning: This is a warning log.');
console.error('Error: This is an error log.');
"""
driver.execute_script(script)
assert False
@pytest.fixture(scope="function")
def capture_browser_logs(driver):
yield
print("\n=== Attempting to capture browser logs ===")
try:
browser_logs = driver.get_log("browser")
print(f"Successfully retrieved {len(browser_logs)} log entries")
if browser_logs:
for entry in browser_logs:
print(f"[{entry['level']}] {entry['message']}")
except Exception as e:
print(f"Error retrieving logs: {e}")
print("=== End capture attempt ===")
Code: Select all
=== Attempting to capture browser logs ===
Successfully retrieved 3 log entries
[INFO] console-api 3:16 "Info: This is a test log."
[WARNING] console-api 4:16 "Warning: This is a warning log."
[SEVERE] console-api 5:16 "Error: This is an error log."
=== End capture attempt ===
Code: Select all
=== Attempting to capture browser logs ===
Successfully retrieved 0 log entries
=== End capture attempt ===
Mobile version