Skip to content

Commit 478655f

Browse files
committed
[py] Add generated BiDi Webdriver classes
Generated from https://w3c.github.io/webdriver-bidi
1 parent 2dcac9f commit 478655f

File tree

3 files changed

+620
-1
lines changed

3 files changed

+620
-1
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
18+
import re
19+
import typing
20+
from dataclasses import dataclass, fields, is_dataclass
21+
22+
from selenium.webdriver.common.bidi.cdp import import_devtools
23+
24+
devtools = import_devtools("")
25+
event_class = devtools.util.event_class
26+
27+
@dataclass
28+
class NavigateParameters:
29+
context: str
30+
url: str
31+
wait: str = "complete"
32+
33+
def to_json(self):
34+
json = {}
35+
for field in fields(self):
36+
key = field.name
37+
value = getattr(self, key)
38+
if not value:
39+
continue
40+
if is_dataclass(value):
41+
value = value.to_json()
42+
json[re.sub(r"^_", "", key)] = value
43+
return json
44+
45+
@classmethod
46+
def from_json(cls, json):
47+
return cls(**json)
48+
49+
@dataclass
50+
class Navigate:
51+
params: NavigateParameters
52+
method: typing.Literal["browsingContext.navigate"] = "browsingContext.navigate"
53+
54+
def to_json(self):
55+
json = {}
56+
for field in fields(self):
57+
key = field.name
58+
value = getattr(self, key)
59+
if not value:
60+
continue
61+
if is_dataclass(value):
62+
value = value.to_json()
63+
json[re.sub(r"^_", "", key)] = value
64+
return json
65+
66+
@classmethod
67+
def from_json(cls, json):
68+
return cls(**json)
69+
70+
def cmd(self):
71+
result = yield self.to_json()
72+
return result

0 commit comments

Comments
 (0)