-
Notifications
You must be signed in to change notification settings - Fork 395
Expand file tree
/
Copy pathrobot.ts
More file actions
153 lines (125 loc) · 3.69 KB
/
robot.ts
File metadata and controls
153 lines (125 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
export interface Dimensions {
width: number;
height: number;
}
export interface ScreenSize extends Dimensions {
scale: number;
}
export interface InstalledApp {
packageName: string;
appName: string;
}
export type SwipeDirection = "up" | "down" | "left" | "right";
export type Button = "HOME" | "BACK" | "VOLUME_UP" | "VOLUME_DOWN" | "ENTER" | "DPAD_CENTER" | "DPAD_UP" | "DPAD_DOWN" | "DPAD_LEFT" | "DPAD_RIGHT";
export interface ScreenElementRect {
x: number;
y: number;
width: number;
height: number;
}
export interface ScreenElement {
type: string;
label?: string;
text?: string;
name?: string;
value?: string;
identifier?: string;
rect: ScreenElementRect;
// currently only on android tv
focused?: boolean;
}
export class ActionableError extends Error {
constructor(message: string) {
super(message);
}
}
export type Orientation = "portrait" | "landscape";
export interface Robot {
/**
* Get the screen size of the device in pixels.
*/
getScreenSize(): Promise<ScreenSize>;
/**
* Swipe in a direction.
*/
swipe(direction: SwipeDirection): Promise<void>;
/**
* Swipe from a specific coordinate in a direction.
*/
swipeFromCoordinate(x: number, y: number, direction: SwipeDirection, distance?: number): Promise<void>;
/**
* Get a screenshot of the screen. Returns a Buffer that contains
* a PNG image of the screen. Will be same dimensions as getScreenSize().
*/
getScreenshot(): Promise<Buffer>;
/**
* List all installed apps on the device. Returns an array of package names (or
* bundle identifiers in iOS) for all installed apps.
*/
listApps(): Promise<InstalledApp[]>;
/**
* Launch an app.
*/
launchApp(packageName: string): Promise<void>;
/**
* Terminate an app. If app was already terminated (or non existent) then this
* is a no-op.
*/
terminateApp(packageName: string): Promise<void>;
/**
* Install an app on the device from a file path.
*/
installApp(path: string): Promise<void>;
/**
* Uninstall an app from the device.
*/
uninstallApp(bundleId: string): Promise<void>;
/**
* Open a URL in the device's web browser. Can be an https:// url, or a
* custom scheme (e.g. "myapp://").
*/
openUrl(url: string): Promise<void>;
/**
* Send keys to the device, simulating keyboard input.
*/
sendKeys(text: string): Promise<void>;
/**
* Press a button on the device, simulating a physical button press.
*/
pressButton(button: Button): Promise<void>;
/**
* Tap on a specific coordinate on the screen.
*/
tap(x: number, y: number): Promise<void>;
/**
* Tap on a specific coordinate on the screen.
*/
doubleTap(x: number, y: number): Promise<void>;
/**
* Long press on a specific coordinate on the screen.
* @param x - The x coordinate to long press
* @param y - The y coordinate to long press
* @param duration - Duration of the long press in milliseconds
*/
longPress(x: number, y: number, duration: number): Promise<void>;
/**
* Get all elements on the screen. Works only on native apps (not webviews). Will
* return a filtered list of elements that make sense to interact with.
*/
getElementsOnScreen(): Promise<ScreenElement[]>;
/**
* Change the screen orientation of the device.
* @param orientation The desired orientation ("portrait" or "landscape")
*/
setOrientation(orientation: Orientation): Promise<void>;
/**
* Get the current screen orientation.
*/
getOrientation(): Promise<Orientation>;
/**
* Get the currently running activity (Android) or foreground app (iOS).
* @returns An object with the `id` field containing the package name (Android) or bundle ID (iOS)
* @throws ActionableError if no activity is currently in focus
*/
getCurrentActivity(): Promise<{ id: string }>;
}