spana-test 0.7.0 → 0.8.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/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +9 -9
- package/dist/{allure-RNMEYTXS.js → allure-RAEK4SIH.js} +2 -2
- package/dist/allure-RAEK4SIH.js.map +1 -0
- package/dist/{android-4NVTZMHL.js → android-6BOQTMM3.js} +2 -2
- package/dist/app-CgbLADmF.d.ts +1191 -0
- package/dist/{chunk-H27IBIGA.js → chunk-2AFWVHQK.js} +63 -43
- package/dist/chunk-2AFWVHQK.js.map +1 -0
- package/dist/{chunk-JYFPZRCN.js → chunk-2T4K7BJ3.js} +3 -1
- package/dist/chunk-2T4K7BJ3.js.map +1 -0
- package/dist/{chunk-6B5Y75V4.js → chunk-3FXDOTFI.js} +840 -271
- package/dist/chunk-3FXDOTFI.js.map +1 -0
- package/dist/{chunk-T5CROOR7.js → chunk-AJCSETN6.js} +1329 -245
- package/dist/chunk-AJCSETN6.js.map +1 -0
- package/dist/chunk-JPZCZHL4.js +79 -0
- package/dist/chunk-JPZCZHL4.js.map +1 -0
- package/dist/{chunk-RURZVMZ7.js → chunk-NS2HLJO4.js} +3 -3
- package/dist/{chunk-2IXXEXTL.js → chunk-PMXSU5MS.js} +2 -2
- package/dist/{chunk-HYSTRWYN.js → chunk-QP4MDUBY.js} +4 -4
- package/dist/chunk-RKYKRGHB.js +236 -0
- package/dist/chunk-RKYKRGHB.js.map +1 -0
- package/dist/{chunk-HCG4CJKR.js → chunk-SF7UYW4I.js} +3 -3
- package/dist/{chunk-T3EBOYLS.js → chunk-SNL4X67N.js} +1043 -99
- package/dist/chunk-SNL4X67N.js.map +1 -0
- package/dist/{chunk-KNSAHEXI.js → chunk-WKVU24B6.js} +8 -8
- package/dist/{chunk-S5JNNDXS.js → chunk-WV3ALL3H.js} +65 -37
- package/dist/chunk-WV3ALL3H.js.map +1 -0
- package/dist/cli.js +23 -11
- package/dist/cli.js.map +1 -1
- package/dist/config-loader-5FU45FXK.js +9 -0
- package/dist/{console-MI2XB5RG.js → console-BGAK7Z2L.js} +11 -1
- package/dist/{console-MI2XB5RG.js.map → console-BGAK7Z2L.js.map} +1 -1
- package/dist/{daemon-manager-FBISTX24.js → daemon-manager-DDYQITPD.js} +4 -2
- package/dist/{discover-LHEBSUIP.js → discover-RLSKEBAX.js} +5 -5
- package/dist/{doctor-command-WPEVZEZ4.js → doctor-command-HEQQOYUR.js} +26 -18
- package/dist/doctor-command-HEQQOYUR.js.map +1 -0
- package/dist/{flow-g6AICPAl.d.ts → flow-Md5xLwbX.d.ts} +3 -29
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/{html-IKCTZH2U.js → html-JO2YNRWX.js} +3 -3
- package/dist/html-JO2YNRWX.js.map +1 -0
- package/dist/index.d.ts +184 -20
- package/dist/index.js +230 -147
- package/dist/index.js.map +1 -1
- package/dist/{installer-VUPFWP5X.js → installer-IYGMG7LS.js} +4 -4
- package/dist/{ios-JPK43TFZ.js → ios-Y4TO5MBR.js} +7 -3
- package/dist/{server-IGLBFEU7.js → server-4PEREPHY.js} +2 -2
- package/dist/{server-EBPYK3VE.js → server-JPNH33MX.js} +50 -36
- package/dist/server-JPNH33MX.js.map +1 -0
- package/dist/{session-cJ_tZjCL.d.ts → session-D9e30RVS.d.ts} +1 -1
- package/dist/session-V4PYJXNB.js +18 -0
- package/dist/{studio-command-FLA5HKRK.js → studio-command-JOIFCOHC.js} +2 -2
- package/dist/{test-command-P5W7UD52.js → test-command-JCO2HPYI.js} +221 -27
- package/dist/test-command-JCO2HPYI.js.map +1 -0
- package/native/darwin-arm64/libspana_native.dylib +0 -0
- package/native/darwin-x64/libspana_native.dylib +0 -0
- package/native/linux-arm64/libspana_native.so +0 -0
- package/native/linux-x64/libspana_native.so +0 -0
- package/native/win32-x64/spana_native.dll +0 -0
- package/package.json +1 -1
- package/studio-dist/assets/index-CBFsOh-9.js +193 -0
- package/studio-dist/assets/index-DH_18EyL.css +1 -0
- package/studio-dist/index.html +2 -2
- package/dist/allure-RNMEYTXS.js.map +0 -1
- package/dist/app-D_UyZBsl.d.ts +0 -915
- package/dist/chunk-6B5Y75V4.js.map +0 -1
- package/dist/chunk-DTNK54C2.js +0 -127
- package/dist/chunk-DTNK54C2.js.map +0 -1
- package/dist/chunk-H27IBIGA.js.map +0 -1
- package/dist/chunk-JYFPZRCN.js.map +0 -1
- package/dist/chunk-OBCFACUW.js +0 -28
- package/dist/chunk-OBCFACUW.js.map +0 -1
- package/dist/chunk-S5JNNDXS.js.map +0 -1
- package/dist/chunk-T3EBOYLS.js.map +0 -1
- package/dist/chunk-T5CROOR7.js.map +0 -1
- package/dist/config-loader-NIDQGP3K.js +0 -9
- package/dist/doctor-command-WPEVZEZ4.js.map +0 -1
- package/dist/html-IKCTZH2U.js.map +0 -1
- package/dist/server-EBPYK3VE.js.map +0 -1
- package/dist/session-QRWH3SPW.js +0 -18
- package/dist/test-command-P5W7UD52.js.map +0 -1
- package/studio-dist/assets/index-C-Io44gy.js +0 -193
- package/studio-dist/assets/index-DfM9lK4p.css +0 -1
- /package/dist/{android-4NVTZMHL.js.map → android-6BOQTMM3.js.map} +0 -0
- /package/dist/{chunk-RURZVMZ7.js.map → chunk-NS2HLJO4.js.map} +0 -0
- /package/dist/{chunk-2IXXEXTL.js.map → chunk-PMXSU5MS.js.map} +0 -0
- /package/dist/{chunk-HYSTRWYN.js.map → chunk-QP4MDUBY.js.map} +0 -0
- /package/dist/{chunk-HCG4CJKR.js.map → chunk-SF7UYW4I.js.map} +0 -0
- /package/dist/{chunk-KNSAHEXI.js.map → chunk-WKVU24B6.js.map} +0 -0
- /package/dist/{config-loader-NIDQGP3K.js.map → config-loader-5FU45FXK.js.map} +0 -0
- /package/dist/{daemon-manager-FBISTX24.js.map → daemon-manager-DDYQITPD.js.map} +0 -0
- /package/dist/{discover-LHEBSUIP.js.map → discover-RLSKEBAX.js.map} +0 -0
- /package/dist/{installer-VUPFWP5X.js.map → installer-IYGMG7LS.js.map} +0 -0
- /package/dist/{ios-JPK43TFZ.js.map → ios-Y4TO5MBR.js.map} +0 -0
- /package/dist/{server-IGLBFEU7.js.map → server-4PEREPHY.js.map} +0 -0
- /package/dist/{session-QRWH3SPW.js.map → session-V4PYJXNB.js.map} +0 -0
- /package/dist/{studio-command-FLA5HKRK.js.map → studio-command-JOIFCOHC.js.map} +0 -0
|
@@ -14,11 +14,11 @@ import {
|
|
|
14
14
|
createCompositeDomChannel,
|
|
15
15
|
createWebKitInspectorChannel,
|
|
16
16
|
domMatchToElement
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-SNL4X67N.js";
|
|
18
18
|
import {
|
|
19
19
|
getHealthyWarmDaemon,
|
|
20
20
|
registerWarmDaemon
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-RKYKRGHB.js";
|
|
22
22
|
import {
|
|
23
23
|
installedUrlSchemesOnSimulator,
|
|
24
24
|
launchOnSimulator,
|
|
@@ -28,11 +28,12 @@ import {
|
|
|
28
28
|
pfctlSetThrottle,
|
|
29
29
|
resetSimulatorKeychain,
|
|
30
30
|
terminateOnSimulator
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-WV3ALL3H.js";
|
|
32
32
|
import {
|
|
33
|
+
allocateFreePort,
|
|
33
34
|
allocatePort,
|
|
34
35
|
releasePort
|
|
35
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-JPZCZHL4.js";
|
|
36
37
|
import {
|
|
37
38
|
adbClearApp,
|
|
38
39
|
adbForceStop,
|
|
@@ -48,7 +49,7 @@ import {
|
|
|
48
49
|
adbSetWifi,
|
|
49
50
|
adbShell,
|
|
50
51
|
findADB
|
|
51
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-2AFWVHQK.js";
|
|
52
53
|
|
|
53
54
|
// src/schemas/selector.ts
|
|
54
55
|
import { Schema } from "effect";
|
|
@@ -61,6 +62,14 @@ var _AccessibilityLabelSelectorSchema = Schema.Struct({
|
|
|
61
62
|
accessibilityLabel: Schema.String,
|
|
62
63
|
systemUI: Schema.optional(Schema.Boolean)
|
|
63
64
|
});
|
|
65
|
+
var _RoleSelectorSchema = Schema.Struct({
|
|
66
|
+
role: Schema.String,
|
|
67
|
+
name: Schema.optional(Schema.String),
|
|
68
|
+
exact: Schema.optional(Schema.Boolean)
|
|
69
|
+
});
|
|
70
|
+
var _CssSelectorSchema = Schema.Struct({
|
|
71
|
+
css: Schema.String
|
|
72
|
+
});
|
|
64
73
|
var _PointSelectorSchema = Schema.Struct({
|
|
65
74
|
point: Schema.Struct({ x: Schema.Number, y: Schema.Number })
|
|
66
75
|
});
|
|
@@ -69,11 +78,59 @@ var SelectorSchema = Schema.Union(
|
|
|
69
78
|
_TestIDSelectorSchema,
|
|
70
79
|
_TextSelectorSchema,
|
|
71
80
|
_AccessibilityLabelSelectorSchema,
|
|
81
|
+
_RoleSelectorSchema,
|
|
82
|
+
_CssSelectorSchema,
|
|
72
83
|
_PointSelectorSchema
|
|
73
84
|
);
|
|
74
85
|
function isRelativeSelector(sel) {
|
|
75
86
|
return typeof sel === "object" && sel !== null && "selector" in sel;
|
|
76
87
|
}
|
|
88
|
+
function toObjectSelector(sel) {
|
|
89
|
+
if (typeof sel === "string") {
|
|
90
|
+
return { text: sel };
|
|
91
|
+
}
|
|
92
|
+
return sel;
|
|
93
|
+
}
|
|
94
|
+
function byRole(role, nameOrOpts, opts) {
|
|
95
|
+
if (typeof nameOrOpts === "string" || nameOrOpts instanceof RegExp) {
|
|
96
|
+
return { role, name: nameOrOpts, ...opts };
|
|
97
|
+
}
|
|
98
|
+
return { role, ...nameOrOpts };
|
|
99
|
+
}
|
|
100
|
+
function byCss(css, opts) {
|
|
101
|
+
return { css, ...opts };
|
|
102
|
+
}
|
|
103
|
+
function within(parent, child) {
|
|
104
|
+
const obj = toObjectSelector(child);
|
|
105
|
+
if ("point" in obj) return obj;
|
|
106
|
+
const chainedWithin = obj.within ? within(parent, obj.within) : parent;
|
|
107
|
+
return { ...obj, within: chainedWithin };
|
|
108
|
+
}
|
|
109
|
+
function inFrame(frame, child) {
|
|
110
|
+
const obj = toObjectSelector(child);
|
|
111
|
+
if ("point" in obj) return obj;
|
|
112
|
+
return { ...obj, frame };
|
|
113
|
+
}
|
|
114
|
+
function nth(sel, index) {
|
|
115
|
+
const obj = toObjectSelector(sel);
|
|
116
|
+
if ("point" in obj) return obj;
|
|
117
|
+
return { ...obj, nth: index, first: void 0, last: void 0 };
|
|
118
|
+
}
|
|
119
|
+
function first(sel) {
|
|
120
|
+
const obj = toObjectSelector(sel);
|
|
121
|
+
if ("point" in obj) return obj;
|
|
122
|
+
return { ...obj, first: true, last: void 0, nth: void 0 };
|
|
123
|
+
}
|
|
124
|
+
function last(sel) {
|
|
125
|
+
const obj = toObjectSelector(sel);
|
|
126
|
+
if ("point" in obj) return obj;
|
|
127
|
+
return { ...obj, last: true, first: void 0, nth: void 0 };
|
|
128
|
+
}
|
|
129
|
+
function filterSelector(sel, filter) {
|
|
130
|
+
const obj = toObjectSelector(sel);
|
|
131
|
+
if ("point" in obj) return obj;
|
|
132
|
+
return { ...obj, ...filter };
|
|
133
|
+
}
|
|
77
134
|
function systemUI(selector) {
|
|
78
135
|
return { ...selector, systemUI: true };
|
|
79
136
|
}
|
|
@@ -87,6 +144,10 @@ function isSystemUISelector(sel) {
|
|
|
87
144
|
function isTestIDSelector(sel) {
|
|
88
145
|
return typeof sel === "object" && sel !== null && "testID" in sel && !isRelativeSelector(sel);
|
|
89
146
|
}
|
|
147
|
+
function isComposableDomSelector(sel) {
|
|
148
|
+
if (typeof sel !== "object" || sel === null || isRelativeSelector(sel)) return false;
|
|
149
|
+
return "role" in sel || "css" in sel || "within" in sel || "frame" in sel || "hasText" in sel || "hasNotText" in sel || "nth" in sel || "first" in sel || "last" in sel;
|
|
150
|
+
}
|
|
90
151
|
|
|
91
152
|
// src/smart/element-matcher.ts
|
|
92
153
|
function flattenElements(root) {
|
|
@@ -107,24 +168,55 @@ function matchesSelector(element, selector) {
|
|
|
107
168
|
if (typeof selector === "string") {
|
|
108
169
|
return element.text?.toLowerCase().includes(selector.toLowerCase()) ?? false;
|
|
109
170
|
}
|
|
171
|
+
let baseMatch = false;
|
|
110
172
|
if ("testID" in selector) {
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if ("
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
173
|
+
baseMatch = element.id === selector.testID;
|
|
174
|
+
} else if ("text" in selector) {
|
|
175
|
+
baseMatch = selector.exact ? element.text === selector.text : element.text?.toLowerCase().includes(selector.text.toLowerCase()) ?? false;
|
|
176
|
+
} else if ("accessibilityLabel" in selector) {
|
|
177
|
+
baseMatch = element.accessibilityLabel === selector.accessibilityLabel;
|
|
178
|
+
} else if ("role" in selector) {
|
|
179
|
+
const elRole = (element.attributes?.role ?? element.elementType ?? "").toLowerCase();
|
|
180
|
+
const roleMatch = elRole === selector.role.toLowerCase();
|
|
181
|
+
if (!roleMatch) return false;
|
|
182
|
+
if (selector.name === void 0) {
|
|
183
|
+
baseMatch = true;
|
|
184
|
+
} else {
|
|
185
|
+
const candidateName = element.accessibilityLabel ?? element.text ?? "";
|
|
186
|
+
baseMatch = selector.name instanceof RegExp ? selector.name.test(candidateName) : selector.exact ? candidateName === selector.name : candidateName.toLowerCase().includes(selector.name.toLowerCase());
|
|
187
|
+
}
|
|
188
|
+
} else if ("css" in selector) {
|
|
189
|
+
baseMatch = false;
|
|
190
|
+
} else if ("point" in selector) {
|
|
120
191
|
const { x, y } = selector.point;
|
|
121
192
|
const b = element.bounds;
|
|
122
|
-
|
|
193
|
+
baseMatch = x >= b.x && x <= b.x + b.width && y >= b.y && y <= b.y + b.height;
|
|
194
|
+
}
|
|
195
|
+
if (!baseMatch) return false;
|
|
196
|
+
if (!("point" in selector)) {
|
|
197
|
+
const text = element.text ?? element.accessibilityLabel ?? "";
|
|
198
|
+
if (selector.hasText !== void 0) {
|
|
199
|
+
const ok = selector.hasText instanceof RegExp ? selector.hasText.test(text) : text.toLowerCase().includes(selector.hasText.toLowerCase());
|
|
200
|
+
if (!ok) return false;
|
|
201
|
+
}
|
|
202
|
+
if (selector.hasNotText !== void 0) {
|
|
203
|
+
const bad = selector.hasNotText instanceof RegExp ? selector.hasNotText.test(text) : text.toLowerCase().includes(selector.hasNotText.toLowerCase());
|
|
204
|
+
if (bad) return false;
|
|
205
|
+
}
|
|
123
206
|
}
|
|
124
|
-
return
|
|
207
|
+
return true;
|
|
125
208
|
}
|
|
126
209
|
function findElements(root, selector) {
|
|
127
|
-
|
|
210
|
+
const matched = flattenElements(root).filter((el) => matchesSelector(el, selector));
|
|
211
|
+
if (typeof selector === "object" && selector !== null && !("point" in selector)) {
|
|
212
|
+
if (selector.first) return matched.length > 0 ? [matched[0]] : [];
|
|
213
|
+
if (selector.last) return matched.length > 0 ? [matched[matched.length - 1]] : [];
|
|
214
|
+
if (selector.nth !== void 0) {
|
|
215
|
+
const idx = selector.nth < 0 ? matched.length + selector.nth : selector.nth;
|
|
216
|
+
return idx >= 0 && idx < matched.length ? [matched[idx]] : [];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return matched;
|
|
128
220
|
}
|
|
129
221
|
function isProbablyOnScreen(element) {
|
|
130
222
|
const centerX = element.bounds.x + element.bounds.width / 2;
|
|
@@ -192,11 +284,32 @@ function formatSelector(sel) {
|
|
|
192
284
|
}
|
|
193
285
|
function formatSimpleSelector(sel) {
|
|
194
286
|
if (typeof sel === "string") return `"${sel}"`;
|
|
195
|
-
|
|
196
|
-
if ("
|
|
197
|
-
if ("
|
|
198
|
-
if ("
|
|
199
|
-
|
|
287
|
+
let base;
|
|
288
|
+
if ("testID" in sel) base = `testID: "${sel.testID}"`;
|
|
289
|
+
else if ("text" in sel) base = `text: "${sel.text}"`;
|
|
290
|
+
else if ("accessibilityLabel" in sel) base = `accessibilityLabel: "${sel.accessibilityLabel}"`;
|
|
291
|
+
else if ("role" in sel) {
|
|
292
|
+
base = sel.name !== void 0 ? `role: "${sel.role}", name: ${sel.name instanceof RegExp ? sel.name.toString() : JSON.stringify(sel.name)}` : `role: "${sel.role}"`;
|
|
293
|
+
} else if ("css" in sel) base = `css: "${sel.css}"`;
|
|
294
|
+
else if ("point" in sel) return `point: (${sel.point.x}, ${sel.point.y})`;
|
|
295
|
+
else return JSON.stringify(sel);
|
|
296
|
+
const mods = [];
|
|
297
|
+
if (sel.frame) mods.push(`inFrame(${formatSimpleSelector(sel.frame)})`);
|
|
298
|
+
if (sel.within) mods.push(`within(${formatSimpleSelector(sel.within)})`);
|
|
299
|
+
if (sel.hasText !== void 0) {
|
|
300
|
+
mods.push(
|
|
301
|
+
`hasText(${sel.hasText instanceof RegExp ? sel.hasText.toString() : JSON.stringify(sel.hasText)})`
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
if (sel.hasNotText !== void 0) {
|
|
305
|
+
mods.push(
|
|
306
|
+
`hasNotText(${sel.hasNotText instanceof RegExp ? sel.hasNotText.toString() : JSON.stringify(sel.hasNotText)})`
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
if (sel.first) mods.push("first");
|
|
310
|
+
else if (sel.last) mods.push("last");
|
|
311
|
+
else if (sel.nth !== void 0) mods.push(`nth(${sel.nth})`);
|
|
312
|
+
return mods.length > 0 ? `${base} [${mods.join(", ")}]` : base;
|
|
200
313
|
}
|
|
201
314
|
function findElementExtended(root, selector) {
|
|
202
315
|
if (!isRelativeSelector(selector)) {
|
|
@@ -324,12 +437,12 @@ function resolveElementAcrossChannels(driver, selector, parse, cache, options =
|
|
|
324
437
|
const isSystemUI = isSystemUISelector(selector);
|
|
325
438
|
const forAction = options.forAction ?? false;
|
|
326
439
|
const tapMode = options.tapMode ?? "native";
|
|
327
|
-
const canTryDom = !isSystemUI && !isRelativeSelector(selector) && domChannel !== void 0 && (isTestIDSelector(selector) || domChannel.isConnected());
|
|
440
|
+
const canTryDom = !isSystemUI && !isRelativeSelector(selector) && domChannel !== void 0 && (isTestIDSelector(selector) || isComposableDomSelector(selector) || domChannel.isConnected());
|
|
328
441
|
if (canTryDom) {
|
|
329
442
|
const domMatches = yield* Effect.tryPromise({
|
|
330
443
|
try: async () => {
|
|
331
444
|
if (!domChannel.isConnected()) {
|
|
332
|
-
if (!isTestIDSelector(selector)) return [];
|
|
445
|
+
if (!isTestIDSelector(selector) && !isComposableDomSelector(selector)) return [];
|
|
333
446
|
try {
|
|
334
447
|
await domChannel.connect();
|
|
335
448
|
} catch {
|
|
@@ -558,7 +671,7 @@ function waitForResolvedAcrossChannels(driver, selector, parse, forAction, opts,
|
|
|
558
671
|
const start = Date.now();
|
|
559
672
|
let waitedForIdle = false;
|
|
560
673
|
let isFirstPoll = true;
|
|
561
|
-
const canReactiveDomWait = !isSystemUISelector(selector) && !isRelativeSelectorLike(selector) && (opts?.platform === "web" || isTestIDSelector(selector));
|
|
674
|
+
const canReactiveDomWait = !isSystemUISelector(selector) && !isRelativeSelectorLike(selector) && (opts?.platform === "web" || isTestIDSelector(selector) || isComposableDomSelector(selector));
|
|
562
675
|
const initialDomChannel = driver.domChannel;
|
|
563
676
|
if (opts?.platform === "web" && canReactiveDomWait && settleTimeout === 0 && initialDomChannel?.isConnected() && initialDomChannel.waitForSelector) {
|
|
564
677
|
const reactiveMatches = yield* Effect2.tryPromise({
|
|
@@ -592,7 +705,7 @@ ${diagMessage2}`,
|
|
|
592
705
|
});
|
|
593
706
|
}
|
|
594
707
|
}
|
|
595
|
-
while (Date.now() - start < timeout) {
|
|
708
|
+
while (isFirstPoll || Date.now() - start < timeout) {
|
|
596
709
|
if (!isFirstPoll && cache) cache.invalidate();
|
|
597
710
|
isFirstPoll = false;
|
|
598
711
|
const resolved = yield* resolveElementAcrossChannels(driver, selector, parse, cache, {
|
|
@@ -681,7 +794,7 @@ function waitForNotVisible(driver, selector, parse, opts, cache) {
|
|
|
681
794
|
let waitedForIdle = false;
|
|
682
795
|
let isFirstPoll = true;
|
|
683
796
|
const domChannel = driver.domChannel;
|
|
684
|
-
const canReactiveHidden = !isSystemUISelector(selector) && !isRelativeSelectorLike(selector) && (opts?.platform === "web" || isTestIDSelector(selector));
|
|
797
|
+
const canReactiveHidden = !isSystemUISelector(selector) && !isRelativeSelectorLike(selector) && (opts?.platform === "web" || isTestIDSelector(selector) || isComposableDomSelector(selector));
|
|
685
798
|
if (canReactiveHidden && domChannel?.isConnected() && domChannel.waitForHidden) {
|
|
686
799
|
const hidden = yield* Effect2.tryPromise({
|
|
687
800
|
try: () => domChannel.waitForHidden(selector, { timeoutMs: timeout }),
|
|
@@ -696,7 +809,7 @@ function waitForNotVisible(driver, selector, parse, opts, cache) {
|
|
|
696
809
|
});
|
|
697
810
|
}
|
|
698
811
|
}
|
|
699
|
-
while (Date.now() - start < timeout) {
|
|
812
|
+
while (isFirstPoll || Date.now() - start < timeout) {
|
|
700
813
|
if (!isFirstPoll && cache) cache.invalidate();
|
|
701
814
|
isFirstPoll = false;
|
|
702
815
|
const resolved = yield* resolveElementAcrossChannels(driver, selector, parse, cache, {
|
|
@@ -817,7 +930,14 @@ function createCoordinator(driver, config) {
|
|
|
817
930
|
500
|
|
818
931
|
);
|
|
819
932
|
if (config.platform !== "web") {
|
|
820
|
-
|
|
933
|
+
if (driver.domChannel?.isConnected() && driver.domChannel.waitForIdle) {
|
|
934
|
+
yield* Effect4.tryPromise({
|
|
935
|
+
try: () => driver.domChannel.waitForIdle({ timeout: 150, quietPeriodMs: 30 }),
|
|
936
|
+
catch: () => void 0
|
|
937
|
+
}).pipe(Effect4.catchAll(() => Effect4.void));
|
|
938
|
+
} else {
|
|
939
|
+
yield* Effect4.promise(() => new Promise((r) => setTimeout(r, 100)));
|
|
940
|
+
}
|
|
821
941
|
}
|
|
822
942
|
yield* afterMutation();
|
|
823
943
|
});
|
|
@@ -1096,11 +1216,11 @@ function createCoordinator(driver, config) {
|
|
|
1096
1216
|
});
|
|
1097
1217
|
if (!result.match) {
|
|
1098
1218
|
const { writeFileSync, mkdirSync } = yield* Effect4.promise(() => import("fs"));
|
|
1099
|
-
const { join:
|
|
1219
|
+
const { join: join3 } = yield* Effect4.promise(() => import("path"));
|
|
1100
1220
|
const outDir = options.outputDir ?? config.outputDir ?? "spana-output";
|
|
1101
1221
|
mkdirSync(outDir, { recursive: true });
|
|
1102
1222
|
const safeFlowName = flowName.toLowerCase().replaceAll(/[^a-z0-9]+/g, "-").replaceAll(/^-|-$/g, "");
|
|
1103
|
-
const prefix =
|
|
1223
|
+
const prefix = join3(outDir, `${safeFlowName}-${platform}-${name}`);
|
|
1104
1224
|
writeFileSync(`${prefix}-expected.png`, existing);
|
|
1105
1225
|
writeFileSync(`${prefix}-actual.png`, actualBuf);
|
|
1106
1226
|
if (result.diffImage) {
|
|
@@ -1131,6 +1251,134 @@ function createCoordinator(driver, config) {
|
|
|
1131
1251
|
},
|
|
1132
1252
|
{ kind: "accessibilityLabel", expected }
|
|
1133
1253
|
),
|
|
1254
|
+
assertAccessibleName: (selector, expected, opts) => pollUntilMatch(
|
|
1255
|
+
selector,
|
|
1256
|
+
opts,
|
|
1257
|
+
(el) => {
|
|
1258
|
+
const actual = el.accessibilityLabel || el.text || "";
|
|
1259
|
+
const matched = expected instanceof RegExp ? expected.test(actual) : actual.trim() === expected.trim();
|
|
1260
|
+
return { matched, actual };
|
|
1261
|
+
},
|
|
1262
|
+
(actual, timeout) => ({
|
|
1263
|
+
message: `Expected accessible name ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got "${actual ?? "(none)"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1264
|
+
expected: String(expected)
|
|
1265
|
+
}),
|
|
1266
|
+
expected instanceof RegExp ? {
|
|
1267
|
+
kind: "accessibleName",
|
|
1268
|
+
patternSource: expected.source,
|
|
1269
|
+
patternFlags: expected.flags
|
|
1270
|
+
} : { kind: "accessibleName", expected }
|
|
1271
|
+
),
|
|
1272
|
+
assertFocused: (selector, opts) => pollUntilMatch(
|
|
1273
|
+
selector,
|
|
1274
|
+
opts,
|
|
1275
|
+
(el) => ({
|
|
1276
|
+
matched: el.focused === true,
|
|
1277
|
+
actual: el.focused ? "focused" : "not focused"
|
|
1278
|
+
}),
|
|
1279
|
+
(actual, timeout) => ({
|
|
1280
|
+
message: `Expected element to be focused but it was "${actual ?? "not focused"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1281
|
+
expected: "focused"
|
|
1282
|
+
}),
|
|
1283
|
+
{ kind: "focused" }
|
|
1284
|
+
),
|
|
1285
|
+
assertCount: (selector, expectedCount, opts) => Effect4.gen(function* () {
|
|
1286
|
+
const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
|
|
1287
|
+
const pollInterval = opts?.pollInterval ?? defaults?.pollInterval ?? 200;
|
|
1288
|
+
const start = Date.now();
|
|
1289
|
+
let lastCount = -1;
|
|
1290
|
+
const domChannel = driver.domChannel;
|
|
1291
|
+
if (config.platform === "web" && !isSystemUISelector(selector) && !isRelativeSelectorLike2(selector) && domChannel?.isConnected() && domChannel.waitForMatch) {
|
|
1292
|
+
const reactive = yield* Effect4.tryPromise({
|
|
1293
|
+
try: () => domChannel.waitForMatch(selector, {
|
|
1294
|
+
kind: "count",
|
|
1295
|
+
expectedCount,
|
|
1296
|
+
timeoutMs: timeout
|
|
1297
|
+
}),
|
|
1298
|
+
catch: () => null
|
|
1299
|
+
}).pipe(Effect4.catchAll(() => Effect4.succeed(null)));
|
|
1300
|
+
if (reactive) {
|
|
1301
|
+
if (reactive.matched) return;
|
|
1302
|
+
return yield* new TextMismatchError({
|
|
1303
|
+
message: `Expected count ${expectedCount} but got ${reactive.actual ?? "0"} after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1304
|
+
expected: String(expectedCount),
|
|
1305
|
+
actual: reactive.actual ?? "0",
|
|
1306
|
+
selector
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
while (Date.now() - start < timeout) {
|
|
1311
|
+
cache.invalidate();
|
|
1312
|
+
if (!isSystemUISelector(selector) && !isRelativeSelectorLike2(selector) && domChannel?.isConnected()) {
|
|
1313
|
+
const matches = yield* Effect4.tryPromise({
|
|
1314
|
+
try: () => domChannel.query(selector),
|
|
1315
|
+
catch: () => null
|
|
1316
|
+
}).pipe(Effect4.catchAll(() => Effect4.succeed(null)));
|
|
1317
|
+
if (matches) {
|
|
1318
|
+
const count2 = matches.filter((m) => m.visible).length;
|
|
1319
|
+
lastCount = count2;
|
|
1320
|
+
if (count2 === expectedCount) return;
|
|
1321
|
+
yield* Effect4.sleep(Duration2.millis(pollInterval));
|
|
1322
|
+
continue;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
const raw = yield* driver.dumpHierarchy();
|
|
1326
|
+
const root = parse(raw);
|
|
1327
|
+
const count = findElements(root, selector).filter(
|
|
1328
|
+
(el) => el.visible !== false
|
|
1329
|
+
).length;
|
|
1330
|
+
lastCount = count;
|
|
1331
|
+
if (count === expectedCount) return;
|
|
1332
|
+
yield* Effect4.sleep(Duration2.millis(pollInterval));
|
|
1333
|
+
}
|
|
1334
|
+
return yield* new TextMismatchError({
|
|
1335
|
+
message: `Expected count ${expectedCount} but got ${lastCount >= 0 ? lastCount : 0} after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1336
|
+
expected: String(expectedCount),
|
|
1337
|
+
actual: String(lastCount >= 0 ? lastCount : 0),
|
|
1338
|
+
selector
|
|
1339
|
+
});
|
|
1340
|
+
}),
|
|
1341
|
+
waitForURL: (expected, opts) => Effect4.gen(function* () {
|
|
1342
|
+
const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
|
|
1343
|
+
const pollInterval = opts?.pollInterval ?? defaults?.pollInterval ?? 100;
|
|
1344
|
+
const start = Date.now();
|
|
1345
|
+
let lastUrl = "";
|
|
1346
|
+
const matchesUrl = (url) => expected instanceof RegExp ? expected.test(url) : url === expected || url.includes(expected);
|
|
1347
|
+
const domChannel = driver.domChannel;
|
|
1348
|
+
if (config.platform === "web" && domChannel?.isConnected() && domChannel.waitForMatch) {
|
|
1349
|
+
const reactive = yield* Effect4.tryPromise({
|
|
1350
|
+
try: () => domChannel.waitForMatch("", {
|
|
1351
|
+
kind: "url",
|
|
1352
|
+
...expected instanceof RegExp ? { patternSource: expected.source, patternFlags: expected.flags } : { expected },
|
|
1353
|
+
timeoutMs: timeout
|
|
1354
|
+
}),
|
|
1355
|
+
catch: () => null
|
|
1356
|
+
}).pipe(Effect4.catchAll(() => Effect4.succeed(null)));
|
|
1357
|
+
if (reactive) {
|
|
1358
|
+
if (reactive.matched) return;
|
|
1359
|
+
return yield* new TextMismatchError({
|
|
1360
|
+
message: `Expected URL ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got ${JSON.stringify(reactive.actual ?? "")} after ${timeout}ms`,
|
|
1361
|
+
expected: String(expected),
|
|
1362
|
+
actual: reactive.actual ?? "",
|
|
1363
|
+
selector: "url"
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
while (Date.now() - start < timeout) {
|
|
1368
|
+
const url = driver.getUrl ? yield* driver.getUrl() : yield* driver.evaluate(
|
|
1369
|
+
"typeof window !== 'undefined' && window.location ? window.location.href : ''"
|
|
1370
|
+
).pipe(Effect4.catchAll(() => Effect4.succeed("")));
|
|
1371
|
+
lastUrl = url;
|
|
1372
|
+
if (matchesUrl(url)) return;
|
|
1373
|
+
yield* Effect4.sleep(Duration2.millis(pollInterval));
|
|
1374
|
+
}
|
|
1375
|
+
return yield* new TextMismatchError({
|
|
1376
|
+
message: `Expected URL ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got ${JSON.stringify(lastUrl)} after ${timeout}ms`,
|
|
1377
|
+
expected: String(expected),
|
|
1378
|
+
actual: lastUrl,
|
|
1379
|
+
selector: "url"
|
|
1380
|
+
});
|
|
1381
|
+
}),
|
|
1134
1382
|
assertFocusable: (selector, platform, opts) => Effect4.gen(function* () {
|
|
1135
1383
|
const { isFocusable } = yield* Effect4.promise(
|
|
1136
1384
|
() => import("./accessibility-audit-YZOPUY3D.js")
|
|
@@ -1317,13 +1565,56 @@ function createCoordinator(driver, config) {
|
|
|
1317
1565
|
}
|
|
1318
1566
|
yield* afterMutation();
|
|
1319
1567
|
}),
|
|
1568
|
+
/**
|
|
1569
|
+
* Hover the pointer over an actionable element (moves pointer to its center).
|
|
1570
|
+
*/
|
|
1571
|
+
hover: (selector, opts) => Effect4.gen(function* () {
|
|
1572
|
+
const mergedOpts = {
|
|
1573
|
+
...defaults,
|
|
1574
|
+
...opts,
|
|
1575
|
+
platform: opts?.platform ?? config.platform
|
|
1576
|
+
};
|
|
1577
|
+
const resolved = yield* waitForResolvedElementResult(
|
|
1578
|
+
driver,
|
|
1579
|
+
selector,
|
|
1580
|
+
parse,
|
|
1581
|
+
true,
|
|
1582
|
+
mergedOpts,
|
|
1583
|
+
cache
|
|
1584
|
+
);
|
|
1585
|
+
const { x, y } = centerOf(resolved.element);
|
|
1586
|
+
if (driver.hoverAtCoordinate) {
|
|
1587
|
+
yield* driver.hoverAtCoordinate(x, y);
|
|
1588
|
+
} else if (config.platform === "web") {
|
|
1589
|
+
yield* driver.evaluate(
|
|
1590
|
+
`(() => {
|
|
1591
|
+
const el = document.elementFromPoint(${x}, ${y});
|
|
1592
|
+
if (!el) return;
|
|
1593
|
+
const init = { bubbles: true, cancelable: true, composed: true, clientX: ${x}, clientY: ${y} };
|
|
1594
|
+
try { el.dispatchEvent(new PointerEvent("pointerover", init)); } catch {}
|
|
1595
|
+
try { el.dispatchEvent(new PointerEvent("pointerenter", { ...init, bubbles: false })); } catch {}
|
|
1596
|
+
try { el.dispatchEvent(new MouseEvent("mouseover", init)); } catch {}
|
|
1597
|
+
try { el.dispatchEvent(new MouseEvent("mouseenter", { ...init, bubbles: false })); } catch {}
|
|
1598
|
+
try { el.dispatchEvent(new MouseEvent("mousemove", init)); } catch {}
|
|
1599
|
+
})()`
|
|
1600
|
+
);
|
|
1601
|
+
} else {
|
|
1602
|
+
return yield* new DriverError({
|
|
1603
|
+
message: "hover() is not supported on this driver/platform"
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
yield* afterMutation();
|
|
1607
|
+
}),
|
|
1320
1608
|
/**
|
|
1321
1609
|
* Atomic 1-round-trip form fill: on web/DOM channels, waits for actionability,
|
|
1322
|
-
* focuses, clears, sets the React/Vue-safe value,
|
|
1323
|
-
*
|
|
1610
|
+
* focuses, clears, sets the React/Vue-safe value, verifies the value survived
|
|
1611
|
+
* React re-render/remount, and retries up to 3x. For contenteditable editors
|
|
1612
|
+
* (TipTap/ProseMirror/Lexical/Slate) or stubborn controlled inputs, falls back
|
|
1613
|
+
* seamlessly to native tap + SelectAll + Backspace + keyboard input.
|
|
1324
1614
|
*/
|
|
1325
1615
|
fill: (selector, text, opts) => Effect4.gen(function* () {
|
|
1326
1616
|
const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
|
|
1617
|
+
const fillStart = Date.now();
|
|
1327
1618
|
const domChannel = driver.domChannel;
|
|
1328
1619
|
if (!isSystemUISelector(selector) && !isRelativeSelectorLike2(selector) && domChannel?.isConnected() && domChannel.fillDom) {
|
|
1329
1620
|
const filled = yield* Effect4.tryPromise({
|
|
@@ -1334,6 +1625,33 @@ function createCoordinator(driver, config) {
|
|
|
1334
1625
|
yield* afterMutation();
|
|
1335
1626
|
return;
|
|
1336
1627
|
}
|
|
1628
|
+
const remaining = Math.max(50, timeout - (Date.now() - fillStart));
|
|
1629
|
+
const fallbackEl = yield* Effect4.either(
|
|
1630
|
+
waitForActionElement(
|
|
1631
|
+
driver,
|
|
1632
|
+
selector,
|
|
1633
|
+
parse,
|
|
1634
|
+
{
|
|
1635
|
+
...defaults,
|
|
1636
|
+
...opts,
|
|
1637
|
+
timeout: Math.min(remaining, 1500),
|
|
1638
|
+
platform: opts?.platform ?? config.platform
|
|
1639
|
+
},
|
|
1640
|
+
cache
|
|
1641
|
+
)
|
|
1642
|
+
);
|
|
1643
|
+
if (fallbackEl._tag === "Right") {
|
|
1644
|
+
const { x: x2, y: y2 } = centerOf(fallbackEl.right);
|
|
1645
|
+
yield* driver.tapAtCoordinate(x2, y2);
|
|
1646
|
+
const selectAllKey = process.platform === "darwin" ? "Meta+a" : "Control+a";
|
|
1647
|
+
yield* Effect4.either(driver.pressKey(selectAllKey));
|
|
1648
|
+
yield* Effect4.either(driver.pressKey("Backspace"));
|
|
1649
|
+
if (text.length > 0) {
|
|
1650
|
+
yield* driver.inputText(text);
|
|
1651
|
+
}
|
|
1652
|
+
yield* afterMutation();
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1337
1655
|
return yield* new ElementNotFoundError({
|
|
1338
1656
|
message: `Element not fillable within ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1339
1657
|
selector,
|
|
@@ -1521,8 +1839,133 @@ function buildStorybookUrl(storyId, options, runtime) {
|
|
|
1521
1839
|
return url.toString();
|
|
1522
1840
|
}
|
|
1523
1841
|
|
|
1524
|
-
// src/api/
|
|
1842
|
+
// src/api/expect.ts
|
|
1525
1843
|
import { Effect as Effect5 } from "effect";
|
|
1844
|
+
function selectorToCss(sel) {
|
|
1845
|
+
if (typeof sel === "string") return sel;
|
|
1846
|
+
if (typeof sel === "object" && sel !== null && "css" in sel && sel.css) return sel.css;
|
|
1847
|
+
if (typeof sel === "object" && sel !== null && "testID" in sel && sel.testID)
|
|
1848
|
+
return `[data-testid="${sel.testID}"]`;
|
|
1849
|
+
if (typeof sel === "object" && sel !== null && "accessibilityLabel" in sel && sel.accessibilityLabel)
|
|
1850
|
+
return `[aria-label="${sel.accessibilityLabel}"]`;
|
|
1851
|
+
return "";
|
|
1852
|
+
}
|
|
1853
|
+
function createPromiseExpect(driver, config, recorder, flowContext, visualRegression) {
|
|
1854
|
+
const ctx = flowContext ?? {
|
|
1855
|
+
flowFilePath: "",
|
|
1856
|
+
flowName: "unknown",
|
|
1857
|
+
platform: "web"
|
|
1858
|
+
};
|
|
1859
|
+
const coord = createCoordinator(driver, config);
|
|
1860
|
+
const run = (effect) => Effect5.runPromise(effect);
|
|
1861
|
+
const runStep = (command, selector, action) => recorder ? recorder.runStep(command, action, { selector, captureScreenshot: false }) : action();
|
|
1862
|
+
const expectFn = ((selector) => ({
|
|
1863
|
+
toBeVisible: (opts) => runStep(
|
|
1864
|
+
"expect.toBeVisible",
|
|
1865
|
+
selector,
|
|
1866
|
+
() => run(coord.assertVisible(selector, opts)).then(() => {
|
|
1867
|
+
})
|
|
1868
|
+
),
|
|
1869
|
+
toBeHidden: (opts) => runStep("expect.toBeHidden", selector, () => run(coord.assertHidden(selector, opts))),
|
|
1870
|
+
toHaveText: (expected, opts) => runStep(
|
|
1871
|
+
`expect.toHaveText(${JSON.stringify(expected)})`,
|
|
1872
|
+
selector,
|
|
1873
|
+
() => run(coord.assertText(selector, expected, opts))
|
|
1874
|
+
),
|
|
1875
|
+
toMatchText: (pattern, opts) => runStep(
|
|
1876
|
+
`expect.toMatchText(${pattern})`,
|
|
1877
|
+
selector,
|
|
1878
|
+
() => run(coord.assertMatchesText(selector, pattern, opts))
|
|
1879
|
+
),
|
|
1880
|
+
toHaveValue: (expected, opts) => runStep(
|
|
1881
|
+
`expect.toHaveValue(${JSON.stringify(expected)})`,
|
|
1882
|
+
selector,
|
|
1883
|
+
() => run(coord.assertValue(selector, expected, opts))
|
|
1884
|
+
),
|
|
1885
|
+
toHaveAttribute: (name, value, opts) => runStep(
|
|
1886
|
+
`expect.toHaveAttribute(${JSON.stringify(name)})`,
|
|
1887
|
+
selector,
|
|
1888
|
+
() => run(coord.assertAttribute(selector, name, value, opts))
|
|
1889
|
+
),
|
|
1890
|
+
toBeEnabled: (opts) => runStep("expect.toBeEnabled", selector, () => run(coord.assertEnabled(selector, opts))),
|
|
1891
|
+
toBeDisabled: (opts) => runStep("expect.toBeDisabled", selector, () => run(coord.assertDisabled(selector, opts))),
|
|
1892
|
+
toContainText: (expected, opts) => runStep(
|
|
1893
|
+
`expect.toContainText(${JSON.stringify(expected)})`,
|
|
1894
|
+
selector,
|
|
1895
|
+
() => run(coord.assertContainsText(selector, expected, opts))
|
|
1896
|
+
),
|
|
1897
|
+
toHaveCount: (expected, opts) => runStep(
|
|
1898
|
+
`expect.toHaveCount(${expected})`,
|
|
1899
|
+
selector,
|
|
1900
|
+
() => run(coord.assertCount(selector, expected, opts))
|
|
1901
|
+
),
|
|
1902
|
+
toBeFocused: (opts) => runStep("expect.toBeFocused", selector, () => run(coord.assertFocused(selector, opts))),
|
|
1903
|
+
toHaveAccessibleName: (expected, opts) => runStep(
|
|
1904
|
+
`expect.toHaveAccessibleName(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
1905
|
+
selector,
|
|
1906
|
+
() => run(coord.assertAccessibleName(selector, expected, opts))
|
|
1907
|
+
),
|
|
1908
|
+
toMatchScreenshot: (name, options) => runStep(
|
|
1909
|
+
`expect.toMatchScreenshot(${JSON.stringify(name)})`,
|
|
1910
|
+
selector,
|
|
1911
|
+
() => run(
|
|
1912
|
+
coord.assertScreenshot(selector, name, ctx.flowFilePath, ctx.flowName, ctx.platform, {
|
|
1913
|
+
threshold: options?.threshold ?? visualRegression?.threshold,
|
|
1914
|
+
maxDiffPixelRatio: options?.maxDiffPixelRatio ?? visualRegression?.maxDiffPixelRatio,
|
|
1915
|
+
mask: [],
|
|
1916
|
+
updateBaselines: ctx.updateBaselines,
|
|
1917
|
+
baselinesDir: visualRegression?.baselinesDir
|
|
1918
|
+
})
|
|
1919
|
+
)
|
|
1920
|
+
),
|
|
1921
|
+
toPassAccessibilityAudit: (options) => {
|
|
1922
|
+
const excludeCss = options?.exclude?.map(selectorToCss).filter(Boolean) ?? [];
|
|
1923
|
+
const targetCss = selectorToCss(selector);
|
|
1924
|
+
return runStep(
|
|
1925
|
+
"expect.toPassAccessibilityAudit",
|
|
1926
|
+
selector,
|
|
1927
|
+
() => run(
|
|
1928
|
+
coord.assertAccessibilityAudit(ctx.platform, {
|
|
1929
|
+
severity: options?.severity,
|
|
1930
|
+
rules: options?.rules,
|
|
1931
|
+
targetSelector: targetCss || void 0,
|
|
1932
|
+
excludeSelectors: excludeCss
|
|
1933
|
+
})
|
|
1934
|
+
)
|
|
1935
|
+
);
|
|
1936
|
+
},
|
|
1937
|
+
toHaveAccessibilityLabel: (expected) => runStep(
|
|
1938
|
+
`expect.toHaveAccessibilityLabel(${expected !== void 0 ? JSON.stringify(expected) : ""})`,
|
|
1939
|
+
selector,
|
|
1940
|
+
() => run(coord.assertAccessibilityLabel(selector, expected))
|
|
1941
|
+
),
|
|
1942
|
+
toBeFocusable: () => runStep(
|
|
1943
|
+
"expect.toBeFocusable",
|
|
1944
|
+
selector,
|
|
1945
|
+
() => run(coord.assertFocusable(selector, ctx.platform))
|
|
1946
|
+
),
|
|
1947
|
+
toHaveRole: (expected) => runStep(
|
|
1948
|
+
`expect.toHaveRole(${JSON.stringify(expected)})`,
|
|
1949
|
+
selector,
|
|
1950
|
+
() => run(coord.assertRole(selector, expected, ctx.platform))
|
|
1951
|
+
),
|
|
1952
|
+
toHaveMinTouchTarget: (size = 44) => runStep(
|
|
1953
|
+
`expect.toHaveMinTouchTarget(${size})`,
|
|
1954
|
+
selector,
|
|
1955
|
+
() => run(coord.assertMinTouchTarget(selector, size))
|
|
1956
|
+
)
|
|
1957
|
+
}));
|
|
1958
|
+
expectFn.toHaveURL = (expected, opts) => {
|
|
1959
|
+
const label = `expect.toHaveURL(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`;
|
|
1960
|
+
return recorder ? recorder.runStep(label, () => run(coord.waitForURL(expected, opts)), {
|
|
1961
|
+
captureScreenshot: false
|
|
1962
|
+
}) : run(coord.waitForURL(expected, opts));
|
|
1963
|
+
};
|
|
1964
|
+
return expectFn;
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
// src/api/app.ts
|
|
1968
|
+
import { Effect as Effect6 } from "effect";
|
|
1526
1969
|
|
|
1527
1970
|
// src/drivers/launch-options.ts
|
|
1528
1971
|
function mergeRecord(base, override) {
|
|
@@ -1630,15 +2073,217 @@ function buildIOSLaunchConfiguration(options) {
|
|
|
1630
2073
|
|
|
1631
2074
|
// src/api/app.ts
|
|
1632
2075
|
var describeMatcher = (matcher) => typeof matcher === "string" ? matcher : matcher.toString();
|
|
2076
|
+
function formatEvaluateCommand(fn) {
|
|
2077
|
+
const raw = typeof fn === "string" ? fn : fn.toString();
|
|
2078
|
+
const compact = raw.replaceAll(/\s+/g, " ").trim();
|
|
2079
|
+
const snippet = compact.length > 72 ? `${compact.slice(0, 69)}...` : compact;
|
|
2080
|
+
return `evaluate(${snippet})`;
|
|
2081
|
+
}
|
|
2082
|
+
function parseSetCookieHeader(headerValue, originUrl) {
|
|
2083
|
+
const parts = headerValue.split(";").map((p) => p.trim());
|
|
2084
|
+
const first2 = parts[0];
|
|
2085
|
+
if (!first2) return null;
|
|
2086
|
+
const eqIdx = first2.indexOf("=");
|
|
2087
|
+
if (eqIdx <= 0) return null;
|
|
2088
|
+
const name = first2.slice(0, eqIdx).trim();
|
|
2089
|
+
const value = first2.slice(eqIdx + 1).trim();
|
|
2090
|
+
const cookie = {
|
|
2091
|
+
name,
|
|
2092
|
+
value,
|
|
2093
|
+
url: `${originUrl.origin}/`,
|
|
2094
|
+
path: "/"
|
|
2095
|
+
};
|
|
2096
|
+
for (const attr of parts.slice(1)) {
|
|
2097
|
+
const [rawK, ...rest] = attr.split("=");
|
|
2098
|
+
const k = (rawK ?? "").trim().toLowerCase();
|
|
2099
|
+
const v = rest.join("=").trim();
|
|
2100
|
+
if (k === "path" && v) cookie.path = v;
|
|
2101
|
+
else if (k === "domain" && v) {
|
|
2102
|
+
cookie.domain = v;
|
|
2103
|
+
delete cookie.url;
|
|
2104
|
+
} else if (k === "httponly") cookie.httpOnly = true;
|
|
2105
|
+
else if (k === "secure") cookie.secure = true;
|
|
2106
|
+
else if (k === "samesite") {
|
|
2107
|
+
const norm = v.toLowerCase();
|
|
2108
|
+
if (norm === "strict") cookie.sameSite = "Strict";
|
|
2109
|
+
else if (norm === "lax") cookie.sameSite = "Lax";
|
|
2110
|
+
else if (norm === "none") cookie.sameSite = "None";
|
|
2111
|
+
} else if (k === "max-age") {
|
|
2112
|
+
const sec = Number.parseInt(v, 10);
|
|
2113
|
+
if (Number.isFinite(sec)) cookie.expires = Math.floor(Date.now() / 1e3) + sec;
|
|
2114
|
+
} else if (k === "expires") {
|
|
2115
|
+
const ts = Date.parse(v);
|
|
2116
|
+
if (Number.isFinite(ts)) cookie.expires = Math.floor(ts / 1e3);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
return cookie;
|
|
2120
|
+
}
|
|
2121
|
+
var RECORDED_RAW_PAGE_METHODS = /* @__PURE__ */ new Set([
|
|
2122
|
+
"goto",
|
|
2123
|
+
"reload",
|
|
2124
|
+
"click",
|
|
2125
|
+
"dblclick",
|
|
2126
|
+
"fill",
|
|
2127
|
+
"hover",
|
|
2128
|
+
"press",
|
|
2129
|
+
"type",
|
|
2130
|
+
"check",
|
|
2131
|
+
"uncheck",
|
|
2132
|
+
"selectOption",
|
|
2133
|
+
"setInputFiles",
|
|
2134
|
+
"waitForURL",
|
|
2135
|
+
"waitForResponse",
|
|
2136
|
+
"waitForSelector",
|
|
2137
|
+
"evaluate"
|
|
2138
|
+
]);
|
|
2139
|
+
function wrapRawPageWithStepRecording(rawPage, recorder) {
|
|
2140
|
+
if (!recorder || !rawPage || typeof rawPage !== "object") return rawPage;
|
|
2141
|
+
const candidate = rawPage;
|
|
2142
|
+
if (typeof candidate["goto"] !== "function" || typeof candidate["click"] !== "function") {
|
|
2143
|
+
return rawPage;
|
|
2144
|
+
}
|
|
2145
|
+
return new Proxy(candidate, {
|
|
2146
|
+
get(target, prop, receiver) {
|
|
2147
|
+
if (prop === "then") return void 0;
|
|
2148
|
+
const value = Reflect.get(target, prop, receiver);
|
|
2149
|
+
if (typeof value !== "function") return value;
|
|
2150
|
+
if (typeof prop === "string" && RECORDED_RAW_PAGE_METHODS.has(prop)) {
|
|
2151
|
+
return (...callArgs) => {
|
|
2152
|
+
const argHint = typeof callArgs[0] === "string" ? callArgs[0].length > 60 ? `${callArgs[0].slice(0, 57)}...` : callArgs[0] : void 0;
|
|
2153
|
+
const cmd = argHint ? `page.${prop}(${JSON.stringify(argHint)})` : `page.${prop}`;
|
|
2154
|
+
return recorder.runStep(cmd, () => Promise.resolve(value.apply(target, callArgs)), {
|
|
2155
|
+
captureScreenshot: false
|
|
2156
|
+
});
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2159
|
+
return value.bind(target);
|
|
2160
|
+
}
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
1633
2163
|
function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
1634
2164
|
const coord = createCoordinator(driver, config);
|
|
1635
2165
|
const platform = options.platform ?? (appId.startsWith("http://") || appId.startsWith("https://") ? "web" : void 0);
|
|
1636
|
-
const run = (effect) =>
|
|
1637
|
-
const unsupportedWebFeature = (feature) =>
|
|
2166
|
+
const run = (effect) => Effect6.runPromise(effect);
|
|
2167
|
+
const unsupportedWebFeature = (feature) => Effect6.fail(new DriverError({ message: `${feature}() is only supported on the web platform` }));
|
|
1638
2168
|
const optionalMethod = (name, method) => method ?? ((..._args) => unsupportedWebFeature(name));
|
|
1639
2169
|
const runStep = (command, action, opts) => recorder ? recorder.runStep(command, action, opts) : action();
|
|
1640
2170
|
const runScreenshotStep = (command, action, opts) => recorder ? recorder.runScreenshotStep(command, action, opts) : action();
|
|
1641
|
-
|
|
2171
|
+
const getCurrentUrl = async () => {
|
|
2172
|
+
if (driver.getUrl) {
|
|
2173
|
+
return run(driver.getUrl());
|
|
2174
|
+
}
|
|
2175
|
+
return run(
|
|
2176
|
+
driver.evaluate(
|
|
2177
|
+
"typeof window !== 'undefined' && window.location ? String(window.location.href || '') : ''"
|
|
2178
|
+
).pipe(Effect6.catchAll(() => Effect6.succeed("")))
|
|
2179
|
+
);
|
|
2180
|
+
};
|
|
2181
|
+
const resolveRequestUrl = async (rawUrl) => {
|
|
2182
|
+
if (rawUrl.startsWith("http://") || rawUrl.startsWith("https://")) {
|
|
2183
|
+
return new URL(rawUrl);
|
|
2184
|
+
}
|
|
2185
|
+
const pageUrl = await getCurrentUrl();
|
|
2186
|
+
const base = pageUrl && (pageUrl.startsWith("http://") || pageUrl.startsWith("https://")) ? pageUrl : appId.startsWith("http://") || appId.startsWith("https://") ? appId : "http://localhost";
|
|
2187
|
+
return new URL(rawUrl, base);
|
|
2188
|
+
};
|
|
2189
|
+
const performBrowserRequest = async (method, rawUrl, init) => {
|
|
2190
|
+
const targetUrl = await resolveRequestUrl(rawUrl);
|
|
2191
|
+
if (init?.query) {
|
|
2192
|
+
for (const [k, v] of Object.entries(init.query)) {
|
|
2193
|
+
if (v !== void 0) targetUrl.searchParams.set(k, String(v));
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
const headers = { ...init?.headers };
|
|
2197
|
+
const hasCookieHeader = Object.keys(headers).some((k) => k.toLowerCase() === "cookie");
|
|
2198
|
+
if (!hasCookieHeader && driver.getCookies) {
|
|
2199
|
+
const cookies = await run(driver.getCookies([targetUrl.toString()])).catch(() => []);
|
|
2200
|
+
if (cookies.length > 0) {
|
|
2201
|
+
headers["cookie"] = cookies.map((c) => `${c.name}=${c.value}`).join("; ");
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
let requestBody;
|
|
2205
|
+
if (init?.body !== void 0) {
|
|
2206
|
+
if (typeof init.body === "string") {
|
|
2207
|
+
requestBody = init.body;
|
|
2208
|
+
} else {
|
|
2209
|
+
requestBody = JSON.stringify(init.body);
|
|
2210
|
+
if (!Object.keys(headers).some((k) => k.toLowerCase() === "content-type")) {
|
|
2211
|
+
headers["content-type"] = "application/json";
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
const res = await fetch(targetUrl.toString(), {
|
|
2216
|
+
method,
|
|
2217
|
+
headers,
|
|
2218
|
+
...requestBody !== void 0 ? { body: requestBody } : {},
|
|
2219
|
+
...init?.signal ? { signal: init.signal } : {}
|
|
2220
|
+
});
|
|
2221
|
+
if (driver.setCookies) {
|
|
2222
|
+
const rawSetCookies = typeof res.headers.getSetCookie === "function" ? res.headers.getSetCookie() : res.headers.get("set-cookie") ? [res.headers.get("set-cookie")] : [];
|
|
2223
|
+
const parsedCookies = rawSetCookies.map((line) => parseSetCookieHeader(line, targetUrl)).filter((c) => c !== null);
|
|
2224
|
+
if (parsedCookies.length > 0) {
|
|
2225
|
+
await run(driver.setCookies(parsedCookies)).catch(() => {
|
|
2226
|
+
});
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
const rawText = await res.text();
|
|
2230
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
2231
|
+
let data = rawText;
|
|
2232
|
+
if (contentType.includes("application/json")) {
|
|
2233
|
+
try {
|
|
2234
|
+
data = JSON.parse(rawText);
|
|
2235
|
+
} catch {
|
|
2236
|
+
data = rawText;
|
|
2237
|
+
}
|
|
2238
|
+
} else if (rawText.trim().startsWith("{") || rawText.trim().startsWith("[")) {
|
|
2239
|
+
try {
|
|
2240
|
+
data = JSON.parse(rawText);
|
|
2241
|
+
} catch {
|
|
2242
|
+
data = rawText;
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
return {
|
|
2246
|
+
status: res.status,
|
|
2247
|
+
statusText: res.statusText,
|
|
2248
|
+
ok: res.ok,
|
|
2249
|
+
url: res.url || targetUrl.toString(),
|
|
2250
|
+
headers: res.headers,
|
|
2251
|
+
data,
|
|
2252
|
+
text: async () => rawText,
|
|
2253
|
+
json: async () => JSON.parse(rawText)
|
|
2254
|
+
};
|
|
2255
|
+
};
|
|
2256
|
+
const requestClient = {
|
|
2257
|
+
fetch: (url, init) => {
|
|
2258
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
2259
|
+
return runStep(
|
|
2260
|
+
`request.${method}(${url})`,
|
|
2261
|
+
() => performBrowserRequest(method, url, init)
|
|
2262
|
+
);
|
|
2263
|
+
},
|
|
2264
|
+
get: (url, opts) => runStep(`request.GET(${url})`, () => performBrowserRequest("GET", url, opts)),
|
|
2265
|
+
post: (url, body, opts) => runStep(
|
|
2266
|
+
`request.POST(${url})`,
|
|
2267
|
+
() => performBrowserRequest("POST", url, { ...opts, body })
|
|
2268
|
+
),
|
|
2269
|
+
put: (url, body, opts) => runStep(
|
|
2270
|
+
`request.PUT(${url})`,
|
|
2271
|
+
() => performBrowserRequest("PUT", url, { ...opts, body })
|
|
2272
|
+
),
|
|
2273
|
+
patch: (url, body, opts) => runStep(
|
|
2274
|
+
`request.PATCH(${url})`,
|
|
2275
|
+
() => performBrowserRequest("PATCH", url, { ...opts, body })
|
|
2276
|
+
),
|
|
2277
|
+
delete: (url, opts) => runStep(`request.DELETE(${url})`, () => performBrowserRequest("DELETE", url, opts))
|
|
2278
|
+
};
|
|
2279
|
+
const appExpect = createPromiseExpect(
|
|
2280
|
+
driver,
|
|
2281
|
+
config,
|
|
2282
|
+
recorder,
|
|
2283
|
+
options.flowContext,
|
|
2284
|
+
options.visualRegression
|
|
2285
|
+
);
|
|
2286
|
+
const appObj = {
|
|
1642
2287
|
tap: (selector, opts) => runStep("tap", () => run(coord.tap(selector, opts)), { selector, captureScreenshot: true }),
|
|
1643
2288
|
tapXY: (x, y) => runStep("tapXY", () => run(coord.tapXY(x, y)), {
|
|
1644
2289
|
selector: { point: { x, y } },
|
|
@@ -1656,6 +2301,10 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
1656
2301
|
selector: { point: { x, y } },
|
|
1657
2302
|
captureScreenshot: true
|
|
1658
2303
|
}),
|
|
2304
|
+
hover: (selector, opts) => runStep("hover", () => run(coord.hover(selector, opts)), {
|
|
2305
|
+
selector,
|
|
2306
|
+
captureScreenshot: true
|
|
2307
|
+
}),
|
|
1659
2308
|
inputText: (text) => runStep("inputText", () => run(coord.inputText(text)), { captureScreenshot: true }),
|
|
1660
2309
|
fill: (selector, value, opts) => runStep("fill", () => run(coord.fill(selector, value, opts)), {
|
|
1661
2310
|
selector,
|
|
@@ -1741,12 +2390,39 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
1741
2390
|
}
|
|
1742
2391
|
),
|
|
1743
2392
|
back: () => runStep("back", () => run(driver.back()), { captureScreenshot: true }),
|
|
2393
|
+
reload: (opts) => runStep(
|
|
2394
|
+
"reload",
|
|
2395
|
+
async () => {
|
|
2396
|
+
if (driver.reload) {
|
|
2397
|
+
await run(driver.reload(opts));
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2400
|
+
if (driver.domChannel?.reload) {
|
|
2401
|
+
await driver.domChannel.reload();
|
|
2402
|
+
return;
|
|
2403
|
+
}
|
|
2404
|
+
await run(driver.evaluate("window.location.reload()"));
|
|
2405
|
+
},
|
|
2406
|
+
{ captureScreenshot: true }
|
|
2407
|
+
),
|
|
2408
|
+
url: () => runStep("url", () => getCurrentUrl()),
|
|
2409
|
+
waitForURL: (expected, opts) => runStep(
|
|
2410
|
+
`waitForURL(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2411
|
+
() => run(coord.waitForURL(expected, opts))
|
|
2412
|
+
),
|
|
2413
|
+
waitForResponse: (matcher, opts) => runStep(
|
|
2414
|
+
`waitForResponse(${typeof matcher === "function" ? "<predicate>" : describeMatcher(matcher)})`,
|
|
2415
|
+
() => run(optionalMethod("waitForResponse", driver.waitForResponse)(matcher, opts))
|
|
2416
|
+
),
|
|
1744
2417
|
takeScreenshot: (name) => runScreenshotStep(
|
|
1745
2418
|
name ? `takeScreenshot(${name})` : "takeScreenshot",
|
|
1746
2419
|
() => run(driver.takeScreenshot()),
|
|
1747
2420
|
{ name }
|
|
1748
2421
|
),
|
|
1749
|
-
evaluate: (fn, ...args) => runStep(
|
|
2422
|
+
evaluate: (fn, ...args) => runStep(
|
|
2423
|
+
formatEvaluateCommand(fn),
|
|
2424
|
+
() => run(driver.evaluate(fn, ...args))
|
|
2425
|
+
),
|
|
1750
2426
|
mockNetwork: (matcher, response) => runStep(
|
|
1751
2427
|
"mockNetwork",
|
|
1752
2428
|
() => run(optionalMethod("mockNetwork", driver.mockNetwork)(matcher, response)),
|
|
@@ -1770,12 +2446,22 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
1770
2446
|
() => run(optionalMethod("setNetworkConditions", driver.setNetworkConditions)(conditions)),
|
|
1771
2447
|
{ selector: conditions }
|
|
1772
2448
|
),
|
|
2449
|
+
setOffline: (offline) => runStep(
|
|
2450
|
+
`setOffline(${offline})`,
|
|
2451
|
+
() => run(optionalMethod("setOffline", driver.setNetworkConditions)({ offline })),
|
|
2452
|
+
{ selector: { offline } }
|
|
2453
|
+
),
|
|
1773
2454
|
saveCookies: (path) => runStep("saveCookies", () => run(optionalMethod("saveCookies", driver.saveCookies)(path)), {
|
|
1774
2455
|
selector: { path }
|
|
1775
2456
|
}),
|
|
1776
2457
|
loadCookies: (path) => runStep("loadCookies", () => run(optionalMethod("loadCookies", driver.loadCookies)(path)), {
|
|
1777
2458
|
selector: { path }
|
|
1778
2459
|
}),
|
|
2460
|
+
getCookies: (urls) => runStep("getCookies", () => run(optionalMethod("getCookies", driver.getCookies)(urls))),
|
|
2461
|
+
setCookies: (cookies) => runStep("setCookies", () => run(optionalMethod("setCookies", driver.setCookies)(cookies)), {
|
|
2462
|
+
selector: { count: cookies.length }
|
|
2463
|
+
}),
|
|
2464
|
+
clearCookies: () => runStep("clearCookies", () => run(optionalMethod("clearCookies", driver.clearCookies)())),
|
|
1779
2465
|
saveAuthState: (path) => runStep(
|
|
1780
2466
|
"saveAuthState",
|
|
1781
2467
|
() => run(optionalMethod("saveAuthState", driver.saveAuthState)(path)),
|
|
@@ -1821,13 +2507,76 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
1821
2507
|
),
|
|
1822
2508
|
getJSErrors: () => runStep("getJSErrors", () => run(optionalMethod("getJSErrors", driver.getJSErrors)())),
|
|
1823
2509
|
getHAR: () => runStep("getHAR", () => run(optionalMethod("getHAR", driver.getHAR)())),
|
|
2510
|
+
request: requestClient,
|
|
2511
|
+
newContext: (ctxOpts) => runStep(
|
|
2512
|
+
"newContext",
|
|
2513
|
+
async () => {
|
|
2514
|
+
const created = await run(
|
|
2515
|
+
optionalMethod("newContext", driver.createIsolatedContext)(ctxOpts)
|
|
2516
|
+
);
|
|
2517
|
+
let closed = false;
|
|
2518
|
+
const safeClose = async () => {
|
|
2519
|
+
if (closed) return;
|
|
2520
|
+
closed = true;
|
|
2521
|
+
await created.close();
|
|
2522
|
+
};
|
|
2523
|
+
options.onRegisterCleanup?.(safeClose);
|
|
2524
|
+
const childDriver = created.driver;
|
|
2525
|
+
const childApp = createPromiseApp(childDriver, appId, config, recorder, options);
|
|
2526
|
+
const childExpect = createPromiseExpect(
|
|
2527
|
+
childDriver,
|
|
2528
|
+
config,
|
|
2529
|
+
recorder,
|
|
2530
|
+
options.flowContext,
|
|
2531
|
+
options.visualRegression
|
|
2532
|
+
);
|
|
2533
|
+
return { app: childApp, expect: childExpect, close: safeClose };
|
|
2534
|
+
},
|
|
2535
|
+
{ selector: ctxOpts }
|
|
2536
|
+
),
|
|
2537
|
+
frame: (frameSelector) => {
|
|
2538
|
+
const scoped = (sel) => inFrame(frameSelector, sel);
|
|
2539
|
+
return {
|
|
2540
|
+
tap: (sel, opts) => appObj.tap(scoped(sel), opts),
|
|
2541
|
+
doubleTap: (sel, opts) => appObj.doubleTap(scoped(sel), opts),
|
|
2542
|
+
longPress: (sel, opts) => appObj.longPress(scoped(sel), opts),
|
|
2543
|
+
hover: (sel, opts) => appObj.hover(scoped(sel), opts),
|
|
2544
|
+
fill: (sel, value, opts) => appObj.fill(scoped(sel), value, opts),
|
|
2545
|
+
uploadFile: (sel, path) => appObj.uploadFile(scoped(sel), path),
|
|
2546
|
+
getText: (sel, opts) => appObj.getText(scoped(sel), opts),
|
|
2547
|
+
getAttribute: (sel, name, opts) => appObj.getAttribute(scoped(sel), name, opts),
|
|
2548
|
+
isVisible: (sel, opts) => appObj.isVisible(scoped(sel), opts),
|
|
2549
|
+
isEnabled: (sel, opts) => appObj.isEnabled(scoped(sel), opts),
|
|
2550
|
+
expect: (sel) => appExpect(scoped(sel))
|
|
2551
|
+
};
|
|
2552
|
+
},
|
|
1824
2553
|
getPage: () => {
|
|
1825
2554
|
if (!driver.getRawPage) {
|
|
1826
2555
|
throw new DriverError({
|
|
1827
2556
|
message: "getPage() is only available when running with a browser driver that exposes a raw page."
|
|
1828
2557
|
});
|
|
1829
2558
|
}
|
|
1830
|
-
return driver.getRawPage();
|
|
2559
|
+
return wrapRawPageWithStepRecording(driver.getRawPage(), recorder);
|
|
2560
|
+
},
|
|
2561
|
+
cdp: () => {
|
|
2562
|
+
const raw = driver.getCdpSession?.();
|
|
2563
|
+
if (!raw) {
|
|
2564
|
+
throw new DriverError({
|
|
2565
|
+
message: "app.cdp() is only available on Chromium web drivers (Direct CDP or Playwright Chromium)."
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2568
|
+
return {
|
|
2569
|
+
send: (method, params) => runStep(`cdp.${method}`, () => raw.send(method, params), {
|
|
2570
|
+
selector: params
|
|
2571
|
+
}),
|
|
2572
|
+
on: (event, listener) => raw.on(event, listener),
|
|
2573
|
+
get sessionId() {
|
|
2574
|
+
return raw.sessionId;
|
|
2575
|
+
},
|
|
2576
|
+
get browserContextId() {
|
|
2577
|
+
return raw.browserContextId;
|
|
2578
|
+
}
|
|
2579
|
+
};
|
|
1831
2580
|
},
|
|
1832
2581
|
enableVirtualAuthenticator: (opts) => runStep(
|
|
1833
2582
|
"enableVirtualAuthenticator",
|
|
@@ -1849,6 +2598,16 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
1849
2598
|
"getVirtualCredentials",
|
|
1850
2599
|
() => run(optionalMethod("getVirtualCredentials", driver.getVirtualCredentials)(authenticatorId))
|
|
1851
2600
|
),
|
|
2601
|
+
addVirtualCredential: (credential, authenticatorId) => runStep(
|
|
2602
|
+
"addVirtualCredential",
|
|
2603
|
+
() => run(
|
|
2604
|
+
optionalMethod("addVirtualCredential", driver.addVirtualCredential)(
|
|
2605
|
+
credential,
|
|
2606
|
+
authenticatorId
|
|
2607
|
+
)
|
|
2608
|
+
),
|
|
2609
|
+
{ selector: { credentialId: credential.credentialId, rpId: credential.rpId } }
|
|
2610
|
+
),
|
|
1852
2611
|
clearVirtualCredentials: (authenticatorId) => runStep(
|
|
1853
2612
|
"clearVirtualCredentials",
|
|
1854
2613
|
() => run(
|
|
@@ -1874,8 +2633,8 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
1874
2633
|
isVisible: (selector, opts) => {
|
|
1875
2634
|
const timeout = opts?.timeout ?? 1e3;
|
|
1876
2635
|
return run(
|
|
1877
|
-
|
|
1878
|
-
const result = yield*
|
|
2636
|
+
Effect6.gen(function* () {
|
|
2637
|
+
const result = yield* Effect6.either(
|
|
1879
2638
|
waitForElement(
|
|
1880
2639
|
driver,
|
|
1881
2640
|
selector,
|
|
@@ -1967,19 +2726,19 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
1967
2726
|
// WebView / hybrid context switching (low-level escape hatches)
|
|
1968
2727
|
getContexts: () => runStep(
|
|
1969
2728
|
"getContexts",
|
|
1970
|
-
() => run((driver.getContexts ?? (() =>
|
|
2729
|
+
() => run((driver.getContexts ?? (() => Effect6.succeed(["NATIVE_APP"])))())
|
|
1971
2730
|
),
|
|
1972
2731
|
getCurrentContext: () => runStep(
|
|
1973
2732
|
"getCurrentContext",
|
|
1974
|
-
() => run((driver.getCurrentContext ?? (() =>
|
|
2733
|
+
() => run((driver.getCurrentContext ?? (() => Effect6.succeed("NATIVE_APP")))())
|
|
1975
2734
|
),
|
|
1976
2735
|
switchToContext: (contextId) => runStep(
|
|
1977
2736
|
`switchToContext(${contextId})`,
|
|
1978
|
-
() => run((driver.setContext ?? ((_id) =>
|
|
2737
|
+
() => run((driver.setContext ?? ((_id) => Effect6.void))(contextId))
|
|
1979
2738
|
),
|
|
1980
2739
|
switchToWebView: () => runStep("switchToWebView", async () => {
|
|
1981
2740
|
const contexts = await run(
|
|
1982
|
-
(driver.getContexts ?? (() =>
|
|
2741
|
+
(driver.getContexts ?? (() => Effect6.succeed(["NATIVE_APP"])))()
|
|
1983
2742
|
);
|
|
1984
2743
|
const webview = contexts.find((c) => c.startsWith("WEBVIEW_"));
|
|
1985
2744
|
if (!webview) {
|
|
@@ -1987,13 +2746,14 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
1987
2746
|
message: `No WebView context found. Available contexts: ${contexts.join(", ")}`
|
|
1988
2747
|
});
|
|
1989
2748
|
}
|
|
1990
|
-
await run((driver.setContext ?? ((_id) =>
|
|
2749
|
+
await run((driver.setContext ?? ((_id) => Effect6.void))(webview));
|
|
1991
2750
|
}),
|
|
1992
2751
|
switchToNativeApp: () => runStep(
|
|
1993
2752
|
"switchToNativeApp",
|
|
1994
|
-
() => run((driver.setContext ?? ((_id) =>
|
|
2753
|
+
() => run((driver.setContext ?? ((_id) => Effect6.void))("NATIVE_APP"))
|
|
1995
2754
|
)
|
|
1996
2755
|
};
|
|
2756
|
+
return appObj;
|
|
1997
2757
|
}
|
|
1998
2758
|
|
|
1999
2759
|
// src/drivers/playwright-parser.ts
|
|
@@ -2025,15 +2785,18 @@ function parseWebHierarchy(json) {
|
|
|
2025
2785
|
}
|
|
2026
2786
|
|
|
2027
2787
|
// src/drivers/raw-driver.ts
|
|
2028
|
-
import { Context, Effect as
|
|
2788
|
+
import { Context, Effect as Effect7 } from "effect";
|
|
2029
2789
|
var RawDriver = class extends Context.Tag("RawDriver")() {
|
|
2030
2790
|
};
|
|
2031
2791
|
|
|
2032
2792
|
// src/drivers/playwright.ts
|
|
2033
2793
|
import { spawn } from "child_process";
|
|
2034
2794
|
import { createHash } from "crypto";
|
|
2795
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
2035
2796
|
import { readFile, writeFile } from "fs/promises";
|
|
2036
|
-
import {
|
|
2797
|
+
import { tmpdir } from "os";
|
|
2798
|
+
import { join } from "path";
|
|
2799
|
+
import { Effect as Effect8, Layer } from "effect";
|
|
2037
2800
|
import {
|
|
2038
2801
|
chromium,
|
|
2039
2802
|
firefox,
|
|
@@ -2082,18 +2845,12 @@ async function evaluateOnPage(activePage, script, args) {
|
|
|
2082
2845
|
if (args.length === 1) {
|
|
2083
2846
|
return await activePage.evaluate(script, args[0]);
|
|
2084
2847
|
}
|
|
2085
|
-
const
|
|
2086
|
-
return await activePage.evaluate(
|
|
2087
|
-
({ src, params }) => {
|
|
2088
|
-
const compiled = (0, eval)(`(${src})`);
|
|
2089
|
-
return compiled(...params);
|
|
2090
|
-
},
|
|
2091
|
-
{ src: fnSource, params: args }
|
|
2092
|
-
);
|
|
2848
|
+
const serializedArgs = args.map((arg) => arg === void 0 ? "undefined" : JSON.stringify(arg)).join(", ");
|
|
2849
|
+
return await activePage.evaluate(`(${script.toString()})(${serializedArgs})`);
|
|
2093
2850
|
}
|
|
2094
2851
|
function resolveWarmBrowserKey(scope) {
|
|
2095
2852
|
if (scope && scope.trim().length > 0) return scope.trim();
|
|
2096
|
-
const cwdHash = createHash("
|
|
2853
|
+
const cwdHash = createHash("sha256").update(process.cwd()).digest("hex").slice(0, 10);
|
|
2097
2854
|
return `scope-${cwdHash}`;
|
|
2098
2855
|
}
|
|
2099
2856
|
var INSTANT_ANIMATIONS_INIT_SCRIPT = `
|
|
@@ -2125,19 +2882,29 @@ async function ensureWarmBrowserDaemon(config = {}) {
|
|
|
2125
2882
|
} catch {
|
|
2126
2883
|
}
|
|
2127
2884
|
}
|
|
2128
|
-
const port =
|
|
2885
|
+
const port = await allocateFreePort(9322);
|
|
2886
|
+
const userDataDir = mkdtempSync(join(tmpdir(), "spana-warm-chrome-"));
|
|
2129
2887
|
const execPath = config.executablePath ?? chromium.executablePath();
|
|
2130
2888
|
const child = spawn(
|
|
2131
2889
|
execPath,
|
|
2132
2890
|
[
|
|
2133
2891
|
...config.headless !== false ? ["--headless=new"] : [],
|
|
2134
2892
|
`--remote-debugging-port=${port}`,
|
|
2893
|
+
"--remote-debugging-address=127.0.0.1",
|
|
2894
|
+
`--user-data-dir=${userDataDir}`,
|
|
2135
2895
|
"--no-first-run",
|
|
2136
2896
|
"--no-default-browser-check",
|
|
2897
|
+
"--disable-background-networking",
|
|
2137
2898
|
"--disable-background-timer-throttling",
|
|
2138
2899
|
"--disable-backgrounding-occluded-windows",
|
|
2139
2900
|
"--disable-renderer-backgrounding",
|
|
2140
2901
|
"--disable-ipc-flooding-protection",
|
|
2902
|
+
"--disable-hang-monitor",
|
|
2903
|
+
"--disable-default-apps",
|
|
2904
|
+
"--disable-extensions",
|
|
2905
|
+
"--disable-sync",
|
|
2906
|
+
"--metrics-recording-only",
|
|
2907
|
+
"--disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints",
|
|
2141
2908
|
...config.headless !== false ? ["--disable-gpu"] : [],
|
|
2142
2909
|
"about:blank"
|
|
2143
2910
|
],
|
|
@@ -2159,6 +2926,11 @@ async function ensureWarmBrowserDaemon(config = {}) {
|
|
|
2159
2926
|
await new Promise((r) => setTimeout(r, 80));
|
|
2160
2927
|
}
|
|
2161
2928
|
if (!ready) {
|
|
2929
|
+
try {
|
|
2930
|
+
child.kill("SIGKILL");
|
|
2931
|
+
} catch {
|
|
2932
|
+
}
|
|
2933
|
+
rmSync(userDataDir, { recursive: true, force: true });
|
|
2162
2934
|
throw new Error(`Warm Chromium daemon failed to start on ${cdpUrl}`);
|
|
2163
2935
|
}
|
|
2164
2936
|
registerWarmDaemon({
|
|
@@ -2167,6 +2939,7 @@ async function ensureWarmBrowserDaemon(config = {}) {
|
|
|
2167
2939
|
host: "127.0.0.1",
|
|
2168
2940
|
port,
|
|
2169
2941
|
pid: child.pid,
|
|
2942
|
+
userDataDir,
|
|
2170
2943
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2171
2944
|
});
|
|
2172
2945
|
const browser = await chromium.connectOverCDP(cdpUrl);
|
|
@@ -2264,24 +3037,81 @@ function totalHarTime(timing) {
|
|
|
2264
3037
|
const end = timing.responseEnd >= 0 ? timing.responseEnd : timing.responseStart >= 0 ? timing.responseStart : timing.requestStart >= 0 ? timing.requestStart : 0;
|
|
2265
3038
|
return Math.max(Math.round(end), 0);
|
|
2266
3039
|
}
|
|
3040
|
+
function selectorToFrameCss(frameSel) {
|
|
3041
|
+
if (typeof frameSel === "string") return frameSel;
|
|
3042
|
+
if (typeof frameSel === "object" && frameSel !== null) {
|
|
3043
|
+
if ("css" in frameSel && frameSel.css) return frameSel.css;
|
|
3044
|
+
if ("testID" in frameSel && frameSel.testID) return `[data-testid="${frameSel.testID}"]`;
|
|
3045
|
+
if ("accessibilityLabel" in frameSel && frameSel.accessibilityLabel) {
|
|
3046
|
+
return `[aria-label="${frameSel.accessibilityLabel}"], iframe[title="${frameSel.accessibilityLabel}"]`;
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
return "iframe";
|
|
3050
|
+
}
|
|
3051
|
+
function resolvePlaywrightLocator(root, selector) {
|
|
3052
|
+
if (typeof selector === "string") {
|
|
3053
|
+
return root.getByLabel(selector, { exact: true });
|
|
3054
|
+
}
|
|
3055
|
+
if ("point" in selector) {
|
|
3056
|
+
throw new DriverError({
|
|
3057
|
+
message: "uploadFile() does not support point selectors on the web platform. Use testID, css, role, text, or accessibilityLabel."
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
let scope = root;
|
|
3061
|
+
if (selector.frame) {
|
|
3062
|
+
scope = scope.frameLocator(selectorToFrameCss(selector.frame));
|
|
3063
|
+
}
|
|
3064
|
+
if (selector.within) {
|
|
3065
|
+
scope = resolvePlaywrightLocator(scope, selector.within);
|
|
3066
|
+
}
|
|
3067
|
+
let locator;
|
|
3068
|
+
if ("css" in selector) {
|
|
3069
|
+
locator = scope.locator(selector.css);
|
|
3070
|
+
} else if ("role" in selector) {
|
|
3071
|
+
locator = scope.getByRole(selector.role, {
|
|
3072
|
+
...selector.name !== void 0 ? { name: selector.name } : {},
|
|
3073
|
+
...selector.exact !== void 0 ? { exact: selector.exact } : {}
|
|
3074
|
+
});
|
|
3075
|
+
} else if ("testID" in selector) {
|
|
3076
|
+
locator = scope.getByTestId(selector.testID);
|
|
3077
|
+
} else if ("accessibilityLabel" in selector) {
|
|
3078
|
+
locator = scope.getByLabel(selector.accessibilityLabel, { exact: true });
|
|
3079
|
+
} else {
|
|
3080
|
+
locator = scope.getByLabel(selector.text, { exact: true });
|
|
3081
|
+
}
|
|
3082
|
+
if (selector.hasText !== void 0) {
|
|
3083
|
+
locator = locator.filter({ hasText: selector.hasText });
|
|
3084
|
+
}
|
|
3085
|
+
if (selector.hasNotText !== void 0) {
|
|
3086
|
+
locator = locator.filter({ hasNotText: selector.hasNotText });
|
|
3087
|
+
}
|
|
3088
|
+
if (selector.first) {
|
|
3089
|
+
locator = locator.first();
|
|
3090
|
+
} else if (selector.last) {
|
|
3091
|
+
locator = locator.last();
|
|
3092
|
+
} else if (typeof selector.nth === "number") {
|
|
3093
|
+
locator = locator.nth(selector.nth);
|
|
3094
|
+
}
|
|
3095
|
+
return locator;
|
|
3096
|
+
}
|
|
2267
3097
|
function makePlaywrightDriver(config) {
|
|
2268
|
-
return
|
|
3098
|
+
return Effect8.gen(function* () {
|
|
2269
3099
|
const browserName = config.browser ?? "chromium";
|
|
2270
3100
|
const ownsBrowser = !config.sharedBrowser && !config.cdpEndpoint && !config.wsEndpoint && !config.warmBrowser;
|
|
2271
|
-
const browser = config.sharedBrowser ? config.sharedBrowser : config.wsEndpoint ? yield*
|
|
3101
|
+
const browser = config.sharedBrowser ? config.sharedBrowser : config.wsEndpoint ? yield* Effect8.tryPromise({
|
|
2272
3102
|
try: () => browserLaunchers[browserName].connect(config.wsEndpoint),
|
|
2273
3103
|
catch: (e) => new DriverError({
|
|
2274
3104
|
message: `Failed to connect to remote Playwright server (${config.wsEndpoint}): ${e}`
|
|
2275
3105
|
})
|
|
2276
|
-
}) : config.cdpEndpoint ? yield*
|
|
3106
|
+
}) : config.cdpEndpoint ? yield* Effect8.tryPromise({
|
|
2277
3107
|
try: () => chromium.connectOverCDP(config.cdpEndpoint),
|
|
2278
3108
|
catch: (e) => new DriverError({
|
|
2279
3109
|
message: `Failed to connect to browser over CDP (${config.cdpEndpoint}): ${e}`
|
|
2280
3110
|
})
|
|
2281
|
-
}) : config.warmBrowser && browserName === "chromium" ? yield*
|
|
3111
|
+
}) : config.warmBrowser && browserName === "chromium" ? yield* Effect8.tryPromise({
|
|
2282
3112
|
try: async () => (await ensureWarmBrowserDaemon(config)).browser,
|
|
2283
3113
|
catch: (e) => new DriverError({ message: `Failed to connect to warm Chromium daemon: ${e}` })
|
|
2284
|
-
}) : yield*
|
|
3114
|
+
}) : yield* Effect8.tryPromise({
|
|
2285
3115
|
try: () => browserLaunchers[browserName].launch({
|
|
2286
3116
|
headless: config.headless ?? true,
|
|
2287
3117
|
...config.channel ? { channel: config.channel } : {},
|
|
@@ -2585,26 +3415,32 @@ function makePlaywrightDriver(config) {
|
|
|
2585
3415
|
}
|
|
2586
3416
|
if ("point" in selector) {
|
|
2587
3417
|
throw new DriverError({
|
|
2588
|
-
message: "uploadFile() does not support point selectors on the web platform. Use testID, text, or accessibilityLabel."
|
|
3418
|
+
message: "uploadFile() does not support point selectors on the web platform. Use testID, css, role, text, or accessibilityLabel."
|
|
2589
3419
|
});
|
|
2590
3420
|
}
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
return;
|
|
2598
|
-
}
|
|
2599
|
-
if ("text" in selector) {
|
|
2600
|
-
try {
|
|
2601
|
-
await page.getByLabel(selector.text, { exact: true }).setInputFiles(path);
|
|
3421
|
+
const hasModifiers = Boolean(
|
|
3422
|
+
selector.within || selector.frame || selector.hasText !== void 0 || selector.hasNotText !== void 0 || selector.nth !== void 0 || selector.first || selector.last
|
|
3423
|
+
);
|
|
3424
|
+
if (!hasModifiers) {
|
|
3425
|
+
if ("testID" in selector) {
|
|
3426
|
+
await page.getByTestId(selector.testID).setInputFiles(path);
|
|
2602
3427
|
return;
|
|
2603
|
-
}
|
|
2604
|
-
|
|
3428
|
+
}
|
|
3429
|
+
if ("accessibilityLabel" in selector) {
|
|
3430
|
+
await page.getByLabel(selector.accessibilityLabel, { exact: true }).setInputFiles(path);
|
|
2605
3431
|
return;
|
|
2606
3432
|
}
|
|
3433
|
+
if ("text" in selector) {
|
|
3434
|
+
try {
|
|
3435
|
+
await page.getByLabel(selector.text, { exact: true }).setInputFiles(path);
|
|
3436
|
+
return;
|
|
3437
|
+
} catch {
|
|
3438
|
+
await page.getByText(selector.text, { exact: true }).setInputFiles(path);
|
|
3439
|
+
return;
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
2607
3442
|
}
|
|
3443
|
+
await resolvePlaywrightLocator(page, selector).setInputFiles(path);
|
|
2608
3444
|
};
|
|
2609
3445
|
const applyContextSpeedOptions = async (ctx) => {
|
|
2610
3446
|
if (config.instantAnimations && typeof ctx.addInitScript === "function") {
|
|
@@ -2752,7 +3588,7 @@ function makePlaywrightDriver(config) {
|
|
|
2752
3588
|
updateHarPage(page);
|
|
2753
3589
|
debugLog("beginFlow", flowName);
|
|
2754
3590
|
};
|
|
2755
|
-
yield*
|
|
3591
|
+
yield* Effect8.tryPromise({
|
|
2756
3592
|
try: () => createContextAndPage(config.storageState),
|
|
2757
3593
|
catch: (e) => new DriverError({ message: `Failed to create page: ${e}` })
|
|
2758
3594
|
});
|
|
@@ -2795,11 +3631,11 @@ function makePlaywrightDriver(config) {
|
|
|
2795
3631
|
};
|
|
2796
3632
|
const service = {
|
|
2797
3633
|
...domChannel ? { domChannel } : {},
|
|
2798
|
-
beginFlow: (flowName) =>
|
|
3634
|
+
beginFlow: (flowName) => Effect8.tryPromise({
|
|
2799
3635
|
try: () => beginFlow(flowName),
|
|
2800
3636
|
catch: (e) => new DriverError({ message: `Failed to prepare flow ${flowName}: ${e}` })
|
|
2801
3637
|
}),
|
|
2802
|
-
dumpHierarchy: () =>
|
|
3638
|
+
dumpHierarchy: () => Effect8.tryPromise({
|
|
2803
3639
|
try: async () => {
|
|
2804
3640
|
const tree = await page.evaluate(`
|
|
2805
3641
|
(function() {
|
|
@@ -2834,17 +3670,17 @@ function makePlaywrightDriver(config) {
|
|
|
2834
3670
|
},
|
|
2835
3671
|
catch: (e) => new DriverError({ message: `Failed to dump hierarchy: ${e}` })
|
|
2836
3672
|
}),
|
|
2837
|
-
tapAtCoordinate: (x, y) =>
|
|
3673
|
+
tapAtCoordinate: (x, y) => Effect8.tryPromise({
|
|
2838
3674
|
try: async () => {
|
|
2839
3675
|
await page.mouse.click(x, y);
|
|
2840
3676
|
},
|
|
2841
3677
|
catch: (e) => new DriverError({ message: `Failed to tap at (${x}, ${y}): ${e}` })
|
|
2842
3678
|
}),
|
|
2843
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
3679
|
+
doubleTapAtCoordinate: (x, y) => Effect8.tryPromise({
|
|
2844
3680
|
try: () => page.mouse.dblclick(x, y),
|
|
2845
3681
|
catch: (e) => new DriverError({ message: `Failed to double tap at (${x}, ${y}): ${e}` })
|
|
2846
3682
|
}),
|
|
2847
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
3683
|
+
longPressAtCoordinate: (x, y, duration) => Effect8.tryPromise({
|
|
2848
3684
|
try: async () => {
|
|
2849
3685
|
await page.mouse.move(x, y);
|
|
2850
3686
|
await page.mouse.down();
|
|
@@ -2853,7 +3689,7 @@ function makePlaywrightDriver(config) {
|
|
|
2853
3689
|
},
|
|
2854
3690
|
catch: (e) => new DriverError({ message: `Failed to long press at (${x}, ${y}): ${e}` })
|
|
2855
3691
|
}),
|
|
2856
|
-
swipe: (startX, startY, endX, endY, duration) =>
|
|
3692
|
+
swipe: (startX, startY, endX, endY, duration) => Effect8.tryPromise({
|
|
2857
3693
|
try: async () => {
|
|
2858
3694
|
await page.evaluate(`
|
|
2859
3695
|
(function() {
|
|
@@ -2890,23 +3726,23 @@ function makePlaywrightDriver(config) {
|
|
|
2890
3726
|
},
|
|
2891
3727
|
catch: (e) => new DriverError({ message: `Failed to swipe: ${e}` })
|
|
2892
3728
|
}),
|
|
2893
|
-
inputText: (text) =>
|
|
3729
|
+
inputText: (text) => Effect8.tryPromise({
|
|
2894
3730
|
try: () => page.keyboard.insertText(text),
|
|
2895
3731
|
catch: (e) => new DriverError({ message: `Failed to input text: ${e}` })
|
|
2896
3732
|
}),
|
|
2897
|
-
pressKey: (key) =>
|
|
3733
|
+
pressKey: (key) => Effect8.tryPromise({
|
|
2898
3734
|
try: () => page.keyboard.press(key),
|
|
2899
3735
|
catch: (e) => new DriverError({ message: `Failed to press key ${key}: ${e}` })
|
|
2900
3736
|
}),
|
|
2901
|
-
hideKeyboard: () =>
|
|
2902
|
-
takeScreenshot: () =>
|
|
3737
|
+
hideKeyboard: () => Effect8.void,
|
|
3738
|
+
takeScreenshot: () => Effect8.tryPromise({
|
|
2903
3739
|
try: async () => {
|
|
2904
3740
|
const buffer = await page.screenshot();
|
|
2905
3741
|
return new Uint8Array(buffer);
|
|
2906
3742
|
},
|
|
2907
3743
|
catch: (e) => new DriverError({ message: `Failed to take screenshot: ${e}` })
|
|
2908
3744
|
}),
|
|
2909
|
-
getDeviceInfo: () =>
|
|
3745
|
+
getDeviceInfo: () => Effect8.tryPromise({
|
|
2910
3746
|
try: async () => {
|
|
2911
3747
|
const viewport = page.viewportSize() ?? { width: 1280, height: 720 };
|
|
2912
3748
|
return {
|
|
@@ -2921,7 +3757,7 @@ function makePlaywrightDriver(config) {
|
|
|
2921
3757
|
},
|
|
2922
3758
|
catch: (e) => new DriverError({ message: `Failed to get device info: ${e}` })
|
|
2923
3759
|
}),
|
|
2924
|
-
launchApp: (url, opts) =>
|
|
3760
|
+
launchApp: (url, opts) => Effect8.tryPromise({
|
|
2925
3761
|
try: async () => {
|
|
2926
3762
|
const targetUrl = opts?.deepLink || url || config.baseUrl || "about:blank";
|
|
2927
3763
|
if (opts?.clearState) {
|
|
@@ -2942,7 +3778,7 @@ function makePlaywrightDriver(config) {
|
|
|
2942
3778
|
},
|
|
2943
3779
|
catch: (e) => new DriverError({ message: `Failed to navigate to ${url}: ${e}` })
|
|
2944
3780
|
}),
|
|
2945
|
-
stopApp: (_id) =>
|
|
3781
|
+
stopApp: (_id) => Effect8.tryPromise({
|
|
2946
3782
|
try: async () => {
|
|
2947
3783
|
await page.goto("about:blank");
|
|
2948
3784
|
updateHarPage(page);
|
|
@@ -2950,7 +3786,7 @@ function makePlaywrightDriver(config) {
|
|
|
2950
3786
|
},
|
|
2951
3787
|
catch: (e) => new DriverError({ message: `Failed to stop app: ${e}` })
|
|
2952
3788
|
}),
|
|
2953
|
-
killApp: (_id) =>
|
|
3789
|
+
killApp: (_id) => Effect8.tryPromise({
|
|
2954
3790
|
try: async () => {
|
|
2955
3791
|
const prefetched = prefetchedSlotPromise;
|
|
2956
3792
|
prefetchedSlotPromise = void 0;
|
|
@@ -2973,14 +3809,14 @@ function makePlaywrightDriver(config) {
|
|
|
2973
3809
|
},
|
|
2974
3810
|
catch: (e) => new DriverError({ message: `Failed to kill app: ${e}` })
|
|
2975
3811
|
}),
|
|
2976
|
-
clearAppState: (_id) =>
|
|
3812
|
+
clearAppState: (_id) => Effect8.tryPromise({
|
|
2977
3813
|
try: async () => {
|
|
2978
3814
|
await clearStorage();
|
|
2979
3815
|
debugLog("clearAppState");
|
|
2980
3816
|
},
|
|
2981
3817
|
catch: (e) => new DriverError({ message: `Failed to clear app state: ${e}` })
|
|
2982
3818
|
}),
|
|
2983
|
-
openLink: (url) =>
|
|
3819
|
+
openLink: (url) => Effect8.tryPromise({
|
|
2984
3820
|
try: async () => {
|
|
2985
3821
|
await page.goto(url, config.waitUntil ? { waitUntil: config.waitUntil } : void 0);
|
|
2986
3822
|
updateHarPage(page);
|
|
@@ -2989,7 +3825,7 @@ function makePlaywrightDriver(config) {
|
|
|
2989
3825
|
},
|
|
2990
3826
|
catch: (e) => new DriverError({ message: `Failed to open link ${url}: ${e}` })
|
|
2991
3827
|
}),
|
|
2992
|
-
back: () =>
|
|
3828
|
+
back: () => Effect8.tryPromise({
|
|
2993
3829
|
try: async () => {
|
|
2994
3830
|
await page.goBack();
|
|
2995
3831
|
updateHarPage(page);
|
|
@@ -2997,12 +3833,56 @@ function makePlaywrightDriver(config) {
|
|
|
2997
3833
|
},
|
|
2998
3834
|
catch: (e) => new DriverError({ message: `Failed to go back: ${e}` })
|
|
2999
3835
|
}),
|
|
3000
|
-
|
|
3836
|
+
reload: (reloadOpts) => Effect8.tryPromise({
|
|
3837
|
+
try: async () => {
|
|
3838
|
+
const waitUntil = reloadOpts?.waitUntil ?? config.waitUntil;
|
|
3839
|
+
await page.reload(waitUntil ? { waitUntil } : void 0);
|
|
3840
|
+
updateHarPage(page);
|
|
3841
|
+
debugLog("reload", currentPageUrl(page));
|
|
3842
|
+
},
|
|
3843
|
+
catch: (e) => new DriverError({ message: `Failed to reload page: ${e}` })
|
|
3844
|
+
}),
|
|
3845
|
+
hoverAtCoordinate: (x, y) => Effect8.tryPromise({
|
|
3846
|
+
try: async () => {
|
|
3847
|
+
await page.mouse.move(x, y);
|
|
3848
|
+
},
|
|
3849
|
+
catch: (e) => new DriverError({ message: `Failed to hover at (${x}, ${y}): ${e}` })
|
|
3850
|
+
}),
|
|
3851
|
+
getUrl: () => Effect8.sync(() => currentPageUrl(page)),
|
|
3852
|
+
evaluate: (script, ...args) => Effect8.tryPromise({
|
|
3001
3853
|
try: () => evaluateOnPage(page, script, args),
|
|
3002
3854
|
catch: (e) => new DriverError({ message: `Evaluate failed: ${e}` })
|
|
3003
3855
|
}),
|
|
3004
3856
|
getRawPage: () => page,
|
|
3005
|
-
|
|
3857
|
+
getCdpSession: () => {
|
|
3858
|
+
if (browserName !== "chromium") return void 0;
|
|
3859
|
+
return {
|
|
3860
|
+
send: async (method, params) => {
|
|
3861
|
+
const session = await ensureCdpSession();
|
|
3862
|
+
return await session.send(method, params);
|
|
3863
|
+
},
|
|
3864
|
+
on: (event, listener) => {
|
|
3865
|
+
let unsubscribed = false;
|
|
3866
|
+
let attachedSession;
|
|
3867
|
+
const wrapped = (params) => {
|
|
3868
|
+
if (!unsubscribed) listener(params ?? {});
|
|
3869
|
+
};
|
|
3870
|
+
void ensureCdpSession().then((session) => {
|
|
3871
|
+
if (unsubscribed) return;
|
|
3872
|
+
attachedSession = session;
|
|
3873
|
+
session.on(event, wrapped);
|
|
3874
|
+
}).catch(() => {
|
|
3875
|
+
});
|
|
3876
|
+
return () => {
|
|
3877
|
+
unsubscribed = true;
|
|
3878
|
+
if (attachedSession && typeof attachedSession.off === "function") {
|
|
3879
|
+
attachedSession.off(event, wrapped);
|
|
3880
|
+
}
|
|
3881
|
+
};
|
|
3882
|
+
}
|
|
3883
|
+
};
|
|
3884
|
+
},
|
|
3885
|
+
enableVirtualAuthenticator: (opts) => Effect8.tryPromise({
|
|
3006
3886
|
try: async () => {
|
|
3007
3887
|
const attached = await attachVirtualAuthenticatorOn(context, page, opts);
|
|
3008
3888
|
activeAuthenticatorId = attached.authenticatorId;
|
|
@@ -3011,7 +3891,7 @@ function makePlaywrightDriver(config) {
|
|
|
3011
3891
|
},
|
|
3012
3892
|
catch: (e) => e instanceof DriverError ? e : new DriverError({ message: `Failed to enable virtual authenticator: ${e}` })
|
|
3013
3893
|
}),
|
|
3014
|
-
removeVirtualAuthenticator: (authenticatorId) =>
|
|
3894
|
+
removeVirtualAuthenticator: (authenticatorId) => Effect8.tryPromise({
|
|
3015
3895
|
try: async () => {
|
|
3016
3896
|
const id = authenticatorId ?? activeAuthenticatorId;
|
|
3017
3897
|
if (!id) return;
|
|
@@ -3022,7 +3902,7 @@ function makePlaywrightDriver(config) {
|
|
|
3022
3902
|
},
|
|
3023
3903
|
catch: (e) => new DriverError({ message: `Failed to remove virtual authenticator: ${e}` })
|
|
3024
3904
|
}),
|
|
3025
|
-
getVirtualCredentials: (authenticatorId) =>
|
|
3905
|
+
getVirtualCredentials: (authenticatorId) => Effect8.tryPromise({
|
|
3026
3906
|
try: async () => {
|
|
3027
3907
|
const id = authenticatorId ?? activeAuthenticatorId;
|
|
3028
3908
|
if (!id) return [];
|
|
@@ -3034,7 +3914,37 @@ function makePlaywrightDriver(config) {
|
|
|
3034
3914
|
},
|
|
3035
3915
|
catch: (e) => new DriverError({ message: `Failed to read virtual credentials: ${e}` })
|
|
3036
3916
|
}),
|
|
3037
|
-
|
|
3917
|
+
addVirtualCredential: (credential, authenticatorId) => Effect8.tryPromise({
|
|
3918
|
+
try: async () => {
|
|
3919
|
+
if (browserName !== "chromium") {
|
|
3920
|
+
throw new DriverError({
|
|
3921
|
+
message: "addVirtualCredential() is only supported on Chromium browsers."
|
|
3922
|
+
});
|
|
3923
|
+
}
|
|
3924
|
+
let id = authenticatorId ?? activeAuthenticatorId;
|
|
3925
|
+
if (!id) {
|
|
3926
|
+
const attached = await attachVirtualAuthenticatorOn(context, page);
|
|
3927
|
+
id = attached.authenticatorId;
|
|
3928
|
+
activeAuthenticatorId = id;
|
|
3929
|
+
}
|
|
3930
|
+
const session = await ensureCdpSession();
|
|
3931
|
+
await session.send("WebAuthn.addCredential", {
|
|
3932
|
+
authenticatorId: id,
|
|
3933
|
+
credential: {
|
|
3934
|
+
credentialId: credential.credentialId,
|
|
3935
|
+
isResidentCredential: credential.isResidentCredential,
|
|
3936
|
+
privateKey: credential.privateKey,
|
|
3937
|
+
signCount: credential.signCount ?? 0,
|
|
3938
|
+
...credential.rpId !== void 0 ? { rpId: credential.rpId } : {},
|
|
3939
|
+
...credential.userHandle !== void 0 ? { userHandle: credential.userHandle } : {},
|
|
3940
|
+
...credential.userName !== void 0 ? { userName: credential.userName } : {}
|
|
3941
|
+
}
|
|
3942
|
+
});
|
|
3943
|
+
debugLog("addVirtualCredential", id, credential.credentialId);
|
|
3944
|
+
},
|
|
3945
|
+
catch: (e) => e instanceof DriverError ? e : new DriverError({ message: `Failed to import virtual credential: ${e}` })
|
|
3946
|
+
}),
|
|
3947
|
+
clearVirtualCredentials: (authenticatorId) => Effect8.tryPromise({
|
|
3038
3948
|
try: async () => {
|
|
3039
3949
|
const id = authenticatorId ?? activeAuthenticatorId;
|
|
3040
3950
|
if (!id) return;
|
|
@@ -3044,7 +3954,7 @@ function makePlaywrightDriver(config) {
|
|
|
3044
3954
|
},
|
|
3045
3955
|
catch: (e) => new DriverError({ message: `Failed to clear virtual credentials: ${e}` })
|
|
3046
3956
|
}),
|
|
3047
|
-
mockNetwork: (matcher, response) =>
|
|
3957
|
+
mockNetwork: (matcher, response) => Effect8.tryPromise({
|
|
3048
3958
|
try: async () => {
|
|
3049
3959
|
buildMockResponse(response);
|
|
3050
3960
|
const definition = { kind: "mock", matcher, response };
|
|
@@ -3054,7 +3964,7 @@ function makePlaywrightDriver(config) {
|
|
|
3054
3964
|
},
|
|
3055
3965
|
catch: (e) => new DriverError({ message: `Failed to mock network route: ${e}` })
|
|
3056
3966
|
}),
|
|
3057
|
-
blockNetwork: (matcher) =>
|
|
3967
|
+
blockNetwork: (matcher) => Effect8.tryPromise({
|
|
3058
3968
|
try: async () => {
|
|
3059
3969
|
const definition = { kind: "block", matcher };
|
|
3060
3970
|
routeDefinitions.push(definition);
|
|
@@ -3063,7 +3973,7 @@ function makePlaywrightDriver(config) {
|
|
|
3063
3973
|
},
|
|
3064
3974
|
catch: (e) => new DriverError({ message: `Failed to block network route: ${e}` })
|
|
3065
3975
|
}),
|
|
3066
|
-
clearNetworkMocks: () =>
|
|
3976
|
+
clearNetworkMocks: () => Effect8.tryPromise({
|
|
3067
3977
|
try: async () => {
|
|
3068
3978
|
for (const appliedRoute of appliedRoutes) {
|
|
3069
3979
|
await context.unroute(appliedRoute.matcher, appliedRoute.handler);
|
|
@@ -3074,7 +3984,7 @@ function makePlaywrightDriver(config) {
|
|
|
3074
3984
|
},
|
|
3075
3985
|
catch: (e) => new DriverError({ message: `Failed to clear network mocks: ${e}` })
|
|
3076
3986
|
}),
|
|
3077
|
-
setNetworkConditions: (conditions) =>
|
|
3987
|
+
setNetworkConditions: (conditions) => Effect8.tryPromise({
|
|
3078
3988
|
try: async () => {
|
|
3079
3989
|
currentNetworkConditions = { ...conditions };
|
|
3080
3990
|
await applyNetworkConditions();
|
|
@@ -3082,7 +3992,7 @@ function makePlaywrightDriver(config) {
|
|
|
3082
3992
|
},
|
|
3083
3993
|
catch: (e) => new DriverError({ message: `Failed to set network conditions: ${e}` })
|
|
3084
3994
|
}),
|
|
3085
|
-
saveCookies: (path) =>
|
|
3995
|
+
saveCookies: (path) => Effect8.tryPromise({
|
|
3086
3996
|
try: async () => {
|
|
3087
3997
|
const cookies = await context.cookies();
|
|
3088
3998
|
await writeFile(path, JSON.stringify(cookies, null, 2), "utf8");
|
|
@@ -3090,7 +4000,7 @@ function makePlaywrightDriver(config) {
|
|
|
3090
4000
|
},
|
|
3091
4001
|
catch: (e) => new DriverError({ message: `Failed to save cookies to ${path}: ${e}` })
|
|
3092
4002
|
}),
|
|
3093
|
-
loadCookies: (path) =>
|
|
4003
|
+
loadCookies: (path) => Effect8.tryPromise({
|
|
3094
4004
|
try: async () => {
|
|
3095
4005
|
const contents = await readFile(path, "utf8");
|
|
3096
4006
|
const cookies = JSON.parse(contents);
|
|
@@ -3102,14 +4012,89 @@ function makePlaywrightDriver(config) {
|
|
|
3102
4012
|
},
|
|
3103
4013
|
catch: (e) => new DriverError({ message: `Failed to load cookies from ${path}: ${e}` })
|
|
3104
4014
|
}),
|
|
3105
|
-
|
|
4015
|
+
getCookies: (urls) => Effect8.tryPromise({
|
|
4016
|
+
try: async () => {
|
|
4017
|
+
const cookies = await (urls && urls.length > 0 ? context.cookies(urls) : context.cookies());
|
|
4018
|
+
return cookies;
|
|
4019
|
+
},
|
|
4020
|
+
catch: (e) => new DriverError({ message: `Failed to read cookies: ${e}` })
|
|
4021
|
+
}),
|
|
4022
|
+
setCookies: (cookies) => Effect8.tryPromise({
|
|
4023
|
+
try: async () => {
|
|
4024
|
+
if (cookies.length === 0) return;
|
|
4025
|
+
await context.addCookies(cookies);
|
|
4026
|
+
},
|
|
4027
|
+
catch: (e) => new DriverError({ message: `Failed to set cookies: ${e}` })
|
|
4028
|
+
}),
|
|
4029
|
+
clearCookies: () => Effect8.tryPromise({
|
|
4030
|
+
try: async () => {
|
|
4031
|
+
await context.clearCookies();
|
|
4032
|
+
},
|
|
4033
|
+
catch: (e) => new DriverError({ message: `Failed to clear cookies: ${e}` })
|
|
4034
|
+
}),
|
|
4035
|
+
waitForResponse: (matcher, waitOpts) => Effect8.tryPromise({
|
|
4036
|
+
try: async () => {
|
|
4037
|
+
const timeout = waitOpts?.timeout ?? 15e3;
|
|
4038
|
+
const response = await page.waitForResponse(
|
|
4039
|
+
(res) => {
|
|
4040
|
+
const info = {
|
|
4041
|
+
url: res.url(),
|
|
4042
|
+
status: res.status(),
|
|
4043
|
+
statusText: res.statusText(),
|
|
4044
|
+
headers: res.headers(),
|
|
4045
|
+
method: res.request().method()
|
|
4046
|
+
};
|
|
4047
|
+
if (typeof matcher === "function") return matcher(info);
|
|
4048
|
+
if (matcher instanceof RegExp) return matcher.test(info.url);
|
|
4049
|
+
return info.url.includes(matcher);
|
|
4050
|
+
},
|
|
4051
|
+
{ timeout }
|
|
4052
|
+
);
|
|
4053
|
+
return {
|
|
4054
|
+
url: response.url(),
|
|
4055
|
+
status: response.status(),
|
|
4056
|
+
statusText: response.statusText(),
|
|
4057
|
+
headers: response.headers(),
|
|
4058
|
+
method: response.request().method(),
|
|
4059
|
+
body: () => response.text(),
|
|
4060
|
+
json: () => response.json()
|
|
4061
|
+
};
|
|
4062
|
+
},
|
|
4063
|
+
catch: (e) => new DriverError({ message: `waitForResponse() failed: ${e}` })
|
|
4064
|
+
}),
|
|
4065
|
+
createIsolatedContext: (ctxOpts) => Effect8.tryPromise({
|
|
4066
|
+
try: async () => {
|
|
4067
|
+
const childDriver = await Effect8.runPromise(
|
|
4068
|
+
makePlaywrightDriver({
|
|
4069
|
+
...config,
|
|
4070
|
+
sharedBrowser: browser,
|
|
4071
|
+
freshContextPerFlow: false,
|
|
4072
|
+
warmBrowser: false,
|
|
4073
|
+
cdpEndpoint: void 0,
|
|
4074
|
+
wsEndpoint: void 0
|
|
4075
|
+
})
|
|
4076
|
+
);
|
|
4077
|
+
if (ctxOpts?.url) {
|
|
4078
|
+
await Effect8.runPromise(childDriver.openLink(ctxOpts.url));
|
|
4079
|
+
}
|
|
4080
|
+
return {
|
|
4081
|
+
driver: childDriver,
|
|
4082
|
+
close: async () => {
|
|
4083
|
+
await Effect8.runPromise(childDriver.killApp("isolated-context")).catch(() => {
|
|
4084
|
+
});
|
|
4085
|
+
}
|
|
4086
|
+
};
|
|
4087
|
+
},
|
|
4088
|
+
catch: (e) => new DriverError({ message: `createIsolatedContext() failed: ${e}` })
|
|
4089
|
+
}),
|
|
4090
|
+
saveAuthState: (path) => Effect8.tryPromise({
|
|
3106
4091
|
try: async () => {
|
|
3107
4092
|
await context.storageState({ path });
|
|
3108
4093
|
debugLog("saveAuthState", path);
|
|
3109
4094
|
},
|
|
3110
4095
|
catch: (e) => new DriverError({ message: `Failed to save auth state to ${path}: ${e}` })
|
|
3111
4096
|
}),
|
|
3112
|
-
loadAuthState: (path) =>
|
|
4097
|
+
loadAuthState: (path) => Effect8.tryPromise({
|
|
3113
4098
|
try: async () => {
|
|
3114
4099
|
await replaceContext(path);
|
|
3115
4100
|
updateHarPage(page);
|
|
@@ -3117,7 +4102,7 @@ function makePlaywrightDriver(config) {
|
|
|
3117
4102
|
},
|
|
3118
4103
|
catch: (e) => new DriverError({ message: `Failed to load auth state from ${path}: ${e}` })
|
|
3119
4104
|
}),
|
|
3120
|
-
downloadFile: (path) =>
|
|
4105
|
+
downloadFile: (path) => Effect8.tryPromise({
|
|
3121
4106
|
try: async () => {
|
|
3122
4107
|
const download = await nextDownload();
|
|
3123
4108
|
await download.saveAs(path);
|
|
@@ -3125,14 +4110,16 @@ function makePlaywrightDriver(config) {
|
|
|
3125
4110
|
},
|
|
3126
4111
|
catch: (e) => new DriverError({ message: `Failed to download file to ${path}: ${e}` })
|
|
3127
4112
|
}),
|
|
3128
|
-
uploadFile: (selector, path) =>
|
|
4113
|
+
uploadFile: (selector, path) => Effect8.tryPromise({
|
|
3129
4114
|
try: async () => {
|
|
3130
4115
|
await setInputFiles(selector, path);
|
|
3131
|
-
debugLog("uploadFile", path);
|
|
4116
|
+
debugLog("uploadFile", Array.isArray(path) ? path.join(", ") : path);
|
|
3132
4117
|
},
|
|
3133
|
-
catch: (e) => new DriverError({
|
|
4118
|
+
catch: (e) => new DriverError({
|
|
4119
|
+
message: `Failed to upload file ${Array.isArray(path) ? path.join(", ") : path}: ${e}`
|
|
4120
|
+
})
|
|
3134
4121
|
}),
|
|
3135
|
-
newTab: (url) =>
|
|
4122
|
+
newTab: (url) => Effect8.tryPromise({
|
|
3136
4123
|
try: async () => {
|
|
3137
4124
|
const nextPage = await context.newPage();
|
|
3138
4125
|
attachPageDiagnostics(nextPage);
|
|
@@ -3147,7 +4134,7 @@ function makePlaywrightDriver(config) {
|
|
|
3147
4134
|
},
|
|
3148
4135
|
catch: (e) => new DriverError({ message: `Failed to open a new tab: ${e}` })
|
|
3149
4136
|
}),
|
|
3150
|
-
switchToTab: (index) =>
|
|
4137
|
+
switchToTab: (index) => Effect8.tryPromise({
|
|
3151
4138
|
try: async () => {
|
|
3152
4139
|
const openPages = context.pages();
|
|
3153
4140
|
const nextPage = openPages[index];
|
|
@@ -3163,7 +4150,7 @@ function makePlaywrightDriver(config) {
|
|
|
3163
4150
|
},
|
|
3164
4151
|
catch: (e) => new DriverError({ message: `Failed to switch tabs: ${e}` })
|
|
3165
4152
|
}),
|
|
3166
|
-
closeTab: () =>
|
|
4153
|
+
closeTab: () => Effect8.tryPromise({
|
|
3167
4154
|
try: async () => {
|
|
3168
4155
|
const openPages = context.pages();
|
|
3169
4156
|
if (openPages.length <= 1) {
|
|
@@ -3183,14 +4170,14 @@ function makePlaywrightDriver(config) {
|
|
|
3183
4170
|
},
|
|
3184
4171
|
catch: (e) => new DriverError({ message: `Failed to close the current tab: ${e}` })
|
|
3185
4172
|
}),
|
|
3186
|
-
getTabIds: () =>
|
|
4173
|
+
getTabIds: () => Effect8.sync(() => {
|
|
3187
4174
|
const ids = context.pages().map((openPage) => getTabId(openPage));
|
|
3188
4175
|
debugLog("getTabIds", ids.join(", "));
|
|
3189
4176
|
return ids;
|
|
3190
4177
|
}),
|
|
3191
|
-
getConsoleLogs: () =>
|
|
3192
|
-
getJSErrors: () =>
|
|
3193
|
-
getHAR: () =>
|
|
4178
|
+
getConsoleLogs: () => Effect8.succeed([...consoleLogs]),
|
|
4179
|
+
getJSErrors: () => Effect8.succeed([...jsErrors]),
|
|
4180
|
+
getHAR: () => Effect8.sync(() => ({
|
|
3194
4181
|
log: {
|
|
3195
4182
|
version: "1.2",
|
|
3196
4183
|
creator: {
|
|
@@ -3210,7 +4197,7 @@ function makePlaywrightDriver(config) {
|
|
|
3210
4197
|
}
|
|
3211
4198
|
|
|
3212
4199
|
// src/drivers/uiautomator2/driver.ts
|
|
3213
|
-
import { Effect as
|
|
4200
|
+
import { Effect as Effect9 } from "effect";
|
|
3214
4201
|
|
|
3215
4202
|
// src/drivers/uiautomator2/client.ts
|
|
3216
4203
|
var UiAutomator2Client = class {
|
|
@@ -3554,9 +4541,21 @@ var UiAutomator2Client = class {
|
|
|
3554
4541
|
|
|
3555
4542
|
// src/drivers/uiautomator2/driver.ts
|
|
3556
4543
|
function createUiAutomator2Driver(host, port, serial, packageName, driverOptions) {
|
|
3557
|
-
return
|
|
4544
|
+
return Effect9.gen(function* () {
|
|
3558
4545
|
const client = new UiAutomator2Client(host, port);
|
|
3559
4546
|
let currentContext = "NATIVE_APP";
|
|
4547
|
+
let hasLaunchedOnce = false;
|
|
4548
|
+
const waitForAndroidReady = async (maxMs) => {
|
|
4549
|
+
const deadline = Date.now() + maxMs;
|
|
4550
|
+
while (Date.now() < deadline) {
|
|
4551
|
+
try {
|
|
4552
|
+
await client.getWindowSize();
|
|
4553
|
+
return;
|
|
4554
|
+
} catch {
|
|
4555
|
+
await new Promise((resolve2) => setTimeout(resolve2, 40));
|
|
4556
|
+
}
|
|
4557
|
+
}
|
|
4558
|
+
};
|
|
3560
4559
|
const cdpChannel = driverOptions?.enableWebViewCdp === false ? void 0 : createAndroidWebViewCdpChannel({
|
|
3561
4560
|
serial,
|
|
3562
4561
|
packageName: packageName || void 0,
|
|
@@ -3566,7 +4565,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3566
4565
|
if (driverOptions?.domChannel) channels.push(driverOptions.domChannel);
|
|
3567
4566
|
if (cdpChannel) channels.push(cdpChannel);
|
|
3568
4567
|
const domChannel = channels.length === 0 ? void 0 : channels.length === 1 ? channels[0] : createCompositeDomChannel(channels);
|
|
3569
|
-
yield*
|
|
4568
|
+
yield* Effect9.tryPromise({
|
|
3570
4569
|
try: () => client.createSession(packageName),
|
|
3571
4570
|
catch: (e) => new DriverError({
|
|
3572
4571
|
message: `Failed to create UiAutomator2 session: ${e}`
|
|
@@ -3577,70 +4576,70 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3577
4576
|
// -----------------------------------------------------------------------
|
|
3578
4577
|
// Hierarchy
|
|
3579
4578
|
// -----------------------------------------------------------------------
|
|
3580
|
-
dumpHierarchy: () =>
|
|
4579
|
+
dumpHierarchy: () => Effect9.tryPromise({
|
|
3581
4580
|
try: () => client.getSource(),
|
|
3582
4581
|
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
3583
4582
|
}),
|
|
3584
4583
|
// -----------------------------------------------------------------------
|
|
3585
4584
|
// Coordinate-level actions
|
|
3586
4585
|
// -----------------------------------------------------------------------
|
|
3587
|
-
tapAtCoordinate: (x, y) =>
|
|
4586
|
+
tapAtCoordinate: (x, y) => Effect9.tryPromise({
|
|
3588
4587
|
try: () => client.performTap(x, y),
|
|
3589
4588
|
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
3590
4589
|
}),
|
|
3591
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
4590
|
+
doubleTapAtCoordinate: (x, y) => Effect9.tryPromise({
|
|
3592
4591
|
try: async () => {
|
|
3593
4592
|
await client.performTap(x, y);
|
|
3594
4593
|
await client.performTap(x, y);
|
|
3595
4594
|
},
|
|
3596
4595
|
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
3597
4596
|
}),
|
|
3598
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
4597
|
+
longPressAtCoordinate: (x, y, duration) => Effect9.tryPromise({
|
|
3599
4598
|
try: () => client.performLongPress(x, y, duration),
|
|
3600
4599
|
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
3601
4600
|
}),
|
|
3602
|
-
swipe: (sx, sy, ex, ey, dur) =>
|
|
4601
|
+
swipe: (sx, sy, ex, ey, dur) => Effect9.tryPromise({
|
|
3603
4602
|
try: () => client.performSwipe(sx, sy, ex, ey, dur),
|
|
3604
4603
|
catch: (e) => new DriverError({ message: `Swipe failed: ${e}` })
|
|
3605
4604
|
}),
|
|
3606
|
-
pinch: (cx, cy, scale, duration) =>
|
|
4605
|
+
pinch: (cx, cy, scale, duration) => Effect9.tryPromise({
|
|
3607
4606
|
try: () => client.performPinch(cx, cy, scale, duration),
|
|
3608
4607
|
catch: (e) => new DriverError({ message: `Pinch failed: ${e}` })
|
|
3609
4608
|
}),
|
|
3610
|
-
zoom: (cx, cy, scale, duration) =>
|
|
4609
|
+
zoom: (cx, cy, scale, duration) => Effect9.tryPromise({
|
|
3611
4610
|
try: () => client.performZoom(cx, cy, scale, duration),
|
|
3612
4611
|
catch: (e) => new DriverError({ message: `Zoom failed: ${e}` })
|
|
3613
4612
|
}),
|
|
3614
|
-
multiTouch: (sequences) =>
|
|
4613
|
+
multiTouch: (sequences) => Effect9.tryPromise({
|
|
3615
4614
|
try: () => client.performMultiTouch(sequences),
|
|
3616
4615
|
catch: (e) => new DriverError({ message: `Multi-touch failed: ${e}` })
|
|
3617
4616
|
}),
|
|
3618
4617
|
// -----------------------------------------------------------------------
|
|
3619
4618
|
// Text input
|
|
3620
4619
|
// -----------------------------------------------------------------------
|
|
3621
|
-
inputText: (text) =>
|
|
4620
|
+
inputText: (text) => Effect9.tryPromise({
|
|
3622
4621
|
try: () => client.sendKeys(text),
|
|
3623
4622
|
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
3624
4623
|
}),
|
|
3625
|
-
pressKey: (key) =>
|
|
4624
|
+
pressKey: (key) => Effect9.tryPromise({
|
|
3626
4625
|
try: () => client.pressKeyCode(parseInt(key, 10) || 0),
|
|
3627
4626
|
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
3628
4627
|
}),
|
|
3629
|
-
hideKeyboard: () =>
|
|
4628
|
+
hideKeyboard: () => Effect9.tryPromise({
|
|
3630
4629
|
try: () => client.hideKeyboard(),
|
|
3631
4630
|
catch: (e) => new DriverError({ message: `Hide keyboard failed: ${e}` })
|
|
3632
4631
|
}),
|
|
3633
4632
|
// -----------------------------------------------------------------------
|
|
3634
4633
|
// Queries
|
|
3635
4634
|
// -----------------------------------------------------------------------
|
|
3636
|
-
takeScreenshot: () =>
|
|
4635
|
+
takeScreenshot: () => Effect9.tryPromise({
|
|
3637
4636
|
try: async () => {
|
|
3638
4637
|
const base64 = await client.getScreenshot();
|
|
3639
|
-
return Uint8Array.from(
|
|
4638
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
3640
4639
|
},
|
|
3641
4640
|
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
3642
4641
|
}),
|
|
3643
|
-
getDeviceInfo: () =>
|
|
4642
|
+
getDeviceInfo: () => Effect9.tryPromise({
|
|
3644
4643
|
try: async () => {
|
|
3645
4644
|
const size = await client.getWindowSize();
|
|
3646
4645
|
return {
|
|
@@ -3658,8 +4657,29 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3658
4657
|
// -----------------------------------------------------------------------
|
|
3659
4658
|
// App lifecycle
|
|
3660
4659
|
// -----------------------------------------------------------------------
|
|
3661
|
-
launchApp: (bundleId, opts) =>
|
|
4660
|
+
launchApp: (bundleId, opts) => Effect9.tryPromise({
|
|
3662
4661
|
try: async () => {
|
|
4662
|
+
const canFastReset = hasLaunchedOnce && driverOptions?.fastWebViewReset !== false && domChannel?.isConnected() && !opts?.deepLink && !opts?.clearKeychain && !hasLaunchDeviceState(opts?.deviceState) && !(opts?.launchArguments && Object.keys(opts.launchArguments).length > 0);
|
|
4663
|
+
if (canFastReset) {
|
|
4664
|
+
try {
|
|
4665
|
+
if (opts?.clearState && domChannel.clearStorage) {
|
|
4666
|
+
await domChannel.clearStorage({
|
|
4667
|
+
localStorage: true,
|
|
4668
|
+
sessionStorage: true,
|
|
4669
|
+
cookies: true,
|
|
4670
|
+
indexedDB: true,
|
|
4671
|
+
capacitorPreferences: true
|
|
4672
|
+
});
|
|
4673
|
+
}
|
|
4674
|
+
if (domChannel.reload) {
|
|
4675
|
+
await domChannel.reload();
|
|
4676
|
+
} else {
|
|
4677
|
+
await domChannel.evaluate("window.location.reload()");
|
|
4678
|
+
}
|
|
4679
|
+
return;
|
|
4680
|
+
} catch {
|
|
4681
|
+
}
|
|
4682
|
+
}
|
|
3663
4683
|
if (opts?.clearState) {
|
|
3664
4684
|
adbClearApp(serial, bundleId);
|
|
3665
4685
|
}
|
|
@@ -3673,12 +4693,12 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3673
4693
|
}
|
|
3674
4694
|
if (opts?.deepLink) {
|
|
3675
4695
|
adbOpenLink(serial, opts.deepLink, bundleId);
|
|
3676
|
-
await
|
|
4696
|
+
await waitForAndroidReady(500);
|
|
3677
4697
|
} else {
|
|
3678
4698
|
adbForceStop(serial, bundleId);
|
|
3679
4699
|
if (opts?.launchArguments && Object.keys(opts.launchArguments).length > 0) {
|
|
3680
|
-
const { execFileSync } = await import("child_process");
|
|
3681
|
-
const { findADB: findADB2 } = await import("./android-
|
|
4700
|
+
const { execFileSync: execFileSync2 } = await import("child_process");
|
|
4701
|
+
const { findADB: findADB2 } = await import("./android-6BOQTMM3.js");
|
|
3682
4702
|
const adb = findADB2();
|
|
3683
4703
|
if (!adb) throw new Error("adb not found");
|
|
3684
4704
|
const startArgs = [
|
|
@@ -3696,22 +4716,23 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3696
4716
|
for (const [k, v] of Object.entries(opts.launchArguments)) {
|
|
3697
4717
|
startArgs.push("--es", k, String(v));
|
|
3698
4718
|
}
|
|
3699
|
-
|
|
4719
|
+
execFileSync2(adb, startArgs, { stdio: "ignore" });
|
|
3700
4720
|
} else {
|
|
3701
4721
|
adbLaunchApp(serial, bundleId);
|
|
3702
4722
|
}
|
|
4723
|
+
await waitForAndroidReady(800);
|
|
3703
4724
|
}
|
|
3704
|
-
|
|
4725
|
+
hasLaunchedOnce = true;
|
|
3705
4726
|
},
|
|
3706
4727
|
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
3707
4728
|
}),
|
|
3708
|
-
stopApp: (bundleId) =>
|
|
4729
|
+
stopApp: (bundleId) => Effect9.tryPromise({
|
|
3709
4730
|
try: async () => {
|
|
3710
4731
|
adbForceStop(serial, bundleId);
|
|
3711
4732
|
},
|
|
3712
4733
|
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
3713
4734
|
}),
|
|
3714
|
-
killApp: (bundleId) =>
|
|
4735
|
+
killApp: (bundleId) => Effect9.tryPromise({
|
|
3715
4736
|
try: async () => {
|
|
3716
4737
|
await domChannel?.disconnect().catch(() => {
|
|
3717
4738
|
});
|
|
@@ -3720,7 +4741,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3720
4741
|
},
|
|
3721
4742
|
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
3722
4743
|
}),
|
|
3723
|
-
clearAppState: (bundleId) =>
|
|
4744
|
+
clearAppState: (bundleId) => Effect9.tryPromise({
|
|
3724
4745
|
try: async () => {
|
|
3725
4746
|
if (domChannel?.isConnected() && domChannel.clearStorage) {
|
|
3726
4747
|
await domChannel.clearStorage({
|
|
@@ -3740,7 +4761,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3740
4761
|
},
|
|
3741
4762
|
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
3742
4763
|
}),
|
|
3743
|
-
resetFast: () =>
|
|
4764
|
+
resetFast: () => Effect9.tryPromise({
|
|
3744
4765
|
try: async () => {
|
|
3745
4766
|
if (!domChannel) {
|
|
3746
4767
|
throw new Error("resetFast() requires a connected DOM channel (spana-bridge or CDP)");
|
|
@@ -3770,14 +4791,14 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3770
4791
|
// -----------------------------------------------------------------------
|
|
3771
4792
|
// Navigation
|
|
3772
4793
|
// -----------------------------------------------------------------------
|
|
3773
|
-
openLink: (url) =>
|
|
4794
|
+
openLink: (url) => Effect9.tryPromise({
|
|
3774
4795
|
try: async () => {
|
|
3775
4796
|
adbOpenLink(serial, url, packageName);
|
|
3776
4797
|
await new Promise((resolve2) => setTimeout(resolve2, 1e3));
|
|
3777
4798
|
},
|
|
3778
4799
|
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
3779
4800
|
}),
|
|
3780
|
-
back: () =>
|
|
4801
|
+
back: () => Effect9.tryPromise({
|
|
3781
4802
|
// KEYCODE_BACK = 4
|
|
3782
4803
|
try: () => client.pressKeyCode(4),
|
|
3783
4804
|
catch: (e) => new DriverError({ message: `Back failed: ${e}` })
|
|
@@ -3786,7 +4807,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3786
4807
|
// Direct DOM evaluation via spana-bridge or Android WebView CDP,
|
|
3787
4808
|
// falling back to UiAutomator2 /execute/sync when no DOM channel attaches.
|
|
3788
4809
|
// -----------------------------------------------------------------------
|
|
3789
|
-
evaluate: (script, ...args) =>
|
|
4810
|
+
evaluate: (script, ...args) => Effect9.tryPromise({
|
|
3790
4811
|
try: async () => {
|
|
3791
4812
|
if (domChannel) {
|
|
3792
4813
|
try {
|
|
@@ -3812,7 +4833,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3812
4833
|
},
|
|
3813
4834
|
catch: (e) => new DriverError({ message: `evaluate() failed: ${e}` })
|
|
3814
4835
|
}),
|
|
3815
|
-
getContexts: () =>
|
|
4836
|
+
getContexts: () => Effect9.tryPromise({
|
|
3816
4837
|
try: async () => {
|
|
3817
4838
|
const contexts = /* @__PURE__ */ new Set(["NATIVE_APP"]);
|
|
3818
4839
|
if (domChannel?.listTargets) {
|
|
@@ -3835,7 +4856,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3835
4856
|
},
|
|
3836
4857
|
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
3837
4858
|
}),
|
|
3838
|
-
getCurrentContext: () =>
|
|
4859
|
+
getCurrentContext: () => Effect9.tryPromise({
|
|
3839
4860
|
try: async () => {
|
|
3840
4861
|
if (currentContext !== "NATIVE_APP") return currentContext;
|
|
3841
4862
|
if (typeof client.getCurrentContext === "function") {
|
|
@@ -3849,7 +4870,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3849
4870
|
},
|
|
3850
4871
|
catch: (e) => new DriverError({ message: `getCurrentContext failed: ${e}` })
|
|
3851
4872
|
}),
|
|
3852
|
-
setContext: (contextId) =>
|
|
4873
|
+
setContext: (contextId) => Effect9.tryPromise({
|
|
3853
4874
|
try: async () => {
|
|
3854
4875
|
if (contextId === "NATIVE_APP") {
|
|
3855
4876
|
currentContext = "NATIVE_APP";
|
|
@@ -3875,7 +4896,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3875
4896
|
},
|
|
3876
4897
|
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
3877
4898
|
}),
|
|
3878
|
-
mockNetwork: (matcher, response) =>
|
|
4899
|
+
mockNetwork: (matcher, response) => Effect9.tryPromise({
|
|
3879
4900
|
try: async () => {
|
|
3880
4901
|
if (!domChannel?.mockNetwork) {
|
|
3881
4902
|
throw new Error("mockNetwork() on Android requires spana-bridge");
|
|
@@ -3884,7 +4905,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3884
4905
|
},
|
|
3885
4906
|
catch: (e) => new DriverError({ message: `mockNetwork failed: ${e}` })
|
|
3886
4907
|
}),
|
|
3887
|
-
blockNetwork: (matcher) =>
|
|
4908
|
+
blockNetwork: (matcher) => Effect9.tryPromise({
|
|
3888
4909
|
try: async () => {
|
|
3889
4910
|
if (!domChannel?.blockNetwork) {
|
|
3890
4911
|
throw new Error("blockNetwork() on Android requires spana-bridge");
|
|
@@ -3893,7 +4914,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3893
4914
|
},
|
|
3894
4915
|
catch: (e) => new DriverError({ message: `blockNetwork failed: ${e}` })
|
|
3895
4916
|
}),
|
|
3896
|
-
clearNetworkMocks: () =>
|
|
4917
|
+
clearNetworkMocks: () => Effect9.tryPromise({
|
|
3897
4918
|
try: async () => {
|
|
3898
4919
|
if (domChannel?.clearNetworkMocks) {
|
|
3899
4920
|
await domChannel.clearNetworkMocks();
|
|
@@ -3901,18 +4922,18 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
3901
4922
|
},
|
|
3902
4923
|
catch: (e) => new DriverError({ message: `clearNetworkMocks failed: ${e}` })
|
|
3903
4924
|
}),
|
|
3904
|
-
getConsoleLogs: () =>
|
|
4925
|
+
getConsoleLogs: () => Effect9.tryPromise({
|
|
3905
4926
|
try: async () => domChannel?.getConsoleLogs ? domChannel.getConsoleLogs() : [],
|
|
3906
4927
|
catch: (e) => new DriverError({ message: `getConsoleLogs failed: ${e}` })
|
|
3907
4928
|
}),
|
|
3908
|
-
getJSErrors: () =>
|
|
4929
|
+
getJSErrors: () => Effect9.tryPromise({
|
|
3909
4930
|
try: async () => domChannel?.getJSErrors ? domChannel.getJSErrors() : [],
|
|
3910
4931
|
catch: (e) => new DriverError({ message: `getJSErrors failed: ${e}` })
|
|
3911
4932
|
}),
|
|
3912
4933
|
// -----------------------------------------------------------------------
|
|
3913
4934
|
// Network conditions
|
|
3914
4935
|
// -----------------------------------------------------------------------
|
|
3915
|
-
setNetworkConditions: (conditions) =>
|
|
4936
|
+
setNetworkConditions: (conditions) => Effect9.tryPromise({
|
|
3916
4937
|
try: async () => {
|
|
3917
4938
|
const isEmulator = serial.startsWith("emulator-");
|
|
3918
4939
|
const resolved = resolveNetworkConditions(conditions);
|
|
@@ -4159,7 +5180,7 @@ function parseAndroidHierarchy(xml) {
|
|
|
4159
5180
|
}
|
|
4160
5181
|
|
|
4161
5182
|
// src/drivers/wda/driver.ts
|
|
4162
|
-
import { Effect as
|
|
5183
|
+
import { Effect as Effect10 } from "effect";
|
|
4163
5184
|
|
|
4164
5185
|
// src/drivers/wda/client.ts
|
|
4165
5186
|
var WDAClient = class {
|
|
@@ -4594,9 +5615,21 @@ function isSessionError(error) {
|
|
|
4594
5615
|
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);
|
|
4595
5616
|
}
|
|
4596
5617
|
function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth = 100, driverOptions) {
|
|
4597
|
-
return
|
|
5618
|
+
return Effect10.gen(function* () {
|
|
4598
5619
|
const client = new WDAClient(host, port);
|
|
4599
5620
|
let currentContext = "NATIVE_APP";
|
|
5621
|
+
let hasLaunchedOnce = false;
|
|
5622
|
+
const waitForWdaReady = async (maxMs) => {
|
|
5623
|
+
const deadline = Date.now() + maxMs;
|
|
5624
|
+
while (Date.now() < deadline) {
|
|
5625
|
+
try {
|
|
5626
|
+
await client.getWindowSize();
|
|
5627
|
+
return;
|
|
5628
|
+
} catch {
|
|
5629
|
+
await sleep(40);
|
|
5630
|
+
}
|
|
5631
|
+
}
|
|
5632
|
+
};
|
|
4600
5633
|
const inspectorChannel = createWebKitInspectorChannel({
|
|
4601
5634
|
endpointUrl: driverOptions?.webkitInspectorUrl,
|
|
4602
5635
|
port: driverOptions?.webkitInspectorPort,
|
|
@@ -4640,7 +5673,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4640
5673
|
const activateSimulatorApp = async (targetBundleId) => {
|
|
4641
5674
|
if (!targetBundleId) return;
|
|
4642
5675
|
await client.activateApp(targetBundleId);
|
|
4643
|
-
await
|
|
5676
|
+
await waitForWdaReady(400);
|
|
4644
5677
|
};
|
|
4645
5678
|
const openSimulatorUrl = async (url, targetBundleId = bundleId) => {
|
|
4646
5679
|
if (!simulatorUdid) {
|
|
@@ -4650,7 +5683,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4650
5683
|
try {
|
|
4651
5684
|
await activateSimulatorApp(targetBundleId);
|
|
4652
5685
|
await client.openUrl(url);
|
|
4653
|
-
await
|
|
5686
|
+
await waitForWdaReady(400);
|
|
4654
5687
|
return;
|
|
4655
5688
|
} catch {
|
|
4656
5689
|
try {
|
|
@@ -4662,7 +5695,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4662
5695
|
await client.disableQuiescence();
|
|
4663
5696
|
await activateSimulatorApp(targetBundleId);
|
|
4664
5697
|
await client.openUrl(url);
|
|
4665
|
-
await
|
|
5698
|
+
await waitForWdaReady(400);
|
|
4666
5699
|
return;
|
|
4667
5700
|
} catch {
|
|
4668
5701
|
}
|
|
@@ -4703,23 +5736,23 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4703
5736
|
let reusedWarmSession = false;
|
|
4704
5737
|
if (driverOptions?.warmSessionId && typeof client.attachSession === "function") {
|
|
4705
5738
|
client.attachSession(driverOptions.warmSessionId);
|
|
4706
|
-
const alive = yield*
|
|
5739
|
+
const alive = yield* Effect10.tryPromise({
|
|
4707
5740
|
try: () => client.isSessionAlive(),
|
|
4708
5741
|
catch: () => false
|
|
4709
|
-
}).pipe(
|
|
5742
|
+
}).pipe(Effect10.catchAll(() => Effect10.succeed(false)));
|
|
4710
5743
|
reusedWarmSession = alive;
|
|
4711
5744
|
}
|
|
4712
5745
|
if (!reusedWarmSession) {
|
|
4713
|
-
const createdId = yield*
|
|
5746
|
+
const createdId = yield* Effect10.tryPromise({
|
|
4714
5747
|
try: () => createSessionWithRetry(bundleId || void 0),
|
|
4715
5748
|
catch: (e) => new DriverError({ message: `Failed to create WDA session: ${e}` })
|
|
4716
5749
|
});
|
|
4717
5750
|
driverOptions?.onSessionCreated?.(createdId);
|
|
4718
|
-
yield*
|
|
5751
|
+
yield* Effect10.tryPromise({
|
|
4719
5752
|
try: () => client.disableQuiescence(),
|
|
4720
5753
|
catch: (e) => new DriverError({ message: `Failed to disable quiescence: ${e}` })
|
|
4721
5754
|
});
|
|
4722
|
-
yield*
|
|
5755
|
+
yield* Effect10.tryPromise({
|
|
4723
5756
|
try: () => client.setSnapshotMaxDepth(snapshotMaxDepth),
|
|
4724
5757
|
catch: (e) => new DriverError({ message: `Failed to set snapshot depth: ${e}` })
|
|
4725
5758
|
});
|
|
@@ -4729,27 +5762,27 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4729
5762
|
// -----------------------------------------------------------------------
|
|
4730
5763
|
// Hierarchy
|
|
4731
5764
|
// -----------------------------------------------------------------------
|
|
4732
|
-
dumpHierarchy: () =>
|
|
5765
|
+
dumpHierarchy: () => Effect10.tryPromise({
|
|
4733
5766
|
try: () => withSessionRecovery(() => client.getSource()),
|
|
4734
5767
|
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
4735
5768
|
}),
|
|
4736
5769
|
// -----------------------------------------------------------------------
|
|
4737
5770
|
// Coordinate-level actions
|
|
4738
5771
|
// -----------------------------------------------------------------------
|
|
4739
|
-
tapAtCoordinate: (x, y) =>
|
|
5772
|
+
tapAtCoordinate: (x, y) => Effect10.tryPromise({
|
|
4740
5773
|
try: () => withSessionRecovery(() => client.tap(x, y)),
|
|
4741
5774
|
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
4742
5775
|
}),
|
|
4743
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
5776
|
+
doubleTapAtCoordinate: (x, y) => Effect10.tryPromise({
|
|
4744
5777
|
try: () => withSessionRecovery(() => client.doubleTap(x, y)),
|
|
4745
5778
|
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
4746
5779
|
}),
|
|
4747
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
5780
|
+
longPressAtCoordinate: (x, y, duration) => Effect10.tryPromise({
|
|
4748
5781
|
// duration arrives in ms (spana convention) → convert to seconds for WDA
|
|
4749
5782
|
try: () => withSessionRecovery(() => client.longPress(x, y, msToSec(duration))),
|
|
4750
5783
|
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
4751
5784
|
}),
|
|
4752
|
-
swipe: (sx, sy, ex, ey, dur) =>
|
|
5785
|
+
swipe: (sx, sy, ex, ey, dur) => Effect10.tryPromise({
|
|
4753
5786
|
// dur arrives in ms → convert to seconds for WDA.
|
|
4754
5787
|
// Clamp Y to avoid iOS system gesture zones (home indicator / App Switcher).
|
|
4755
5788
|
try: async () => {
|
|
@@ -4767,26 +5800,26 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4767
5800
|
},
|
|
4768
5801
|
catch: (e) => new DriverError({ message: `Swipe failed: ${e}` })
|
|
4769
5802
|
}),
|
|
4770
|
-
pinch: (cx, cy, scale, duration) =>
|
|
5803
|
+
pinch: (cx, cy, scale, duration) => Effect10.tryPromise({
|
|
4771
5804
|
try: () => withSessionRecovery(() => client.pinch(cx, cy, scale, msToSec(duration))),
|
|
4772
5805
|
catch: (e) => new DriverError({ message: `Pinch failed: ${e}` })
|
|
4773
5806
|
}),
|
|
4774
|
-
zoom: (cx, cy, scale, duration) =>
|
|
5807
|
+
zoom: (cx, cy, scale, duration) => Effect10.tryPromise({
|
|
4775
5808
|
try: () => withSessionRecovery(() => client.zoom(cx, cy, scale, msToSec(duration))),
|
|
4776
5809
|
catch: (e) => new DriverError({ message: `Zoom failed: ${e}` })
|
|
4777
5810
|
}),
|
|
4778
|
-
multiTouch: (sequences) =>
|
|
5811
|
+
multiTouch: (sequences) => Effect10.tryPromise({
|
|
4779
5812
|
try: () => withSessionRecovery(() => client.multiTouch(sequences)),
|
|
4780
5813
|
catch: (e) => new DriverError({ message: `Multi-touch failed: ${e}` })
|
|
4781
5814
|
}),
|
|
4782
5815
|
// -----------------------------------------------------------------------
|
|
4783
5816
|
// Text input
|
|
4784
5817
|
// -----------------------------------------------------------------------
|
|
4785
|
-
inputText: (text) =>
|
|
5818
|
+
inputText: (text) => Effect10.tryPromise({
|
|
4786
5819
|
try: () => withSessionRecovery(() => client.sendKeys(text)),
|
|
4787
5820
|
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
4788
5821
|
}),
|
|
4789
|
-
pressKey: (key) =>
|
|
5822
|
+
pressKey: (key) => Effect10.tryPromise({
|
|
4790
5823
|
// WDA uses named hardware buttons; map common names, fall back to home
|
|
4791
5824
|
try: async () => {
|
|
4792
5825
|
const buttonMap = {
|
|
@@ -4801,7 +5834,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4801
5834
|
},
|
|
4802
5835
|
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
4803
5836
|
}),
|
|
4804
|
-
hideKeyboard: () =>
|
|
5837
|
+
hideKeyboard: () => Effect10.tryPromise({
|
|
4805
5838
|
// Dismiss keyboard by tapping above the keyboard area.
|
|
4806
5839
|
// The previous approach (pressHome) backgrounds the app on iOS.
|
|
4807
5840
|
try: async () => {
|
|
@@ -4814,11 +5847,11 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4814
5847
|
// -----------------------------------------------------------------------
|
|
4815
5848
|
// Queries
|
|
4816
5849
|
// -----------------------------------------------------------------------
|
|
4817
|
-
takeScreenshot: () =>
|
|
5850
|
+
takeScreenshot: () => Effect10.tryPromise({
|
|
4818
5851
|
try: () => withSessionRecovery(() => client.getScreenshot()),
|
|
4819
5852
|
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
4820
5853
|
}),
|
|
4821
|
-
getDeviceInfo: () =>
|
|
5854
|
+
getDeviceInfo: () => Effect10.tryPromise({
|
|
4822
5855
|
try: async () => {
|
|
4823
5856
|
const size = await withSessionRecovery(() => client.getWindowSize());
|
|
4824
5857
|
return {
|
|
@@ -4836,15 +5869,40 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4836
5869
|
// -----------------------------------------------------------------------
|
|
4837
5870
|
// App lifecycle
|
|
4838
5871
|
// -----------------------------------------------------------------------
|
|
4839
|
-
launchApp: (appBundleId, opts) =>
|
|
5872
|
+
launchApp: (appBundleId, opts) => Effect10.tryPromise({
|
|
4840
5873
|
try: async () => {
|
|
5874
|
+
const canFastReset = hasLaunchedOnce && driverOptions?.fastWebViewReset !== false && domChannel.isConnected() && !opts?.deepLink && !opts?.clearKeychain && !hasLaunchDeviceState(opts?.deviceState) && !(opts?.launchArguments && Object.keys(opts.launchArguments).length > 0);
|
|
5875
|
+
if (canFastReset) {
|
|
5876
|
+
try {
|
|
5877
|
+
if (opts?.clearState && domChannel.clearStorage) {
|
|
5878
|
+
await domChannel.clearStorage({
|
|
5879
|
+
localStorage: true,
|
|
5880
|
+
sessionStorage: true,
|
|
5881
|
+
cookies: true,
|
|
5882
|
+
indexedDB: true,
|
|
5883
|
+
capacitorPreferences: true
|
|
5884
|
+
});
|
|
5885
|
+
}
|
|
5886
|
+
if (domChannel.reload) {
|
|
5887
|
+
await domChannel.reload();
|
|
5888
|
+
} else {
|
|
5889
|
+
await domChannel.evaluate("window.location.reload()");
|
|
5890
|
+
}
|
|
5891
|
+
return;
|
|
5892
|
+
} catch {
|
|
5893
|
+
}
|
|
5894
|
+
}
|
|
4841
5895
|
if (opts?.clearState && simulatorUdid) {
|
|
4842
5896
|
terminateOnSimulator(simulatorUdid, appBundleId);
|
|
4843
5897
|
try {
|
|
4844
|
-
const {
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
5898
|
+
const { execFileSync: execFileSync2 } = await import("child_process");
|
|
5899
|
+
execFileSync2(
|
|
5900
|
+
"xcrun",
|
|
5901
|
+
["simctl", "privacy", simulatorUdid, "reset", "all", appBundleId],
|
|
5902
|
+
{
|
|
5903
|
+
stdio: "ignore"
|
|
5904
|
+
}
|
|
5905
|
+
);
|
|
4848
5906
|
} catch {
|
|
4849
5907
|
}
|
|
4850
5908
|
}
|
|
@@ -4870,13 +5928,12 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4870
5928
|
} catch {
|
|
4871
5929
|
}
|
|
4872
5930
|
}
|
|
4873
|
-
await sleep(300);
|
|
4874
5931
|
try {
|
|
4875
5932
|
await client.launchApp(appBundleId);
|
|
4876
|
-
await
|
|
5933
|
+
await waitForWdaReady(500);
|
|
4877
5934
|
} catch {
|
|
4878
5935
|
launchOnSimulator(simulatorUdid, appBundleId);
|
|
4879
|
-
await sleep(
|
|
5936
|
+
await sleep(250);
|
|
4880
5937
|
try {
|
|
4881
5938
|
await client.deleteSession();
|
|
4882
5939
|
} catch {
|
|
@@ -4888,13 +5945,15 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4888
5945
|
}
|
|
4889
5946
|
}
|
|
4890
5947
|
}
|
|
5948
|
+
hasLaunchedOnce = true;
|
|
4891
5949
|
return;
|
|
4892
5950
|
}
|
|
4893
5951
|
await (opts?.deepLink ? client.openUrl(opts.deepLink) : client.launchApp(appBundleId));
|
|
5952
|
+
hasLaunchedOnce = true;
|
|
4894
5953
|
},
|
|
4895
5954
|
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
4896
5955
|
}),
|
|
4897
|
-
stopApp: (appBundleId) =>
|
|
5956
|
+
stopApp: (appBundleId) => Effect10.tryPromise({
|
|
4898
5957
|
try: () => {
|
|
4899
5958
|
if (simulatorUdid) {
|
|
4900
5959
|
terminateOnSimulator(simulatorUdid, appBundleId);
|
|
@@ -4904,7 +5963,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4904
5963
|
},
|
|
4905
5964
|
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
4906
5965
|
}),
|
|
4907
|
-
killApp: (appBundleId) =>
|
|
5966
|
+
killApp: (appBundleId) => Effect10.tryPromise({
|
|
4908
5967
|
try: async () => {
|
|
4909
5968
|
await domChannel.disconnect().catch(() => {
|
|
4910
5969
|
});
|
|
@@ -4917,7 +5976,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4917
5976
|
},
|
|
4918
5977
|
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
4919
5978
|
}),
|
|
4920
|
-
clearAppState: (appBundleId) =>
|
|
5979
|
+
clearAppState: (appBundleId) => Effect10.tryPromise({
|
|
4921
5980
|
try: async () => {
|
|
4922
5981
|
if (domChannel.isConnected() && domChannel.clearStorage) {
|
|
4923
5982
|
await domChannel.clearStorage({
|
|
@@ -4940,7 +5999,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4940
5999
|
},
|
|
4941
6000
|
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
4942
6001
|
}),
|
|
4943
|
-
resetFast: () =>
|
|
6002
|
+
resetFast: () => Effect10.tryPromise({
|
|
4944
6003
|
try: async () => {
|
|
4945
6004
|
if (domChannel.clearStorage) {
|
|
4946
6005
|
await domChannel.clearStorage({
|
|
@@ -4967,7 +6026,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4967
6026
|
// -----------------------------------------------------------------------
|
|
4968
6027
|
// Navigation
|
|
4969
6028
|
// -----------------------------------------------------------------------
|
|
4970
|
-
openLink: (url) =>
|
|
6029
|
+
openLink: (url) => Effect10.tryPromise({
|
|
4971
6030
|
try: async () => {
|
|
4972
6031
|
if (simulatorUdid) {
|
|
4973
6032
|
await openSimulatorUrl(url);
|
|
@@ -4977,7 +6036,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4977
6036
|
},
|
|
4978
6037
|
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
4979
6038
|
}),
|
|
4980
|
-
back: () =>
|
|
6039
|
+
back: () => Effect10.tryPromise({
|
|
4981
6040
|
// iOS has no hardware back button; pressing home is the closest
|
|
4982
6041
|
// equivalent for dismissing the current context.
|
|
4983
6042
|
try: () => client.pressHome(),
|
|
@@ -4987,13 +6046,13 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
4987
6046
|
// Direct DOM evaluation via spana-bridge or WebKit Remote Inspector
|
|
4988
6047
|
// (no Appium required)
|
|
4989
6048
|
// -----------------------------------------------------------------------
|
|
4990
|
-
evaluate: (script, ...args) =>
|
|
6049
|
+
evaluate: (script, ...args) => Effect10.tryPromise({
|
|
4991
6050
|
try: () => domChannel.evaluate(script, ...args),
|
|
4992
6051
|
catch: (e) => new DriverError({
|
|
4993
6052
|
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.`
|
|
4994
6053
|
})
|
|
4995
6054
|
}),
|
|
4996
|
-
getContexts: () =>
|
|
6055
|
+
getContexts: () => Effect10.tryPromise({
|
|
4997
6056
|
try: async () => {
|
|
4998
6057
|
const contexts = ["NATIVE_APP"];
|
|
4999
6058
|
if (domChannel.listTargets) {
|
|
@@ -5012,8 +6071,8 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
5012
6071
|
},
|
|
5013
6072
|
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
5014
6073
|
}),
|
|
5015
|
-
getCurrentContext: () =>
|
|
5016
|
-
setContext: (contextId) =>
|
|
6074
|
+
getCurrentContext: () => Effect10.succeed(currentContext),
|
|
6075
|
+
setContext: (contextId) => Effect10.tryPromise({
|
|
5017
6076
|
try: async () => {
|
|
5018
6077
|
if (contextId === "NATIVE_APP") {
|
|
5019
6078
|
currentContext = "NATIVE_APP";
|
|
@@ -5033,7 +6092,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
5033
6092
|
},
|
|
5034
6093
|
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
5035
6094
|
}),
|
|
5036
|
-
mockNetwork: (matcher, response) =>
|
|
6095
|
+
mockNetwork: (matcher, response) => Effect10.tryPromise({
|
|
5037
6096
|
try: async () => {
|
|
5038
6097
|
if (!domChannel.mockNetwork) {
|
|
5039
6098
|
throw new Error("mockNetwork() on iOS requires spana-bridge");
|
|
@@ -5042,7 +6101,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
5042
6101
|
},
|
|
5043
6102
|
catch: (e) => new DriverError({ message: `mockNetwork failed: ${e}` })
|
|
5044
6103
|
}),
|
|
5045
|
-
blockNetwork: (matcher) =>
|
|
6104
|
+
blockNetwork: (matcher) => Effect10.tryPromise({
|
|
5046
6105
|
try: async () => {
|
|
5047
6106
|
if (!domChannel.blockNetwork) {
|
|
5048
6107
|
throw new Error("blockNetwork() on iOS requires spana-bridge");
|
|
@@ -5051,7 +6110,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
5051
6110
|
},
|
|
5052
6111
|
catch: (e) => new DriverError({ message: `blockNetwork failed: ${e}` })
|
|
5053
6112
|
}),
|
|
5054
|
-
clearNetworkMocks: () =>
|
|
6113
|
+
clearNetworkMocks: () => Effect10.tryPromise({
|
|
5055
6114
|
try: async () => {
|
|
5056
6115
|
if (domChannel.clearNetworkMocks) {
|
|
5057
6116
|
await domChannel.clearNetworkMocks();
|
|
@@ -5059,18 +6118,18 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
5059
6118
|
},
|
|
5060
6119
|
catch: (e) => new DriverError({ message: `clearNetworkMocks failed: ${e}` })
|
|
5061
6120
|
}),
|
|
5062
|
-
getConsoleLogs: () =>
|
|
6121
|
+
getConsoleLogs: () => Effect10.tryPromise({
|
|
5063
6122
|
try: async () => domChannel.getConsoleLogs ? domChannel.getConsoleLogs() : [],
|
|
5064
6123
|
catch: (e) => new DriverError({ message: `getConsoleLogs failed: ${e}` })
|
|
5065
6124
|
}),
|
|
5066
|
-
getJSErrors: () =>
|
|
6125
|
+
getJSErrors: () => Effect10.tryPromise({
|
|
5067
6126
|
try: async () => domChannel.getJSErrors ? domChannel.getJSErrors() : [],
|
|
5068
6127
|
catch: (e) => new DriverError({ message: `getJSErrors failed: ${e}` })
|
|
5069
6128
|
}),
|
|
5070
6129
|
// -----------------------------------------------------------------------
|
|
5071
6130
|
// Network simulation
|
|
5072
6131
|
// -----------------------------------------------------------------------
|
|
5073
|
-
setNetworkConditions: (conditions) =>
|
|
6132
|
+
setNetworkConditions: (conditions) => Effect10.tryPromise({
|
|
5074
6133
|
try: async () => {
|
|
5075
6134
|
if (!simulatorUdid) {
|
|
5076
6135
|
throw new DriverError({
|
|
@@ -5193,7 +6252,7 @@ function parseIOSHierarchy(xml) {
|
|
|
5193
6252
|
}
|
|
5194
6253
|
|
|
5195
6254
|
// src/drivers/electron.ts
|
|
5196
|
-
import { Effect as
|
|
6255
|
+
import { Effect as Effect11 } from "effect";
|
|
5197
6256
|
import {
|
|
5198
6257
|
_electron,
|
|
5199
6258
|
chromium as chromium2
|
|
@@ -5237,7 +6296,7 @@ var CLEAR_STORAGE_SCRIPT2 = `
|
|
|
5237
6296
|
})();
|
|
5238
6297
|
`;
|
|
5239
6298
|
function makeElectronDriver(options) {
|
|
5240
|
-
return
|
|
6299
|
+
return Effect11.gen(function* () {
|
|
5241
6300
|
let electronApp;
|
|
5242
6301
|
let cdpBrowser;
|
|
5243
6302
|
let context;
|
|
@@ -5261,13 +6320,13 @@ function makeElectronDriver(options) {
|
|
|
5261
6320
|
const resolvedCdpUrl = options.cdpUrl ?? (options.cdpPort && !options.entry && !options.executablePath ? `http://127.0.0.1:${options.cdpPort}` : void 0);
|
|
5262
6321
|
if (resolvedCdpUrl) {
|
|
5263
6322
|
const connect = options.connectOverCDP ?? chromium2.connectOverCDP.bind(chromium2);
|
|
5264
|
-
cdpBrowser = yield*
|
|
6323
|
+
cdpBrowser = yield* Effect11.tryPromise({
|
|
5265
6324
|
try: () => connect(resolvedCdpUrl),
|
|
5266
6325
|
catch: (e) => new DriverError({
|
|
5267
6326
|
message: `Failed to connect to Electron over CDP (${resolvedCdpUrl}): ${e}`
|
|
5268
6327
|
})
|
|
5269
6328
|
});
|
|
5270
|
-
page = yield*
|
|
6329
|
+
page = yield* Effect11.tryPromise({
|
|
5271
6330
|
try: async () => {
|
|
5272
6331
|
const contexts = cdpBrowser.contexts();
|
|
5273
6332
|
context = contexts[0];
|
|
@@ -5292,7 +6351,7 @@ function makeElectronDriver(options) {
|
|
|
5292
6351
|
});
|
|
5293
6352
|
}
|
|
5294
6353
|
const launcher = options.launchElectron ?? _electron.launch.bind(_electron);
|
|
5295
|
-
electronApp = yield*
|
|
6354
|
+
electronApp = yield* Effect11.tryPromise({
|
|
5296
6355
|
try: () => launcher({
|
|
5297
6356
|
...options.executablePath ? { executablePath: options.executablePath } : {},
|
|
5298
6357
|
...launchArgs.length > 0 ? { args: launchArgs } : {},
|
|
@@ -5301,7 +6360,7 @@ function makeElectronDriver(options) {
|
|
|
5301
6360
|
}),
|
|
5302
6361
|
catch: (e) => new DriverError({ message: `Failed to launch Electron app: ${e}` })
|
|
5303
6362
|
});
|
|
5304
|
-
page = yield*
|
|
6363
|
+
page = yield* Effect11.tryPromise({
|
|
5305
6364
|
try: async () => {
|
|
5306
6365
|
const win = await electronApp.firstWindow();
|
|
5307
6366
|
context = electronApp.context();
|
|
@@ -5331,26 +6390,26 @@ function makeElectronDriver(options) {
|
|
|
5331
6390
|
};
|
|
5332
6391
|
const service = {
|
|
5333
6392
|
domChannel,
|
|
5334
|
-
beginFlow: () =>
|
|
6393
|
+
beginFlow: () => Effect11.sync(() => {
|
|
5335
6394
|
consoleLogs.length = 0;
|
|
5336
6395
|
jsErrors.length = 0;
|
|
5337
6396
|
}),
|
|
5338
|
-
dumpHierarchy: () =>
|
|
6397
|
+
dumpHierarchy: () => Effect11.tryPromise({
|
|
5339
6398
|
try: async () => {
|
|
5340
6399
|
const tree = await page.evaluate(DOM_HIERARCHY_WALK_SCRIPT);
|
|
5341
6400
|
return JSON.stringify(tree);
|
|
5342
6401
|
},
|
|
5343
6402
|
catch: (e) => new DriverError({ message: `Electron dumpHierarchy failed: ${e}` })
|
|
5344
6403
|
}),
|
|
5345
|
-
tapAtCoordinate: (x, y) =>
|
|
6404
|
+
tapAtCoordinate: (x, y) => Effect11.tryPromise({
|
|
5346
6405
|
try: () => page.mouse.click(x, y),
|
|
5347
6406
|
catch: (e) => new DriverError({ message: `Electron tap failed at (${x}, ${y}): ${e}` })
|
|
5348
6407
|
}),
|
|
5349
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
6408
|
+
doubleTapAtCoordinate: (x, y) => Effect11.tryPromise({
|
|
5350
6409
|
try: () => page.mouse.dblclick(x, y),
|
|
5351
6410
|
catch: (e) => new DriverError({ message: `Electron doubleTap failed at (${x}, ${y}): ${e}` })
|
|
5352
6411
|
}),
|
|
5353
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
6412
|
+
longPressAtCoordinate: (x, y, duration) => Effect11.tryPromise({
|
|
5354
6413
|
try: async () => {
|
|
5355
6414
|
await page.mouse.move(x, y);
|
|
5356
6415
|
await page.mouse.down();
|
|
@@ -5359,7 +6418,7 @@ function makeElectronDriver(options) {
|
|
|
5359
6418
|
},
|
|
5360
6419
|
catch: (e) => new DriverError({ message: `Electron longPress failed: ${e}` })
|
|
5361
6420
|
}),
|
|
5362
|
-
swipe: (startX, startY, endX, endY, duration) =>
|
|
6421
|
+
swipe: (startX, startY, endX, endY, duration) => Effect11.tryPromise({
|
|
5363
6422
|
try: async () => {
|
|
5364
6423
|
await page.mouse.move(startX, startY);
|
|
5365
6424
|
await page.mouse.wheel(startX - endX, startY - endY);
|
|
@@ -5367,20 +6426,20 @@ function makeElectronDriver(options) {
|
|
|
5367
6426
|
},
|
|
5368
6427
|
catch: (e) => new DriverError({ message: `Electron swipe failed: ${e}` })
|
|
5369
6428
|
}),
|
|
5370
|
-
inputText: (text) =>
|
|
6429
|
+
inputText: (text) => Effect11.tryPromise({
|
|
5371
6430
|
try: () => page.keyboard.insertText(text),
|
|
5372
6431
|
catch: (e) => new DriverError({ message: `Electron inputText failed: ${e}` })
|
|
5373
6432
|
}),
|
|
5374
|
-
pressKey: (key) =>
|
|
6433
|
+
pressKey: (key) => Effect11.tryPromise({
|
|
5375
6434
|
try: () => page.keyboard.press(key),
|
|
5376
6435
|
catch: (e) => new DriverError({ message: `Electron pressKey failed: ${e}` })
|
|
5377
6436
|
}),
|
|
5378
|
-
hideKeyboard: () =>
|
|
5379
|
-
takeScreenshot: () =>
|
|
6437
|
+
hideKeyboard: () => Effect11.void,
|
|
6438
|
+
takeScreenshot: () => Effect11.tryPromise({
|
|
5380
6439
|
try: async () => new Uint8Array(await page.screenshot()),
|
|
5381
6440
|
catch: (e) => new DriverError({ message: `Electron screenshot failed: ${e}` })
|
|
5382
6441
|
}),
|
|
5383
|
-
getDeviceInfo: () =>
|
|
6442
|
+
getDeviceInfo: () => Effect11.tryPromise({
|
|
5384
6443
|
try: async () => {
|
|
5385
6444
|
const viewport = page.viewportSize() ?? { width: 1280, height: 800 };
|
|
5386
6445
|
return {
|
|
@@ -5395,7 +6454,7 @@ function makeElectronDriver(options) {
|
|
|
5395
6454
|
},
|
|
5396
6455
|
catch: (e) => new DriverError({ message: `Electron getDeviceInfo failed: ${e}` })
|
|
5397
6456
|
}),
|
|
5398
|
-
launchApp: (appRef, opts) =>
|
|
6457
|
+
launchApp: (appRef, opts) => Effect11.tryPromise({
|
|
5399
6458
|
try: async () => {
|
|
5400
6459
|
if (opts?.clearState) {
|
|
5401
6460
|
await clearStorageAndCookies();
|
|
@@ -5407,8 +6466,8 @@ function makeElectronDriver(options) {
|
|
|
5407
6466
|
},
|
|
5408
6467
|
catch: (e) => new DriverError({ message: `Electron launchApp failed: ${e}` })
|
|
5409
6468
|
}),
|
|
5410
|
-
stopApp: () =>
|
|
5411
|
-
killApp: () =>
|
|
6469
|
+
stopApp: () => Effect11.void,
|
|
6470
|
+
killApp: () => Effect11.tryPromise({
|
|
5412
6471
|
try: async () => {
|
|
5413
6472
|
await domChannel?.disconnect().catch(() => {
|
|
5414
6473
|
});
|
|
@@ -5420,32 +6479,32 @@ function makeElectronDriver(options) {
|
|
|
5420
6479
|
},
|
|
5421
6480
|
catch: (e) => new DriverError({ message: `Electron killApp failed: ${e}` })
|
|
5422
6481
|
}),
|
|
5423
|
-
clearAppState: () =>
|
|
6482
|
+
clearAppState: () => Effect11.tryPromise({
|
|
5424
6483
|
try: async () => {
|
|
5425
6484
|
await clearStorageAndCookies();
|
|
5426
6485
|
},
|
|
5427
6486
|
catch: (e) => new DriverError({ message: `Electron clearAppState failed: ${e}` })
|
|
5428
6487
|
}),
|
|
5429
|
-
resetFast: () =>
|
|
6488
|
+
resetFast: () => Effect11.tryPromise({
|
|
5430
6489
|
try: async () => {
|
|
5431
6490
|
await clearStorageAndCookies();
|
|
5432
6491
|
await page.reload();
|
|
5433
6492
|
},
|
|
5434
6493
|
catch: (e) => new DriverError({ message: `Electron resetFast failed: ${e}` })
|
|
5435
6494
|
}),
|
|
5436
|
-
openLink: (url) =>
|
|
6495
|
+
openLink: (url) => Effect11.tryPromise({
|
|
5437
6496
|
try: async () => {
|
|
5438
6497
|
await page.goto(url);
|
|
5439
6498
|
},
|
|
5440
6499
|
catch: (e) => new DriverError({ message: `Electron openLink failed: ${e}` })
|
|
5441
6500
|
}),
|
|
5442
|
-
back: () =>
|
|
6501
|
+
back: () => Effect11.tryPromise({
|
|
5443
6502
|
try: async () => {
|
|
5444
6503
|
await page.goBack();
|
|
5445
6504
|
},
|
|
5446
6505
|
catch: (e) => new DriverError({ message: `Electron back failed: ${e}` })
|
|
5447
6506
|
}),
|
|
5448
|
-
evaluate: (script, ...args) =>
|
|
6507
|
+
evaluate: (script, ...args) => Effect11.tryPromise({
|
|
5449
6508
|
try: async () => {
|
|
5450
6509
|
if (domChannel?.isConnected()) {
|
|
5451
6510
|
return await domChannel.evaluate(script, ...args);
|
|
@@ -5463,7 +6522,7 @@ function makeElectronDriver(options) {
|
|
|
5463
6522
|
},
|
|
5464
6523
|
catch: (e) => new DriverError({ message: `Electron evaluate failed: ${e}` })
|
|
5465
6524
|
}),
|
|
5466
|
-
mockNetwork: (matcher, response) =>
|
|
6525
|
+
mockNetwork: (matcher, response) => Effect11.tryPromise({
|
|
5467
6526
|
try: async () => {
|
|
5468
6527
|
if (!context) throw new Error("No Electron BrowserContext available");
|
|
5469
6528
|
await context.route(matcher, async (route) => {
|
|
@@ -5478,7 +6537,7 @@ function makeElectronDriver(options) {
|
|
|
5478
6537
|
},
|
|
5479
6538
|
catch: (e) => new DriverError({ message: `Electron mockNetwork failed: ${e}` })
|
|
5480
6539
|
}),
|
|
5481
|
-
blockNetwork: (matcher) =>
|
|
6540
|
+
blockNetwork: (matcher) => Effect11.tryPromise({
|
|
5482
6541
|
try: async () => {
|
|
5483
6542
|
if (!context) throw new Error("No Electron BrowserContext available");
|
|
5484
6543
|
await context.route(matcher, async (route) => {
|
|
@@ -5488,7 +6547,7 @@ function makeElectronDriver(options) {
|
|
|
5488
6547
|
},
|
|
5489
6548
|
catch: (e) => new DriverError({ message: `Electron blockNetwork failed: ${e}` })
|
|
5490
6549
|
}),
|
|
5491
|
-
clearNetworkMocks: () =>
|
|
6550
|
+
clearNetworkMocks: () => Effect11.tryPromise({
|
|
5492
6551
|
try: async () => {
|
|
5493
6552
|
if (!context) return;
|
|
5494
6553
|
for (const entry of appliedRoutes) {
|
|
@@ -5499,18 +6558,18 @@ function makeElectronDriver(options) {
|
|
|
5499
6558
|
},
|
|
5500
6559
|
catch: (e) => new DriverError({ message: `Electron clearNetworkMocks failed: ${e}` })
|
|
5501
6560
|
}),
|
|
5502
|
-
getConsoleLogs: () =>
|
|
5503
|
-
getJSErrors: () =>
|
|
6561
|
+
getConsoleLogs: () => Effect11.succeed([...consoleLogs]),
|
|
6562
|
+
getJSErrors: () => Effect11.succeed([...jsErrors])
|
|
5504
6563
|
};
|
|
5505
6564
|
return service;
|
|
5506
6565
|
});
|
|
5507
6566
|
}
|
|
5508
6567
|
|
|
5509
6568
|
// src/drivers/uiautomator2/installer.ts
|
|
5510
|
-
import {
|
|
6569
|
+
import { execFileSync, spawn as spawn2 } from "child_process";
|
|
5511
6570
|
import { existsSync, readdirSync } from "fs";
|
|
5512
6571
|
import { createRequire } from "module";
|
|
5513
|
-
import { dirname, resolve, join } from "path";
|
|
6572
|
+
import { dirname, resolve, join as join2 } from "path";
|
|
5514
6573
|
import { fileURLToPath } from "url";
|
|
5515
6574
|
var __dirname2 = fileURLToPath(new URL(".", import.meta.url));
|
|
5516
6575
|
var require2 = createRequire(import.meta.url);
|
|
@@ -5539,7 +6598,7 @@ function findUiAutomator2APK() {
|
|
|
5539
6598
|
);
|
|
5540
6599
|
const testApk = files.find((f) => f.includes("androidTest") && f.endsWith(".apk"));
|
|
5541
6600
|
if (serverApk && testApk) {
|
|
5542
|
-
return { serverApk:
|
|
6601
|
+
return { serverApk: join2(dir, serverApk), testApk: join2(dir, testApk) };
|
|
5543
6602
|
}
|
|
5544
6603
|
}
|
|
5545
6604
|
return null;
|
|
@@ -5568,10 +6627,23 @@ function startUiAutomator2Server(serial) {
|
|
|
5568
6627
|
const adb = findADB();
|
|
5569
6628
|
if (!adb) throw new Error("adb not found");
|
|
5570
6629
|
try {
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
6630
|
+
const proc = spawn2(
|
|
6631
|
+
adb,
|
|
6632
|
+
[
|
|
6633
|
+
"-s",
|
|
6634
|
+
serial,
|
|
6635
|
+
"shell",
|
|
6636
|
+
"am",
|
|
6637
|
+
"instrument",
|
|
6638
|
+
"-w",
|
|
6639
|
+
"-e",
|
|
6640
|
+
"disableAnalytics",
|
|
6641
|
+
"true",
|
|
6642
|
+
"io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner"
|
|
6643
|
+
],
|
|
6644
|
+
{ detached: true, stdio: "ignore" }
|
|
5574
6645
|
);
|
|
6646
|
+
proc.unref();
|
|
5575
6647
|
} catch {
|
|
5576
6648
|
}
|
|
5577
6649
|
}
|
|
@@ -5599,7 +6671,7 @@ async function setupUiAutomator2(serial, hostPort, options = {}) {
|
|
|
5599
6671
|
const adb = findADB();
|
|
5600
6672
|
if (adb) {
|
|
5601
6673
|
try {
|
|
5602
|
-
|
|
6674
|
+
execFileSync(adb, ["-s", serial, "forward", "--remove", `tcp:${port}`], { stdio: "ignore" });
|
|
5603
6675
|
} catch {
|
|
5604
6676
|
}
|
|
5605
6677
|
}
|
|
@@ -5629,7 +6701,9 @@ async function setupUiAutomator2(serial, hostPort, options = {}) {
|
|
|
5629
6701
|
if (warm) return;
|
|
5630
6702
|
try {
|
|
5631
6703
|
if (adb)
|
|
5632
|
-
|
|
6704
|
+
execFileSync(adb, ["-s", serial, "forward", "--remove", `tcp:${port}`], {
|
|
6705
|
+
stdio: "ignore"
|
|
6706
|
+
});
|
|
5633
6707
|
} catch {
|
|
5634
6708
|
}
|
|
5635
6709
|
releasePort(port);
|
|
@@ -5649,9 +6723,18 @@ export {
|
|
|
5649
6723
|
hasLaunchDeviceState,
|
|
5650
6724
|
deviceStateToAppiumCapabilities,
|
|
5651
6725
|
buildIOSLaunchConfiguration,
|
|
6726
|
+
byRole,
|
|
6727
|
+
byCss,
|
|
6728
|
+
within,
|
|
6729
|
+
inFrame,
|
|
6730
|
+
nth,
|
|
6731
|
+
first,
|
|
6732
|
+
last,
|
|
6733
|
+
filterSelector,
|
|
5652
6734
|
systemUI,
|
|
5653
6735
|
isSystemUISelector,
|
|
5654
6736
|
isTestIDSelector,
|
|
6737
|
+
isComposableDomSelector,
|
|
5655
6738
|
splitGraphemes,
|
|
5656
6739
|
flattenElements,
|
|
5657
6740
|
invalidateWebViewFrameCache,
|
|
@@ -5661,6 +6744,7 @@ export {
|
|
|
5661
6744
|
resolveElementAcrossChannels,
|
|
5662
6745
|
createCoordinator,
|
|
5663
6746
|
buildStorybookUrl,
|
|
6747
|
+
createPromiseExpect,
|
|
5664
6748
|
createPromiseApp,
|
|
5665
6749
|
parseWebHierarchy,
|
|
5666
6750
|
resolveNetworkConditions,
|
|
@@ -5676,4 +6760,4 @@ export {
|
|
|
5676
6760
|
makeElectronDriver,
|
|
5677
6761
|
setupUiAutomator2
|
|
5678
6762
|
};
|
|
5679
|
-
//# sourceMappingURL=chunk-
|
|
6763
|
+
//# sourceMappingURL=chunk-AJCSETN6.js.map
|