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,1046 @@
|
|
|
1
|
+
import {
|
|
2
|
+
installedUrlSchemesOnSimulator,
|
|
3
|
+
launchOnSimulator,
|
|
4
|
+
launchWithUrlOnSimulator,
|
|
5
|
+
pfctlResetNetwork,
|
|
6
|
+
pfctlSetOffline,
|
|
7
|
+
pfctlSetThrottle,
|
|
8
|
+
resetSimulatorKeychain,
|
|
9
|
+
terminateOnSimulator
|
|
10
|
+
} from "./chunk-2MA5G2VH.js";
|
|
11
|
+
import {
|
|
12
|
+
createWebKitInspectorChannel
|
|
13
|
+
} from "./chunk-LKGF75QJ.js";
|
|
14
|
+
import {
|
|
15
|
+
deviceEffect,
|
|
16
|
+
iosSimulatorControls
|
|
17
|
+
} from "./chunk-HWS3XUEF.js";
|
|
18
|
+
import {
|
|
19
|
+
resolveNetworkConditions
|
|
20
|
+
} from "./chunk-HNQLWFHL.js";
|
|
21
|
+
import {
|
|
22
|
+
createCompositeDomChannel
|
|
23
|
+
} from "./chunk-DMF2BPPA.js";
|
|
24
|
+
import {
|
|
25
|
+
splitGraphemes
|
|
26
|
+
} from "./chunk-MUMIMDRJ.js";
|
|
27
|
+
import {
|
|
28
|
+
hasLaunchDeviceState
|
|
29
|
+
} from "./chunk-NWGA3R2E.js";
|
|
30
|
+
import {
|
|
31
|
+
DriverError
|
|
32
|
+
} from "./chunk-A7Z52TDQ.js";
|
|
33
|
+
import {
|
|
34
|
+
init_esm_shims
|
|
35
|
+
} from "./chunk-FTXUQMGH.js";
|
|
36
|
+
|
|
37
|
+
// src/drivers/wda/driver.ts
|
|
38
|
+
init_esm_shims();
|
|
39
|
+
import { Effect } from "effect";
|
|
40
|
+
|
|
41
|
+
// src/drivers/wda/client.ts
|
|
42
|
+
init_esm_shims();
|
|
43
|
+
var WDAClient = class {
|
|
44
|
+
baseUrl;
|
|
45
|
+
sessionId = null;
|
|
46
|
+
constructor(host, port) {
|
|
47
|
+
this.baseUrl = `http://${host}:${port}`;
|
|
48
|
+
}
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// HTTP helpers
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
async request(method, path, body) {
|
|
53
|
+
const url = `${this.baseUrl}${path}`;
|
|
54
|
+
const init = {
|
|
55
|
+
method,
|
|
56
|
+
headers: { "Content-Type": "application/json" }
|
|
57
|
+
};
|
|
58
|
+
if (body !== void 0) {
|
|
59
|
+
init.body = JSON.stringify(body);
|
|
60
|
+
}
|
|
61
|
+
const res = await fetch(url, init);
|
|
62
|
+
const text = await res.text();
|
|
63
|
+
let parsed;
|
|
64
|
+
try {
|
|
65
|
+
parsed = JSON.parse(text);
|
|
66
|
+
} catch {
|
|
67
|
+
throw new Error(`WDA: failed to parse response: ${text}`);
|
|
68
|
+
}
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
const val = parsed.value;
|
|
71
|
+
const msg = val?.message ?? val?.error ?? text;
|
|
72
|
+
throw new Error(`WDA ${method} ${path} \u2192 ${res.status}: ${msg}`);
|
|
73
|
+
}
|
|
74
|
+
if (parsed.value !== null && typeof parsed.value === "object" && "error" in parsed.value) {
|
|
75
|
+
const val = parsed.value;
|
|
76
|
+
throw new Error(`WDA error: ${val.message ?? val.error}`);
|
|
77
|
+
}
|
|
78
|
+
return parsed.value;
|
|
79
|
+
}
|
|
80
|
+
sessionPath(path) {
|
|
81
|
+
if (this.sessionId === null) {
|
|
82
|
+
throw new Error("WDA: no active session");
|
|
83
|
+
}
|
|
84
|
+
return `/session/${this.sessionId}${path}`;
|
|
85
|
+
}
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// Session management
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new WDA session.
|
|
91
|
+
*
|
|
92
|
+
* @param bundleId - the app bundle ID to attach to (e.g. "com.example.app")
|
|
93
|
+
* @param alertAction - optional auto-alert handling: "accept" | "dismiss"
|
|
94
|
+
*/
|
|
95
|
+
async createSession(bundleId, alertAction) {
|
|
96
|
+
const alwaysMatch = {
|
|
97
|
+
shouldWaitForQuiescence: false,
|
|
98
|
+
waitForIdleTimeout: 0,
|
|
99
|
+
shouldUseTestManagerForVisibilityDetection: false
|
|
100
|
+
};
|
|
101
|
+
if (bundleId) {
|
|
102
|
+
alwaysMatch["bundleId"] = bundleId;
|
|
103
|
+
}
|
|
104
|
+
if (alertAction) {
|
|
105
|
+
alwaysMatch["defaultAlertAction"] = alertAction;
|
|
106
|
+
}
|
|
107
|
+
const res = await fetch(`${this.baseUrl}/session`, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: { "Content-Type": "application/json" },
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
capabilities: { alwaysMatch }
|
|
112
|
+
})
|
|
113
|
+
});
|
|
114
|
+
const text = await res.text();
|
|
115
|
+
let parsed;
|
|
116
|
+
try {
|
|
117
|
+
parsed = JSON.parse(text);
|
|
118
|
+
} catch {
|
|
119
|
+
throw new Error(`WDA: failed to parse session response: ${text}`);
|
|
120
|
+
}
|
|
121
|
+
if (!res.ok) {
|
|
122
|
+
const val = parsed["value"];
|
|
123
|
+
throw new Error(`WDA: failed to create session: ${val?.message ?? text}`);
|
|
124
|
+
}
|
|
125
|
+
let sessionId = parsed["sessionId"] ?? parsed["value"]?.["sessionId"];
|
|
126
|
+
if (!sessionId) {
|
|
127
|
+
throw new Error("WDA: no sessionId in session response");
|
|
128
|
+
}
|
|
129
|
+
this.sessionId = sessionId;
|
|
130
|
+
return sessionId;
|
|
131
|
+
}
|
|
132
|
+
async deleteSession() {
|
|
133
|
+
if (this.sessionId === null) return;
|
|
134
|
+
const path = `/session/${this.sessionId}`;
|
|
135
|
+
try {
|
|
136
|
+
await fetch(`${this.baseUrl}${path}`, { method: "DELETE" });
|
|
137
|
+
} finally {
|
|
138
|
+
this.sessionId = null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
hasSession() {
|
|
142
|
+
return this.sessionId !== null;
|
|
143
|
+
}
|
|
144
|
+
sessionID() {
|
|
145
|
+
return this.sessionId;
|
|
146
|
+
}
|
|
147
|
+
/** Reattach to an existing warm WDA session ID without paying `POST /session` latency. */
|
|
148
|
+
attachSession(sessionId) {
|
|
149
|
+
this.sessionId = sessionId;
|
|
150
|
+
}
|
|
151
|
+
/** Probe whether the currently attached session still responds cleanly. */
|
|
152
|
+
async isSessionAlive() {
|
|
153
|
+
if (!this.sessionId) return false;
|
|
154
|
+
try {
|
|
155
|
+
await this.getWindowSize();
|
|
156
|
+
return true;
|
|
157
|
+
} catch {
|
|
158
|
+
this.sessionId = null;
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
// Settings
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
async updateSettings(settings) {
|
|
166
|
+
await this.request("POST", this.sessionPath("/appium/settings"), {
|
|
167
|
+
settings
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
async disableQuiescence() {
|
|
171
|
+
await this.updateSettings({
|
|
172
|
+
shouldWaitForQuiescence: false,
|
|
173
|
+
waitForIdleTimeout: 0
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Sets the maximum depth for UI hierarchy snapshots.
|
|
178
|
+
* Higher values (e.g. 100) are required for deeply nested React Native apps.
|
|
179
|
+
*/
|
|
180
|
+
async setSnapshotMaxDepth(depth) {
|
|
181
|
+
await this.updateSettings({ snapshotMaxDepth: depth });
|
|
182
|
+
}
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
184
|
+
// Screen queries
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
/** Returns the UI hierarchy as XML. */
|
|
187
|
+
async getSource() {
|
|
188
|
+
const value = await this.request("GET", this.sessionPath("/source"));
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Captures the screen and returns PNG bytes.
|
|
193
|
+
*
|
|
194
|
+
* The Go client calls GET /session/{id}/screenshot (session-prefixed) and
|
|
195
|
+
* decodes the base64 value. We follow the same pattern.
|
|
196
|
+
*/
|
|
197
|
+
async getScreenshot() {
|
|
198
|
+
const base64 = await this.request("GET", this.sessionPath("/screenshot"));
|
|
199
|
+
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
200
|
+
}
|
|
201
|
+
/** Returns the screen dimensions in logical points. */
|
|
202
|
+
async getWindowSize() {
|
|
203
|
+
const value = await this.request(
|
|
204
|
+
"GET",
|
|
205
|
+
this.sessionPath("/window/size")
|
|
206
|
+
);
|
|
207
|
+
return value;
|
|
208
|
+
}
|
|
209
|
+
async setOrientation(orientation) {
|
|
210
|
+
await this.request("POST", this.sessionPath("/orientation"), { orientation });
|
|
211
|
+
}
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
// Touch actions — WDA-specific endpoints
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
async tap(x, y) {
|
|
216
|
+
await this.request("POST", this.sessionPath("/wda/tap"), { x, y });
|
|
217
|
+
}
|
|
218
|
+
async doubleTap(x, y) {
|
|
219
|
+
const rx = Math.round(x);
|
|
220
|
+
const ry = Math.round(y);
|
|
221
|
+
const singleTap = [
|
|
222
|
+
{
|
|
223
|
+
type: "pointer",
|
|
224
|
+
id: "finger1",
|
|
225
|
+
parameters: { pointerType: "touch" },
|
|
226
|
+
actions: [
|
|
227
|
+
{ type: "pointerMove", duration: 0, x: rx, y: ry },
|
|
228
|
+
{ type: "pointerDown", button: 0 },
|
|
229
|
+
{ type: "pointerUp", button: 0 }
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
];
|
|
233
|
+
await this.request("POST", this.sessionPath("/actions"), { actions: singleTap });
|
|
234
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
235
|
+
await this.request("POST", this.sessionPath("/actions"), { actions: singleTap });
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Long-presses at coordinates.
|
|
239
|
+
*
|
|
240
|
+
* @param durationSec - hold duration in **seconds** (WDA convention)
|
|
241
|
+
*/
|
|
242
|
+
async longPress(x, y, durationSec) {
|
|
243
|
+
await this.request("POST", this.sessionPath("/wda/touchAndHold"), {
|
|
244
|
+
x,
|
|
245
|
+
y,
|
|
246
|
+
duration: durationSec
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Swipes from one point to another.
|
|
251
|
+
*
|
|
252
|
+
* @param durationSec - gesture duration in **seconds** (WDA convention)
|
|
253
|
+
*/
|
|
254
|
+
async swipe(fromX, fromY, toX, toY, durationSec) {
|
|
255
|
+
await this.request("POST", this.sessionPath("/wda/dragfromtoforduration"), {
|
|
256
|
+
fromX,
|
|
257
|
+
fromY,
|
|
258
|
+
toX,
|
|
259
|
+
toY,
|
|
260
|
+
duration: durationSec
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Pinch gesture (zoom out) — two fingers move toward center.
|
|
265
|
+
*
|
|
266
|
+
* @param cx - center X coordinate
|
|
267
|
+
* @param cy - center Y coordinate
|
|
268
|
+
* @param scale - 0..1 representing how far fingers start from center (as fraction of 200px)
|
|
269
|
+
* @param durationSec - gesture duration in seconds (WDA convention)
|
|
270
|
+
*/
|
|
271
|
+
async pinch(cx, cy, scale, durationSec) {
|
|
272
|
+
const dist = 200 * scale;
|
|
273
|
+
const durationMs = durationSec * 1e3;
|
|
274
|
+
await this.request("POST", this.sessionPath("/actions"), {
|
|
275
|
+
actions: [
|
|
276
|
+
{
|
|
277
|
+
type: "pointer",
|
|
278
|
+
id: "finger1",
|
|
279
|
+
parameters: { pointerType: "touch" },
|
|
280
|
+
actions: [
|
|
281
|
+
{ type: "pointerMove", duration: 0, x: Math.round(cx - dist), y: Math.round(cy) },
|
|
282
|
+
{ type: "pointerDown", button: 0 },
|
|
283
|
+
{
|
|
284
|
+
type: "pointerMove",
|
|
285
|
+
duration: durationMs,
|
|
286
|
+
x: Math.round(cx - 10),
|
|
287
|
+
y: Math.round(cy)
|
|
288
|
+
},
|
|
289
|
+
{ type: "pointerUp", button: 0 }
|
|
290
|
+
]
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
type: "pointer",
|
|
294
|
+
id: "finger2",
|
|
295
|
+
parameters: { pointerType: "touch" },
|
|
296
|
+
actions: [
|
|
297
|
+
{ type: "pointerMove", duration: 0, x: Math.round(cx + dist), y: Math.round(cy) },
|
|
298
|
+
{ type: "pointerDown", button: 0 },
|
|
299
|
+
{
|
|
300
|
+
type: "pointerMove",
|
|
301
|
+
duration: durationMs,
|
|
302
|
+
x: Math.round(cx + 10),
|
|
303
|
+
y: Math.round(cy)
|
|
304
|
+
},
|
|
305
|
+
{ type: "pointerUp", button: 0 }
|
|
306
|
+
]
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Zoom gesture (zoom in) — two fingers move away from center.
|
|
313
|
+
*
|
|
314
|
+
* @param cx - center X coordinate
|
|
315
|
+
* @param cy - center Y coordinate
|
|
316
|
+
* @param scale - 0..1 representing how far fingers end from center (as fraction of 200px)
|
|
317
|
+
* @param durationSec - gesture duration in seconds (WDA convention)
|
|
318
|
+
*/
|
|
319
|
+
async zoom(cx, cy, scale, durationSec) {
|
|
320
|
+
const dist = 200 * scale;
|
|
321
|
+
const durationMs = durationSec * 1e3;
|
|
322
|
+
await this.request("POST", this.sessionPath("/actions"), {
|
|
323
|
+
actions: [
|
|
324
|
+
{
|
|
325
|
+
type: "pointer",
|
|
326
|
+
id: "finger1",
|
|
327
|
+
parameters: { pointerType: "touch" },
|
|
328
|
+
actions: [
|
|
329
|
+
{ type: "pointerMove", duration: 0, x: Math.round(cx - 10), y: Math.round(cy) },
|
|
330
|
+
{ type: "pointerDown", button: 0 },
|
|
331
|
+
{
|
|
332
|
+
type: "pointerMove",
|
|
333
|
+
duration: durationMs,
|
|
334
|
+
x: Math.round(cx - dist),
|
|
335
|
+
y: Math.round(cy)
|
|
336
|
+
},
|
|
337
|
+
{ type: "pointerUp", button: 0 }
|
|
338
|
+
]
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
type: "pointer",
|
|
342
|
+
id: "finger2",
|
|
343
|
+
parameters: { pointerType: "touch" },
|
|
344
|
+
actions: [
|
|
345
|
+
{ type: "pointerMove", duration: 0, x: Math.round(cx + 10), y: Math.round(cy) },
|
|
346
|
+
{ type: "pointerDown", button: 0 },
|
|
347
|
+
{
|
|
348
|
+
type: "pointerMove",
|
|
349
|
+
duration: durationMs,
|
|
350
|
+
x: Math.round(cx + dist),
|
|
351
|
+
y: Math.round(cy)
|
|
352
|
+
},
|
|
353
|
+
{ type: "pointerUp", button: 0 }
|
|
354
|
+
]
|
|
355
|
+
}
|
|
356
|
+
]
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Arbitrary multi-touch gesture using W3C Actions.
|
|
361
|
+
*/
|
|
362
|
+
async multiTouch(sequences) {
|
|
363
|
+
const actions = sequences.map((seq) => ({
|
|
364
|
+
type: "pointer",
|
|
365
|
+
id: `finger${seq.id}`,
|
|
366
|
+
parameters: { pointerType: "touch" },
|
|
367
|
+
actions: seq.actions.map((a) => {
|
|
368
|
+
switch (a.type) {
|
|
369
|
+
case "move":
|
|
370
|
+
return {
|
|
371
|
+
type: "pointerMove",
|
|
372
|
+
duration: a.duration ?? 0,
|
|
373
|
+
x: Math.round(a.x),
|
|
374
|
+
y: Math.round(a.y)
|
|
375
|
+
};
|
|
376
|
+
case "down":
|
|
377
|
+
return { type: "pointerDown", button: 0 };
|
|
378
|
+
case "up":
|
|
379
|
+
return { type: "pointerUp", button: 0 };
|
|
380
|
+
case "pause":
|
|
381
|
+
return { type: "pause", duration: a.duration };
|
|
382
|
+
}
|
|
383
|
+
})
|
|
384
|
+
}));
|
|
385
|
+
await this.request("POST", this.sessionPath("/actions"), { actions });
|
|
386
|
+
}
|
|
387
|
+
// ---------------------------------------------------------------------------
|
|
388
|
+
// Text / keyboard
|
|
389
|
+
// ---------------------------------------------------------------------------
|
|
390
|
+
/**
|
|
391
|
+
* Types text. WDA expects the value as an array of individual characters.
|
|
392
|
+
*
|
|
393
|
+
* @param frequency - typing speed in keys/sec (0 = WDA default ~60/s)
|
|
394
|
+
*/
|
|
395
|
+
async sendKeys(text, frequency = 25) {
|
|
396
|
+
const body = {
|
|
397
|
+
value: splitGraphemes(text)
|
|
398
|
+
};
|
|
399
|
+
if (frequency > 0) {
|
|
400
|
+
body["frequency"] = frequency;
|
|
401
|
+
}
|
|
402
|
+
await this.request("POST", this.sessionPath("/wda/keys"), body);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Presses a hardware button by name.
|
|
406
|
+
*
|
|
407
|
+
* @param button - "home" | "volumeUp" | "volumeDown"
|
|
408
|
+
*/
|
|
409
|
+
async pressButton(button) {
|
|
410
|
+
await this.request("POST", this.sessionPath("/wda/pressButton"), {
|
|
411
|
+
name: button
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
async pressHome() {
|
|
415
|
+
await this.pressButton("home");
|
|
416
|
+
}
|
|
417
|
+
// ---------------------------------------------------------------------------
|
|
418
|
+
// App lifecycle
|
|
419
|
+
// ---------------------------------------------------------------------------
|
|
420
|
+
async launchApp(bundleId, args) {
|
|
421
|
+
const body = { bundleId };
|
|
422
|
+
if (args && args.length > 0) {
|
|
423
|
+
body["arguments"] = args;
|
|
424
|
+
}
|
|
425
|
+
await this.request("POST", this.sessionPath("/wda/apps/launch"), body);
|
|
426
|
+
}
|
|
427
|
+
async terminateApp(bundleId) {
|
|
428
|
+
await this.request("POST", this.sessionPath("/wda/apps/terminate"), {
|
|
429
|
+
bundleId
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
async activateApp(bundleId) {
|
|
433
|
+
await this.request("POST", this.sessionPath("/wda/apps/activate"), {
|
|
434
|
+
bundleId
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
// ---------------------------------------------------------------------------
|
|
438
|
+
// Deep link / URL
|
|
439
|
+
// ---------------------------------------------------------------------------
|
|
440
|
+
/** Opens a URL or deep link. Works for both simulator and real device. */
|
|
441
|
+
async openUrl(url) {
|
|
442
|
+
await this.request("POST", this.sessionPath("/url"), { url });
|
|
443
|
+
}
|
|
444
|
+
// ---------------------------------------------------------------------------
|
|
445
|
+
// Alerts
|
|
446
|
+
// ---------------------------------------------------------------------------
|
|
447
|
+
async acceptAlert() {
|
|
448
|
+
await this.request("POST", this.sessionPath("/alert/accept"), void 0);
|
|
449
|
+
}
|
|
450
|
+
async dismissAlert() {
|
|
451
|
+
await this.request("POST", this.sessionPath("/alert/dismiss"), void 0);
|
|
452
|
+
}
|
|
453
|
+
// ---------------------------------------------------------------------------
|
|
454
|
+
// Device status
|
|
455
|
+
// ---------------------------------------------------------------------------
|
|
456
|
+
async getStatus() {
|
|
457
|
+
return this.request("GET", "/status");
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
// src/drivers/wda/driver.ts
|
|
462
|
+
function msToSec(ms) {
|
|
463
|
+
return ms / 1e3;
|
|
464
|
+
}
|
|
465
|
+
function sleep(ms) {
|
|
466
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
467
|
+
}
|
|
468
|
+
function replaceUrlScheme(url, scheme) {
|
|
469
|
+
const match = url.match(/^([a-zA-Z][a-zA-Z0-9+.-]*):(\/\/.*)$/);
|
|
470
|
+
if (!match) return null;
|
|
471
|
+
return `${scheme}:${match[2]}`;
|
|
472
|
+
}
|
|
473
|
+
function isSessionError(error) {
|
|
474
|
+
const msg = String(error).toLowerCase();
|
|
475
|
+
return msg.includes("session does not exist") || msg.includes("unable to connect") || msg.includes("no active session") || msg.includes("invalid session") || /status[:\s]*404/.test(msg);
|
|
476
|
+
}
|
|
477
|
+
function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth = 100, driverOptions) {
|
|
478
|
+
return Effect.gen(function* () {
|
|
479
|
+
const client = new WDAClient(host, port);
|
|
480
|
+
let currentContext = "NATIVE_APP";
|
|
481
|
+
let hasLaunchedOnce = false;
|
|
482
|
+
const waitForWdaReady = async (maxMs) => {
|
|
483
|
+
const deadline = Date.now() + maxMs;
|
|
484
|
+
while (Date.now() < deadline) {
|
|
485
|
+
try {
|
|
486
|
+
await client.getWindowSize();
|
|
487
|
+
return;
|
|
488
|
+
} catch {
|
|
489
|
+
await sleep(40);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
const inspectorChannel = createWebKitInspectorChannel({
|
|
494
|
+
endpointUrl: driverOptions?.webkitInspectorUrl,
|
|
495
|
+
port: driverOptions?.webkitInspectorPort,
|
|
496
|
+
udid: simulatorUdid,
|
|
497
|
+
bundleId: bundleId || void 0,
|
|
498
|
+
autoStartProxy: driverOptions?.autoStartInspectorProxy ?? false
|
|
499
|
+
});
|
|
500
|
+
const domChannel = driverOptions?.domChannel ? createCompositeDomChannel([driverOptions.domChannel, inspectorChannel]) : inspectorChannel;
|
|
501
|
+
const createSessionWithRetry = async (targetBundleId) => {
|
|
502
|
+
let lastError;
|
|
503
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
504
|
+
try {
|
|
505
|
+
return await client.createSession(targetBundleId);
|
|
506
|
+
} catch (error) {
|
|
507
|
+
lastError = error;
|
|
508
|
+
if (attempt === 4) {
|
|
509
|
+
throw error;
|
|
510
|
+
}
|
|
511
|
+
await sleep(1e3);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
throw lastError ?? new Error("Failed to create WDA session");
|
|
515
|
+
};
|
|
516
|
+
const withSessionRecovery = async (fn) => {
|
|
517
|
+
try {
|
|
518
|
+
return await fn();
|
|
519
|
+
} catch (error) {
|
|
520
|
+
if (!isSessionError(error)) throw error;
|
|
521
|
+
try {
|
|
522
|
+
await client.deleteSession();
|
|
523
|
+
} catch {
|
|
524
|
+
}
|
|
525
|
+
await createSessionWithRetry(bundleId || void 0);
|
|
526
|
+
try {
|
|
527
|
+
await client.disableQuiescence();
|
|
528
|
+
} catch {
|
|
529
|
+
}
|
|
530
|
+
return await fn();
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
const activateSimulatorApp = async (targetBundleId) => {
|
|
534
|
+
if (!targetBundleId) return;
|
|
535
|
+
await client.activateApp(targetBundleId);
|
|
536
|
+
await waitForWdaReady(400);
|
|
537
|
+
};
|
|
538
|
+
const openSimulatorUrl = async (url, targetBundleId = bundleId) => {
|
|
539
|
+
if (!simulatorUdid) {
|
|
540
|
+
await client.openUrl(url);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
try {
|
|
544
|
+
await activateSimulatorApp(targetBundleId);
|
|
545
|
+
await client.openUrl(url);
|
|
546
|
+
await waitForWdaReady(400);
|
|
547
|
+
return;
|
|
548
|
+
} catch {
|
|
549
|
+
try {
|
|
550
|
+
await client.deleteSession();
|
|
551
|
+
} catch {
|
|
552
|
+
}
|
|
553
|
+
try {
|
|
554
|
+
await createSessionWithRetry(targetBundleId);
|
|
555
|
+
await client.disableQuiescence();
|
|
556
|
+
await activateSimulatorApp(targetBundleId);
|
|
557
|
+
await client.openUrl(url);
|
|
558
|
+
await waitForWdaReady(400);
|
|
559
|
+
return;
|
|
560
|
+
} catch {
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
const fallbackSchemes = installedUrlSchemesOnSimulator(simulatorUdid, targetBundleId);
|
|
564
|
+
const candidates = [
|
|
565
|
+
url,
|
|
566
|
+
...fallbackSchemes.map((scheme) => replaceUrlScheme(url, scheme)).filter((candidate) => Boolean(candidate))
|
|
567
|
+
].filter((candidate, index, all) => all.indexOf(candidate) === index);
|
|
568
|
+
let lastError;
|
|
569
|
+
for (const candidate of candidates) {
|
|
570
|
+
try {
|
|
571
|
+
terminateOnSimulator(simulatorUdid, targetBundleId);
|
|
572
|
+
await sleep(500);
|
|
573
|
+
launchWithUrlOnSimulator(simulatorUdid, targetBundleId, candidate);
|
|
574
|
+
await sleep(1500);
|
|
575
|
+
try {
|
|
576
|
+
await client.deleteSession();
|
|
577
|
+
} catch {
|
|
578
|
+
}
|
|
579
|
+
await createSessionWithRetry(targetBundleId);
|
|
580
|
+
await client.disableQuiescence();
|
|
581
|
+
await activateSimulatorApp(targetBundleId);
|
|
582
|
+
return;
|
|
583
|
+
} catch (error) {
|
|
584
|
+
lastError = error;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if (!client.hasSession()) {
|
|
588
|
+
try {
|
|
589
|
+
await createSessionWithRetry(targetBundleId);
|
|
590
|
+
await client.disableQuiescence();
|
|
591
|
+
} catch {
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
throw lastError ?? new Error(`Failed to open URL: ${url}`);
|
|
595
|
+
};
|
|
596
|
+
let reusedWarmSession = false;
|
|
597
|
+
if (driverOptions?.warmSessionId && typeof client.attachSession === "function") {
|
|
598
|
+
client.attachSession(driverOptions.warmSessionId);
|
|
599
|
+
const alive = yield* Effect.tryPromise({
|
|
600
|
+
try: () => client.isSessionAlive(),
|
|
601
|
+
catch: () => false
|
|
602
|
+
}).pipe(Effect.catch(() => Effect.succeed(false)));
|
|
603
|
+
reusedWarmSession = alive;
|
|
604
|
+
}
|
|
605
|
+
if (!reusedWarmSession) {
|
|
606
|
+
const createdId = yield* Effect.tryPromise({
|
|
607
|
+
try: () => createSessionWithRetry(bundleId || void 0),
|
|
608
|
+
catch: (e) => new DriverError({ message: `Failed to create WDA session: ${e}` })
|
|
609
|
+
});
|
|
610
|
+
driverOptions?.onSessionCreated?.(createdId);
|
|
611
|
+
yield* Effect.tryPromise({
|
|
612
|
+
try: () => client.disableQuiescence(),
|
|
613
|
+
catch: (e) => new DriverError({ message: `Failed to disable quiescence: ${e}` })
|
|
614
|
+
});
|
|
615
|
+
yield* Effect.tryPromise({
|
|
616
|
+
try: () => client.setSnapshotMaxDepth(snapshotMaxDepth),
|
|
617
|
+
catch: (e) => new DriverError({ message: `Failed to set snapshot depth: ${e}` })
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
const service = {
|
|
621
|
+
...iosSimulatorControls(simulatorUdid),
|
|
622
|
+
setOrientation: (orientation) => deviceEffect(
|
|
623
|
+
"setOrientation",
|
|
624
|
+
() => withSessionRecovery(
|
|
625
|
+
() => client.setOrientation(orientation === "portrait" ? "PORTRAIT" : "LANDSCAPE")
|
|
626
|
+
)
|
|
627
|
+
),
|
|
628
|
+
domChannel,
|
|
629
|
+
// -----------------------------------------------------------------------
|
|
630
|
+
// Hierarchy
|
|
631
|
+
// -----------------------------------------------------------------------
|
|
632
|
+
dumpHierarchy: () => Effect.tryPromise({
|
|
633
|
+
try: () => withSessionRecovery(() => client.getSource()),
|
|
634
|
+
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
635
|
+
}),
|
|
636
|
+
// -----------------------------------------------------------------------
|
|
637
|
+
// Coordinate-level actions
|
|
638
|
+
// -----------------------------------------------------------------------
|
|
639
|
+
tapAtCoordinate: (x, y) => Effect.tryPromise({
|
|
640
|
+
try: () => withSessionRecovery(() => client.tap(x, y)),
|
|
641
|
+
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
642
|
+
}),
|
|
643
|
+
doubleTapAtCoordinate: (x, y) => Effect.tryPromise({
|
|
644
|
+
try: () => withSessionRecovery(() => client.doubleTap(x, y)),
|
|
645
|
+
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
646
|
+
}),
|
|
647
|
+
longPressAtCoordinate: (x, y, duration) => Effect.tryPromise({
|
|
648
|
+
// duration arrives in ms (spana convention) → convert to seconds for WDA
|
|
649
|
+
try: () => withSessionRecovery(() => client.longPress(x, y, msToSec(duration))),
|
|
650
|
+
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
651
|
+
}),
|
|
652
|
+
swipe: (sx, sy, ex, ey, dur) => Effect.tryPromise({
|
|
653
|
+
// dur arrives in ms → convert to seconds for WDA.
|
|
654
|
+
// Clamp Y to avoid iOS system gesture zones (home indicator / App Switcher).
|
|
655
|
+
try: async () => {
|
|
656
|
+
let csy = sy;
|
|
657
|
+
let cey = ey;
|
|
658
|
+
try {
|
|
659
|
+
const size = await client.getWindowSize();
|
|
660
|
+
const minY = size.height * 0.15;
|
|
661
|
+
const maxY = size.height * 0.85;
|
|
662
|
+
csy = Math.max(minY, Math.min(maxY, sy));
|
|
663
|
+
cey = Math.max(minY, Math.min(maxY, ey));
|
|
664
|
+
} catch {
|
|
665
|
+
}
|
|
666
|
+
await client.swipe(sx, csy, ex, cey, msToSec(dur));
|
|
667
|
+
},
|
|
668
|
+
catch: (e) => new DriverError({ message: `Swipe failed: ${e}` })
|
|
669
|
+
}),
|
|
670
|
+
pinch: (cx, cy, scale, duration) => Effect.tryPromise({
|
|
671
|
+
try: () => withSessionRecovery(() => client.pinch(cx, cy, scale, msToSec(duration))),
|
|
672
|
+
catch: (e) => new DriverError({ message: `Pinch failed: ${e}` })
|
|
673
|
+
}),
|
|
674
|
+
zoom: (cx, cy, scale, duration) => Effect.tryPromise({
|
|
675
|
+
try: () => withSessionRecovery(() => client.zoom(cx, cy, scale, msToSec(duration))),
|
|
676
|
+
catch: (e) => new DriverError({ message: `Zoom failed: ${e}` })
|
|
677
|
+
}),
|
|
678
|
+
multiTouch: (sequences) => Effect.tryPromise({
|
|
679
|
+
try: () => withSessionRecovery(() => client.multiTouch(sequences)),
|
|
680
|
+
catch: (e) => new DriverError({ message: `Multi-touch failed: ${e}` })
|
|
681
|
+
}),
|
|
682
|
+
// -----------------------------------------------------------------------
|
|
683
|
+
// Text input
|
|
684
|
+
// -----------------------------------------------------------------------
|
|
685
|
+
inputText: (text) => Effect.tryPromise({
|
|
686
|
+
try: () => withSessionRecovery(() => client.sendKeys(text)),
|
|
687
|
+
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
688
|
+
}),
|
|
689
|
+
pressKey: (key) => Effect.tryPromise({
|
|
690
|
+
// WDA uses named hardware buttons; map common names, fall back to home
|
|
691
|
+
try: async () => {
|
|
692
|
+
const buttonMap = {
|
|
693
|
+
home: "home",
|
|
694
|
+
volumeup: "volumeUp",
|
|
695
|
+
volumedown: "volumeDown"
|
|
696
|
+
};
|
|
697
|
+
const button = buttonMap[key.toLowerCase()];
|
|
698
|
+
if (button) {
|
|
699
|
+
await client.pressButton(button);
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
703
|
+
}),
|
|
704
|
+
hideKeyboard: () => Effect.tryPromise({
|
|
705
|
+
// Dismiss keyboard by tapping above the keyboard area.
|
|
706
|
+
// The previous approach (pressHome) backgrounds the app on iOS.
|
|
707
|
+
try: async () => {
|
|
708
|
+
const size = await client.getWindowSize();
|
|
709
|
+
await client.tap(size.width / 2, Math.round(size.height * 0.2));
|
|
710
|
+
await sleep(300);
|
|
711
|
+
},
|
|
712
|
+
catch: (e) => new DriverError({ message: `Hide keyboard failed: ${e}` })
|
|
713
|
+
}),
|
|
714
|
+
// -----------------------------------------------------------------------
|
|
715
|
+
// Queries
|
|
716
|
+
// -----------------------------------------------------------------------
|
|
717
|
+
takeScreenshot: () => Effect.tryPromise({
|
|
718
|
+
try: () => withSessionRecovery(() => client.getScreenshot()),
|
|
719
|
+
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
720
|
+
}),
|
|
721
|
+
getDeviceInfo: () => Effect.tryPromise({
|
|
722
|
+
try: async () => {
|
|
723
|
+
const size = await withSessionRecovery(() => client.getWindowSize());
|
|
724
|
+
return {
|
|
725
|
+
platform: "ios",
|
|
726
|
+
deviceId: `${host}:${port}`,
|
|
727
|
+
name: "iOS Device",
|
|
728
|
+
isEmulator: host === "localhost" || host === "127.0.0.1",
|
|
729
|
+
screenWidth: size.width,
|
|
730
|
+
screenHeight: size.height,
|
|
731
|
+
driverType: "wda"
|
|
732
|
+
};
|
|
733
|
+
},
|
|
734
|
+
catch: (e) => new DriverError({ message: `Get device info failed: ${e}` })
|
|
735
|
+
}),
|
|
736
|
+
// -----------------------------------------------------------------------
|
|
737
|
+
// App lifecycle
|
|
738
|
+
// -----------------------------------------------------------------------
|
|
739
|
+
launchApp: (appBundleId, opts) => Effect.tryPromise({
|
|
740
|
+
try: async () => {
|
|
741
|
+
const canFastReset = hasLaunchedOnce && driverOptions?.fastWebViewReset !== false && domChannel.isConnected() && !opts?.deepLink && !opts?.clearKeychain && !hasLaunchDeviceState(opts?.deviceState) && !(opts?.launchArguments && Object.keys(opts.launchArguments).length > 0);
|
|
742
|
+
if (canFastReset) {
|
|
743
|
+
try {
|
|
744
|
+
if (opts?.clearState && domChannel.clearStorage) {
|
|
745
|
+
await domChannel.clearStorage({
|
|
746
|
+
localStorage: true,
|
|
747
|
+
sessionStorage: true,
|
|
748
|
+
cookies: true,
|
|
749
|
+
indexedDB: true,
|
|
750
|
+
capacitorPreferences: true
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
if (domChannel.reload) {
|
|
754
|
+
await domChannel.reload();
|
|
755
|
+
} else {
|
|
756
|
+
await domChannel.evaluate("window.location.reload()");
|
|
757
|
+
}
|
|
758
|
+
return;
|
|
759
|
+
} catch {
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
if (opts?.clearState && simulatorUdid) {
|
|
763
|
+
terminateOnSimulator(simulatorUdid, appBundleId);
|
|
764
|
+
try {
|
|
765
|
+
const { execFileSync } = await import("child_process");
|
|
766
|
+
execFileSync(
|
|
767
|
+
"xcrun",
|
|
768
|
+
["simctl", "privacy", simulatorUdid, "reset", "all", appBundleId],
|
|
769
|
+
{
|
|
770
|
+
stdio: "ignore"
|
|
771
|
+
}
|
|
772
|
+
);
|
|
773
|
+
} catch {
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (opts?.clearKeychain && simulatorUdid) {
|
|
777
|
+
resetSimulatorKeychain(simulatorUdid);
|
|
778
|
+
} else if (opts?.clearKeychain) {
|
|
779
|
+
console.warn("clearKeychain is only supported on iOS simulators, skipping.");
|
|
780
|
+
}
|
|
781
|
+
if (hasLaunchDeviceState(opts?.deviceState) || opts?.launchArguments && Object.keys(opts.launchArguments).length > 0) {
|
|
782
|
+
console.warn(
|
|
783
|
+
"launchArguments and deviceState are not supported in local iOS WDA mode yet. Use Appium iOS mode when you need launch-time localization, timezone, or custom process arguments."
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
if (simulatorUdid) {
|
|
787
|
+
if (opts?.deepLink) {
|
|
788
|
+
await openSimulatorUrl(opts.deepLink, appBundleId);
|
|
789
|
+
} else {
|
|
790
|
+
try {
|
|
791
|
+
await client.terminateApp(appBundleId);
|
|
792
|
+
} catch {
|
|
793
|
+
try {
|
|
794
|
+
terminateOnSimulator(simulatorUdid, appBundleId);
|
|
795
|
+
} catch {
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
try {
|
|
799
|
+
await client.launchApp(appBundleId);
|
|
800
|
+
await waitForWdaReady(500);
|
|
801
|
+
} catch {
|
|
802
|
+
launchOnSimulator(simulatorUdid, appBundleId);
|
|
803
|
+
await sleep(250);
|
|
804
|
+
try {
|
|
805
|
+
await client.deleteSession();
|
|
806
|
+
} catch {
|
|
807
|
+
}
|
|
808
|
+
await createSessionWithRetry(appBundleId);
|
|
809
|
+
try {
|
|
810
|
+
await client.disableQuiescence();
|
|
811
|
+
} catch {
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
hasLaunchedOnce = true;
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
await (opts?.deepLink ? client.openUrl(opts.deepLink) : client.launchApp(appBundleId));
|
|
819
|
+
hasLaunchedOnce = true;
|
|
820
|
+
},
|
|
821
|
+
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
822
|
+
}),
|
|
823
|
+
stopApp: (appBundleId) => Effect.tryPromise({
|
|
824
|
+
try: () => {
|
|
825
|
+
if (simulatorUdid) {
|
|
826
|
+
terminateOnSimulator(simulatorUdid, appBundleId);
|
|
827
|
+
return Promise.resolve();
|
|
828
|
+
}
|
|
829
|
+
return client.terminateApp(appBundleId);
|
|
830
|
+
},
|
|
831
|
+
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
832
|
+
}),
|
|
833
|
+
killApp: (appBundleId) => Effect.tryPromise({
|
|
834
|
+
try: async () => {
|
|
835
|
+
await domChannel.disconnect().catch(() => {
|
|
836
|
+
});
|
|
837
|
+
if (!appBundleId) return;
|
|
838
|
+
if (simulatorUdid) {
|
|
839
|
+
terminateOnSimulator(simulatorUdid, appBundleId);
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
await client.terminateApp(appBundleId);
|
|
843
|
+
},
|
|
844
|
+
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
845
|
+
}),
|
|
846
|
+
clearAppState: (appBundleId) => Effect.tryPromise({
|
|
847
|
+
try: async () => {
|
|
848
|
+
if (domChannel.isConnected() && domChannel.clearStorage) {
|
|
849
|
+
await domChannel.clearStorage({
|
|
850
|
+
localStorage: true,
|
|
851
|
+
sessionStorage: true,
|
|
852
|
+
cookies: true,
|
|
853
|
+
indexedDB: true,
|
|
854
|
+
capacitorPreferences: true
|
|
855
|
+
});
|
|
856
|
+
if (domChannel.reload) {
|
|
857
|
+
await domChannel.reload();
|
|
858
|
+
}
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
if (simulatorUdid) {
|
|
862
|
+
terminateOnSimulator(simulatorUdid, appBundleId);
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
await client.terminateApp(appBundleId);
|
|
866
|
+
},
|
|
867
|
+
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
868
|
+
}),
|
|
869
|
+
resetFast: () => Effect.tryPromise({
|
|
870
|
+
try: async () => {
|
|
871
|
+
if (domChannel.clearStorage) {
|
|
872
|
+
await domChannel.clearStorage({
|
|
873
|
+
localStorage: true,
|
|
874
|
+
sessionStorage: true,
|
|
875
|
+
cookies: true,
|
|
876
|
+
indexedDB: true,
|
|
877
|
+
capacitorPreferences: true
|
|
878
|
+
});
|
|
879
|
+
} else {
|
|
880
|
+
await domChannel.evaluate(`(() => {
|
|
881
|
+
try { localStorage.clear(); } catch {}
|
|
882
|
+
try { sessionStorage.clear(); } catch {}
|
|
883
|
+
})()`);
|
|
884
|
+
}
|
|
885
|
+
if (domChannel.reload) {
|
|
886
|
+
await domChannel.reload();
|
|
887
|
+
} else {
|
|
888
|
+
await domChannel.evaluate("window.location.reload()");
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
catch: (e) => new DriverError({ message: `Fast reset failed: ${e}` })
|
|
892
|
+
}),
|
|
893
|
+
// -----------------------------------------------------------------------
|
|
894
|
+
// Navigation
|
|
895
|
+
// -----------------------------------------------------------------------
|
|
896
|
+
openLink: (url) => Effect.tryPromise({
|
|
897
|
+
try: async () => {
|
|
898
|
+
if (simulatorUdid) {
|
|
899
|
+
await openSimulatorUrl(url);
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
await client.openUrl(url);
|
|
903
|
+
},
|
|
904
|
+
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
905
|
+
}),
|
|
906
|
+
back: () => Effect.tryPromise({
|
|
907
|
+
// iOS has no hardware back button; pressing home is the closest
|
|
908
|
+
// equivalent for dismissing the current context.
|
|
909
|
+
try: () => client.pressHome(),
|
|
910
|
+
catch: (e) => new DriverError({ message: `Back failed: ${e}` })
|
|
911
|
+
}),
|
|
912
|
+
// -----------------------------------------------------------------------
|
|
913
|
+
// Direct DOM evaluation via spana-bridge or WebKit Remote Inspector
|
|
914
|
+
// (no Appium required)
|
|
915
|
+
// -----------------------------------------------------------------------
|
|
916
|
+
evaluate: (script, ...args) => Effect.tryPromise({
|
|
917
|
+
try: () => domChannel.evaluate(script, ...args),
|
|
918
|
+
catch: (e) => new DriverError({
|
|
919
|
+
message: `iOS direct WDA evaluate() failed via ${domChannel.kind}: ${e instanceof Error ? e.message : e}. Ensure WKWebView.isInspectable = true (iOS 16.4+) with ios_webkit_debug_proxy running, or include spana-bridge in test builds.`
|
|
920
|
+
})
|
|
921
|
+
}),
|
|
922
|
+
getContexts: () => Effect.tryPromise({
|
|
923
|
+
try: async () => {
|
|
924
|
+
const contexts = ["NATIVE_APP"];
|
|
925
|
+
if (domChannel.listTargets) {
|
|
926
|
+
try {
|
|
927
|
+
const targets = await domChannel.listTargets();
|
|
928
|
+
for (const target of targets) {
|
|
929
|
+
contexts.push(`WEBVIEW_${target.id}`);
|
|
930
|
+
}
|
|
931
|
+
} catch {
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
if (domChannel.isConnected() && contexts.length === 1) {
|
|
935
|
+
contexts.push(`WEBVIEW_${domChannel.kind}`);
|
|
936
|
+
}
|
|
937
|
+
return contexts;
|
|
938
|
+
},
|
|
939
|
+
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
940
|
+
}),
|
|
941
|
+
getCurrentContext: () => Effect.succeed(currentContext),
|
|
942
|
+
setContext: (contextId) => Effect.tryPromise({
|
|
943
|
+
try: async () => {
|
|
944
|
+
if (contextId === "NATIVE_APP") {
|
|
945
|
+
currentContext = "NATIVE_APP";
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
if (contextId.startsWith("WEBVIEW_")) {
|
|
949
|
+
const targetId = contextId.slice("WEBVIEW_".length);
|
|
950
|
+
if (domChannel.selectTarget && targetId !== "bridge" && targetId !== "webkit-inspector") {
|
|
951
|
+
await domChannel.selectTarget(targetId);
|
|
952
|
+
} else {
|
|
953
|
+
await domChannel.connect();
|
|
954
|
+
}
|
|
955
|
+
currentContext = contextId;
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
throw new Error(`Unknown context "${contextId}"`);
|
|
959
|
+
},
|
|
960
|
+
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
961
|
+
}),
|
|
962
|
+
mockNetwork: (matcher, response) => Effect.tryPromise({
|
|
963
|
+
try: async () => {
|
|
964
|
+
if (!domChannel.mockNetwork) {
|
|
965
|
+
throw new Error(
|
|
966
|
+
"mockNetwork() is not supported on native iOS traffic; install spana-bridge in your WebView to intercept JavaScript requests"
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
await domChannel.mockNetwork(matcher, response);
|
|
970
|
+
},
|
|
971
|
+
catch: (e) => new DriverError({ message: `mockNetwork failed: ${e}` })
|
|
972
|
+
}),
|
|
973
|
+
blockNetwork: (matcher) => Effect.tryPromise({
|
|
974
|
+
try: async () => {
|
|
975
|
+
if (!domChannel.blockNetwork) {
|
|
976
|
+
throw new Error(
|
|
977
|
+
"blockNetwork() is not supported on native iOS traffic; install spana-bridge in your WebView to intercept JavaScript requests"
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
await domChannel.blockNetwork(matcher);
|
|
981
|
+
},
|
|
982
|
+
catch: (e) => new DriverError({ message: `blockNetwork failed: ${e}` })
|
|
983
|
+
}),
|
|
984
|
+
clearNetworkMocks: () => Effect.tryPromise({
|
|
985
|
+
try: async () => {
|
|
986
|
+
if (domChannel.clearNetworkMocks) {
|
|
987
|
+
await domChannel.clearNetworkMocks();
|
|
988
|
+
}
|
|
989
|
+
},
|
|
990
|
+
catch: (e) => new DriverError({ message: `clearNetworkMocks failed: ${e}` })
|
|
991
|
+
}),
|
|
992
|
+
getConsoleLogs: () => Effect.tryPromise({
|
|
993
|
+
try: async () => domChannel.getConsoleLogs ? domChannel.getConsoleLogs() : [],
|
|
994
|
+
catch: (e) => new DriverError({ message: `getConsoleLogs failed: ${e}` })
|
|
995
|
+
}),
|
|
996
|
+
getJSErrors: () => Effect.tryPromise({
|
|
997
|
+
try: async () => domChannel.getJSErrors ? domChannel.getJSErrors() : [],
|
|
998
|
+
catch: (e) => new DriverError({ message: `getJSErrors failed: ${e}` })
|
|
999
|
+
}),
|
|
1000
|
+
// -----------------------------------------------------------------------
|
|
1001
|
+
// Network simulation
|
|
1002
|
+
// -----------------------------------------------------------------------
|
|
1003
|
+
setNetworkConditions: (conditions) => Effect.tryPromise({
|
|
1004
|
+
try: async () => {
|
|
1005
|
+
if (!simulatorUdid) {
|
|
1006
|
+
throw new DriverError({
|
|
1007
|
+
message: "Network simulation is not supported on physical iOS devices. Use a cloud provider (BrowserStack, SauceLabs) for network profiles."
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
const hasProfile = !!conditions.profile;
|
|
1011
|
+
const hasOffline = conditions.offline !== void 0;
|
|
1012
|
+
const hasCustom = conditions.latencyMs !== void 0 || conditions.downloadThroughputKbps !== void 0 || conditions.uploadThroughputKbps !== void 0;
|
|
1013
|
+
if (!hasProfile && !hasOffline && !hasCustom) {
|
|
1014
|
+
pfctlResetNetwork();
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
if (hasOffline && conditions.offline) {
|
|
1018
|
+
pfctlSetOffline(true);
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
if (hasProfile || hasCustom) {
|
|
1022
|
+
const resolved = resolveNetworkConditions(conditions);
|
|
1023
|
+
if (resolved.offline) {
|
|
1024
|
+
pfctlSetOffline(true);
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
const throughput = resolved.downloadThroughputKbps === -1 ? 0 : resolved.downloadThroughputKbps;
|
|
1028
|
+
pfctlSetThrottle(throughput, resolved.latencyMs);
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
pfctlSetOffline(false);
|
|
1032
|
+
},
|
|
1033
|
+
catch: (e) => {
|
|
1034
|
+
if (e instanceof DriverError) return e;
|
|
1035
|
+
return new DriverError({ message: `Set network conditions failed: ${e}` });
|
|
1036
|
+
}
|
|
1037
|
+
})
|
|
1038
|
+
};
|
|
1039
|
+
return service;
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
export {
|
|
1044
|
+
createWDADriver
|
|
1045
|
+
};
|
|
1046
|
+
//# sourceMappingURL=chunk-5SDVP53E.js.map
|