feat(driver): add Driver.long_press on WDA and Android

This commit is contained in:
2026-07-15 18:57:53 +08:00
parent 7d79f677fe
commit ff91bd4f70
8 changed files with 59 additions and 0 deletions
+11
View File
@@ -87,6 +87,17 @@ class AndroidDriver(Driver):
except Exception as exc:
raise DriverError("tap failed") from exc
def long_press(self, x: float, y: float, duration_ms: int = 1200) -> None:
# Android ``mobile: longClickGesture`` uses a system-fixed hold
# duration; the caller's ``duration_ms`` is intentionally ignored
# (see design R2). Verify on real Appium against the running device
# driver — see plan task 2.
client = self._require_client()
try:
client.execute_script("mobile: longClickGesture", {"x": x, "y": y})
except Exception as exc:
raise DriverError("long press failed") from exc
def swipe(
self,
start_x: float,
+7
View File
@@ -27,6 +27,13 @@ class Driver(ABC):
def tap(self, x: float, y: float) -> None:
"""Tap the screen at the given coordinates."""
@abstractmethod
def long_press(self, x: float, y: float, duration_ms: int = 1200) -> None:
"""Press and hold at the given coordinates for ``duration_ms``.
Some platforms ignore ``duration_ms`` (fixed system hold duration).
"""
@abstractmethod
def swipe(
self,
+13
View File
@@ -77,6 +77,19 @@ class WDADriver(Driver):
except Exception as exc:
raise DriverError("tap failed") from exc
def long_press(self, x: float, y: float, duration_ms: int = 1200) -> None:
# ``mobile: touchAndHold`` is an XCUITest WDA endpoint; ``duration`` is
# in seconds (float). Verify on real Appium against the running device
# driver — see plan task 2.
client = self._require_client()
try:
client.execute_script(
"mobile: touchAndHold",
{"x": x, "y": y, "duration": duration_ms / 1000},
)
except Exception as exc:
raise DriverError("long press failed") from exc
def swipe(
self,
start_x: float,