Retrieve and optionally filter browser console logs.
Source code in pytest_splunk_addon_ui_smartx/utils.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 | def get_browser_logs(
browser,
log_level: Optional[LogLevel] = None,
log_source: Optional[LogSource] = None,
) -> List[LogEntry]:
"""
Retrieve and optionally filter browser console logs.
"""
if browser.name.lower() != "chrome":
return []
logs = browser.get_log("browser")
filtered_logs: List[LogEntry] = []
for log in logs:
entry = LogEntry(
level=LogLevel[log["level"]],
message=log["message"],
source=LogSource(log["source"]),
timestamp=log["timestamp"],
)
if (log_level is None or entry.level == log_level) and (
log_source is None or entry.source == log_source
):
filtered_logs.append(entry)
return filtered_logs
|