spana-test 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/agent/index.js +28 -10
- package/dist/agent/index.js.map +1 -1
- package/dist/api/app.d.ts +40 -0
- package/dist/api/app.d.ts.map +1 -1
- package/dist/api/expect.d.ts +13 -0
- package/dist/api/expect.d.ts.map +1 -1
- package/dist/app-W6PRRBMD.js +13 -0
- package/dist/appium-CC77BJNK.js +935 -0
- package/dist/appium-CC77BJNK.js.map +1 -0
- package/dist/bridge-server-S3DHK7XE.js +12 -0
- package/dist/channels/cdp-client.d.ts +13 -0
- package/dist/channels/cdp-client.d.ts.map +1 -1
- package/dist/channels/dom-channel.d.ts +1 -1
- package/dist/channels/dom-channel.d.ts.map +1 -1
- package/dist/chunk-27H6NDA5.js +845 -0
- package/dist/chunk-27H6NDA5.js.map +1 -0
- package/dist/chunk-4LJ3KYCX.js +94 -0
- package/dist/chunk-4LJ3KYCX.js.map +1 -0
- package/dist/chunk-5SDVP53E.js +1046 -0
- package/dist/chunk-5SDVP53E.js.map +1 -0
- package/dist/{chunk-OQRGR542.js → chunk-5T7LSBDM.js} +7 -7
- package/dist/chunk-5T7LSBDM.js.map +1 -0
- package/dist/{screenshot-compare-V4JQG73R.js → chunk-6C2EILMC.js} +185 -6
- package/dist/chunk-6C2EILMC.js.map +1 -0
- package/dist/{chunk-BWEQ4XT2.js → chunk-7IUD55GY.js} +455 -1178
- package/dist/chunk-7IUD55GY.js.map +1 -0
- package/dist/chunk-A7Z52TDQ.js +97 -0
- package/dist/chunk-A7Z52TDQ.js.map +1 -0
- package/dist/{chunk-AMBU26PB.js → chunk-BUNMIMGA.js} +2 -2
- package/dist/chunk-DMF2BPPA.js +547 -0
- package/dist/chunk-DMF2BPPA.js.map +1 -0
- package/dist/chunk-FUXFXFBM.js +1962 -0
- package/dist/chunk-FUXFXFBM.js.map +1 -0
- package/dist/{chunk-F2YUBD4E.js → chunk-FV7ONGQ7.js} +3 -3
- package/dist/{chunk-QOL44BNJ.js → chunk-GDVHJBR2.js} +4 -4
- package/dist/chunk-GLNTGHR6.js +330 -0
- package/dist/chunk-GLNTGHR6.js.map +1 -0
- package/dist/chunk-HJY5YN4N.js +272 -0
- package/dist/chunk-HJY5YN4N.js.map +1 -0
- package/dist/chunk-HNQLWFHL.js +40 -0
- package/dist/chunk-HNQLWFHL.js.map +1 -0
- package/dist/chunk-HUYC4OAL.js +72 -0
- package/dist/chunk-HUYC4OAL.js.map +1 -0
- package/dist/chunk-HWS3XUEF.js +109 -0
- package/dist/chunk-HWS3XUEF.js.map +1 -0
- package/dist/{chunk-F3AFZ6UX.js → chunk-IDIHDVGC.js} +3 -1
- package/dist/chunk-IDIHDVGC.js.map +1 -0
- package/dist/{chunk-53TGNQTM.js → chunk-IUK3RJ6W.js} +32 -18
- package/dist/{chunk-53TGNQTM.js.map → chunk-IUK3RJ6W.js.map} +1 -1
- package/dist/chunk-K4K2ACT2.js +179 -0
- package/dist/chunk-K4K2ACT2.js.map +1 -0
- package/dist/chunk-LKGF75QJ.js +654 -0
- package/dist/chunk-LKGF75QJ.js.map +1 -0
- package/dist/chunk-MAKZK7GY.js +935 -0
- package/dist/chunk-MAKZK7GY.js.map +1 -0
- package/dist/chunk-MPJCUL2B.js +154 -0
- package/dist/chunk-MPJCUL2B.js.map +1 -0
- package/dist/chunk-MUMIMDRJ.js +24 -0
- package/dist/chunk-MUMIMDRJ.js.map +1 -0
- package/dist/{chunk-XQRXQBDQ.js → chunk-NWGA3R2E.js} +2 -19
- package/dist/chunk-NWGA3R2E.js.map +1 -0
- package/dist/chunk-PPRNCRTS.js +1104 -0
- package/dist/chunk-PPRNCRTS.js.map +1 -0
- package/dist/{chunk-LQQNE2OE.js → chunk-RHQJSPOS.js} +371 -40
- package/dist/chunk-RHQJSPOS.js.map +1 -0
- package/dist/{chunk-GAWJL6Q3.js → chunk-VWJNINPX.js} +490 -89
- package/dist/chunk-VWJNINPX.js.map +1 -0
- package/dist/chunk-WFC4DCFF.js +529 -0
- package/dist/chunk-WFC4DCFF.js.map +1 -0
- package/dist/chunk-X5FRYDZ3.js +91 -0
- package/dist/chunk-X5FRYDZ3.js.map +1 -0
- package/dist/chunk-YFTHJRDO.js +37 -0
- package/dist/chunk-YFTHJRDO.js.map +1 -0
- package/dist/cli/test-command.d.ts.map +1 -1
- package/dist/cli.js +18 -18
- package/dist/config-loader-7W7OEWRG.js +10 -0
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/{discover-43C3BE7I.js → discover-6ULCTB5T.js} +3 -3
- package/dist/{doctor-command-CLKEEOAX.js → doctor-command-4CQQLB7M.js} +16 -9
- package/dist/{doctor-command-CLKEEOAX.js.map → doctor-command-4CQQLB7M.js.map} +1 -1
- package/dist/driver-3MEIFYST.js +19 -0
- package/dist/driver-QTIAADUZ.js +19 -0
- package/dist/drivers/cdp-browser.d.ts +27 -0
- package/dist/drivers/cdp-browser.d.ts.map +1 -1
- package/dist/drivers/electron.d.ts +1 -1
- package/dist/drivers/electron.d.ts.map +1 -1
- package/dist/drivers/playwright.d.ts +1 -5
- package/dist/drivers/playwright.d.ts.map +1 -1
- package/dist/drivers/raw-driver.d.ts +4 -0
- package/dist/drivers/raw-driver.d.ts.map +1 -1
- package/dist/drivers/wasm-utils.d.ts +100 -0
- package/dist/drivers/wasm-utils.d.ts.map +1 -0
- package/dist/drivers/wasm.d.ts +57 -0
- package/dist/drivers/wasm.d.ts.map +1 -0
- package/dist/electrobun-MPAHMSI2.js +15 -0
- package/dist/electrobun-MPAHMSI2.js.map +1 -0
- package/dist/electron-SQACDON3.js +9 -0
- package/dist/electron-SQACDON3.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +400 -53
- package/dist/index.js.map +1 -1
- package/dist/installer-KL2NCILK.js +17 -0
- package/dist/installer-KL2NCILK.js.map +1 -0
- package/dist/{local-RH5EFGYF.js → local-SWHWINSA.js} +8 -9
- package/dist/local-SWHWINSA.js.map +1 -0
- package/dist/pagesource-KIQ5T5MA.js +9 -0
- package/dist/pagesource-KIQ5T5MA.js.map +1 -0
- package/dist/pagesource-KKG7WMFJ.js +9 -0
- package/dist/pagesource-KKG7WMFJ.js.map +1 -0
- package/dist/playwright-42QYIZEE.js +28 -0
- package/dist/playwright-42QYIZEE.js.map +1 -0
- package/dist/runtime/local.d.ts.map +1 -1
- package/dist/schemas/config.d.ts +32 -0
- package/dist/schemas/config.d.ts.map +1 -1
- package/dist/schemas/device.d.ts +1 -1
- package/dist/schemas/device.d.ts.map +1 -1
- package/dist/screenshot-compare-BJRJHKNQ.js +12 -0
- package/dist/screenshot-compare-BJRJHKNQ.js.map +1 -0
- package/dist/{server-D45AO34E.js → server-2Y46CDVB.js} +30 -12
- package/dist/{server-D45AO34E.js.map → server-2Y46CDVB.js.map} +1 -1
- package/dist/{server-KLZBJOMQ.js → server-ZCBZ4UYF.js} +2 -2
- package/dist/server-ZCBZ4UYF.js.map +1 -0
- package/dist/session-5XW6TKF4.js +39 -0
- package/dist/session-5XW6TKF4.js.map +1 -0
- package/dist/smart/coordinator.d.ts.map +1 -1
- package/dist/{studio-command-TNSJGTFA.js → studio-command-BNBOL424.js} +2 -2
- package/dist/{test-command-EXPYFDTF.js → test-command-T4PLAZXU.js} +58 -1036
- package/dist/test-command-T4PLAZXU.js.map +1 -0
- package/dist/watch-mode-NR5MHNNL.js +10 -0
- package/dist/watch-mode-NR5MHNNL.js.map +1 -0
- package/native/win32-x64/spana_native.dll +0 -0
- package/package.json +2 -2
- package/dist/app-CBHH5GMB.js +0 -10
- package/dist/chunk-BWEQ4XT2.js.map +0 -1
- package/dist/chunk-F3AFZ6UX.js.map +0 -1
- package/dist/chunk-GAWJL6Q3.js.map +0 -1
- package/dist/chunk-GDDCZ2PL.js +0 -2619
- package/dist/chunk-GDDCZ2PL.js.map +0 -1
- package/dist/chunk-LQQNE2OE.js.map +0 -1
- package/dist/chunk-OQRGR542.js.map +0 -1
- package/dist/chunk-PPAPRKQU.js +0 -4739
- package/dist/chunk-PPAPRKQU.js.map +0 -1
- package/dist/chunk-VOYJQDSI.js +0 -188
- package/dist/chunk-VOYJQDSI.js.map +0 -1
- package/dist/chunk-XQRXQBDQ.js.map +0 -1
- package/dist/config-loader-V26XXHPH.js +0 -10
- package/dist/screenshot-compare-V4JQG73R.js.map +0 -1
- package/dist/session-N6DEYVPM.js +0 -21
- package/dist/test-command-EXPYFDTF.js.map +0 -1
- /package/dist/{app-CBHH5GMB.js.map → app-W6PRRBMD.js.map} +0 -0
- /package/dist/{config-loader-V26XXHPH.js.map → bridge-server-S3DHK7XE.js.map} +0 -0
- /package/dist/{chunk-AMBU26PB.js.map → chunk-BUNMIMGA.js.map} +0 -0
- /package/dist/{chunk-F2YUBD4E.js.map → chunk-FV7ONGQ7.js.map} +0 -0
- /package/dist/{chunk-QOL44BNJ.js.map → chunk-GDVHJBR2.js.map} +0 -0
- /package/dist/{discover-43C3BE7I.js.map → config-loader-7W7OEWRG.js.map} +0 -0
- /package/dist/{local-RH5EFGYF.js.map → discover-6ULCTB5T.js.map} +0 -0
- /package/dist/{server-KLZBJOMQ.js.map → driver-3MEIFYST.js.map} +0 -0
- /package/dist/{session-N6DEYVPM.js.map → driver-QTIAADUZ.js.map} +0 -0
- /package/dist/{studio-command-TNSJGTFA.js.map → studio-command-BNBOL424.js.map} +0 -0
|
@@ -0,0 +1,845 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAndroidWebViewCdpChannel
|
|
3
|
+
} from "./chunk-HJY5YN4N.js";
|
|
4
|
+
import {
|
|
5
|
+
androidDeviceControls,
|
|
6
|
+
deviceEffect
|
|
7
|
+
} from "./chunk-HWS3XUEF.js";
|
|
8
|
+
import {
|
|
9
|
+
resolveNetworkConditions
|
|
10
|
+
} from "./chunk-HNQLWFHL.js";
|
|
11
|
+
import {
|
|
12
|
+
adbClearApp,
|
|
13
|
+
adbForceStop,
|
|
14
|
+
adbLaunchApp,
|
|
15
|
+
adbOpenLink,
|
|
16
|
+
adbResetNetwork,
|
|
17
|
+
adbSetAirplaneMode,
|
|
18
|
+
adbSetCustomNetwork,
|
|
19
|
+
adbSetData,
|
|
20
|
+
adbSetNetworkProfile,
|
|
21
|
+
adbSetWifi
|
|
22
|
+
} from "./chunk-XVL4FHXA.js";
|
|
23
|
+
import {
|
|
24
|
+
createCompositeDomChannel
|
|
25
|
+
} from "./chunk-DMF2BPPA.js";
|
|
26
|
+
import {
|
|
27
|
+
splitGraphemes
|
|
28
|
+
} from "./chunk-MUMIMDRJ.js";
|
|
29
|
+
import {
|
|
30
|
+
hasLaunchDeviceState
|
|
31
|
+
} from "./chunk-NWGA3R2E.js";
|
|
32
|
+
import {
|
|
33
|
+
DriverError
|
|
34
|
+
} from "./chunk-A7Z52TDQ.js";
|
|
35
|
+
import {
|
|
36
|
+
init_esm_shims
|
|
37
|
+
} from "./chunk-FTXUQMGH.js";
|
|
38
|
+
|
|
39
|
+
// src/drivers/uiautomator2/driver.ts
|
|
40
|
+
init_esm_shims();
|
|
41
|
+
import { Effect } from "effect";
|
|
42
|
+
|
|
43
|
+
// src/drivers/uiautomator2/client.ts
|
|
44
|
+
init_esm_shims();
|
|
45
|
+
var UiAutomator2Client = class {
|
|
46
|
+
baseUrl;
|
|
47
|
+
sessionId = null;
|
|
48
|
+
constructor(host, port) {
|
|
49
|
+
this.baseUrl = `http://${host}:${port}`;
|
|
50
|
+
}
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// HTTP helpers
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
async request(method, path, body) {
|
|
55
|
+
const url = `${this.baseUrl}${path}`;
|
|
56
|
+
const init = {
|
|
57
|
+
method,
|
|
58
|
+
headers: { "Content-Type": "application/json" }
|
|
59
|
+
};
|
|
60
|
+
if (body !== void 0) {
|
|
61
|
+
init.body = JSON.stringify(body);
|
|
62
|
+
}
|
|
63
|
+
const res = await fetch(url, init);
|
|
64
|
+
const text = await res.text();
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = JSON.parse(text);
|
|
68
|
+
} catch {
|
|
69
|
+
throw new Error(`UiAutomator2: failed to parse response: ${text}`);
|
|
70
|
+
}
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
const val = parsed.value;
|
|
73
|
+
const msg = val?.message ?? val?.error ?? text;
|
|
74
|
+
throw new Error(`UiAutomator2 ${method} ${path} \u2192 ${res.status}: ${msg}`);
|
|
75
|
+
}
|
|
76
|
+
if (parsed.value !== null && typeof parsed.value === "object" && "error" in parsed.value) {
|
|
77
|
+
const val = parsed.value;
|
|
78
|
+
throw new Error(`UiAutomator2 error: ${val.message ?? val.error}`);
|
|
79
|
+
}
|
|
80
|
+
return parsed.value;
|
|
81
|
+
}
|
|
82
|
+
sessionPath(path) {
|
|
83
|
+
if (this.sessionId === null) {
|
|
84
|
+
throw new Error("UiAutomator2: no active session");
|
|
85
|
+
}
|
|
86
|
+
return `/session/${this.sessionId}${path}`;
|
|
87
|
+
}
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// Session management
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
async createSession(appPackage) {
|
|
92
|
+
const capabilities = {
|
|
93
|
+
platformName: "Android"
|
|
94
|
+
};
|
|
95
|
+
if (appPackage) {
|
|
96
|
+
capabilities["appium:appPackage"] = appPackage;
|
|
97
|
+
}
|
|
98
|
+
const body = { capabilities };
|
|
99
|
+
const res = await fetch(`${this.baseUrl}/session`, {
|
|
100
|
+
method: "POST",
|
|
101
|
+
headers: { "Content-Type": "application/json" },
|
|
102
|
+
body: JSON.stringify(body)
|
|
103
|
+
});
|
|
104
|
+
const text = await res.text();
|
|
105
|
+
let parsed;
|
|
106
|
+
try {
|
|
107
|
+
parsed = JSON.parse(text);
|
|
108
|
+
} catch {
|
|
109
|
+
throw new Error(`UiAutomator2: failed to parse session response: ${text}`);
|
|
110
|
+
}
|
|
111
|
+
if (!res.ok) {
|
|
112
|
+
const val = parsed["value"];
|
|
113
|
+
throw new Error(`UiAutomator2: failed to create session: ${val?.message ?? text}`);
|
|
114
|
+
}
|
|
115
|
+
let sessionId = parsed["sessionId"] ?? parsed["value"]?.["sessionId"];
|
|
116
|
+
if (!sessionId) {
|
|
117
|
+
throw new Error("UiAutomator2: no sessionId in session response");
|
|
118
|
+
}
|
|
119
|
+
this.sessionId = sessionId;
|
|
120
|
+
return sessionId;
|
|
121
|
+
}
|
|
122
|
+
async deleteSession() {
|
|
123
|
+
if (this.sessionId === null) return;
|
|
124
|
+
const path = `/session/${this.sessionId}`;
|
|
125
|
+
this.sessionId = null;
|
|
126
|
+
await fetch(`${this.baseUrl}${path}`, { method: "DELETE" });
|
|
127
|
+
}
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
// Screen queries
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
async getSource() {
|
|
132
|
+
const value = await this.request("GET", this.sessionPath("/source"));
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
async getScreenshot() {
|
|
136
|
+
const value = await this.request("GET", this.sessionPath("/screenshot"));
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
async getWindowSize() {
|
|
140
|
+
try {
|
|
141
|
+
return await this.request(
|
|
142
|
+
"GET",
|
|
143
|
+
this.sessionPath("/window/current/size")
|
|
144
|
+
);
|
|
145
|
+
} catch {
|
|
146
|
+
try {
|
|
147
|
+
return await this.request(
|
|
148
|
+
"GET",
|
|
149
|
+
this.sessionPath("/window/size")
|
|
150
|
+
);
|
|
151
|
+
} catch {
|
|
152
|
+
return { width: 1080, height: 1920 };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async setOrientation(orientation) {
|
|
157
|
+
await this.request("POST", this.sessionPath("/orientation"), { orientation });
|
|
158
|
+
}
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
// Gestures — Appium gesture extensions
|
|
161
|
+
// These match the endpoints used by maestro-runner's uiautomator2 client.
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
async performTap(x, y) {
|
|
164
|
+
await this.request("POST", this.sessionPath("/appium/gestures/click"), {
|
|
165
|
+
offset: { x, y }
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
async performDoubleTap(x, y) {
|
|
169
|
+
await this.request("POST", this.sessionPath("/appium/gestures/double_click"), {
|
|
170
|
+
offset: { x, y }
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
async performLongPress(x, y, duration) {
|
|
174
|
+
await this.request("POST", this.sessionPath("/appium/gestures/long_click"), {
|
|
175
|
+
offset: { x, y },
|
|
176
|
+
duration
|
|
177
|
+
// milliseconds
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Coordinate-based swipe from (startX, startY) to (endX, endY).
|
|
182
|
+
*
|
|
183
|
+
* The Appium swipe extension only accepts direction + percent; for arbitrary
|
|
184
|
+
* from/to coordinates we use the W3C Actions API instead.
|
|
185
|
+
*
|
|
186
|
+
* @param duration - gesture duration in milliseconds
|
|
187
|
+
*/
|
|
188
|
+
async performSwipe(startX, startY, endX, endY, duration) {
|
|
189
|
+
await this.request("POST", this.sessionPath("/actions"), {
|
|
190
|
+
actions: [
|
|
191
|
+
{
|
|
192
|
+
type: "pointer",
|
|
193
|
+
id: "finger1",
|
|
194
|
+
parameters: { pointerType: "touch" },
|
|
195
|
+
actions: [
|
|
196
|
+
{ type: "pointerMove", duration: 0, x: startX, y: startY },
|
|
197
|
+
{ type: "pointerDown", button: 0 },
|
|
198
|
+
{ type: "pointerMove", duration, x: endX, y: endY },
|
|
199
|
+
{ type: "pointerUp", button: 0 }
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Pinch gesture (zoom out) — two fingers move toward center.
|
|
207
|
+
*
|
|
208
|
+
* @param cx - center X coordinate
|
|
209
|
+
* @param cy - center Y coordinate
|
|
210
|
+
* @param scale - 0..1 representing how far fingers start from center (as fraction of 200px)
|
|
211
|
+
* @param duration - gesture duration in milliseconds
|
|
212
|
+
*/
|
|
213
|
+
async performPinch(cx, cy, scale, duration) {
|
|
214
|
+
const dist = 200 * scale;
|
|
215
|
+
await this.request("POST", this.sessionPath("/actions"), {
|
|
216
|
+
actions: [
|
|
217
|
+
{
|
|
218
|
+
type: "pointer",
|
|
219
|
+
id: "finger1",
|
|
220
|
+
parameters: { pointerType: "touch" },
|
|
221
|
+
actions: [
|
|
222
|
+
{ type: "pointerMove", duration: 0, x: Math.round(cx - dist), y: Math.round(cy) },
|
|
223
|
+
{ type: "pointerDown", button: 0 },
|
|
224
|
+
{ type: "pointerMove", duration, x: Math.round(cx - 10), y: Math.round(cy) },
|
|
225
|
+
{ type: "pointerUp", button: 0 }
|
|
226
|
+
]
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
type: "pointer",
|
|
230
|
+
id: "finger2",
|
|
231
|
+
parameters: { pointerType: "touch" },
|
|
232
|
+
actions: [
|
|
233
|
+
{ type: "pointerMove", duration: 0, x: Math.round(cx + dist), y: Math.round(cy) },
|
|
234
|
+
{ type: "pointerDown", button: 0 },
|
|
235
|
+
{ type: "pointerMove", duration, x: Math.round(cx + 10), y: Math.round(cy) },
|
|
236
|
+
{ type: "pointerUp", button: 0 }
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Zoom gesture (zoom in) — two fingers move away from center.
|
|
244
|
+
*
|
|
245
|
+
* @param cx - center X coordinate
|
|
246
|
+
* @param cy - center Y coordinate
|
|
247
|
+
* @param scale - 0..1 representing how far fingers end from center (as fraction of 200px)
|
|
248
|
+
* @param duration - gesture duration in milliseconds
|
|
249
|
+
*/
|
|
250
|
+
async performZoom(cx, cy, scale, duration) {
|
|
251
|
+
const dist = 200 * scale;
|
|
252
|
+
await this.request("POST", this.sessionPath("/actions"), {
|
|
253
|
+
actions: [
|
|
254
|
+
{
|
|
255
|
+
type: "pointer",
|
|
256
|
+
id: "finger1",
|
|
257
|
+
parameters: { pointerType: "touch" },
|
|
258
|
+
actions: [
|
|
259
|
+
{ type: "pointerMove", duration: 0, x: Math.round(cx - 10), y: Math.round(cy) },
|
|
260
|
+
{ type: "pointerDown", button: 0 },
|
|
261
|
+
{ type: "pointerMove", duration, x: Math.round(cx - dist), y: Math.round(cy) },
|
|
262
|
+
{ type: "pointerUp", button: 0 }
|
|
263
|
+
]
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
type: "pointer",
|
|
267
|
+
id: "finger2",
|
|
268
|
+
parameters: { pointerType: "touch" },
|
|
269
|
+
actions: [
|
|
270
|
+
{ type: "pointerMove", duration: 0, x: Math.round(cx + 10), y: Math.round(cy) },
|
|
271
|
+
{ type: "pointerDown", button: 0 },
|
|
272
|
+
{ type: "pointerMove", duration, x: Math.round(cx + dist), y: Math.round(cy) },
|
|
273
|
+
{ type: "pointerUp", button: 0 }
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
]
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Arbitrary multi-touch gesture using W3C Actions.
|
|
281
|
+
* Each sequence represents one finger with a series of actions.
|
|
282
|
+
*/
|
|
283
|
+
async performMultiTouch(sequences) {
|
|
284
|
+
const actions = sequences.map((seq) => ({
|
|
285
|
+
type: "pointer",
|
|
286
|
+
id: `finger${seq.id}`,
|
|
287
|
+
parameters: { pointerType: "touch" },
|
|
288
|
+
actions: seq.actions.map((a) => {
|
|
289
|
+
switch (a.type) {
|
|
290
|
+
case "move":
|
|
291
|
+
return {
|
|
292
|
+
type: "pointerMove",
|
|
293
|
+
duration: a.duration ?? 0,
|
|
294
|
+
x: Math.round(a.x),
|
|
295
|
+
y: Math.round(a.y)
|
|
296
|
+
};
|
|
297
|
+
case "down":
|
|
298
|
+
return { type: "pointerDown", button: 0 };
|
|
299
|
+
case "up":
|
|
300
|
+
return { type: "pointerUp", button: 0 };
|
|
301
|
+
case "pause":
|
|
302
|
+
return { type: "pause", duration: a.duration };
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
}));
|
|
306
|
+
await this.request("POST", this.sessionPath("/actions"), { actions });
|
|
307
|
+
}
|
|
308
|
+
// ---------------------------------------------------------------------------
|
|
309
|
+
// Text / keyboard
|
|
310
|
+
// ---------------------------------------------------------------------------
|
|
311
|
+
async sendKeys(text) {
|
|
312
|
+
const hasComplexChars = /[\u{10000}-\u{10FFFF}]|\u200D/u.test(text);
|
|
313
|
+
if (hasComplexChars) {
|
|
314
|
+
const segments = splitGraphemes(text);
|
|
315
|
+
let simpleBatch = "";
|
|
316
|
+
for (const segment of segments) {
|
|
317
|
+
if (/[\u{10000}-\u{10FFFF}]|\u200D/u.test(segment)) {
|
|
318
|
+
if (simpleBatch) {
|
|
319
|
+
await this.sendKeysViaActions(simpleBatch);
|
|
320
|
+
simpleBatch = "";
|
|
321
|
+
}
|
|
322
|
+
} else {
|
|
323
|
+
simpleBatch += segment;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (simpleBatch) {
|
|
327
|
+
await this.sendKeysViaActions(simpleBatch);
|
|
328
|
+
}
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
await this.sendKeysViaActions(text);
|
|
332
|
+
}
|
|
333
|
+
async sendKeysViaActions(text) {
|
|
334
|
+
const keyActions = [];
|
|
335
|
+
for (const segment of splitGraphemes(text)) {
|
|
336
|
+
keyActions.push({ type: "keyDown", value: segment });
|
|
337
|
+
keyActions.push({ type: "keyUp", value: segment });
|
|
338
|
+
}
|
|
339
|
+
await this.request("POST", this.sessionPath("/actions"), {
|
|
340
|
+
actions: [
|
|
341
|
+
{
|
|
342
|
+
type: "key",
|
|
343
|
+
id: "keyboard",
|
|
344
|
+
actions: keyActions
|
|
345
|
+
}
|
|
346
|
+
]
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
async pressKeyCode(keyCode) {
|
|
350
|
+
await this.request("POST", this.sessionPath("/appium/device/press_keycode"), {
|
|
351
|
+
keycode: keyCode
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
async hideKeyboard() {
|
|
355
|
+
await this.request("POST", this.sessionPath("/appium/device/hide_keyboard"), void 0);
|
|
356
|
+
}
|
|
357
|
+
// ---------------------------------------------------------------------------
|
|
358
|
+
// App lifecycle
|
|
359
|
+
// ---------------------------------------------------------------------------
|
|
360
|
+
async activateApp(appPackage) {
|
|
361
|
+
await this.request("POST", this.sessionPath("/appium/device/activate_app"), {
|
|
362
|
+
appId: appPackage
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
async terminateApp(appPackage) {
|
|
366
|
+
await this.request("POST", this.sessionPath("/appium/device/terminate_app"), {
|
|
367
|
+
appId: appPackage
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
// ---------------------------------------------------------------------------
|
|
371
|
+
// WebView / hybrid context switching
|
|
372
|
+
// ---------------------------------------------------------------------------
|
|
373
|
+
async getContexts() {
|
|
374
|
+
return this.request("GET", this.sessionPath("/contexts"));
|
|
375
|
+
}
|
|
376
|
+
async getCurrentContext() {
|
|
377
|
+
return this.request("GET", this.sessionPath("/context"));
|
|
378
|
+
}
|
|
379
|
+
async setContext(contextId) {
|
|
380
|
+
await this.request("POST", this.sessionPath("/context"), { name: contextId });
|
|
381
|
+
}
|
|
382
|
+
async executeScript(script, args = []) {
|
|
383
|
+
return this.request("POST", this.sessionPath("/execute/sync"), { script, args });
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// src/drivers/uiautomator2/driver.ts
|
|
388
|
+
function createUiAutomator2Driver(host, port, serial, packageName, driverOptions) {
|
|
389
|
+
return Effect.gen(function* () {
|
|
390
|
+
const client = new UiAutomator2Client(host, port);
|
|
391
|
+
let currentContext = "NATIVE_APP";
|
|
392
|
+
let hasLaunchedOnce = false;
|
|
393
|
+
const waitForAndroidReady = async (maxMs) => {
|
|
394
|
+
const deadline = Date.now() + maxMs;
|
|
395
|
+
while (Date.now() < deadline) {
|
|
396
|
+
try {
|
|
397
|
+
await client.getWindowSize();
|
|
398
|
+
return;
|
|
399
|
+
} catch {
|
|
400
|
+
await new Promise((resolve) => setTimeout(resolve, 40));
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
const cdpChannel = driverOptions?.enableWebViewCdp === false ? void 0 : createAndroidWebViewCdpChannel({
|
|
405
|
+
serial,
|
|
406
|
+
packageName: packageName || void 0,
|
|
407
|
+
localPort: driverOptions?.cdpPort
|
|
408
|
+
});
|
|
409
|
+
const channels = [];
|
|
410
|
+
if (driverOptions?.domChannel) channels.push(driverOptions.domChannel);
|
|
411
|
+
if (cdpChannel) channels.push(cdpChannel);
|
|
412
|
+
const domChannel = channels.length === 0 ? void 0 : channels.length === 1 ? channels[0] : createCompositeDomChannel(channels);
|
|
413
|
+
yield* Effect.tryPromise({
|
|
414
|
+
try: () => client.createSession(packageName),
|
|
415
|
+
catch: (e) => new DriverError({
|
|
416
|
+
message: `Failed to create UiAutomator2 session: ${e}`
|
|
417
|
+
})
|
|
418
|
+
});
|
|
419
|
+
const service = {
|
|
420
|
+
domChannel,
|
|
421
|
+
...androidDeviceControls(serial),
|
|
422
|
+
setOrientation: (orientation) => deviceEffect(
|
|
423
|
+
"setOrientation",
|
|
424
|
+
() => client.setOrientation(orientation === "portrait" ? "PORTRAIT" : "LANDSCAPE")
|
|
425
|
+
),
|
|
426
|
+
// -----------------------------------------------------------------------
|
|
427
|
+
// Hierarchy
|
|
428
|
+
// -----------------------------------------------------------------------
|
|
429
|
+
dumpHierarchy: () => Effect.tryPromise({
|
|
430
|
+
try: () => client.getSource(),
|
|
431
|
+
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
432
|
+
}),
|
|
433
|
+
// -----------------------------------------------------------------------
|
|
434
|
+
// Coordinate-level actions
|
|
435
|
+
// -----------------------------------------------------------------------
|
|
436
|
+
tapAtCoordinate: (x, y) => Effect.tryPromise({
|
|
437
|
+
try: () => client.performTap(x, y),
|
|
438
|
+
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
439
|
+
}),
|
|
440
|
+
doubleTapAtCoordinate: (x, y) => Effect.tryPromise({
|
|
441
|
+
try: async () => {
|
|
442
|
+
await client.performTap(x, y);
|
|
443
|
+
await client.performTap(x, y);
|
|
444
|
+
},
|
|
445
|
+
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
446
|
+
}),
|
|
447
|
+
longPressAtCoordinate: (x, y, duration) => Effect.tryPromise({
|
|
448
|
+
try: () => client.performLongPress(x, y, duration),
|
|
449
|
+
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
450
|
+
}),
|
|
451
|
+
swipe: (sx, sy, ex, ey, dur) => Effect.tryPromise({
|
|
452
|
+
try: () => client.performSwipe(sx, sy, ex, ey, dur),
|
|
453
|
+
catch: (e) => new DriverError({ message: `Swipe failed: ${e}` })
|
|
454
|
+
}),
|
|
455
|
+
pinch: (cx, cy, scale, duration) => Effect.tryPromise({
|
|
456
|
+
try: () => client.performPinch(cx, cy, scale, duration),
|
|
457
|
+
catch: (e) => new DriverError({ message: `Pinch failed: ${e}` })
|
|
458
|
+
}),
|
|
459
|
+
zoom: (cx, cy, scale, duration) => Effect.tryPromise({
|
|
460
|
+
try: () => client.performZoom(cx, cy, scale, duration),
|
|
461
|
+
catch: (e) => new DriverError({ message: `Zoom failed: ${e}` })
|
|
462
|
+
}),
|
|
463
|
+
multiTouch: (sequences) => Effect.tryPromise({
|
|
464
|
+
try: () => client.performMultiTouch(sequences),
|
|
465
|
+
catch: (e) => new DriverError({ message: `Multi-touch failed: ${e}` })
|
|
466
|
+
}),
|
|
467
|
+
// -----------------------------------------------------------------------
|
|
468
|
+
// Text input
|
|
469
|
+
// -----------------------------------------------------------------------
|
|
470
|
+
inputText: (text) => Effect.tryPromise({
|
|
471
|
+
try: () => client.sendKeys(text),
|
|
472
|
+
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
473
|
+
}),
|
|
474
|
+
pressKey: (key) => Effect.tryPromise({
|
|
475
|
+
try: () => client.pressKeyCode(parseInt(key, 10) || 0),
|
|
476
|
+
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
477
|
+
}),
|
|
478
|
+
hideKeyboard: () => Effect.tryPromise({
|
|
479
|
+
try: () => client.hideKeyboard(),
|
|
480
|
+
catch: (e) => new DriverError({ message: `Hide keyboard failed: ${e}` })
|
|
481
|
+
}),
|
|
482
|
+
// -----------------------------------------------------------------------
|
|
483
|
+
// Queries
|
|
484
|
+
// -----------------------------------------------------------------------
|
|
485
|
+
takeScreenshot: () => Effect.tryPromise({
|
|
486
|
+
try: async () => {
|
|
487
|
+
const base64 = await client.getScreenshot();
|
|
488
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
489
|
+
},
|
|
490
|
+
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
491
|
+
}),
|
|
492
|
+
getDeviceInfo: () => Effect.tryPromise({
|
|
493
|
+
try: async () => {
|
|
494
|
+
const size = await client.getWindowSize();
|
|
495
|
+
return {
|
|
496
|
+
platform: "android",
|
|
497
|
+
deviceId: `${host}:${port}`,
|
|
498
|
+
name: "Android Device",
|
|
499
|
+
isEmulator: host === "localhost" || host === "127.0.0.1",
|
|
500
|
+
screenWidth: size.width,
|
|
501
|
+
screenHeight: size.height,
|
|
502
|
+
driverType: "uiautomator2"
|
|
503
|
+
};
|
|
504
|
+
},
|
|
505
|
+
catch: (e) => new DriverError({ message: `Get device info failed: ${e}` })
|
|
506
|
+
}),
|
|
507
|
+
// -----------------------------------------------------------------------
|
|
508
|
+
// App lifecycle
|
|
509
|
+
// -----------------------------------------------------------------------
|
|
510
|
+
launchApp: (bundleId, opts) => Effect.tryPromise({
|
|
511
|
+
try: async () => {
|
|
512
|
+
const canFastReset = hasLaunchedOnce && driverOptions?.fastWebViewReset !== false && domChannel?.isConnected() && !opts?.deepLink && !opts?.clearKeychain && !hasLaunchDeviceState(opts?.deviceState) && !(opts?.launchArguments && Object.keys(opts.launchArguments).length > 0);
|
|
513
|
+
if (canFastReset) {
|
|
514
|
+
try {
|
|
515
|
+
if (opts?.clearState && domChannel.clearStorage) {
|
|
516
|
+
await domChannel.clearStorage({
|
|
517
|
+
localStorage: true,
|
|
518
|
+
sessionStorage: true,
|
|
519
|
+
cookies: true,
|
|
520
|
+
indexedDB: true,
|
|
521
|
+
capacitorPreferences: true
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
if (domChannel.reload) {
|
|
525
|
+
await domChannel.reload();
|
|
526
|
+
} else {
|
|
527
|
+
await domChannel.evaluate("window.location.reload()");
|
|
528
|
+
}
|
|
529
|
+
return;
|
|
530
|
+
} catch {
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if (opts?.clearState) {
|
|
534
|
+
adbClearApp(serial, bundleId);
|
|
535
|
+
}
|
|
536
|
+
if (opts?.clearKeychain) {
|
|
537
|
+
console.warn("clearKeychain is not supported on Android, skipping.");
|
|
538
|
+
}
|
|
539
|
+
if (hasLaunchDeviceState(opts?.deviceState)) {
|
|
540
|
+
console.warn(
|
|
541
|
+
"deviceState launch overrides are not supported in local Android mode yet. Use Appium Android mode for language/locale/timeZone session defaults."
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
if (opts?.deepLink) {
|
|
545
|
+
adbOpenLink(serial, opts.deepLink, bundleId);
|
|
546
|
+
await waitForAndroidReady(500);
|
|
547
|
+
} else {
|
|
548
|
+
adbForceStop(serial, bundleId);
|
|
549
|
+
if (opts?.launchArguments && Object.keys(opts.launchArguments).length > 0) {
|
|
550
|
+
const { execFileSync } = await import("child_process");
|
|
551
|
+
const { findADB } = await import("./android-C2S4B4TH.js");
|
|
552
|
+
const adb = findADB();
|
|
553
|
+
if (!adb) throw new Error("adb not found");
|
|
554
|
+
const startArgs = [
|
|
555
|
+
"-s",
|
|
556
|
+
serial,
|
|
557
|
+
"shell",
|
|
558
|
+
"am",
|
|
559
|
+
"start",
|
|
560
|
+
"-a",
|
|
561
|
+
"android.intent.action.MAIN",
|
|
562
|
+
"-c",
|
|
563
|
+
"android.intent.category.LAUNCHER",
|
|
564
|
+
bundleId
|
|
565
|
+
];
|
|
566
|
+
for (const [k, v] of Object.entries(opts.launchArguments)) {
|
|
567
|
+
startArgs.push("--es", k, String(v));
|
|
568
|
+
}
|
|
569
|
+
execFileSync(adb, startArgs, { stdio: "ignore" });
|
|
570
|
+
} else {
|
|
571
|
+
adbLaunchApp(serial, bundleId);
|
|
572
|
+
}
|
|
573
|
+
await waitForAndroidReady(800);
|
|
574
|
+
}
|
|
575
|
+
hasLaunchedOnce = true;
|
|
576
|
+
},
|
|
577
|
+
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
578
|
+
}),
|
|
579
|
+
stopApp: (bundleId) => Effect.tryPromise({
|
|
580
|
+
try: async () => {
|
|
581
|
+
adbForceStop(serial, bundleId);
|
|
582
|
+
},
|
|
583
|
+
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
584
|
+
}),
|
|
585
|
+
killApp: (bundleId) => Effect.tryPromise({
|
|
586
|
+
try: async () => {
|
|
587
|
+
await domChannel?.disconnect().catch(() => {
|
|
588
|
+
});
|
|
589
|
+
if (!bundleId) return;
|
|
590
|
+
adbForceStop(serial, bundleId);
|
|
591
|
+
},
|
|
592
|
+
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
593
|
+
}),
|
|
594
|
+
clearAppState: (bundleId) => Effect.tryPromise({
|
|
595
|
+
try: async () => {
|
|
596
|
+
if (domChannel?.isConnected() && domChannel.clearStorage) {
|
|
597
|
+
await domChannel.clearStorage({
|
|
598
|
+
localStorage: true,
|
|
599
|
+
sessionStorage: true,
|
|
600
|
+
cookies: true,
|
|
601
|
+
indexedDB: true,
|
|
602
|
+
capacitorPreferences: true
|
|
603
|
+
});
|
|
604
|
+
if (domChannel.reload) {
|
|
605
|
+
await domChannel.reload();
|
|
606
|
+
}
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
adbForceStop(serial, bundleId);
|
|
610
|
+
adbClearApp(serial, bundleId);
|
|
611
|
+
},
|
|
612
|
+
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
613
|
+
}),
|
|
614
|
+
resetFast: () => Effect.tryPromise({
|
|
615
|
+
try: async () => {
|
|
616
|
+
if (!domChannel) {
|
|
617
|
+
throw new Error("resetFast() requires a connected DOM channel (spana-bridge or CDP)");
|
|
618
|
+
}
|
|
619
|
+
if (domChannel.clearStorage) {
|
|
620
|
+
await domChannel.clearStorage({
|
|
621
|
+
localStorage: true,
|
|
622
|
+
sessionStorage: true,
|
|
623
|
+
cookies: true,
|
|
624
|
+
indexedDB: true,
|
|
625
|
+
capacitorPreferences: true
|
|
626
|
+
});
|
|
627
|
+
} else {
|
|
628
|
+
await domChannel.evaluate(`(() => {
|
|
629
|
+
try { localStorage.clear(); } catch {}
|
|
630
|
+
try { sessionStorage.clear(); } catch {}
|
|
631
|
+
})()`);
|
|
632
|
+
}
|
|
633
|
+
if (domChannel.reload) {
|
|
634
|
+
await domChannel.reload();
|
|
635
|
+
} else {
|
|
636
|
+
await domChannel.evaluate("window.location.reload()");
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
catch: (e) => new DriverError({ message: `Fast reset failed: ${e}` })
|
|
640
|
+
}),
|
|
641
|
+
// -----------------------------------------------------------------------
|
|
642
|
+
// Navigation
|
|
643
|
+
// -----------------------------------------------------------------------
|
|
644
|
+
openLink: (url) => Effect.tryPromise({
|
|
645
|
+
try: async () => {
|
|
646
|
+
adbOpenLink(serial, url, packageName);
|
|
647
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
648
|
+
},
|
|
649
|
+
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
650
|
+
}),
|
|
651
|
+
back: () => Effect.tryPromise({
|
|
652
|
+
// KEYCODE_BACK = 4
|
|
653
|
+
try: () => client.pressKeyCode(4),
|
|
654
|
+
catch: (e) => new DriverError({ message: `Back failed: ${e}` })
|
|
655
|
+
}),
|
|
656
|
+
// -----------------------------------------------------------------------
|
|
657
|
+
// Direct DOM evaluation via spana-bridge or Android WebView CDP,
|
|
658
|
+
// falling back to UiAutomator2 /execute/sync when no DOM channel attaches.
|
|
659
|
+
// -----------------------------------------------------------------------
|
|
660
|
+
evaluate: (script, ...args) => Effect.tryPromise({
|
|
661
|
+
try: async () => {
|
|
662
|
+
if (domChannel) {
|
|
663
|
+
try {
|
|
664
|
+
return await domChannel.evaluate(script, ...args);
|
|
665
|
+
} catch (domErr) {
|
|
666
|
+
if (typeof client.executeScript === "function") {
|
|
667
|
+
try {
|
|
668
|
+
return await client.executeScript(
|
|
669
|
+
typeof script === "function" ? `return (${script})(...arguments)` : script,
|
|
670
|
+
args
|
|
671
|
+
);
|
|
672
|
+
} catch {
|
|
673
|
+
throw domErr;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
throw domErr;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return await client.executeScript(
|
|
680
|
+
typeof script === "function" ? `return (${script})(...arguments)` : script,
|
|
681
|
+
args
|
|
682
|
+
);
|
|
683
|
+
},
|
|
684
|
+
catch: (e) => new DriverError({ message: `evaluate() failed: ${e}` })
|
|
685
|
+
}),
|
|
686
|
+
getContexts: () => Effect.tryPromise({
|
|
687
|
+
try: async () => {
|
|
688
|
+
const contexts = /* @__PURE__ */ new Set(["NATIVE_APP"]);
|
|
689
|
+
if (domChannel?.listTargets) {
|
|
690
|
+
try {
|
|
691
|
+
const targets = await domChannel.listTargets();
|
|
692
|
+
for (const target of targets) {
|
|
693
|
+
contexts.add(`WEBVIEW_${target.id}`);
|
|
694
|
+
}
|
|
695
|
+
} catch {
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
if (typeof client.getContexts === "function") {
|
|
699
|
+
try {
|
|
700
|
+
const uaContexts = await client.getContexts();
|
|
701
|
+
for (const ctx of uaContexts) contexts.add(ctx);
|
|
702
|
+
} catch {
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return Array.from(contexts);
|
|
706
|
+
},
|
|
707
|
+
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
708
|
+
}),
|
|
709
|
+
getCurrentContext: () => Effect.tryPromise({
|
|
710
|
+
try: async () => {
|
|
711
|
+
if (currentContext !== "NATIVE_APP") return currentContext;
|
|
712
|
+
if (typeof client.getCurrentContext === "function") {
|
|
713
|
+
try {
|
|
714
|
+
return await client.getCurrentContext();
|
|
715
|
+
} catch {
|
|
716
|
+
return currentContext;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return currentContext;
|
|
720
|
+
},
|
|
721
|
+
catch: (e) => new DriverError({ message: `getCurrentContext failed: ${e}` })
|
|
722
|
+
}),
|
|
723
|
+
setContext: (contextId) => Effect.tryPromise({
|
|
724
|
+
try: async () => {
|
|
725
|
+
if (contextId === "NATIVE_APP") {
|
|
726
|
+
currentContext = "NATIVE_APP";
|
|
727
|
+
if (typeof client.setContext === "function") {
|
|
728
|
+
await client.setContext("NATIVE_APP").catch(() => {
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (contextId.startsWith("WEBVIEW_") && domChannel) {
|
|
734
|
+
const targetId = contextId.slice("WEBVIEW_".length);
|
|
735
|
+
if (domChannel.selectTarget) {
|
|
736
|
+
try {
|
|
737
|
+
await domChannel.selectTarget(targetId);
|
|
738
|
+
currentContext = contextId;
|
|
739
|
+
return;
|
|
740
|
+
} catch {
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
await client.setContext(contextId);
|
|
745
|
+
currentContext = contextId;
|
|
746
|
+
},
|
|
747
|
+
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
748
|
+
}),
|
|
749
|
+
mockNetwork: (matcher, response) => Effect.tryPromise({
|
|
750
|
+
try: async () => {
|
|
751
|
+
if (!domChannel?.mockNetwork) {
|
|
752
|
+
throw new Error(
|
|
753
|
+
"mockNetwork() is not supported on native Android traffic; enable WebView debugging or install spana-bridge for WebView requests"
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
await domChannel.mockNetwork(matcher, response);
|
|
757
|
+
},
|
|
758
|
+
catch: (e) => new DriverError({ message: `mockNetwork failed: ${e}` })
|
|
759
|
+
}),
|
|
760
|
+
blockNetwork: (matcher) => Effect.tryPromise({
|
|
761
|
+
try: async () => {
|
|
762
|
+
if (!domChannel?.blockNetwork) {
|
|
763
|
+
throw new Error(
|
|
764
|
+
"blockNetwork() is not supported on native Android traffic; enable WebView debugging or install spana-bridge for WebView requests"
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
await domChannel.blockNetwork(matcher);
|
|
768
|
+
},
|
|
769
|
+
catch: (e) => new DriverError({ message: `blockNetwork failed: ${e}` })
|
|
770
|
+
}),
|
|
771
|
+
clearNetworkMocks: () => Effect.tryPromise({
|
|
772
|
+
try: async () => {
|
|
773
|
+
if (domChannel?.clearNetworkMocks) {
|
|
774
|
+
await domChannel.clearNetworkMocks();
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
catch: (e) => new DriverError({ message: `clearNetworkMocks failed: ${e}` })
|
|
778
|
+
}),
|
|
779
|
+
getConsoleLogs: () => Effect.tryPromise({
|
|
780
|
+
try: async () => domChannel?.getConsoleLogs ? domChannel.getConsoleLogs() : [],
|
|
781
|
+
catch: (e) => new DriverError({ message: `getConsoleLogs failed: ${e}` })
|
|
782
|
+
}),
|
|
783
|
+
getJSErrors: () => Effect.tryPromise({
|
|
784
|
+
try: async () => domChannel?.getJSErrors ? domChannel.getJSErrors() : [],
|
|
785
|
+
catch: (e) => new DriverError({ message: `getJSErrors failed: ${e}` })
|
|
786
|
+
}),
|
|
787
|
+
// -----------------------------------------------------------------------
|
|
788
|
+
// Network conditions
|
|
789
|
+
// -----------------------------------------------------------------------
|
|
790
|
+
setNetworkConditions: (conditions) => Effect.tryPromise({
|
|
791
|
+
try: async () => {
|
|
792
|
+
const isEmulator = serial.startsWith("emulator-");
|
|
793
|
+
const resolved = resolveNetworkConditions(conditions);
|
|
794
|
+
const hasThrottling = conditions.profile !== void 0 || conditions.latencyMs !== void 0 || conditions.downloadThroughputKbps !== void 0 || conditions.uploadThroughputKbps !== void 0;
|
|
795
|
+
if (!resolved.offline && !hasThrottling) {
|
|
796
|
+
if (isEmulator) {
|
|
797
|
+
adbResetNetwork(serial);
|
|
798
|
+
} else {
|
|
799
|
+
adbSetAirplaneMode(serial, false);
|
|
800
|
+
}
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
if (resolved.offline) {
|
|
804
|
+
if (isEmulator) {
|
|
805
|
+
adbSetWifi(serial, false);
|
|
806
|
+
adbSetData(serial, false);
|
|
807
|
+
} else {
|
|
808
|
+
adbSetAirplaneMode(serial, true);
|
|
809
|
+
}
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
if (hasThrottling) {
|
|
813
|
+
if (!isEmulator) {
|
|
814
|
+
throw new DriverError({
|
|
815
|
+
message: "Network throttling is not supported on physical Android devices. Use an emulator or a cloud provider."
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
adbSetWifi(serial, true);
|
|
819
|
+
adbSetData(serial, true);
|
|
820
|
+
if (conditions.profile) {
|
|
821
|
+
adbSetNetworkProfile(serial, conditions.profile);
|
|
822
|
+
} else {
|
|
823
|
+
adbSetCustomNetwork(
|
|
824
|
+
serial,
|
|
825
|
+
resolved.downloadThroughputKbps,
|
|
826
|
+
resolved.uploadThroughputKbps,
|
|
827
|
+
resolved.latencyMs
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
},
|
|
832
|
+
catch: (e) => {
|
|
833
|
+
if (e instanceof DriverError) return e;
|
|
834
|
+
return new DriverError({ message: `setNetworkConditions failed: ${e}` });
|
|
835
|
+
}
|
|
836
|
+
})
|
|
837
|
+
};
|
|
838
|
+
return service;
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
export {
|
|
843
|
+
createUiAutomator2Driver
|
|
844
|
+
};
|
|
845
|
+
//# sourceMappingURL=chunk-27H6NDA5.js.map
|