Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/selenium/webdriver/common/bidi/log.py
4012 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
from __future__ import annotations
18
19
from dataclasses import dataclass
20
from typing import Any
21
22
23
class LogEntryAdded:
24
event_class = "log.entryAdded"
25
26
@classmethod
27
def from_json(cls, json: dict[str, Any]) -> ConsoleLogEntry | JavaScriptLogEntry | None:
28
if json["type"] == "console":
29
return ConsoleLogEntry.from_json(json)
30
elif json["type"] == "javascript":
31
return JavaScriptLogEntry.from_json(json)
32
return None
33
34
35
@dataclass
36
class ConsoleLogEntry:
37
level: str
38
text: str
39
timestamp: str
40
method: str
41
args: list[dict[str, Any]]
42
type_: str
43
44
@classmethod
45
def from_json(cls, json: dict[str, Any]) -> ConsoleLogEntry:
46
return cls(
47
level=json["level"],
48
text=json["text"],
49
timestamp=json["timestamp"],
50
method=json["method"],
51
args=json["args"],
52
type_=json["type"],
53
)
54
55
56
@dataclass
57
class JavaScriptLogEntry:
58
level: str
59
text: str
60
timestamp: str
61
stacktrace: dict[str, Any]
62
type_: str
63
64
@classmethod
65
def from_json(cls, json: dict[str, Any]) -> JavaScriptLogEntry:
66
return cls(
67
level=json["level"],
68
text=json["text"],
69
timestamp=json["timestamp"],
70
stacktrace=json["stackTrace"],
71
type_=json["type"],
72
)
73
74
75
class LogLevel:
76
"""Represents log level."""
77
78
DEBUG = "debug"
79
INFO = "info"
80
WARN = "warn"
81
ERROR = "error"
82
83