Implement Apex Agent MVP scaffold
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from core.driver import Driver
|
||||
|
||||
PNG_10X20 = (
|
||||
b"\x89PNG\r\n\x1a\n"
|
||||
b"\x00\x00\x00\r"
|
||||
b"IHDR"
|
||||
b"\x00\x00\x00\x0a"
|
||||
b"\x00\x00\x00\x14"
|
||||
)
|
||||
|
||||
TREE_XML = """
|
||||
<AppiumAUT x="0" y="0" width="10" height="20">
|
||||
<XCUIElementTypeButton name="Search" label="Search" x="1" y="2" width="4" height="4" />
|
||||
<XCUIElementTypeImage name="Settings" label="Settings" x="6" y="2" width="3" height="3" />
|
||||
</AppiumAUT>
|
||||
"""
|
||||
|
||||
|
||||
class FakeDriver(Driver):
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
fail_connect: bool = False,
|
||||
tree: Any = TREE_XML,
|
||||
screenshot: bytes = PNG_10X20,
|
||||
) -> None:
|
||||
self.fail_connect = fail_connect
|
||||
self.connected = False
|
||||
self.calls: list[tuple[str, tuple[Any, ...]]] = []
|
||||
self._tree = tree
|
||||
self._screenshot = screenshot
|
||||
|
||||
def connect(self) -> None:
|
||||
self.calls.append(("connect", ()))
|
||||
if self.fail_connect:
|
||||
raise RuntimeError("connection refused")
|
||||
self.connected = True
|
||||
|
||||
def disconnect(self) -> None:
|
||||
self.calls.append(("disconnect", ()))
|
||||
self.connected = False
|
||||
|
||||
def screenshot(self) -> bytes:
|
||||
self.calls.append(("screenshot", ()))
|
||||
return self._screenshot
|
||||
|
||||
def tap(self, x: float, y: float) -> None:
|
||||
self.calls.append(("tap", (x, y)))
|
||||
|
||||
def swipe(
|
||||
self,
|
||||
start_x: float,
|
||||
start_y: float,
|
||||
end_x: float,
|
||||
end_y: float,
|
||||
duration_ms: int = 500,
|
||||
) -> None:
|
||||
self.calls.append(("swipe", (start_x, start_y, end_x, end_y, duration_ms)))
|
||||
|
||||
def input(self, text: str) -> None:
|
||||
self.calls.append(("input", (text,)))
|
||||
|
||||
def launch(self, app_id: str) -> None:
|
||||
self.calls.append(("launch", (app_id,)))
|
||||
|
||||
def terminate(self, app_id: str) -> None:
|
||||
self.calls.append(("terminate", (app_id,)))
|
||||
|
||||
def tree(self) -> Any:
|
||||
self.calls.append(("tree", ()))
|
||||
return self._tree
|
||||
|
||||
def home(self) -> None:
|
||||
self.calls.append(("home", ()))
|
||||
|
||||
def lock(self) -> None:
|
||||
self.calls.append(("lock", ()))
|
||||
|
||||
def unlock(self) -> None:
|
||||
self.calls.append(("unlock", ()))
|
||||
|
||||
Reference in New Issue
Block a user