Skip to content

Commit 9932b4a

Browse files
committed
Extend from Bidi objects
1 parent 59cf0a6 commit 9932b4a

File tree

5 files changed

+90
-466
lines changed

5 files changed

+90
-466
lines changed

Diff for: py/selenium/webdriver/common/bidi/browsing_context.py

+11-46
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,27 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import re
1918
import typing
2019
from dataclasses import dataclass
21-
from dataclasses import fields
22-
from dataclasses import is_dataclass
2320

24-
from selenium.webdriver.common.bidi.cdp import import_devtools
21+
from .bidi import BidiCommand
22+
from .bidi import BidiObject
2523

26-
devtools = import_devtools("")
27-
event_class = devtools.util.event_class
24+
BrowsingContext = str
2825

26+
Navigation = str
2927

30-
@dataclass
31-
class NavigateParameters:
32-
context: str
33-
url: str
34-
wait: str = "complete"
28+
ReadinessState = typing.Literal["none", "interactive", "complete"]
3529

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
4730

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
5136

5237

5338
@dataclass
54-
class Navigate:
39+
class Navigate(BidiCommand):
5540
params: NavigateParameters
5641
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

Comments
 (0)