Skip to content

Commit

Permalink
[wdspec] Add support for "clip" argument to bidi test client.
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D183399

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1840998
gecko-commit: a5803246392a08af19b81c8f322a7cd38a91a8e3
gecko-reviewers: webdriver-reviewers, jgraham
  • Loading branch information
moz-wptsync-bot authored and lutien committed Jul 28, 2023
1 parent d8c9a69 commit f93ba5b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tools/webdriver/webdriver/bidi/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class NoSuchScriptException(BidiException):
error_code = "no such script"


class UnableToCaptureScreenException(BidiException):
error_code = "unable to capture screen"


class UnknownCommandException(BidiException):
error_code = "unknown command"

Expand Down
32 changes: 30 additions & 2 deletions tools/webdriver/webdriver/bidi/modules/browsing_context.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
import base64
from typing import Any, List, Mapping, MutableMapping, Optional
from typing import Any, Dict, List, Mapping, MutableMapping, Optional, Union

from ._module import BidiModule, command


class ElementOptions(Dict[str, Any]):
def __init__(
self, element: Mapping[str, Any], scroll_into_view: Optional[bool] = None
):
self["type"] = "element"
self["element"] = element

if scroll_into_view is not None:
self["scrollIntoView"] = scroll_into_view


class ViewportOptions(Dict[str, Any]):
def __init__(self, x: float, y: float, width: float, height: float):
self["type"] = "viewport"
self["x"] = x
self["y"] = y
self["width"] = width
self["height"] = height


ClipOptions = Union[ElementOptions, ViewportOptions]


class BrowsingContext(BidiModule):
@command
def activate(self, context: str) -> Mapping[str, Any]:
return {"context": context}

@command
def capture_screenshot(self, context: str) -> Mapping[str, Any]:
def capture_screenshot(
self, context: str, clip: Optional[ClipOptions] = None
) -> Mapping[str, Any]:
params: MutableMapping[str, Any] = {"context": context}

if clip is not None:
params["clip"] = clip

return params

@capture_screenshot.result
Expand Down

0 comments on commit f93ba5b

Please sign in to comment.