Skip to content

Commit

Permalink
[wdspec] Improvements for WebDriver BiDi Python client.
Browse files Browse the repository at this point in the history
The "session.new" command currently doesn't work because the
transport is started after sending the command. This needed
to be flipped.

Also it is helpful to have the event loop of the current
transport available as property on the BiDi session directly.

Differential Revision: https://phabricator.services.mozilla.com/D144979

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1719505
gecko-commit: 7ac82aff1852eaf89acc99714a7359596b093d2a
gecko-reviewers: webdriver-reviewers, jgraham
  • Loading branch information
whimboo authored and moz-wptsync-bot committed Apr 30, 2022
1 parent 2422b4e commit 6b14e01
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tools/webdriver/webdriver/bidi/client.py
Expand Up @@ -91,6 +91,13 @@ def __init__(self,
self.session = modules.Session(self)
self.browsing_context = modules.BrowsingContext(self)

@property
def event_loop(self):
if self.transport:
return self.transport.loop

return None

@classmethod
def from_http(cls,
session_id: str,
Expand All @@ -109,7 +116,7 @@ def from_http(cls,
@classmethod
def bidi_only(cls,
websocket_url: str,
requested_capabilities: Optional[Mapping[str, Any]]) -> "BidiSession":
requested_capabilities: Optional[Mapping[str, Any]] = None) -> "BidiSession":
"""Create a BiDi session where there is no existing HTTP session
:param webdocket_url: URL to the WebSocket server listening for BiDi connections
Expand All @@ -129,13 +136,13 @@ async def start(self,

if loop is None:
loop = get_running_loop()

self.transport = Transport(self.websocket_url, self.on_message, loop=loop)
await self.transport.start()

if self.session_id is None:
self.session_id, self.capabilities = await self.session.new(
self.requested_capabilities)

await self.transport.start()
capabilities=self.requested_capabilities)

async def send_command(
self,
Expand Down

0 comments on commit 6b14e01

Please sign in to comment.