|
26 | 26 | from .input_device import InputDevice |
27 | 27 | from .interaction import POINTER |
28 | 28 | from .interaction import POINTER_KINDS |
| 29 | +from .interaction import POINTER_KINDS_LITERAL, SOURCE_TYPES_LITERAL |
29 | 30 |
|
30 | 31 |
|
31 | 32 | class PointerInput(InputDevice): |
32 | 33 | DEFAULT_MOVE_DURATION = 250 |
33 | 34 |
|
34 | | - def __init__(self, kind, name): |
| 35 | + def __init__(self, kind: POINTER_KINDS_LITERAL, name: str) -> None: |
35 | 36 | super().__init__() |
36 | 37 | if kind not in POINTER_KINDS: |
37 | 38 | raise InvalidArgumentException(f"Invalid PointerInput kind '{kind}'") |
38 | | - self.type = POINTER |
39 | | - self.kind = kind |
| 39 | + self.type: SOURCE_TYPES_LITERAL = POINTER |
| 40 | + self.kind: POINTER_KINDS_LITERAL = kind |
40 | 41 | self.name = name |
41 | 42 |
|
42 | 43 | def create_pointer_move( |
43 | 44 | self, |
44 | | - duration=DEFAULT_MOVE_DURATION, |
45 | | - x: float = 0, |
46 | | - y: float = 0, |
47 | | - origin: Optional[WebElement] = None, |
| 45 | + duration: Union[int, float] = DEFAULT_MOVE_DURATION, |
| 46 | + x: Union[int, float] = 0, |
| 47 | + y: Union[int, float] = 0, |
| 48 | + origin: Union[WebElement, str, None] = None, |
48 | 49 | **kwargs, |
49 | | - ): |
| 50 | + ) -> None: |
50 | 51 | action = {"type": "pointerMove", "duration": duration, "x": x, "y": y, **kwargs} |
51 | 52 | if isinstance(origin, WebElement): |
52 | 53 | action["origin"] = {"element-6066-11e4-a52e-4f735466cecf": origin.id} |
53 | 54 | elif origin is not None: |
54 | 55 | action["origin"] = origin |
55 | 56 | self.add_action(self._convert_keys(action)) |
56 | 57 |
|
57 | | - def create_pointer_down(self, **kwargs): |
| 58 | + def create_pointer_down(self, **kwargs) -> None: |
58 | 59 | data = {"type": "pointerDown", "duration": 0, **kwargs} |
59 | 60 | self.add_action(self._convert_keys(data)) |
60 | 61 |
|
61 | | - def create_pointer_up(self, button): |
| 62 | + def create_pointer_up(self, button) -> None: |
62 | 63 | self.add_action({"type": "pointerUp", "duration": 0, "button": button}) |
63 | 64 |
|
64 | | - def create_pointer_cancel(self): |
| 65 | + def create_pointer_cancel(self) -> None: |
65 | 66 | self.add_action({"type": "pointerCancel"}) |
66 | 67 |
|
67 | 68 | def create_pause(self, pause_duration: Union[int, float] = 0) -> None: |
68 | 69 | self.add_action({"type": "pause", "duration": int(pause_duration * 1000)}) |
69 | 70 |
|
70 | | - def encode(self): |
| 71 | + def encode(self) -> Dict[str, Any]: |
71 | 72 | return {"type": self.type, "parameters": {"pointerType": self.kind}, "id": self.name, "actions": self.actions} |
72 | 73 |
|
73 | | - def _convert_keys(self, actions: Dict[str, Any]): |
| 74 | + def _convert_keys(self, actions: Dict[str, Any]) -> Dict[str, Any]: |
74 | 75 | out = {} |
75 | 76 | for k, v in actions.items(): |
76 | 77 | if v is None: |
|
0 commit comments