|
15 | 15 | # specific language governing permissions and limitations
|
16 | 16 | # under the License.
|
17 | 17 |
|
18 |
| -import re |
19 | 18 | import typing
|
20 | 19 | from dataclasses import dataclass
|
21 |
| -from dataclasses import fields |
22 |
| -from dataclasses import is_dataclass |
23 | 20 |
|
24 |
| -from selenium.webdriver.common.bidi.cdp import import_devtools |
| 21 | +from .bidi import BidiCommand |
| 22 | +from .bidi import BidiObject |
25 | 23 |
|
26 |
| -devtools = import_devtools("") |
27 |
| -event_class = devtools.util.event_class |
| 24 | +BrowsingContext = str |
28 | 25 |
|
| 26 | +Navigation = str |
29 | 27 |
|
30 |
| -@dataclass |
31 |
| -class NavigateParameters: |
32 |
| - context: str |
33 |
| - url: str |
34 |
| - wait: str = "complete" |
| 28 | +ReadinessState = typing.Literal["none", "interactive", "complete"] |
35 | 29 |
|
36 |
| - def to_json(self): |
37 |
| - json = {} |
38 |
| - for field in fields(self): |
39 |
| - key = field.name |
40 |
| - value = getattr(self, key) |
41 |
| - if not value: |
42 |
| - continue |
43 |
| - if is_dataclass(value): |
44 |
| - value = value.to_json() |
45 |
| - json[re.sub(r"^_", "", key)] = value |
46 |
| - return json |
47 | 30 |
|
48 |
| - @classmethod |
49 |
| - def from_json(cls, json): |
50 |
| - return cls(**json) |
| 31 | +@dataclass |
| 32 | +class NavigateParameters(BidiObject): |
| 33 | + context: BrowsingContext |
| 34 | + url: str |
| 35 | + wait: typing.Optional[ReadinessState] = None |
51 | 36 |
|
52 | 37 |
|
53 | 38 | @dataclass
|
54 |
| -class Navigate: |
| 39 | +class Navigate(BidiCommand): |
55 | 40 | params: NavigateParameters
|
56 | 41 | method: typing.Literal["browsingContext.navigate"] = "browsingContext.navigate"
|
57 |
| - |
58 |
| - def to_json(self): |
59 |
| - json = {} |
60 |
| - for field in fields(self): |
61 |
| - key = field.name |
62 |
| - value = getattr(self, key) |
63 |
| - if not value: |
64 |
| - continue |
65 |
| - if is_dataclass(value): |
66 |
| - value = value.to_json() |
67 |
| - json[re.sub(r"^_", "", key)] = value |
68 |
| - return json |
69 |
| - |
70 |
| - @classmethod |
71 |
| - def from_json(cls, json): |
72 |
| - return cls(**json) |
73 |
| - |
74 |
| - def cmd(self): |
75 |
| - result = yield self.to_json() |
76 |
| - return result |
0 commit comments