Skip to content

Commit

Permalink
Extend from Bidi objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jman-sketch committed Oct 27, 2024
1 parent 59cf0a6 commit 9932b4a
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 466 deletions.
57 changes: 11 additions & 46 deletions py/selenium/webdriver/common/bidi/browsing_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,27 @@
# specific language governing permissions and limitations
# under the License.

import re
import typing
from dataclasses import dataclass
from dataclasses import fields
from dataclasses import is_dataclass

from selenium.webdriver.common.bidi.cdp import import_devtools
from .bidi import BidiCommand
from .bidi import BidiObject

devtools = import_devtools("")
event_class = devtools.util.event_class
BrowsingContext = str

Navigation = str

@dataclass
class NavigateParameters:
context: str
url: str
wait: str = "complete"
ReadinessState = typing.Literal["none", "interactive", "complete"]

def to_json(self):
json = {}
for field in fields(self):
key = field.name
value = getattr(self, key)
if not value:
continue
if is_dataclass(value):
value = value.to_json()
json[re.sub(r"^_", "", key)] = value
return json

@classmethod
def from_json(cls, json):
return cls(**json)
@dataclass
class NavigateParameters(BidiObject):
context: BrowsingContext
url: str
wait: typing.Optional[ReadinessState] = None


@dataclass
class Navigate:
class Navigate(BidiCommand):
params: NavigateParameters
method: typing.Literal["browsingContext.navigate"] = "browsingContext.navigate"

def to_json(self):
json = {}
for field in fields(self):
key = field.name
value = getattr(self, key)
if not value:
continue
if is_dataclass(value):
value = value.to_json()
json[re.sub(r"^_", "", key)] = value
return json

@classmethod
def from_json(cls, json):
return cls(**json)

def cmd(self):
result = yield self.to_json()
return result
Loading

0 comments on commit 9932b4a

Please sign in to comment.