feat(driver): add W3C actions helper and Driver.swipe_path

This commit is contained in:
2026-07-15 19:04:57 +08:00
parent ff91bd4f70
commit c25ccb491d
10 changed files with 189 additions and 0 deletions
+18
View File
@@ -104,6 +104,7 @@ def test_connect_failure_raises_device_offline_and_clears_client() -> None:
("unlock", {}),
("disconnect", {}),
("long_press", {"x": 1, "y": 2}),
("swipe_path", {"waypoints": [(0, 0), (1, 1)], "duration_ms": 100}),
],
)
def test_operation_before_connect_raises_device_offline(
@@ -229,6 +230,23 @@ def test_home_uses_presskey_with_home_keycode() -> None:
)
def test_swipe_path_sends_w3c_actions() -> None:
from driver._w3c_actions import build_swipe_actions
driver = _connected_driver()
waypoints = [(0, 0), (50, 5), (100, 0)]
driver.swipe_path(waypoints, 600)
args = driver._client.execute.call_args.args
assert args[1] == {"actions": build_swipe_actions(waypoints, 600)}
def test_swipe_path_wraps_exception_into_driver_error() -> None:
driver = _connected_driver()
driver._client.execute.side_effect = RuntimeError("boom")
with pytest.raises(DriverError):
driver.swipe_path([(0, 0), (1, 1)], 100)
def test_swipe_uses_drag_gesture_with_converted_speed() -> None:
driver = _connected_driver()
# 100px horizontal drag over 100ms => 100 / 0.1 = 1000 px/s