spana-test 0.10.0 → 0.11.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 +10 -7
- package/dist/agent-fixture-5C4MCWRD.js +20 -0
- package/dist/app-RSDPDTKT.js +10 -0
- package/dist/cache-command-PANUAEMZ.js +12 -0
- package/dist/{chunk-C2HBFEMQ.js → chunk-26NJXP55.js} +2 -2
- package/dist/{chunk-66D3C7NB.js → chunk-3IZMPNE7.js} +504 -2071
- package/dist/chunk-3IZMPNE7.js.map +1 -0
- package/dist/chunk-4KK4E3N3.js +3587 -0
- package/dist/chunk-4KK4E3N3.js.map +1 -0
- package/dist/{chunk-6GBAPW6K.js → chunk-4SA7JK5D.js} +15 -11
- package/dist/{chunk-6GBAPW6K.js.map → chunk-4SA7JK5D.js.map} +1 -1
- package/dist/{chunk-DP7MGXHN.js → chunk-64UZQP7Z.js} +27 -3
- package/dist/chunk-64UZQP7Z.js.map +1 -0
- package/dist/chunk-6PTUVG6A.js +127 -0
- package/dist/chunk-6PTUVG6A.js.map +1 -0
- package/dist/chunk-FPQAJNE3.js +2874 -0
- package/dist/chunk-FPQAJNE3.js.map +1 -0
- package/dist/{chunk-B35G77DN.js → chunk-FXBWACUT.js} +351 -3471
- package/dist/chunk-FXBWACUT.js.map +1 -0
- package/dist/chunk-OPTNFLBL.js +556 -0
- package/dist/chunk-OPTNFLBL.js.map +1 -0
- package/dist/chunk-S7MSBZ3F.js +72 -0
- package/dist/chunk-S7MSBZ3F.js.map +1 -0
- package/dist/chunk-SGZMO456.js +2125 -0
- package/dist/chunk-SGZMO456.js.map +1 -0
- package/dist/{chunk-Y6KMJJ2T.js → chunk-SIJJVN2D.js} +358 -3
- package/dist/chunk-SIJJVN2D.js.map +1 -0
- package/dist/{chunk-SF7UYW4I.js → chunk-VUNH4AJD.js} +4 -4
- package/dist/{chunk-B473XZOM.js → chunk-WS2TVNMY.js} +18 -1964
- package/dist/chunk-WS2TVNMY.js.map +1 -0
- package/dist/{chunk-IXON7DMB.js → chunk-WZAQANN6.js} +2 -2
- package/dist/{chunk-7QFJ7MDH.js → chunk-XA6LWLZQ.js} +64 -3
- package/dist/chunk-XA6LWLZQ.js.map +1 -0
- package/dist/cli.js +190 -17
- package/dist/cli.js.map +1 -1
- package/dist/config-loader-CNGIW2XK.js +9 -0
- package/dist/{discover-RLSKEBAX.js → discover-NKDMB4UI.js} +3 -3
- package/dist/{doctor-command-QIYBI7ZF.js → doctor-command-6ZVJWCW7.js} +5 -4
- package/dist/{doctor-command-QIYBI7ZF.js.map → doctor-command-6ZVJWCW7.js.map} +1 -1
- package/dist/{app-xIYd2jde.d.ts → flow-DddAj1xv.d.ts} +960 -356
- package/dist/gherkin/steps.d.ts +1 -2
- package/dist/index.d.ts +486 -131
- package/dist/index.js +474 -275
- package/dist/index.js.map +1 -1
- package/dist/local-DM3YBSV5.js +31 -0
- package/dist/{runner-JID2YWRE.js → runner-WOVZWUQR.js} +2 -2
- package/dist/runner-WOVZWUQR.js.map +1 -0
- package/dist/{server-UIRGHUYM.js → server-ING5D5ZJ.js} +2 -2
- package/dist/server-ING5D5ZJ.js.map +1 -0
- package/dist/{server-6KQSTQIG.js → server-JNQ2PLCC.js} +10 -7
- package/dist/{server-6KQSTQIG.js.map → server-JNQ2PLCC.js.map} +1 -1
- package/dist/session-5TNWVGQQ.js +21 -0
- package/dist/session-5TNWVGQQ.js.map +1 -0
- package/dist/{session-Bt_mbUWg.d.ts → session-uT8xL03K.d.ts} +5 -1
- package/dist/{studio-command-TXQTIWRS.js → studio-command-KK7A3KN6.js} +2 -2
- package/dist/{test-command-CCSQPKWU.js → test-command-QGIJBRH7.js} +187 -29
- package/dist/test-command-QGIJBRH7.js.map +1 -0
- package/dist/{validator-YWNHCU2S.js → validator-WO5IL7IY.js} +3 -3
- package/dist/validator-WO5IL7IY.js.map +1 -0
- package/package.json +10 -10
- package/dist/chunk-66D3C7NB.js.map +0 -1
- package/dist/chunk-7QFJ7MDH.js.map +0 -1
- package/dist/chunk-B35G77DN.js.map +0 -1
- package/dist/chunk-B473XZOM.js.map +0 -1
- package/dist/chunk-DP7MGXHN.js.map +0 -1
- package/dist/chunk-Y6KMJJ2T.js.map +0 -1
- package/dist/config-loader-WLPQ5WVH.js +0 -9
- package/dist/flow-CI5parw2.d.ts +0 -90
- package/dist/session-BE6U34DA.js +0 -18
- package/dist/test-command-CCSQPKWU.js.map +0 -1
- /package/dist/{config-loader-WLPQ5WVH.js.map → agent-fixture-5C4MCWRD.js.map} +0 -0
- /package/dist/{discover-RLSKEBAX.js.map → app-RSDPDTKT.js.map} +0 -0
- /package/dist/{runner-JID2YWRE.js.map → cache-command-PANUAEMZ.js.map} +0 -0
- /package/dist/{chunk-C2HBFEMQ.js.map → chunk-26NJXP55.js.map} +0 -0
- /package/dist/{chunk-SF7UYW4I.js.map → chunk-VUNH4AJD.js.map} +0 -0
- /package/dist/{chunk-IXON7DMB.js.map → chunk-WZAQANN6.js.map} +0 -0
- /package/dist/{server-UIRGHUYM.js.map → config-loader-CNGIW2XK.js.map} +0 -0
- /package/dist/{session-BE6U34DA.js.map → discover-NKDMB4UI.js.map} +0 -0
- /package/dist/{validator-YWNHCU2S.js.map → local-DM3YBSV5.js.map} +0 -0
- /package/dist/{studio-command-TXQTIWRS.js.map → studio-command-KK7A3KN6.js.map} +0 -0
|
@@ -1,3280 +1,57 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// src/schemas/selector.ts
|
|
56
|
-
import { Schema } from "effect";
|
|
57
|
-
var _TestIDSelectorSchema = Schema.Struct({ testID: Schema.String });
|
|
58
|
-
var _TextSelectorSchema = Schema.Struct({
|
|
59
|
-
text: Schema.String,
|
|
60
|
-
systemUI: Schema.optional(Schema.Boolean)
|
|
61
|
-
});
|
|
62
|
-
var _AccessibilityLabelSelectorSchema = Schema.Struct({
|
|
63
|
-
accessibilityLabel: Schema.String,
|
|
64
|
-
systemUI: Schema.optional(Schema.Boolean)
|
|
65
|
-
});
|
|
66
|
-
var _RoleSelectorSchema = Schema.Struct({
|
|
67
|
-
role: Schema.String,
|
|
68
|
-
name: Schema.optional(Schema.String),
|
|
69
|
-
exact: Schema.optional(Schema.Boolean),
|
|
70
|
-
level: Schema.optional(Schema.Number),
|
|
71
|
-
includeHidden: Schema.optional(Schema.Boolean)
|
|
72
|
-
});
|
|
73
|
-
var _CssSelectorSchema = Schema.Struct({
|
|
74
|
-
css: Schema.String
|
|
75
|
-
});
|
|
76
|
-
var _PointSelectorSchema = Schema.Struct({
|
|
77
|
-
point: Schema.Struct({ x: Schema.Number, y: Schema.Number })
|
|
78
|
-
});
|
|
79
|
-
var SelectorSchema = Schema.Union(
|
|
80
|
-
Schema.String,
|
|
81
|
-
_TestIDSelectorSchema,
|
|
82
|
-
_TextSelectorSchema,
|
|
83
|
-
_AccessibilityLabelSelectorSchema,
|
|
84
|
-
_RoleSelectorSchema,
|
|
85
|
-
_CssSelectorSchema,
|
|
86
|
-
_PointSelectorSchema
|
|
87
|
-
);
|
|
88
|
-
function isRelativeSelector(sel) {
|
|
89
|
-
return typeof sel === "object" && sel !== null && "selector" in sel;
|
|
90
|
-
}
|
|
91
|
-
function toObjectSelector(sel) {
|
|
92
|
-
if (typeof sel === "string") {
|
|
93
|
-
return { text: sel };
|
|
94
|
-
}
|
|
95
|
-
return sel;
|
|
96
|
-
}
|
|
97
|
-
function byRole(role, nameOrOpts, opts) {
|
|
98
|
-
if (typeof nameOrOpts === "string" || nameOrOpts instanceof RegExp) {
|
|
99
|
-
return { role, name: nameOrOpts, ...opts };
|
|
100
|
-
}
|
|
101
|
-
return { role, ...nameOrOpts };
|
|
102
|
-
}
|
|
103
|
-
function byCss(css, opts) {
|
|
104
|
-
return { css, ...opts };
|
|
105
|
-
}
|
|
106
|
-
function or(...selectors) {
|
|
107
|
-
const flat = [];
|
|
108
|
-
for (const s of selectors) {
|
|
109
|
-
if (typeof s === "object" && s !== null && "anyOf" in s && Array.isArray(s.anyOf) && !("within" in s && s.within) && !("frame" in s && s.frame) && !("hasText" in s && s.hasText !== void 0) && !("hasNotText" in s && s.hasNotText !== void 0) && !("has" in s && s.has !== void 0) && !("hasNot" in s && s.hasNot !== void 0) && !("first" in s && s.first) && !("last" in s && s.last) && !("nth" in s && s.nth !== void 0)) {
|
|
110
|
-
flat.push(...s.anyOf);
|
|
111
|
-
} else {
|
|
112
|
-
flat.push(s);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return { anyOf: flat };
|
|
116
|
-
}
|
|
117
|
-
function within(parent, child) {
|
|
118
|
-
const obj = toObjectSelector(child);
|
|
119
|
-
if ("point" in obj) return obj;
|
|
120
|
-
const chainedWithin = obj.within ? within(parent, obj.within) : parent;
|
|
121
|
-
return { ...obj, within: chainedWithin };
|
|
122
|
-
}
|
|
123
|
-
function inFrame(frame, child) {
|
|
124
|
-
const obj = toObjectSelector(child);
|
|
125
|
-
if ("point" in obj) return obj;
|
|
126
|
-
return { ...obj, frame };
|
|
127
|
-
}
|
|
128
|
-
function nth(sel, index) {
|
|
129
|
-
const obj = toObjectSelector(sel);
|
|
130
|
-
if ("point" in obj) return obj;
|
|
131
|
-
return { ...obj, nth: index, first: void 0, last: void 0 };
|
|
132
|
-
}
|
|
133
|
-
function first(sel) {
|
|
134
|
-
const obj = toObjectSelector(sel);
|
|
135
|
-
if ("point" in obj) return obj;
|
|
136
|
-
return { ...obj, first: true, last: void 0, nth: void 0 };
|
|
137
|
-
}
|
|
138
|
-
function last(sel) {
|
|
139
|
-
const obj = toObjectSelector(sel);
|
|
140
|
-
if ("point" in obj) return obj;
|
|
141
|
-
return { ...obj, last: true, first: void 0, nth: void 0 };
|
|
142
|
-
}
|
|
143
|
-
function filterSelector(sel, filter) {
|
|
144
|
-
const obj = toObjectSelector(sel);
|
|
145
|
-
if ("point" in obj) return obj;
|
|
146
|
-
return { ...obj, ...filter };
|
|
147
|
-
}
|
|
148
|
-
function systemUI(selector) {
|
|
149
|
-
return { ...selector, systemUI: true };
|
|
150
|
-
}
|
|
151
|
-
function isSystemUISelector(sel) {
|
|
152
|
-
if (typeof sel !== "object" || sel === null) return false;
|
|
153
|
-
if (isRelativeSelector(sel)) {
|
|
154
|
-
return isSystemUISelector(sel.selector);
|
|
155
|
-
}
|
|
156
|
-
return "systemUI" in sel && sel.systemUI === true;
|
|
157
|
-
}
|
|
158
|
-
function isTestIDSelector(sel) {
|
|
159
|
-
return typeof sel === "object" && sel !== null && "testID" in sel && !isRelativeSelector(sel);
|
|
160
|
-
}
|
|
161
|
-
function isComposableDomSelector(sel) {
|
|
162
|
-
if (typeof sel !== "object" || sel === null || isRelativeSelector(sel)) return false;
|
|
163
|
-
return "role" in sel || "css" in sel || "anyOf" in sel || "within" in sel || "frame" in sel || "hasText" in sel || "hasNotText" in sel || "has" in sel || "hasNot" in sel || "nth" in sel || "first" in sel || "last" in sel;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// src/smart/element-matcher.ts
|
|
167
|
-
function flattenElements(root) {
|
|
168
|
-
const result = [];
|
|
169
|
-
const stack = [root];
|
|
170
|
-
while (stack.length > 0) {
|
|
171
|
-
const node = stack.pop();
|
|
172
|
-
result.push(node);
|
|
173
|
-
if (node.children) {
|
|
174
|
-
for (let i = node.children.length - 1; i >= 0; i--) {
|
|
175
|
-
stack.push(node.children[i]);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return result;
|
|
180
|
-
}
|
|
181
|
-
function matchesSelector(element, selector) {
|
|
182
|
-
if (typeof selector === "string") {
|
|
183
|
-
return element.text?.toLowerCase().includes(selector.toLowerCase()) ?? false;
|
|
184
|
-
}
|
|
185
|
-
let baseMatch = false;
|
|
186
|
-
if ("testID" in selector) {
|
|
187
|
-
baseMatch = element.id === selector.testID;
|
|
188
|
-
} else if ("text" in selector) {
|
|
189
|
-
baseMatch = selector.exact ? element.text === selector.text : element.text?.toLowerCase().includes(selector.text.toLowerCase()) ?? false;
|
|
190
|
-
} else if ("accessibilityLabel" in selector) {
|
|
191
|
-
baseMatch = element.accessibilityLabel === selector.accessibilityLabel;
|
|
192
|
-
} else if ("role" in selector) {
|
|
193
|
-
const elRole = (element.attributes?.role ?? element.elementType ?? "").toLowerCase();
|
|
194
|
-
const roleMatch = elRole === selector.role.toLowerCase();
|
|
195
|
-
if (!roleMatch) return false;
|
|
196
|
-
if (selector.name === void 0) {
|
|
197
|
-
baseMatch = true;
|
|
198
|
-
} else {
|
|
199
|
-
const candidateName = element.accessibilityLabel ?? element.text ?? "";
|
|
200
|
-
baseMatch = selector.name instanceof RegExp ? selector.name.test(candidateName) : selector.exact ? candidateName === selector.name : candidateName.toLowerCase().includes(selector.name.toLowerCase());
|
|
201
|
-
}
|
|
202
|
-
} else if ("css" in selector) {
|
|
203
|
-
baseMatch = false;
|
|
204
|
-
} else if ("anyOf" in selector && Array.isArray(selector.anyOf)) {
|
|
205
|
-
baseMatch = selector.anyOf.some((branch) => matchesSelector(element, branch));
|
|
206
|
-
} else if ("point" in selector) {
|
|
207
|
-
const { x, y } = selector.point;
|
|
208
|
-
const b = element.bounds;
|
|
209
|
-
baseMatch = x >= b.x && x <= b.x + b.width && y >= b.y && y <= b.y + b.height;
|
|
210
|
-
}
|
|
211
|
-
if (!baseMatch) return false;
|
|
212
|
-
if (!("point" in selector)) {
|
|
213
|
-
const text = element.text ?? element.accessibilityLabel ?? "";
|
|
214
|
-
if (selector.hasText !== void 0) {
|
|
215
|
-
const ok = selector.hasText instanceof RegExp ? selector.hasText.test(text) : text.toLowerCase().includes(selector.hasText.toLowerCase());
|
|
216
|
-
if (!ok) return false;
|
|
217
|
-
}
|
|
218
|
-
if (selector.hasNotText !== void 0) {
|
|
219
|
-
const bad = selector.hasNotText instanceof RegExp ? selector.hasNotText.test(text) : text.toLowerCase().includes(selector.hasNotText.toLowerCase());
|
|
220
|
-
if (bad) return false;
|
|
221
|
-
}
|
|
222
|
-
if (selector.has !== void 0) {
|
|
223
|
-
const descendants = flattenElements(element).slice(1);
|
|
224
|
-
if (!descendants.some((d) => matchesSelector(d, selector.has))) return false;
|
|
225
|
-
}
|
|
226
|
-
if (selector.hasNot !== void 0) {
|
|
227
|
-
const descendants = flattenElements(element).slice(1);
|
|
228
|
-
if (descendants.some((d) => matchesSelector(d, selector.hasNot))) return false;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
function findElements(root, selector) {
|
|
234
|
-
const matched = flattenElements(root).filter((el) => matchesSelector(el, selector));
|
|
235
|
-
if (typeof selector === "object" && selector !== null && !("point" in selector)) {
|
|
236
|
-
if (selector.first) return matched.length > 0 ? [matched[0]] : [];
|
|
237
|
-
if (selector.last) return matched.length > 0 ? [matched[matched.length - 1]] : [];
|
|
238
|
-
if (selector.nth !== void 0) {
|
|
239
|
-
const idx = selector.nth < 0 ? matched.length + selector.nth : selector.nth;
|
|
240
|
-
return idx >= 0 && idx < matched.length ? [matched[idx]] : [];
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return matched;
|
|
244
|
-
}
|
|
245
|
-
function isProbablyOnScreen(element) {
|
|
246
|
-
const centerX = element.bounds.x + element.bounds.width / 2;
|
|
247
|
-
const centerY = element.bounds.y + element.bounds.height / 2;
|
|
248
|
-
return element.bounds.width > 0 && element.bounds.height > 0 && centerX >= 0 && centerY >= 0;
|
|
249
|
-
}
|
|
250
|
-
function findPathToElement(root, target) {
|
|
251
|
-
const stack = [{ element: root, ancestors: [] }];
|
|
252
|
-
while (stack.length > 0) {
|
|
253
|
-
const current = stack.pop();
|
|
254
|
-
if (current.element === target) {
|
|
255
|
-
return current;
|
|
256
|
-
}
|
|
257
|
-
const children = current.element.children;
|
|
258
|
-
if (!children) {
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
for (let index = children.length - 1; index >= 0; index -= 1) {
|
|
262
|
-
const child = children[index];
|
|
263
|
-
stack.push({
|
|
264
|
-
element: child,
|
|
265
|
-
ancestors: [...current.ancestors, current.element]
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return void 0;
|
|
270
|
-
}
|
|
271
|
-
function isActionable(element) {
|
|
272
|
-
return element.visible !== false && element.enabled !== false && element.clickable === true && isProbablyOnScreen(element);
|
|
273
|
-
}
|
|
274
|
-
function resolveActionTarget(root, element) {
|
|
275
|
-
const path = findPathToElement(root, element);
|
|
276
|
-
if (!path) {
|
|
277
|
-
return element;
|
|
278
|
-
}
|
|
279
|
-
const candidates = [path.element, ...path.ancestors.toReversed()];
|
|
280
|
-
return candidates.find(isActionable) ?? element;
|
|
281
|
-
}
|
|
282
|
-
function findElement(root, selector) {
|
|
283
|
-
const matches = findElements(root, selector).filter((el) => el.visible !== false);
|
|
284
|
-
if (matches.length === 0) return void 0;
|
|
285
|
-
const visibleMatches = matches.filter(isProbablyOnScreen);
|
|
286
|
-
if (visibleMatches.length === 0) return void 0;
|
|
287
|
-
const clickable = visibleMatches.filter((el) => el.clickable);
|
|
288
|
-
if (clickable.length > 0) return clickable[clickable.length - 1];
|
|
289
|
-
return visibleMatches[visibleMatches.length - 1];
|
|
290
|
-
}
|
|
291
|
-
function centerOf(element) {
|
|
292
|
-
return {
|
|
293
|
-
x: Math.round(element.bounds.x + element.bounds.width / 2),
|
|
294
|
-
y: Math.round(element.bounds.y + element.bounds.height / 2)
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
function formatSelector(sel) {
|
|
298
|
-
if (isRelativeSelector(sel)) {
|
|
299
|
-
const parts = [formatSimpleSelector(sel.selector)];
|
|
300
|
-
if (sel.below) parts.push(`below ${formatSimpleSelector(sel.below)}`);
|
|
301
|
-
if (sel.above) parts.push(`above ${formatSimpleSelector(sel.above)}`);
|
|
302
|
-
if (sel.leftOf) parts.push(`leftOf ${formatSimpleSelector(sel.leftOf)}`);
|
|
303
|
-
if (sel.rightOf) parts.push(`rightOf ${formatSimpleSelector(sel.rightOf)}`);
|
|
304
|
-
if (sel.childOf) parts.push(`childOf ${formatSimpleSelector(sel.childOf)}`);
|
|
305
|
-
return parts.join(" ");
|
|
306
|
-
}
|
|
307
|
-
return formatSimpleSelector(sel);
|
|
308
|
-
}
|
|
309
|
-
function formatSimpleSelector(sel) {
|
|
310
|
-
if (typeof sel === "string") return `"${sel}"`;
|
|
311
|
-
let base;
|
|
312
|
-
if ("testID" in sel) base = `testID: "${sel.testID}"`;
|
|
313
|
-
else if ("text" in sel) base = `text: "${sel.text}"`;
|
|
314
|
-
else if ("accessibilityLabel" in sel) base = `accessibilityLabel: "${sel.accessibilityLabel}"`;
|
|
315
|
-
else if ("role" in sel) {
|
|
316
|
-
const parts = [`role: "${sel.role}"`];
|
|
317
|
-
if (sel.name !== void 0) {
|
|
318
|
-
parts.push(
|
|
319
|
-
`name: ${sel.name instanceof RegExp ? sel.name.toString() : JSON.stringify(sel.name)}`
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
if (sel.level !== void 0) parts.push(`level: ${sel.level}`);
|
|
323
|
-
base = parts.join(", ");
|
|
324
|
-
} else if ("css" in sel) base = `css: "${sel.css}"`;
|
|
325
|
-
else if ("anyOf" in sel) base = `or(${sel.anyOf.map(formatSimpleSelector).join(", ")})`;
|
|
326
|
-
else if ("point" in sel) return `point: (${sel.point.x}, ${sel.point.y})`;
|
|
327
|
-
else return JSON.stringify(sel);
|
|
328
|
-
const mods = [];
|
|
329
|
-
if (sel.frame) mods.push(`inFrame(${formatSimpleSelector(sel.frame)})`);
|
|
330
|
-
if (sel.within) mods.push(`within(${formatSimpleSelector(sel.within)})`);
|
|
331
|
-
if (sel.hasText !== void 0) {
|
|
332
|
-
mods.push(
|
|
333
|
-
`hasText(${sel.hasText instanceof RegExp ? sel.hasText.toString() : JSON.stringify(sel.hasText)})`
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
if (sel.hasNotText !== void 0) {
|
|
337
|
-
mods.push(
|
|
338
|
-
`hasNotText(${sel.hasNotText instanceof RegExp ? sel.hasNotText.toString() : JSON.stringify(sel.hasNotText)})`
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
if (sel.has !== void 0) mods.push(`has(${formatSimpleSelector(sel.has)})`);
|
|
342
|
-
if (sel.hasNot !== void 0) mods.push(`hasNot(${formatSimpleSelector(sel.hasNot)})`);
|
|
343
|
-
if (sel.first) mods.push("first");
|
|
344
|
-
else if (sel.last) mods.push("last");
|
|
345
|
-
else if (sel.nth !== void 0) mods.push(`nth(${sel.nth})`);
|
|
346
|
-
return mods.length > 0 ? `${base} [${mods.join(", ")}]` : base;
|
|
347
|
-
}
|
|
348
|
-
function findElementExtended(root, selector) {
|
|
349
|
-
if (!isRelativeSelector(selector)) {
|
|
350
|
-
return findElement(root, selector);
|
|
351
|
-
}
|
|
352
|
-
return findRelativeElement(root, selector);
|
|
353
|
-
}
|
|
354
|
-
function findActionElementExtended(root, selector) {
|
|
355
|
-
const match = findElementExtended(root, selector);
|
|
356
|
-
return match ? resolveActionTarget(root, match) : void 0;
|
|
357
|
-
}
|
|
358
|
-
function findRelativeElement(root, rel) {
|
|
359
|
-
const all = flattenElements(root).filter((el) => el.visible !== false && isProbablyOnScreen(el));
|
|
360
|
-
let candidates = all.filter((el) => matchesSelector(el, rel.selector));
|
|
361
|
-
if (candidates.length === 0) return void 0;
|
|
362
|
-
if (rel.below) {
|
|
363
|
-
const anchor = findElement(root, rel.below);
|
|
364
|
-
if (!anchor) return void 0;
|
|
365
|
-
const anchorBottom = anchor.bounds.y + anchor.bounds.height;
|
|
366
|
-
candidates = candidates.filter((el) => el.bounds.y >= anchorBottom);
|
|
367
|
-
candidates.sort((a, b) => a.bounds.y - b.bounds.y);
|
|
368
|
-
}
|
|
369
|
-
if (rel.above) {
|
|
370
|
-
const anchor = findElement(root, rel.above);
|
|
371
|
-
if (!anchor) return void 0;
|
|
372
|
-
const anchorTop = anchor.bounds.y;
|
|
373
|
-
candidates = candidates.filter((el) => el.bounds.y + el.bounds.height <= anchorTop);
|
|
374
|
-
candidates.sort((a, b) => b.bounds.y - a.bounds.y);
|
|
375
|
-
}
|
|
376
|
-
if (rel.leftOf) {
|
|
377
|
-
const anchor = findElement(root, rel.leftOf);
|
|
378
|
-
if (!anchor) return void 0;
|
|
379
|
-
const anchorLeft = anchor.bounds.x;
|
|
380
|
-
candidates = candidates.filter((el) => el.bounds.x + el.bounds.width <= anchorLeft);
|
|
381
|
-
candidates.sort((a, b) => b.bounds.x - a.bounds.x);
|
|
382
|
-
}
|
|
383
|
-
if (rel.rightOf) {
|
|
384
|
-
const anchor = findElement(root, rel.rightOf);
|
|
385
|
-
if (!anchor) return void 0;
|
|
386
|
-
const anchorRight = anchor.bounds.x + anchor.bounds.width;
|
|
387
|
-
candidates = candidates.filter((el) => el.bounds.x >= anchorRight);
|
|
388
|
-
candidates.sort((a, b) => a.bounds.x - b.bounds.x);
|
|
389
|
-
}
|
|
390
|
-
if (rel.childOf) {
|
|
391
|
-
const parent = findElement(root, rel.childOf);
|
|
392
|
-
if (!parent) return void 0;
|
|
393
|
-
const descendants = flattenElements(parent);
|
|
394
|
-
const descendantSet = new Set(descendants);
|
|
395
|
-
candidates = candidates.filter((el) => descendantSet.has(el) && el !== parent);
|
|
396
|
-
}
|
|
397
|
-
return candidates[0];
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
// src/smart/channel-resolver.ts
|
|
401
|
-
import { Effect } from "effect";
|
|
402
|
-
var WEBVIEW_TYPES = /* @__PURE__ */ new Set([
|
|
403
|
-
"XCUIElementTypeWebView",
|
|
404
|
-
"android.webkit.WebView",
|
|
405
|
-
"WebView",
|
|
406
|
-
"WKWebView"
|
|
407
|
-
]);
|
|
408
|
-
var WEBVIEW_FRAME_CACHE_TTL_MS = 1e4;
|
|
409
|
-
var webViewFrameCache = /* @__PURE__ */ new WeakMap();
|
|
410
|
-
function invalidateWebViewFrameCache(driver) {
|
|
411
|
-
webViewFrameCache.delete(driver);
|
|
412
|
-
}
|
|
413
|
-
function findWebViewFrame(nativeRoot) {
|
|
414
|
-
const all = flattenElements(nativeRoot);
|
|
415
|
-
const webviews = all.filter(
|
|
416
|
-
(el) => el.visible !== false && el.bounds.width > 0 && el.bounds.height > 0 && (el.elementType && WEBVIEW_TYPES.has(el.elementType) || (el.elementType?.toLowerCase().includes("webview") ?? false))
|
|
417
|
-
);
|
|
418
|
-
if (webviews.length === 0) {
|
|
419
|
-
return void 0;
|
|
420
|
-
}
|
|
421
|
-
webviews.sort((a, b) => b.bounds.width * b.bounds.height - a.bounds.width * a.bounds.height);
|
|
422
|
-
return webviews[0].bounds;
|
|
423
|
-
}
|
|
424
|
-
function domRectToScreenBounds(match, webViewFrame, options = {}) {
|
|
425
|
-
const frameX = webViewFrame?.x ?? 0;
|
|
426
|
-
const frameY = webViewFrame?.y ?? 0;
|
|
427
|
-
let scale = options.scaleOverride;
|
|
428
|
-
if (scale === void 0) {
|
|
429
|
-
if (webViewFrame && webViewFrame.width > 0 && match.viewportWidth > 0) {
|
|
430
|
-
scale = webViewFrame.width / match.viewportWidth;
|
|
431
|
-
} else if (options.platform === "android") {
|
|
432
|
-
scale = match.devicePixelRatio || 1;
|
|
433
|
-
} else {
|
|
434
|
-
scale = 1;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
const relX = options.subtractScrollOffset ? match.rect.x - match.scrollX : match.rect.x;
|
|
438
|
-
const relY = options.subtractScrollOffset ? match.rect.y - match.scrollY : match.rect.y;
|
|
439
|
-
return {
|
|
440
|
-
x: Math.round(frameX + relX * scale),
|
|
441
|
-
y: Math.round(frameY + relY * scale),
|
|
442
|
-
width: Math.round(match.rect.width * scale),
|
|
443
|
-
height: Math.round(match.rect.height * scale)
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
function isOffscreenInViewport(match) {
|
|
447
|
-
if (match.viewportWidth <= 0 || match.viewportHeight <= 0) return false;
|
|
448
|
-
const centerX = match.rect.x + match.rect.width / 2;
|
|
449
|
-
const centerY = match.rect.y + match.rect.height / 2;
|
|
450
|
-
return centerX < 0 || centerY < 0 || centerX > match.viewportWidth || centerY > match.viewportHeight;
|
|
451
|
-
}
|
|
452
|
-
function pickBestDomMatch(matches) {
|
|
453
|
-
const visible = matches.filter((m) => m.visible && m.rect.width > 0 && m.rect.height > 0);
|
|
454
|
-
if (visible.length === 0) return void 0;
|
|
455
|
-
const clickable = visible.filter((m) => m.clickable);
|
|
456
|
-
if (clickable.length > 0) {
|
|
457
|
-
return clickable[clickable.length - 1];
|
|
458
|
-
}
|
|
459
|
-
return visible[visible.length - 1];
|
|
460
|
-
}
|
|
461
|
-
function getNativeHierarchy(driver, parse, cache) {
|
|
462
|
-
if (cache) return cache.get(driver, parse);
|
|
463
|
-
return Effect.gen(function* () {
|
|
464
|
-
const raw = yield* driver.dumpHierarchy();
|
|
465
|
-
return parse(raw);
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
function resolveElementAcrossChannels(driver, selector, parse, cache, options = {}) {
|
|
469
|
-
return Effect.gen(function* () {
|
|
470
|
-
const domChannel = driver.domChannel;
|
|
471
|
-
const isSystemUI = isSystemUISelector(selector);
|
|
472
|
-
const forAction = options.forAction ?? false;
|
|
473
|
-
const tapMode = options.tapMode ?? "native";
|
|
474
|
-
const canTryDom = !isSystemUI && !isRelativeSelector(selector) && domChannel !== void 0 && (isTestIDSelector(selector) || isComposableDomSelector(selector) || domChannel.isConnected());
|
|
475
|
-
if (canTryDom) {
|
|
476
|
-
const domMatches = yield* Effect.tryPromise({
|
|
477
|
-
try: async () => {
|
|
478
|
-
if (!domChannel.isConnected()) {
|
|
479
|
-
if (!isTestIDSelector(selector) && !isComposableDomSelector(selector)) return [];
|
|
480
|
-
try {
|
|
481
|
-
await domChannel.connect();
|
|
482
|
-
} catch {
|
|
483
|
-
return [];
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
return await domChannel.query(selector);
|
|
487
|
-
},
|
|
488
|
-
catch: () => void 0
|
|
489
|
-
}).pipe(Effect.catchAll(() => Effect.succeed([])));
|
|
490
|
-
const best = pickBestDomMatch(domMatches);
|
|
491
|
-
if (best) {
|
|
492
|
-
if (!forAction || tapMode === "dom") {
|
|
493
|
-
return {
|
|
494
|
-
element: domMatchToElement(best),
|
|
495
|
-
channel: "dom",
|
|
496
|
-
domMatch: best
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
let targetMatch = best;
|
|
500
|
-
if (isOffscreenInViewport(best) && domChannel.scrollIntoView) {
|
|
501
|
-
const scrolled = yield* Effect.tryPromise({
|
|
502
|
-
try: () => domChannel.scrollIntoView(selector),
|
|
503
|
-
catch: () => null
|
|
504
|
-
}).pipe(Effect.catchAll(() => Effect.succeed(null)));
|
|
505
|
-
if (scrolled) {
|
|
506
|
-
targetMatch = scrolled;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
if (options.platform === "web") {
|
|
510
|
-
const webFrame = {
|
|
511
|
-
x: 0,
|
|
512
|
-
y: 0,
|
|
513
|
-
width: targetMatch.viewportWidth,
|
|
514
|
-
height: targetMatch.viewportHeight
|
|
515
|
-
};
|
|
516
|
-
const screenBounds2 = domRectToScreenBounds(targetMatch, webFrame, {
|
|
517
|
-
platform: "web"
|
|
518
|
-
});
|
|
519
|
-
return {
|
|
520
|
-
element: domMatchToElement(targetMatch, screenBounds2),
|
|
521
|
-
channel: "dom",
|
|
522
|
-
domMatch: targetMatch,
|
|
523
|
-
webViewFrame: webFrame
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
const now = Date.now();
|
|
527
|
-
const cachedFrame = webViewFrameCache.get(driver);
|
|
528
|
-
let webViewFrame;
|
|
529
|
-
if (cachedFrame && cachedFrame.viewportWidth === targetMatch.viewportWidth && cachedFrame.viewportHeight === targetMatch.viewportHeight && now - cachedFrame.cachedAt < WEBVIEW_FRAME_CACHE_TTL_MS) {
|
|
530
|
-
webViewFrame = cachedFrame.frame;
|
|
531
|
-
} else {
|
|
532
|
-
const nativeRoot2 = yield* getNativeHierarchy(driver, parse, cache);
|
|
533
|
-
webViewFrame = findWebViewFrame(nativeRoot2);
|
|
534
|
-
webViewFrameCache.set(driver, {
|
|
535
|
-
frame: webViewFrame,
|
|
536
|
-
viewportWidth: targetMatch.viewportWidth,
|
|
537
|
-
viewportHeight: targetMatch.viewportHeight,
|
|
538
|
-
cachedAt: now
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
const screenBounds = domRectToScreenBounds(targetMatch, webViewFrame, {
|
|
542
|
-
platform: options.platform
|
|
543
|
-
});
|
|
544
|
-
return {
|
|
545
|
-
element: domMatchToElement(targetMatch, screenBounds),
|
|
546
|
-
channel: "dom",
|
|
547
|
-
domMatch: targetMatch,
|
|
548
|
-
webViewFrame
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
const nativeRoot = yield* getNativeHierarchy(driver, parse, cache);
|
|
553
|
-
const nativeEl = forAction ? findActionElementExtended(nativeRoot, selector) : findElementExtended(nativeRoot, selector);
|
|
554
|
-
if (!nativeEl) {
|
|
555
|
-
return void 0;
|
|
556
|
-
}
|
|
557
|
-
return {
|
|
558
|
-
element: nativeEl,
|
|
559
|
-
channel: "native"
|
|
560
|
-
};
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
// src/smart/coordinator.ts
|
|
565
|
-
import { Duration as Duration2, Effect as Effect4 } from "effect";
|
|
566
|
-
|
|
567
|
-
// src/core/graphemes.ts
|
|
568
|
-
function splitGraphemes(text) {
|
|
569
|
-
if (text.length === 0) {
|
|
570
|
-
return [];
|
|
571
|
-
}
|
|
572
|
-
const Segmenter = globalThis.Intl?.Segmenter;
|
|
573
|
-
if (!Segmenter) {
|
|
574
|
-
return Array.from(text);
|
|
575
|
-
}
|
|
576
|
-
return Array.from(
|
|
577
|
-
new Segmenter(void 0, { granularity: "grapheme" }).segment(text),
|
|
578
|
-
(part) => part.segment
|
|
579
|
-
);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
// src/smart/auto-wait.ts
|
|
583
|
-
import { Duration, Effect as Effect2 } from "effect";
|
|
584
|
-
|
|
585
|
-
// src/smart/diagnostics.ts
|
|
586
|
-
function diagnoseElementNotFound(root, selector) {
|
|
587
|
-
const allElements = flattenElements(root);
|
|
588
|
-
const totalElements = allElements.length;
|
|
589
|
-
const suggestions = [];
|
|
590
|
-
const simpleSelector = isRelativeSelector(selector) ? selector.selector : selector;
|
|
591
|
-
const matchingButHidden = allElements.filter(
|
|
592
|
-
(el) => matchesSelector(el, simpleSelector) && el.visible === false
|
|
593
|
-
);
|
|
594
|
-
if (matchingButHidden.length > 0) {
|
|
595
|
-
return {
|
|
596
|
-
reason: "not-visible",
|
|
597
|
-
suggestions: [
|
|
598
|
-
`Element matches selector but has visible=false (${matchingButHidden.length} match(es))`
|
|
599
|
-
],
|
|
600
|
-
totalElements
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
const matchingButOffScreen = allElements.filter(
|
|
604
|
-
(el) => matchesSelector(el, simpleSelector) && el.visible !== false && (el.bounds.width <= 0 || el.bounds.height <= 0 || el.bounds.x + el.bounds.width / 2 < 0 || el.bounds.y + el.bounds.height / 2 < 0)
|
|
605
|
-
);
|
|
606
|
-
if (matchingButOffScreen.length > 0) {
|
|
607
|
-
return {
|
|
608
|
-
reason: "off-screen",
|
|
609
|
-
suggestions: [
|
|
610
|
-
`Element matches selector but is off-screen or has zero size (${matchingButOffScreen.length} match(es))`
|
|
611
|
-
],
|
|
612
|
-
totalElements
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
const matchingButDisabled = allElements.filter(
|
|
616
|
-
(el) => matchesSelector(el, simpleSelector) && el.visible !== false && el.enabled === false
|
|
617
|
-
);
|
|
618
|
-
if (matchingButDisabled.length > 0) {
|
|
619
|
-
return {
|
|
620
|
-
reason: "not-interactive",
|
|
621
|
-
suggestions: [`Element matches selector but is disabled (enabled=false)`],
|
|
622
|
-
totalElements
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
if (typeof simpleSelector === "string") {
|
|
626
|
-
const similar = findSimilarByText(allElements, simpleSelector);
|
|
627
|
-
suggestions.push(...similar);
|
|
628
|
-
} else if ("testID" in simpleSelector && simpleSelector.testID) {
|
|
629
|
-
const similar = findSimilarByTestID(allElements, simpleSelector.testID);
|
|
630
|
-
suggestions.push(...similar);
|
|
631
|
-
} else if ("text" in simpleSelector && simpleSelector.text) {
|
|
632
|
-
const similar = findSimilarByText(allElements, simpleSelector.text);
|
|
633
|
-
suggestions.push(...similar);
|
|
634
|
-
}
|
|
635
|
-
return { reason: "not-found", suggestions, totalElements };
|
|
636
|
-
}
|
|
637
|
-
function findSimilarByTestID(elements, targetId) {
|
|
638
|
-
const lower = targetId.toLowerCase();
|
|
639
|
-
const prefix = lower.slice(0, Math.max(3, Math.floor(lower.length / 2)));
|
|
640
|
-
return elements.filter((el) => el.id && el.id.toLowerCase().includes(prefix)).slice(0, 3).map((el) => `Did you mean testID "${el.id}"?`);
|
|
641
|
-
}
|
|
642
|
-
function findSimilarByText(elements, targetText) {
|
|
643
|
-
const lower = targetText.toLowerCase();
|
|
644
|
-
const prefix = lower.slice(0, 3);
|
|
645
|
-
return elements.filter((el) => {
|
|
646
|
-
if (!el.text) return false;
|
|
647
|
-
const elLower = el.text.toLowerCase();
|
|
648
|
-
return elLower.includes(prefix) || lower.includes(elLower.slice(0, 3));
|
|
649
|
-
}).filter((el) => el.visible !== false).slice(0, 3).map((el) => `Did you mean text "${el.text}"?`);
|
|
650
|
-
}
|
|
651
|
-
function formatDiagnostic(diag) {
|
|
652
|
-
const parts = [];
|
|
653
|
-
if (diag.reason === "not-visible") {
|
|
654
|
-
parts.push("Element exists but is not visible.");
|
|
655
|
-
} else if (diag.reason === "off-screen") {
|
|
656
|
-
parts.push("Element exists but is off-screen or has zero size. Try scrolling to it.");
|
|
657
|
-
} else if (diag.reason === "not-interactive") {
|
|
658
|
-
parts.push("Element exists but is disabled (not interactive).");
|
|
659
|
-
}
|
|
660
|
-
if (diag.suggestions.length > 0) {
|
|
661
|
-
parts.push(...diag.suggestions);
|
|
662
|
-
}
|
|
663
|
-
parts.push(`(${diag.totalElements} elements in hierarchy)`);
|
|
664
|
-
return parts.join("\n");
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
// src/smart/auto-wait.ts
|
|
668
|
-
var DEFAULT_TIMEOUT = 5e3;
|
|
669
|
-
var DEFAULT_POLL_INTERVAL = 200;
|
|
670
|
-
var DEFAULT_INITIAL_POLL_INTERVAL = 50;
|
|
671
|
-
var DEFAULT_SETTLE_TIMEOUT = 0;
|
|
672
|
-
function getHierarchy(driver, parse, cache) {
|
|
673
|
-
if (cache) return cache.get(driver, parse);
|
|
674
|
-
return Effect2.gen(function* () {
|
|
675
|
-
const raw = yield* driver.dumpHierarchy();
|
|
676
|
-
return parse(raw);
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
function nextInterval(elapsed, timeout, initial, max) {
|
|
680
|
-
if (initial >= max) return max;
|
|
681
|
-
const rampDuration = timeout / 2;
|
|
682
|
-
const progress = Math.min(elapsed / rampDuration, 1);
|
|
683
|
-
return Math.round(initial + (max - initial) * progress);
|
|
684
|
-
}
|
|
685
|
-
function maybeWaitForBridgeIdle(driver, timeout) {
|
|
686
|
-
const domChannel = driver.domChannel;
|
|
687
|
-
if (!domChannel || !domChannel.isConnected() || !domChannel.waitForIdle) {
|
|
688
|
-
return Effect2.void;
|
|
689
|
-
}
|
|
690
|
-
return Effect2.tryPromise({
|
|
691
|
-
try: () => domChannel.waitForIdle({ timeout: Math.min(timeout, 2500) }),
|
|
692
|
-
catch: () => void 0
|
|
693
|
-
}).pipe(Effect2.catchAll(() => Effect2.void));
|
|
694
|
-
}
|
|
695
|
-
function isRelativeSelectorLike(selector) {
|
|
696
|
-
if (typeof selector !== "object" || selector === null) return false;
|
|
697
|
-
return "below" in selector || "above" in selector || "leftOf" in selector || "rightOf" in selector || "childOf" in selector;
|
|
698
|
-
}
|
|
699
|
-
function waitForResolvedAcrossChannels(driver, selector, parse, forAction, opts, cache) {
|
|
700
|
-
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
701
|
-
const pollInterval = opts?.pollInterval ?? DEFAULT_POLL_INTERVAL;
|
|
702
|
-
const initialPollInterval = opts?.initialPollInterval ?? DEFAULT_INITIAL_POLL_INTERVAL;
|
|
703
|
-
const settleTimeout = opts?.settleTimeout ?? DEFAULT_SETTLE_TIMEOUT;
|
|
704
|
-
return Effect2.gen(function* () {
|
|
705
|
-
const start = Date.now();
|
|
706
|
-
let waitedForIdle = false;
|
|
707
|
-
let isFirstPoll = true;
|
|
708
|
-
const canReactiveDomWait = !isSystemUISelector(selector) && !isRelativeSelectorLike(selector) && (opts?.platform === "web" || isTestIDSelector(selector) || isComposableDomSelector(selector));
|
|
709
|
-
const initialDomChannel = driver.domChannel;
|
|
710
|
-
if (opts?.platform === "web" && canReactiveDomWait && settleTimeout === 0 && initialDomChannel?.isConnected() && initialDomChannel.waitForSelector) {
|
|
711
|
-
const reactiveMatches = yield* Effect2.tryPromise({
|
|
712
|
-
try: () => initialDomChannel.waitForSelector(selector, {
|
|
713
|
-
timeoutMs: timeout,
|
|
714
|
-
forAction,
|
|
715
|
-
failFastWhenIdle: opts?.failFastWhenIdle,
|
|
716
|
-
idleQuietMs: opts?.idleQuietMs,
|
|
717
|
-
...opts?.actionStableFrames !== void 0 ? { stableFrames: opts.actionStableFrames } : {}
|
|
718
|
-
}),
|
|
719
|
-
catch: () => null
|
|
720
|
-
}).pipe(Effect2.catchAll(() => Effect2.succeed(null)));
|
|
721
|
-
if (Array.isArray(reactiveMatches) && reactiveMatches.length > 0) {
|
|
722
|
-
const match = reactiveMatches[reactiveMatches.length - 1];
|
|
723
|
-
return {
|
|
724
|
-
element: domMatchToElement(match),
|
|
725
|
-
channel: "dom",
|
|
726
|
-
tapMode: opts?.tapMode ?? "native",
|
|
727
|
-
domMatch: match
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
if (Array.isArray(reactiveMatches) && reactiveMatches.length === 0 && (forAction || opts?.failFastWhenIdle || Date.now() - start >= timeout)) {
|
|
731
|
-
if (forAction) {
|
|
732
|
-
const actionDiag = yield* Effect2.tryPromise({
|
|
733
|
-
try: () => initialDomChannel.evaluate(buildDomActionabilityDiagScript(selector)),
|
|
734
|
-
catch: () => null
|
|
735
|
-
}).pipe(Effect2.catchAll(() => Effect2.succeed(null)));
|
|
736
|
-
if (actionDiag?.found && actionDiag.obstructedBy) {
|
|
737
|
-
return yield* new ElementNotFoundError({
|
|
738
|
-
message: `Element is covered by ${actionDiag.obstructedBy} (not actionable within ${timeout}ms) \u2014 selector: ${formatSelector(selector)}`,
|
|
739
|
-
selector,
|
|
740
|
-
timeoutMs: timeout
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
if (actionDiag?.found && actionDiag.visible && actionDiag.enabled === false) {
|
|
744
|
-
return yield* new ElementNotFoundError({
|
|
745
|
-
message: `Element is disabled (not actionable within ${timeout}ms) \u2014 selector: ${formatSelector(selector)}`,
|
|
746
|
-
selector,
|
|
747
|
-
timeoutMs: timeout
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
if (cache) cache.invalidate();
|
|
752
|
-
const diagRoot2 = yield* getHierarchy(driver, parse, cache);
|
|
753
|
-
const diagnostic2 = diagnoseElementNotFound(diagRoot2, selector);
|
|
754
|
-
const diagMessage2 = formatDiagnostic(diagnostic2);
|
|
755
|
-
return yield* new ElementNotFoundError({
|
|
756
|
-
message: `Element not found within ${timeout}ms \u2014 selector: ${formatSelector(selector)}
|
|
757
|
-
${diagMessage2}`,
|
|
758
|
-
selector,
|
|
759
|
-
timeoutMs: timeout
|
|
760
|
-
});
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
while (isFirstPoll || Date.now() - start < timeout) {
|
|
764
|
-
if (!isFirstPoll && cache) cache.invalidate();
|
|
765
|
-
isFirstPoll = false;
|
|
766
|
-
const resolved = yield* resolveElementAcrossChannels(driver, selector, parse, cache, {
|
|
767
|
-
forAction,
|
|
768
|
-
tapMode: opts?.tapMode,
|
|
769
|
-
platform: opts?.platform
|
|
770
|
-
});
|
|
771
|
-
if (resolved) {
|
|
772
|
-
if (settleTimeout > 0) {
|
|
773
|
-
yield* Effect2.sleep(Duration.millis(settleTimeout));
|
|
774
|
-
if (cache) cache.invalidate();
|
|
775
|
-
const settled = yield* resolveElementAcrossChannels(driver, selector, parse, cache, {
|
|
776
|
-
forAction,
|
|
777
|
-
tapMode: opts?.tapMode,
|
|
778
|
-
platform: opts?.platform
|
|
779
|
-
});
|
|
780
|
-
if (settled) return settled;
|
|
781
|
-
} else {
|
|
782
|
-
return resolved;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
const domChannel = driver.domChannel;
|
|
786
|
-
if (canReactiveDomWait && domChannel?.isConnected() && domChannel.waitForSelector) {
|
|
787
|
-
const remaining = Math.max(0, timeout - (Date.now() - start));
|
|
788
|
-
if (remaining > 0) {
|
|
789
|
-
const reactiveResult = yield* Effect2.tryPromise({
|
|
790
|
-
try: () => domChannel.waitForSelector(selector, {
|
|
791
|
-
timeoutMs: Math.min(remaining, opts?.platform === "web" ? remaining : 1e3),
|
|
792
|
-
forAction,
|
|
793
|
-
failFastWhenIdle: opts?.failFastWhenIdle,
|
|
794
|
-
idleQuietMs: opts?.idleQuietMs,
|
|
795
|
-
...opts?.actionStableFrames !== void 0 ? { stableFrames: opts.actionStableFrames } : {}
|
|
796
|
-
}),
|
|
797
|
-
catch: () => null
|
|
798
|
-
}).pipe(Effect2.catchAll(() => Effect2.succeed(null)));
|
|
799
|
-
if (Array.isArray(reactiveResult) && reactiveResult.length > 0) {
|
|
800
|
-
continue;
|
|
801
|
-
}
|
|
802
|
-
if (Array.isArray(reactiveResult) && reactiveResult.length === 0 && opts?.failFastWhenIdle && opts?.platform === "web") {
|
|
803
|
-
break;
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
if (!waitedForIdle && driver.domChannel?.isConnected() && driver.domChannel.waitForIdle) {
|
|
808
|
-
waitedForIdle = true;
|
|
809
|
-
const remaining = Math.max(0, timeout - (Date.now() - start));
|
|
810
|
-
if (remaining > 0) {
|
|
811
|
-
yield* maybeWaitForBridgeIdle(driver, Math.min(remaining, 1500));
|
|
812
|
-
continue;
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
const elapsed = Date.now() - start;
|
|
816
|
-
const interval = nextInterval(elapsed, timeout, initialPollInterval, pollInterval);
|
|
817
|
-
yield* Effect2.sleep(Duration.millis(interval));
|
|
818
|
-
}
|
|
819
|
-
if (cache) cache.invalidate();
|
|
820
|
-
const diagRoot = yield* getHierarchy(driver, parse, cache);
|
|
821
|
-
const diagnostic = diagnoseElementNotFound(diagRoot, selector);
|
|
822
|
-
const diagMessage = formatDiagnostic(diagnostic);
|
|
823
|
-
return yield* new ElementNotFoundError({
|
|
824
|
-
message: `Element not found within ${timeout}ms \u2014 selector: ${formatSelector(selector)}
|
|
825
|
-
${diagMessage}`,
|
|
826
|
-
selector,
|
|
827
|
-
timeoutMs: timeout
|
|
828
|
-
});
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
function waitForResolvedElementResult(driver, selector, parse, forAction, opts, cache) {
|
|
832
|
-
return waitForResolvedAcrossChannels(driver, selector, parse, forAction, opts, cache);
|
|
833
|
-
}
|
|
834
|
-
function waitForElement(driver, selector, parse, opts, cache) {
|
|
835
|
-
return waitForResolvedAcrossChannels(driver, selector, parse, false, opts, cache).pipe(
|
|
836
|
-
Effect2.map((r) => r.element)
|
|
837
|
-
);
|
|
838
|
-
}
|
|
839
|
-
function waitForActionElement(driver, selector, parse, opts, cache) {
|
|
840
|
-
return waitForResolvedAcrossChannels(driver, selector, parse, true, opts, cache).pipe(
|
|
841
|
-
Effect2.map((r) => r.element)
|
|
842
|
-
);
|
|
843
|
-
}
|
|
844
|
-
function waitForNotVisible(driver, selector, parse, opts, cache) {
|
|
845
|
-
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
846
|
-
const pollInterval = opts?.pollInterval ?? DEFAULT_POLL_INTERVAL;
|
|
847
|
-
const initialPollInterval = opts?.initialPollInterval ?? DEFAULT_INITIAL_POLL_INTERVAL;
|
|
848
|
-
return Effect2.gen(function* () {
|
|
849
|
-
const start = Date.now();
|
|
850
|
-
let waitedForIdle = false;
|
|
851
|
-
let isFirstPoll = true;
|
|
852
|
-
const domChannel = driver.domChannel;
|
|
853
|
-
const canReactiveHidden = !isSystemUISelector(selector) && !isRelativeSelectorLike(selector) && (opts?.platform === "web" || isTestIDSelector(selector) || isComposableDomSelector(selector));
|
|
854
|
-
if (canReactiveHidden && domChannel?.isConnected() && domChannel.waitForHidden) {
|
|
855
|
-
const hidden = yield* Effect2.tryPromise({
|
|
856
|
-
try: () => domChannel.waitForHidden(selector, { timeoutMs: timeout }),
|
|
857
|
-
catch: () => null
|
|
858
|
-
}).pipe(Effect2.catchAll(() => Effect2.succeed(null)));
|
|
859
|
-
if (hidden === true) return;
|
|
860
|
-
if (hidden === false) {
|
|
861
|
-
return yield* new WaitTimeoutError({
|
|
862
|
-
message: `Element still visible after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
863
|
-
selector,
|
|
864
|
-
timeoutMs: timeout
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
while (isFirstPoll || Date.now() - start < timeout) {
|
|
869
|
-
if (!isFirstPoll && cache) cache.invalidate();
|
|
870
|
-
isFirstPoll = false;
|
|
871
|
-
const resolved = yield* resolveElementAcrossChannels(driver, selector, parse, cache, {
|
|
872
|
-
forAction: false,
|
|
873
|
-
platform: opts?.platform
|
|
874
|
-
});
|
|
875
|
-
if (!resolved) return;
|
|
876
|
-
if (!waitedForIdle && driver.domChannel?.isConnected() && driver.domChannel.waitForIdle) {
|
|
877
|
-
waitedForIdle = true;
|
|
878
|
-
const remaining = Math.max(0, timeout - (Date.now() - start));
|
|
879
|
-
if (remaining > 0) {
|
|
880
|
-
yield* maybeWaitForBridgeIdle(driver, Math.min(remaining, 1500));
|
|
881
|
-
continue;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
const elapsed = Date.now() - start;
|
|
885
|
-
const interval = nextInterval(elapsed, timeout, initialPollInterval, pollInterval);
|
|
886
|
-
yield* Effect2.sleep(Duration.millis(interval));
|
|
887
|
-
}
|
|
888
|
-
return yield* new WaitTimeoutError({
|
|
889
|
-
message: `Element still visible after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
890
|
-
selector,
|
|
891
|
-
timeoutMs: timeout
|
|
892
|
-
});
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
// src/smart/hierarchy-cache.ts
|
|
897
|
-
import { Effect as Effect3 } from "effect";
|
|
898
|
-
var DEFAULT_CACHE_TTL = 100;
|
|
899
|
-
function createHierarchyCache(config) {
|
|
900
|
-
const ttl = config?.hierarchyCacheTtl ?? DEFAULT_CACHE_TTL;
|
|
901
|
-
let cachedRoot;
|
|
902
|
-
let cachedAt = 0;
|
|
903
|
-
return {
|
|
904
|
-
get(driver, parse) {
|
|
905
|
-
return Effect3.gen(function* () {
|
|
906
|
-
const now = Date.now();
|
|
907
|
-
if (ttl > 0 && cachedRoot && now - cachedAt < ttl) {
|
|
908
|
-
return cachedRoot;
|
|
909
|
-
}
|
|
910
|
-
const raw = yield* driver.dumpHierarchy();
|
|
911
|
-
const root = parse(raw);
|
|
912
|
-
if (ttl > 0) {
|
|
913
|
-
cachedRoot = root;
|
|
914
|
-
cachedAt = Date.now();
|
|
915
|
-
}
|
|
916
|
-
return root;
|
|
917
|
-
});
|
|
918
|
-
},
|
|
919
|
-
invalidate() {
|
|
920
|
-
cachedRoot = void 0;
|
|
921
|
-
cachedAt = 0;
|
|
922
|
-
}
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
// src/smart/coordinator.ts
|
|
927
|
-
var DEFAULT_SCROLL_SEARCH_DIRECTION = "down";
|
|
928
|
-
var DEFAULT_MAX_SCROLLS = 5;
|
|
929
|
-
var DEFAULT_DISMISS_KEYBOARD_STRATEGY = "auto";
|
|
930
|
-
var DEFAULT_MAX_BACKS = 3;
|
|
931
|
-
function computeSwipeCoords(direction, screenW, screenH, offsetFraction) {
|
|
932
|
-
const cx = screenW / 2;
|
|
933
|
-
const cy = screenH / 2;
|
|
934
|
-
const offset = Math.min(screenW, screenH) * offsetFraction;
|
|
935
|
-
return {
|
|
936
|
-
up: { startX: cx, startY: cy + offset, endX: cx, endY: cy - offset },
|
|
937
|
-
down: { startX: cx, startY: cy - offset, endX: cx, endY: cy + offset },
|
|
938
|
-
left: { startX: cx + offset, startY: cy, endX: cx - offset, endY: cy },
|
|
939
|
-
right: { startX: cx - offset, startY: cy, endX: cx + offset, endY: cy }
|
|
940
|
-
}[direction];
|
|
941
|
-
}
|
|
942
|
-
function isRelativeSelectorLike2(selector) {
|
|
943
|
-
if (typeof selector !== "object" || selector === null) return false;
|
|
944
|
-
return "below" in selector || "above" in selector || "leftOf" in selector || "rightOf" in selector || "childOf" in selector;
|
|
945
|
-
}
|
|
946
|
-
function createCoordinator(driver, config) {
|
|
947
|
-
const { parse, defaults } = config;
|
|
948
|
-
const cacheConfig = {
|
|
949
|
-
hierarchyCacheTtl: config.hierarchyCacheTtl
|
|
950
|
-
};
|
|
951
|
-
const cache = createHierarchyCache(cacheConfig);
|
|
952
|
-
const idleWait = () => {
|
|
953
|
-
const ms = config.waitForIdleTimeout;
|
|
954
|
-
return ms && ms > 0 ? Effect4.sleep(Duration2.millis(ms)) : Effect4.void;
|
|
955
|
-
};
|
|
956
|
-
const afterMutation = () => Effect4.gen(function* () {
|
|
957
|
-
cache.invalidate();
|
|
958
|
-
yield* idleWait();
|
|
959
|
-
});
|
|
960
|
-
const screenH = config.screenHeight ?? 1920;
|
|
961
|
-
const safeMinY = screenH * 0.15;
|
|
962
|
-
const safeMaxY = screenH * 0.85;
|
|
963
|
-
const clampY = (y) => Math.max(safeMinY, Math.min(safeMaxY, y));
|
|
964
|
-
const swipeEffect = (direction, opts) => Effect4.gen(function* () {
|
|
965
|
-
const w = config.screenWidth ?? 1080;
|
|
966
|
-
const h = config.screenHeight ?? 1920;
|
|
967
|
-
const coords = computeSwipeCoords(direction, w, h, 0.2);
|
|
968
|
-
yield* driver.swipe(
|
|
969
|
-
coords.startX,
|
|
970
|
-
clampY(coords.startY),
|
|
971
|
-
coords.endX,
|
|
972
|
-
clampY(coords.endY),
|
|
973
|
-
opts?.duration ?? 300
|
|
974
|
-
);
|
|
975
|
-
yield* afterMutation();
|
|
976
|
-
});
|
|
977
|
-
const scrollEffect = (direction) => Effect4.gen(function* () {
|
|
978
|
-
const w = config.screenWidth ?? 1080;
|
|
979
|
-
const h = config.screenHeight ?? 1920;
|
|
980
|
-
const coords = computeSwipeCoords(direction, w, h, 0.3);
|
|
981
|
-
yield* driver.swipe(
|
|
982
|
-
coords.startX,
|
|
983
|
-
clampY(coords.startY),
|
|
984
|
-
coords.endX,
|
|
985
|
-
clampY(coords.endY),
|
|
986
|
-
500
|
|
987
|
-
);
|
|
988
|
-
if (config.platform !== "web") {
|
|
989
|
-
if (driver.domChannel?.isConnected() && driver.domChannel.waitForIdle) {
|
|
990
|
-
yield* Effect4.tryPromise({
|
|
991
|
-
try: () => driver.domChannel.waitForIdle({ timeout: 150, quietPeriodMs: 30 }),
|
|
992
|
-
catch: () => void 0
|
|
993
|
-
}).pipe(Effect4.catchAll(() => Effect4.void));
|
|
994
|
-
} else {
|
|
995
|
-
yield* Effect4.promise(() => new Promise((r) => setTimeout(r, 100)));
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
yield* afterMutation();
|
|
999
|
-
});
|
|
1000
|
-
const probeVisible = (selector, opts) => Effect4.gen(function* () {
|
|
1001
|
-
cache.invalidate();
|
|
1002
|
-
const probeTimeout = opts?.probeTimeout ?? 1;
|
|
1003
|
-
const result = yield* Effect4.either(
|
|
1004
|
-
waitForElement(
|
|
1005
|
-
driver,
|
|
1006
|
-
selector,
|
|
1007
|
-
parse,
|
|
1008
|
-
{ ...defaults, ...opts, timeout: probeTimeout },
|
|
1009
|
-
cache
|
|
1010
|
-
)
|
|
1011
|
-
);
|
|
1012
|
-
if (result._tag === "Right") {
|
|
1013
|
-
return true;
|
|
1014
|
-
}
|
|
1015
|
-
if (result.left._tag === "ElementNotFoundError" || result.left._tag === "WaitTimeoutError") {
|
|
1016
|
-
return false;
|
|
1017
|
-
}
|
|
1018
|
-
return yield* result.left;
|
|
1019
|
-
});
|
|
1020
|
-
const gestureDirectionForSearch = (direction) => {
|
|
1021
|
-
const directionMap = {
|
|
1022
|
-
up: "down",
|
|
1023
|
-
down: "up",
|
|
1024
|
-
left: "right",
|
|
1025
|
-
right: "left"
|
|
1026
|
-
};
|
|
1027
|
-
return directionMap[direction];
|
|
1028
|
-
};
|
|
1029
|
-
const normalizeWhitespace = (s) => s.replaceAll(/\s+/g, " ").trim();
|
|
1030
|
-
const collectContainerText = (el) => {
|
|
1031
|
-
if (el.text) return el.text;
|
|
1032
|
-
const parts = [];
|
|
1033
|
-
const stack = [...el.children ?? []].toReversed();
|
|
1034
|
-
while (stack.length > 0) {
|
|
1035
|
-
const node = stack.pop();
|
|
1036
|
-
if (node.visible === false) continue;
|
|
1037
|
-
if (node.text) parts.push(node.text);
|
|
1038
|
-
if (node.children) {
|
|
1039
|
-
for (let i = node.children.length - 1; i >= 0; i--) {
|
|
1040
|
-
stack.push(node.children[i]);
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
return parts.join(" ").trim();
|
|
1045
|
-
};
|
|
1046
|
-
const pollUntilMatch = (selector, opts, check, formatError, domMatchSpec, negate = false) => Effect4.gen(function* () {
|
|
1047
|
-
const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
|
|
1048
|
-
const pollInterval = opts?.pollInterval ?? defaults?.pollInterval ?? 200;
|
|
1049
|
-
const start = Date.now();
|
|
1050
|
-
let lastActual;
|
|
1051
|
-
const domChannel = driver.domChannel;
|
|
1052
|
-
if (domMatchSpec && config.platform === "web" && !isSystemUISelector(selector) && !isRelativeSelectorLike2(selector) && domChannel?.isConnected() && domChannel.waitForMatch) {
|
|
1053
|
-
const reactive = yield* Effect4.tryPromise({
|
|
1054
|
-
try: () => domChannel.waitForMatch(selector, {
|
|
1055
|
-
...domMatchSpec,
|
|
1056
|
-
...negate ? { negate: true } : {},
|
|
1057
|
-
timeoutMs: timeout
|
|
1058
|
-
}),
|
|
1059
|
-
catch: () => null
|
|
1060
|
-
}).pipe(Effect4.catchAll(() => Effect4.succeed(null)));
|
|
1061
|
-
if (reactive) {
|
|
1062
|
-
if (reactive.matched) return;
|
|
1063
|
-
lastActual = reactive.actual;
|
|
1064
|
-
const err2 = formatError(lastActual, timeout);
|
|
1065
|
-
return yield* new TextMismatchError({
|
|
1066
|
-
message: err2.message,
|
|
1067
|
-
expected: err2.expected,
|
|
1068
|
-
actual: lastActual,
|
|
1069
|
-
selector
|
|
1070
|
-
});
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
while (Date.now() - start < timeout) {
|
|
1074
|
-
if (cache) cache.invalidate();
|
|
1075
|
-
const resolved = yield* resolveElementAcrossChannels(driver, selector, parse, cache, {
|
|
1076
|
-
forAction: false,
|
|
1077
|
-
platform: config.platform
|
|
1078
|
-
});
|
|
1079
|
-
const element = resolved?.element;
|
|
1080
|
-
if (element) {
|
|
1081
|
-
const result = check(element);
|
|
1082
|
-
if (negate ? !result.matched : result.matched) return;
|
|
1083
|
-
lastActual = result.actual;
|
|
1084
|
-
}
|
|
1085
|
-
yield* Effect4.sleep(Duration2.millis(pollInterval));
|
|
1086
|
-
}
|
|
1087
|
-
const err = formatError(lastActual, timeout);
|
|
1088
|
-
return yield* new TextMismatchError({
|
|
1089
|
-
message: err.message,
|
|
1090
|
-
expected: err.expected,
|
|
1091
|
-
actual: lastActual,
|
|
1092
|
-
selector
|
|
1093
|
-
});
|
|
1094
|
-
});
|
|
1095
|
-
const dismissKeyboardWithDriver = () => Effect4.gen(function* () {
|
|
1096
|
-
yield* driver.hideKeyboard();
|
|
1097
|
-
yield* afterMutation();
|
|
1098
|
-
});
|
|
1099
|
-
const dismissKeyboardWithBack = () => Effect4.gen(function* () {
|
|
1100
|
-
yield* driver.back();
|
|
1101
|
-
yield* afterMutation();
|
|
1102
|
-
});
|
|
1103
|
-
const scaleGesture = (methodName, selector, opts) => Effect4.gen(function* () {
|
|
1104
|
-
const element = yield* waitForActionElement(
|
|
1105
|
-
driver,
|
|
1106
|
-
selector,
|
|
1107
|
-
parse,
|
|
1108
|
-
{ ...defaults, ...opts },
|
|
1109
|
-
cache
|
|
1110
|
-
);
|
|
1111
|
-
const { x, y } = centerOf(element);
|
|
1112
|
-
const scale = opts?.scale ?? 0.5;
|
|
1113
|
-
const duration = opts?.duration ?? 1500;
|
|
1114
|
-
const fn = methodName === "pinch" ? driver.pinch : driver.zoom;
|
|
1115
|
-
if (!fn) {
|
|
1116
|
-
return yield* new DriverError({
|
|
1117
|
-
message: `${methodName}() is only supported on mobile platforms (Android/iOS)`
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
yield* fn.call(driver, x, y, scale, duration);
|
|
1121
|
-
yield* afterMutation();
|
|
1122
|
-
});
|
|
1123
|
-
const assertEnabledState = (selector, expectedEnabled, opts) => Effect4.gen(function* () {
|
|
1124
|
-
const element = yield* waitForElement(
|
|
1125
|
-
driver,
|
|
1126
|
-
selector,
|
|
1127
|
-
parse,
|
|
1128
|
-
{ ...defaults, ...opts },
|
|
1129
|
-
cache
|
|
1130
|
-
);
|
|
1131
|
-
const isEnabled = element.enabled !== false;
|
|
1132
|
-
if (isEnabled !== expectedEnabled) {
|
|
1133
|
-
const state = expectedEnabled ? "enabled" : "disabled";
|
|
1134
|
-
const actual = expectedEnabled ? "disabled" : "enabled";
|
|
1135
|
-
return yield* new TextMismatchError({
|
|
1136
|
-
message: `Expected element to be ${state} but it is ${actual} \u2014 selector: ${formatSelector(selector)}`,
|
|
1137
|
-
expected: state,
|
|
1138
|
-
actual,
|
|
1139
|
-
selector
|
|
1140
|
-
});
|
|
1141
|
-
}
|
|
1142
|
-
});
|
|
1143
|
-
const createAssertions = () => ({
|
|
1144
|
-
assertVisible: (selector, opts) => waitForElement(driver, selector, parse, { ...defaults, ...opts }, cache),
|
|
1145
|
-
assertHidden: (selector, opts) => waitForNotVisible(driver, selector, parse, { ...defaults, ...opts }, cache),
|
|
1146
|
-
assertText: (selector, expected, opts, negate = false) => {
|
|
1147
|
-
const normalizedExpected = normalizeWhitespace(expected);
|
|
1148
|
-
return pollUntilMatch(
|
|
1149
|
-
selector,
|
|
1150
|
-
opts,
|
|
1151
|
-
(el) => {
|
|
1152
|
-
const raw = el.textContent ?? el.text;
|
|
1153
|
-
const actual = raw !== void 0 ? normalizeWhitespace(raw) : void 0;
|
|
1154
|
-
return { matched: actual === normalizedExpected, actual };
|
|
1155
|
-
},
|
|
1156
|
-
(actual, timeout) => ({
|
|
1157
|
-
message: negate ? `Expected text NOT to be "${expected}" after ${timeout}ms` : `Expected text "${expected}" but got "${actual ?? "(no text)"}" after ${timeout}ms`,
|
|
1158
|
-
expected: negate ? `not ${expected}` : expected
|
|
1159
|
-
}),
|
|
1160
|
-
{ kind: "text", expected },
|
|
1161
|
-
negate
|
|
1162
|
-
);
|
|
1163
|
-
},
|
|
1164
|
-
assertContainsText: (selector, expected, opts, negate = false) => {
|
|
1165
|
-
const normalizedExpected = normalizeWhitespace(expected).toLowerCase();
|
|
1166
|
-
return pollUntilMatch(
|
|
1167
|
-
selector,
|
|
1168
|
-
opts,
|
|
1169
|
-
(el) => {
|
|
1170
|
-
const raw = el.textContent ?? el.text ?? "";
|
|
1171
|
-
const actual = normalizeWhitespace(raw);
|
|
1172
|
-
return {
|
|
1173
|
-
matched: actual.toLowerCase().includes(normalizedExpected),
|
|
1174
|
-
actual
|
|
1175
|
-
};
|
|
1176
|
-
},
|
|
1177
|
-
(actual, timeout) => ({
|
|
1178
|
-
message: negate ? `Expected text NOT to contain "${expected}" but got "${actual ?? "(no text)"}" after ${timeout}ms` : `Expected text to contain "${expected}" but got "${actual ?? "(no text)"}" after ${timeout}ms`,
|
|
1179
|
-
expected: negate ? `not containing ${expected}` : expected
|
|
1180
|
-
}),
|
|
1181
|
-
{ kind: "containsText", expected },
|
|
1182
|
-
negate
|
|
1183
|
-
);
|
|
1184
|
-
},
|
|
1185
|
-
assertEnabled: (selector, opts) => assertEnabledState(selector, true, opts),
|
|
1186
|
-
assertDisabled: (selector, opts) => assertEnabledState(selector, false, opts),
|
|
1187
|
-
getText: (selector, opts) => Effect4.gen(function* () {
|
|
1188
|
-
const element = yield* waitForElement(
|
|
1189
|
-
driver,
|
|
1190
|
-
selector,
|
|
1191
|
-
parse,
|
|
1192
|
-
{ ...defaults, ...opts, platform: opts?.platform ?? config.platform },
|
|
1193
|
-
cache
|
|
1194
|
-
);
|
|
1195
|
-
return collectContainerText(element);
|
|
1196
|
-
}),
|
|
1197
|
-
count: (selector, opts) => Effect4.gen(function* () {
|
|
1198
|
-
cache.invalidate();
|
|
1199
|
-
const domChannel = driver.domChannel;
|
|
1200
|
-
if (!isSystemUISelector(selector) && !isRelativeSelectorLike2(selector) && domChannel?.isConnected()) {
|
|
1201
|
-
const matches = yield* Effect4.tryPromise({
|
|
1202
|
-
try: () => domChannel.query(selector),
|
|
1203
|
-
catch: () => null
|
|
1204
|
-
}).pipe(Effect4.catchAll(() => Effect4.succeed(null)));
|
|
1205
|
-
if (matches) {
|
|
1206
|
-
return matches.filter((m) => m.visible).length;
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
const raw = yield* driver.dumpHierarchy();
|
|
1210
|
-
const root = parse(raw);
|
|
1211
|
-
if (isRelativeSelectorLike2(selector)) {
|
|
1212
|
-
const resolved = yield* resolveElementAcrossChannels(driver, selector, parse, cache, {
|
|
1213
|
-
forAction: false,
|
|
1214
|
-
platform: opts?.platform ?? config.platform
|
|
1215
|
-
});
|
|
1216
|
-
return resolved ? 1 : 0;
|
|
1217
|
-
}
|
|
1218
|
-
return findElements(root, selector).filter((el) => el.visible !== false).length;
|
|
1219
|
-
}),
|
|
1220
|
-
isElementEnabled: (selector, opts) => Effect4.gen(function* () {
|
|
1221
|
-
const element = yield* waitForElement(
|
|
1222
|
-
driver,
|
|
1223
|
-
selector,
|
|
1224
|
-
parse,
|
|
1225
|
-
{ ...defaults, ...opts, platform: opts?.platform ?? config.platform },
|
|
1226
|
-
cache
|
|
1227
|
-
);
|
|
1228
|
-
return element.enabled !== false;
|
|
1229
|
-
}),
|
|
1230
|
-
assertValue: (selector, expected, opts, negate = false) => {
|
|
1231
|
-
const expectedStr = String(expected);
|
|
1232
|
-
return pollUntilMatch(
|
|
1233
|
-
selector,
|
|
1234
|
-
opts,
|
|
1235
|
-
(el) => {
|
|
1236
|
-
const actual = el.value ?? "";
|
|
1237
|
-
return { matched: actual === expectedStr, actual };
|
|
1238
|
-
},
|
|
1239
|
-
(actual, timeout) => ({
|
|
1240
|
-
message: negate ? `Expected value NOT to be "${expectedStr}" after ${timeout}ms` : `Expected value "${expectedStr}" but got "${actual ?? "(no value)"}" after ${timeout}ms`,
|
|
1241
|
-
expected: negate ? `not ${expectedStr}` : expectedStr
|
|
1242
|
-
}),
|
|
1243
|
-
{ kind: "value", expected: expectedStr },
|
|
1244
|
-
negate
|
|
1245
|
-
);
|
|
1246
|
-
},
|
|
1247
|
-
assertAttribute: (selector, name, expectedValue, opts, negate = false) => pollUntilMatch(
|
|
1248
|
-
selector,
|
|
1249
|
-
opts,
|
|
1250
|
-
(el) => {
|
|
1251
|
-
const actual = el.attributes?.[name];
|
|
1252
|
-
if (expectedValue === void 0) {
|
|
1253
|
-
return { matched: actual !== void 0, actual };
|
|
1254
|
-
}
|
|
1255
|
-
return { matched: actual === expectedValue, actual };
|
|
1256
|
-
},
|
|
1257
|
-
(actual, timeout) => negate ? expectedValue === void 0 ? {
|
|
1258
|
-
message: `Expected attribute "${name}" NOT to exist but got "${actual ?? ""}" after ${timeout}ms`,
|
|
1259
|
-
expected: `not ${name}`
|
|
1260
|
-
} : {
|
|
1261
|
-
message: `Expected attribute "${name}" NOT to be "${expectedValue}" after ${timeout}ms`,
|
|
1262
|
-
expected: `not ${expectedValue}`
|
|
1263
|
-
} : expectedValue === void 0 ? {
|
|
1264
|
-
message: `Expected attribute "${name}" to exist but it was not found after ${timeout}ms`,
|
|
1265
|
-
expected: name
|
|
1266
|
-
} : {
|
|
1267
|
-
message: `Expected attribute "${name}" to be "${expectedValue}" but got "${actual ?? "(not found)"}" after ${timeout}ms`,
|
|
1268
|
-
expected: expectedValue
|
|
1269
|
-
},
|
|
1270
|
-
{ kind: "attribute", attributeName: name, expected: expectedValue },
|
|
1271
|
-
negate
|
|
1272
|
-
),
|
|
1273
|
-
assertMatchesText: (selector, pattern, opts, negate = false) => pollUntilMatch(
|
|
1274
|
-
selector,
|
|
1275
|
-
opts,
|
|
1276
|
-
(el) => {
|
|
1277
|
-
const actual = normalizeWhitespace(el.textContent ?? el.text ?? "");
|
|
1278
|
-
return { matched: pattern.test(actual), actual };
|
|
1279
|
-
},
|
|
1280
|
-
(actual, timeout) => ({
|
|
1281
|
-
message: negate ? `Expected text NOT to match ${pattern} but got "${actual ?? "(no text)"}" after ${timeout}ms` : `Expected text to match ${pattern} but got "${actual ?? "(no text)"}" after ${timeout}ms`,
|
|
1282
|
-
expected: negate ? `not ${String(pattern)}` : String(pattern)
|
|
1283
|
-
}),
|
|
1284
|
-
{ kind: "matchesText", patternSource: pattern.source, patternFlags: pattern.flags },
|
|
1285
|
-
negate
|
|
1286
|
-
),
|
|
1287
|
-
getAttribute: (selector, name, opts) => Effect4.gen(function* () {
|
|
1288
|
-
const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
|
|
1289
|
-
const pollInterval = opts?.pollInterval ?? defaults?.pollInterval ?? 100;
|
|
1290
|
-
const domChannel = driver.domChannel;
|
|
1291
|
-
if (!isSystemUISelector(selector) && !isRelativeSelectorLike2(selector) && domChannel?.isConnected()) {
|
|
1292
|
-
const start = Date.now();
|
|
1293
|
-
while (true) {
|
|
1294
|
-
const matches = yield* Effect4.tryPromise({
|
|
1295
|
-
try: () => domChannel.query(selector),
|
|
1296
|
-
catch: () => null
|
|
1297
|
-
}).pipe(Effect4.catchAll(() => Effect4.succeed(null)));
|
|
1298
|
-
if (matches && matches.length > 0) {
|
|
1299
|
-
const target = matches[matches.length - 1];
|
|
1300
|
-
return target.attributes?.[name];
|
|
1301
|
-
}
|
|
1302
|
-
if (Date.now() - start >= timeout) {
|
|
1303
|
-
return yield* new ElementNotFoundError({
|
|
1304
|
-
message: `Element not found within ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1305
|
-
selector,
|
|
1306
|
-
timeoutMs: timeout
|
|
1307
|
-
});
|
|
1308
|
-
}
|
|
1309
|
-
yield* Effect4.sleep(Duration2.millis(Math.min(pollInterval, 100)));
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
const element = yield* waitForElement(
|
|
1313
|
-
driver,
|
|
1314
|
-
selector,
|
|
1315
|
-
parse,
|
|
1316
|
-
{ ...defaults, ...opts, platform: opts?.platform ?? config.platform },
|
|
1317
|
-
cache
|
|
1318
|
-
);
|
|
1319
|
-
return element.attributes?.[name];
|
|
1320
|
-
}),
|
|
1321
|
-
assertScreenshot: (selector, name, flowFilePath, flowName, platform, options) => Effect4.gen(function* () {
|
|
1322
|
-
const { resolveBaselinePath, readBaseline, writeBaseline } = yield* Effect4.promise(
|
|
1323
|
-
() => import("./baseline-manager-5TIUCNP5.js")
|
|
1324
|
-
);
|
|
1325
|
-
const { cropToElement, applyMask, compareScreenshots } = yield* Effect4.promise(
|
|
1326
|
-
() => import("./screenshot-compare-POTXVUTL.js")
|
|
1327
|
-
);
|
|
1328
|
-
const raw = yield* driver.takeScreenshot();
|
|
1329
|
-
let screenshotBuf;
|
|
1330
|
-
if (selector !== void 0) {
|
|
1331
|
-
const element = yield* waitForElement(driver, selector, parse, { ...defaults }, cache);
|
|
1332
|
-
screenshotBuf = yield* Effect4.promise(() => cropToElement(raw, element.bounds));
|
|
1333
|
-
} else {
|
|
1334
|
-
screenshotBuf = Buffer.from(raw);
|
|
1335
|
-
}
|
|
1336
|
-
const baselinePath = resolveBaselinePath(
|
|
1337
|
-
flowFilePath,
|
|
1338
|
-
flowName,
|
|
1339
|
-
platform,
|
|
1340
|
-
name,
|
|
1341
|
-
options.baselinesDir
|
|
1342
|
-
);
|
|
1343
|
-
if (options.updateBaselines) {
|
|
1344
|
-
yield* Effect4.promise(() => Promise.resolve(writeBaseline(baselinePath, screenshotBuf)));
|
|
1345
|
-
return;
|
|
1346
|
-
}
|
|
1347
|
-
const existing = readBaseline(baselinePath);
|
|
1348
|
-
if (existing === null) {
|
|
1349
|
-
yield* Effect4.promise(() => Promise.resolve(writeBaseline(baselinePath, screenshotBuf)));
|
|
1350
|
-
return;
|
|
1351
|
-
}
|
|
1352
|
-
let actualBuf = screenshotBuf;
|
|
1353
|
-
if (options.mask && options.mask.length > 0) {
|
|
1354
|
-
actualBuf = yield* Effect4.promise(() => applyMask(screenshotBuf, options.mask));
|
|
1355
|
-
}
|
|
1356
|
-
const result = compareScreenshots(existing, actualBuf, {
|
|
1357
|
-
threshold: options.threshold,
|
|
1358
|
-
maxDiffPixelRatio: options.maxDiffPixelRatio
|
|
1359
|
-
});
|
|
1360
|
-
if (!result.match) {
|
|
1361
|
-
const { writeFileSync, mkdirSync } = yield* Effect4.promise(() => import("fs"));
|
|
1362
|
-
const { join: join3 } = yield* Effect4.promise(() => import("path"));
|
|
1363
|
-
const outDir = options.outputDir ?? config.outputDir ?? "spana-output";
|
|
1364
|
-
mkdirSync(outDir, { recursive: true });
|
|
1365
|
-
const safeFlowName = flowName.toLowerCase().replaceAll(/[^a-z0-9]+/g, "-").replaceAll(/^-|-$/g, "");
|
|
1366
|
-
const prefix = join3(outDir, `${safeFlowName}-${platform}-${name}`);
|
|
1367
|
-
writeFileSync(`${prefix}-expected.png`, existing);
|
|
1368
|
-
writeFileSync(`${prefix}-actual.png`, actualBuf);
|
|
1369
|
-
if (result.diffImage) {
|
|
1370
|
-
writeFileSync(`${prefix}-diff.png`, result.diffImage);
|
|
1371
|
-
}
|
|
1372
|
-
const detail = result.sizeMismatch ? "image dimensions differ" : `${result.diffPixelCount} differing pixels (ratio: ${(result.diffPixelRatio * 100).toFixed(2)}%)`;
|
|
1373
|
-
return yield* new DriverError({
|
|
1374
|
-
message: `Screenshot mismatch for "${name}": ${detail}. Expected: ${prefix}-expected.png, Actual: ${prefix}-actual.png${result.diffImage ? `, Diff: ${prefix}-diff.png` : ""}`
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
|
-
}),
|
|
1378
|
-
assertAccessibilityLabel: (selector, expected, opts) => pollUntilMatch(
|
|
1379
|
-
selector,
|
|
1380
|
-
opts,
|
|
1381
|
-
(el) => {
|
|
1382
|
-
const label = el.accessibilityLabel;
|
|
1383
|
-
if (expected === void 0) {
|
|
1384
|
-
return { matched: label !== void 0 && label.length > 0, actual: label };
|
|
1385
|
-
}
|
|
1386
|
-
return { matched: label === expected, actual: label };
|
|
1387
|
-
},
|
|
1388
|
-
(actual, timeout) => expected === void 0 ? {
|
|
1389
|
-
message: `Expected element to have a non-empty accessibilityLabel but got "${actual ?? "(none)"}" after ${timeout}ms`,
|
|
1390
|
-
expected: "(non-empty)"
|
|
1391
|
-
} : {
|
|
1392
|
-
message: `Expected accessibilityLabel "${expected}" but got "${actual ?? "(none)"}" after ${timeout}ms`,
|
|
1393
|
-
expected
|
|
1394
|
-
},
|
|
1395
|
-
{ kind: "accessibilityLabel", expected }
|
|
1396
|
-
),
|
|
1397
|
-
assertAccessibleName: (selector, expected, opts, negate = false) => pollUntilMatch(
|
|
1398
|
-
selector,
|
|
1399
|
-
opts,
|
|
1400
|
-
(el) => {
|
|
1401
|
-
const actual = el.accessibilityLabel || el.text || "";
|
|
1402
|
-
const matched = expected instanceof RegExp ? expected.test(actual) : actual.trim() === expected.trim();
|
|
1403
|
-
return { matched, actual };
|
|
1404
|
-
},
|
|
1405
|
-
(actual, timeout) => ({
|
|
1406
|
-
message: negate ? `Expected accessible name NOT to match ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got "${actual ?? "(none)"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}` : `Expected accessible name ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got "${actual ?? "(none)"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1407
|
-
expected: negate ? `not ${String(expected)}` : String(expected)
|
|
1408
|
-
}),
|
|
1409
|
-
expected instanceof RegExp ? {
|
|
1410
|
-
kind: "accessibleName",
|
|
1411
|
-
patternSource: expected.source,
|
|
1412
|
-
patternFlags: expected.flags
|
|
1413
|
-
} : { kind: "accessibleName", expected },
|
|
1414
|
-
negate
|
|
1415
|
-
),
|
|
1416
|
-
assertAccessibleDescription: (selector, expected, opts, negate = false) => pollUntilMatch(
|
|
1417
|
-
selector,
|
|
1418
|
-
opts,
|
|
1419
|
-
(el) => {
|
|
1420
|
-
const actual = el.accessibleDescription ?? el.attributes?.["aria-description"] ?? "";
|
|
1421
|
-
const matched = expected instanceof RegExp ? expected.test(actual) : actual.trim() === expected.trim();
|
|
1422
|
-
return { matched, actual };
|
|
1423
|
-
},
|
|
1424
|
-
(actual, timeout) => ({
|
|
1425
|
-
message: negate ? `Expected accessible description NOT to match ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got "${actual ?? "(none)"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}` : `Expected accessible description ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got "${actual ?? "(none)"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1426
|
-
expected: negate ? `not ${String(expected)}` : String(expected)
|
|
1427
|
-
}),
|
|
1428
|
-
expected instanceof RegExp ? {
|
|
1429
|
-
kind: "accessibleDescription",
|
|
1430
|
-
patternSource: expected.source,
|
|
1431
|
-
patternFlags: expected.flags
|
|
1432
|
-
} : { kind: "accessibleDescription", expected },
|
|
1433
|
-
negate
|
|
1434
|
-
),
|
|
1435
|
-
assertFocused: (selector, opts, negate = false) => pollUntilMatch(
|
|
1436
|
-
selector,
|
|
1437
|
-
opts,
|
|
1438
|
-
(el) => ({
|
|
1439
|
-
matched: el.focused === true,
|
|
1440
|
-
actual: el.focused ? "focused" : "not focused"
|
|
1441
|
-
}),
|
|
1442
|
-
(actual, timeout) => ({
|
|
1443
|
-
message: negate ? `Expected element NOT to be focused but it was "${actual ?? "focused"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}` : `Expected element to be focused but it was "${actual ?? "not focused"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1444
|
-
expected: negate ? "not focused" : "focused"
|
|
1445
|
-
}),
|
|
1446
|
-
{ kind: "focused" },
|
|
1447
|
-
negate
|
|
1448
|
-
),
|
|
1449
|
-
assertCount: (selector, expectedCount, opts, negate = false) => Effect4.gen(function* () {
|
|
1450
|
-
const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
|
|
1451
|
-
const pollInterval = opts?.pollInterval ?? defaults?.pollInterval ?? 200;
|
|
1452
|
-
const start = Date.now();
|
|
1453
|
-
let lastCount = -1;
|
|
1454
|
-
const domChannel = driver.domChannel;
|
|
1455
|
-
if (config.platform === "web" && !isSystemUISelector(selector) && !isRelativeSelectorLike2(selector) && domChannel?.isConnected() && domChannel.waitForMatch) {
|
|
1456
|
-
const reactive = yield* Effect4.tryPromise({
|
|
1457
|
-
try: () => domChannel.waitForMatch(selector, {
|
|
1458
|
-
kind: "count",
|
|
1459
|
-
expectedCount,
|
|
1460
|
-
...negate ? { negate: true } : {},
|
|
1461
|
-
timeoutMs: timeout
|
|
1462
|
-
}),
|
|
1463
|
-
catch: () => null
|
|
1464
|
-
}).pipe(Effect4.catchAll(() => Effect4.succeed(null)));
|
|
1465
|
-
if (reactive) {
|
|
1466
|
-
if (reactive.matched) return;
|
|
1467
|
-
return yield* new TextMismatchError({
|
|
1468
|
-
message: negate ? `Expected count NOT to be ${expectedCount} after ${timeout}ms \u2014 selector: ${formatSelector(selector)}` : `Expected count ${expectedCount} but got ${reactive.actual ?? "0"} after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1469
|
-
expected: negate ? `not ${expectedCount}` : String(expectedCount),
|
|
1470
|
-
actual: reactive.actual ?? "0",
|
|
1471
|
-
selector
|
|
1472
|
-
});
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
while (Date.now() - start < timeout) {
|
|
1476
|
-
cache.invalidate();
|
|
1477
|
-
if (!isSystemUISelector(selector) && !isRelativeSelectorLike2(selector) && domChannel?.isConnected()) {
|
|
1478
|
-
const matches = yield* Effect4.tryPromise({
|
|
1479
|
-
try: () => domChannel.query(selector),
|
|
1480
|
-
catch: () => null
|
|
1481
|
-
}).pipe(Effect4.catchAll(() => Effect4.succeed(null)));
|
|
1482
|
-
if (matches) {
|
|
1483
|
-
const count2 = matches.filter((m) => m.visible).length;
|
|
1484
|
-
lastCount = count2;
|
|
1485
|
-
if (negate ? count2 !== expectedCount : count2 === expectedCount) return;
|
|
1486
|
-
yield* Effect4.sleep(Duration2.millis(pollInterval));
|
|
1487
|
-
continue;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
const raw = yield* driver.dumpHierarchy();
|
|
1491
|
-
const root = parse(raw);
|
|
1492
|
-
const count = findElements(root, selector).filter(
|
|
1493
|
-
(el) => el.visible !== false
|
|
1494
|
-
).length;
|
|
1495
|
-
lastCount = count;
|
|
1496
|
-
if (negate ? count !== expectedCount : count === expectedCount) return;
|
|
1497
|
-
yield* Effect4.sleep(Duration2.millis(pollInterval));
|
|
1498
|
-
}
|
|
1499
|
-
return yield* new TextMismatchError({
|
|
1500
|
-
message: negate ? `Expected count NOT to be ${expectedCount} after ${timeout}ms \u2014 selector: ${formatSelector(selector)}` : `Expected count ${expectedCount} but got ${lastCount >= 0 ? lastCount : 0} after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1501
|
-
expected: negate ? `not ${expectedCount}` : String(expectedCount),
|
|
1502
|
-
actual: String(lastCount >= 0 ? lastCount : 0),
|
|
1503
|
-
selector
|
|
1504
|
-
});
|
|
1505
|
-
}),
|
|
1506
|
-
waitForURL: (expected, opts, negate = false) => Effect4.gen(function* () {
|
|
1507
|
-
const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
|
|
1508
|
-
const pollInterval = opts?.pollInterval ?? defaults?.pollInterval ?? 100;
|
|
1509
|
-
const start = Date.now();
|
|
1510
|
-
let lastUrl = "";
|
|
1511
|
-
const matchesUrl = (url) => expected instanceof RegExp ? expected.test(url) : url === expected || url.includes(expected);
|
|
1512
|
-
const domChannel = driver.domChannel;
|
|
1513
|
-
if (config.platform === "web" && domChannel?.isConnected() && domChannel.waitForMatch) {
|
|
1514
|
-
const reactive = yield* Effect4.tryPromise({
|
|
1515
|
-
try: () => domChannel.waitForMatch("", {
|
|
1516
|
-
kind: "url",
|
|
1517
|
-
...expected instanceof RegExp ? { patternSource: expected.source, patternFlags: expected.flags } : { expected },
|
|
1518
|
-
...negate ? { negate: true } : {},
|
|
1519
|
-
timeoutMs: timeout
|
|
1520
|
-
}),
|
|
1521
|
-
catch: () => null
|
|
1522
|
-
}).pipe(Effect4.catchAll(() => Effect4.succeed(null)));
|
|
1523
|
-
if (reactive) {
|
|
1524
|
-
if (reactive.matched) return;
|
|
1525
|
-
return yield* new TextMismatchError({
|
|
1526
|
-
message: negate ? `Expected URL NOT to match ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got ${JSON.stringify(reactive.actual ?? "")} after ${timeout}ms` : `Expected URL ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got ${JSON.stringify(reactive.actual ?? "")} after ${timeout}ms`,
|
|
1527
|
-
expected: negate ? `not ${String(expected)}` : String(expected),
|
|
1528
|
-
actual: reactive.actual ?? "",
|
|
1529
|
-
selector: "url"
|
|
1530
|
-
});
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
while (Date.now() - start < timeout) {
|
|
1534
|
-
const url = driver.getUrl ? yield* driver.getUrl() : yield* driver.evaluate(
|
|
1535
|
-
"typeof window !== 'undefined' && window.location ? window.location.href : ''"
|
|
1536
|
-
).pipe(Effect4.catchAll(() => Effect4.succeed("")));
|
|
1537
|
-
lastUrl = url;
|
|
1538
|
-
if (negate ? !matchesUrl(url) : matchesUrl(url)) return;
|
|
1539
|
-
yield* Effect4.sleep(Duration2.millis(pollInterval));
|
|
1540
|
-
}
|
|
1541
|
-
return yield* new TextMismatchError({
|
|
1542
|
-
message: negate ? `Expected URL NOT to match ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got ${JSON.stringify(lastUrl)} after ${timeout}ms` : `Expected URL ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got ${JSON.stringify(lastUrl)} after ${timeout}ms`,
|
|
1543
|
-
expected: negate ? `not ${String(expected)}` : String(expected),
|
|
1544
|
-
actual: lastUrl,
|
|
1545
|
-
selector: "url"
|
|
1546
|
-
});
|
|
1547
|
-
}),
|
|
1548
|
-
assertFocusable: (selector, platform, opts) => Effect4.gen(function* () {
|
|
1549
|
-
const { isFocusable } = yield* Effect4.promise(
|
|
1550
|
-
() => import("./accessibility-audit-YZOPUY3D.js")
|
|
1551
|
-
);
|
|
1552
|
-
yield* pollUntilMatch(
|
|
1553
|
-
selector,
|
|
1554
|
-
opts,
|
|
1555
|
-
(el) => {
|
|
1556
|
-
const focusable = isFocusable(el, {
|
|
1557
|
-
platform
|
|
1558
|
-
});
|
|
1559
|
-
return { matched: focusable, actual: focusable ? "focusable" : "not focusable" };
|
|
1560
|
-
},
|
|
1561
|
-
(actual, timeout) => ({
|
|
1562
|
-
message: `Expected element to be focusable but it was "${actual ?? "not focusable"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1563
|
-
expected: "focusable"
|
|
1564
|
-
})
|
|
1565
|
-
);
|
|
1566
|
-
}),
|
|
1567
|
-
assertRole: (selector, expectedRole, platform, opts) => Effect4.gen(function* () {
|
|
1568
|
-
const { normalizeRole } = yield* Effect4.promise(
|
|
1569
|
-
() => import("./accessibility-audit-YZOPUY3D.js")
|
|
1570
|
-
);
|
|
1571
|
-
yield* pollUntilMatch(
|
|
1572
|
-
selector,
|
|
1573
|
-
opts,
|
|
1574
|
-
(el) => {
|
|
1575
|
-
const actual = normalizeRole(
|
|
1576
|
-
platform,
|
|
1577
|
-
el.elementType ?? "",
|
|
1578
|
-
el.attributes ?? {}
|
|
1579
|
-
);
|
|
1580
|
-
return { matched: actual === expectedRole, actual };
|
|
1581
|
-
},
|
|
1582
|
-
(actual, timeout) => ({
|
|
1583
|
-
message: `Expected role "${expectedRole}" but got "${actual ?? "(unknown)"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1584
|
-
expected: expectedRole
|
|
1585
|
-
})
|
|
1586
|
-
);
|
|
1587
|
-
}),
|
|
1588
|
-
assertMinTouchTarget: (selector, minSize, opts) => pollUntilMatch(
|
|
1589
|
-
selector,
|
|
1590
|
-
opts,
|
|
1591
|
-
(el) => {
|
|
1592
|
-
const { width, height } = el.bounds;
|
|
1593
|
-
const passed = width >= minSize && height >= minSize;
|
|
1594
|
-
const actual = `${width}x${height}`;
|
|
1595
|
-
return { matched: passed, actual };
|
|
1596
|
-
},
|
|
1597
|
-
(actual, timeout) => ({
|
|
1598
|
-
message: `Expected touch target to be at least ${minSize}x${minSize}px but got "${actual ?? "(unknown)"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1599
|
-
expected: `${minSize}x${minSize}`
|
|
1600
|
-
})
|
|
1601
|
-
),
|
|
1602
|
-
assertAccessibilityAudit: (platform, options = {}) => Effect4.gen(function* () {
|
|
1603
|
-
if (platform !== "web") {
|
|
1604
|
-
return yield* new DriverError({
|
|
1605
|
-
message: `assertAccessibilityAudit() is only supported on web \u2014 platform "${platform}" is not supported`
|
|
1606
|
-
});
|
|
1607
|
-
}
|
|
1608
|
-
const { readFileSync } = yield* Effect4.promise(() => import("fs"));
|
|
1609
|
-
const { createRequire: createRequire2 } = yield* Effect4.promise(() => import("module"));
|
|
1610
|
-
const require3 = createRequire2(import.meta.url);
|
|
1611
|
-
const axePath = require3.resolve("axe-core/axe.js");
|
|
1612
|
-
const axeSource = readFileSync(axePath, "utf-8");
|
|
1613
|
-
const { filterViolations, formatViolationSummary } = yield* Effect4.promise(
|
|
1614
|
-
() => import("./accessibility-audit-YZOPUY3D.js")
|
|
1615
|
-
);
|
|
1616
|
-
const axeContext = {};
|
|
1617
|
-
if (options.targetSelector) {
|
|
1618
|
-
axeContext["include"] = [[options.targetSelector]];
|
|
1619
|
-
}
|
|
1620
|
-
if (options.excludeSelectors && options.excludeSelectors.length > 0) {
|
|
1621
|
-
axeContext["exclude"] = options.excludeSelectors.map((s) => [s]);
|
|
1622
|
-
}
|
|
1623
|
-
const serializedContext = Object.keys(axeContext).length > 0 ? JSON.stringify(axeContext) : "document";
|
|
1624
|
-
const axeOptions = {};
|
|
1625
|
-
if (options.rules && options.rules.length > 0) {
|
|
1626
|
-
const rulesConfig = {};
|
|
1627
|
-
for (const r of options.rules) rulesConfig[r] = { enabled: true };
|
|
1628
|
-
axeOptions["rules"] = rulesConfig;
|
|
1629
|
-
}
|
|
1630
|
-
const script = `
|
|
1631
|
-
(function() {
|
|
1632
|
-
${axeSource}
|
|
1633
|
-
return axe.run(${serializedContext}, ${JSON.stringify(axeOptions)});
|
|
1634
|
-
})()
|
|
1635
|
-
`;
|
|
1636
|
-
const axeResult = yield* driver.evaluate(script);
|
|
1637
|
-
const violations = axeResult.violations.map((v) => ({
|
|
1638
|
-
ruleId: v.id,
|
|
1639
|
-
severity: v.impact ?? "minor",
|
|
1640
|
-
description: v.description,
|
|
1641
|
-
helpUrl: v.helpUrl,
|
|
1642
|
-
wcagCriteria: v.tags.filter((t) => t.startsWith("wcag")),
|
|
1643
|
-
elements: v.nodes.map((n) => ({
|
|
1644
|
-
selector: n.target.join(", "),
|
|
1645
|
-
html: n.html,
|
|
1646
|
-
failureSummary: n.failureSummary
|
|
1647
|
-
}))
|
|
1648
|
-
}));
|
|
1649
|
-
const minSeverity = options.severity ?? "serious";
|
|
1650
|
-
const filtered = filterViolations(violations, minSeverity);
|
|
1651
|
-
if (filtered.length > 0) {
|
|
1652
|
-
const summary = formatViolationSummary(filtered);
|
|
1653
|
-
return yield* new DriverError({ message: summary });
|
|
1654
|
-
}
|
|
1655
|
-
})
|
|
1656
|
-
});
|
|
1657
|
-
return {
|
|
1658
|
-
tap: (selector, opts) => Effect4.gen(function* () {
|
|
1659
|
-
const effectiveTapMode = opts?.tapMode ?? config.tapMode ?? "native";
|
|
1660
|
-
const mergedOpts = {
|
|
1661
|
-
...defaults,
|
|
1662
|
-
...opts,
|
|
1663
|
-
tapMode: effectiveTapMode,
|
|
1664
|
-
platform: opts?.platform ?? config.platform
|
|
1665
|
-
};
|
|
1666
|
-
const resolved = yield* waitForResolvedElementResult(
|
|
1667
|
-
driver,
|
|
1668
|
-
selector,
|
|
1669
|
-
parse,
|
|
1670
|
-
true,
|
|
1671
|
-
mergedOpts,
|
|
1672
|
-
cache
|
|
1673
|
-
);
|
|
1674
|
-
if (resolved.channel === "dom" && effectiveTapMode === "dom" && driver.domChannel) {
|
|
1675
|
-
const tapped = yield* Effect4.tryPromise({
|
|
1676
|
-
try: () => driver.domChannel.tapDom(selector),
|
|
1677
|
-
catch: (e) => new DriverError({ message: `DOM tap failed: ${e}` })
|
|
1678
|
-
});
|
|
1679
|
-
if (tapped) {
|
|
1680
|
-
yield* afterMutation();
|
|
1681
|
-
return;
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
const { x, y } = centerOf(resolved.element);
|
|
1685
|
-
yield* driver.tapAtCoordinate(x, y);
|
|
1686
|
-
yield* afterMutation();
|
|
1687
|
-
}),
|
|
1688
|
-
tapXY: (x, y) => Effect4.gen(function* () {
|
|
1689
|
-
yield* driver.tapAtCoordinate(x, y);
|
|
1690
|
-
yield* afterMutation();
|
|
1691
|
-
}),
|
|
1692
|
-
doubleTap: (selector, opts) => Effect4.gen(function* () {
|
|
1693
|
-
const element = yield* waitForActionElement(
|
|
1694
|
-
driver,
|
|
1695
|
-
selector,
|
|
1696
|
-
parse,
|
|
1697
|
-
{ ...defaults, ...opts, platform: opts?.platform ?? config.platform },
|
|
1698
|
-
cache
|
|
1699
|
-
);
|
|
1700
|
-
const { x, y } = centerOf(element);
|
|
1701
|
-
yield* driver.tapAtCoordinate(x, y);
|
|
1702
|
-
yield* Effect4.promise(() => new Promise((r) => setTimeout(r, 200)));
|
|
1703
|
-
yield* driver.tapAtCoordinate(x, y);
|
|
1704
|
-
yield* afterMutation();
|
|
1705
|
-
}),
|
|
1706
|
-
longPress: (selector, duration = 1e3, opts) => Effect4.gen(function* () {
|
|
1707
|
-
const element = yield* waitForActionElement(
|
|
1708
|
-
driver,
|
|
1709
|
-
selector,
|
|
1710
|
-
parse,
|
|
1711
|
-
{ ...defaults, ...opts, platform: opts?.platform ?? config.platform },
|
|
1712
|
-
cache
|
|
1713
|
-
);
|
|
1714
|
-
const { x, y } = centerOf(element);
|
|
1715
|
-
yield* driver.longPressAtCoordinate(x, y, duration);
|
|
1716
|
-
yield* afterMutation();
|
|
1717
|
-
}),
|
|
1718
|
-
longPressXY: (x, y, duration = 1e3) => Effect4.gen(function* () {
|
|
1719
|
-
yield* driver.longPressAtCoordinate(x, y, duration);
|
|
1720
|
-
yield* afterMutation();
|
|
1721
|
-
}),
|
|
1722
|
-
inputText: (text) => Effect4.gen(function* () {
|
|
1723
|
-
const delay = config.typingDelay;
|
|
1724
|
-
if (delay && delay > 0) {
|
|
1725
|
-
for (const segment of splitGraphemes(text)) {
|
|
1726
|
-
yield* driver.inputText(segment);
|
|
1727
|
-
yield* Effect4.sleep(Duration2.millis(delay));
|
|
1728
|
-
}
|
|
1729
|
-
} else {
|
|
1730
|
-
yield* driver.inputText(text);
|
|
1731
|
-
}
|
|
1732
|
-
yield* afterMutation();
|
|
1733
|
-
}),
|
|
1734
|
-
/**
|
|
1735
|
-
* Hover the pointer over an actionable element (moves pointer to its center).
|
|
1736
|
-
*/
|
|
1737
|
-
hover: (selector, opts) => Effect4.gen(function* () {
|
|
1738
|
-
const mergedOpts = {
|
|
1739
|
-
...defaults,
|
|
1740
|
-
...opts,
|
|
1741
|
-
platform: opts?.platform ?? config.platform
|
|
1742
|
-
};
|
|
1743
|
-
const resolved = yield* waitForResolvedElementResult(
|
|
1744
|
-
driver,
|
|
1745
|
-
selector,
|
|
1746
|
-
parse,
|
|
1747
|
-
true,
|
|
1748
|
-
mergedOpts,
|
|
1749
|
-
cache
|
|
1750
|
-
);
|
|
1751
|
-
const { x, y } = centerOf(resolved.element);
|
|
1752
|
-
if (driver.hoverAtCoordinate) {
|
|
1753
|
-
yield* driver.hoverAtCoordinate(x, y);
|
|
1754
|
-
} else if (config.platform === "web") {
|
|
1755
|
-
yield* driver.evaluate(
|
|
1756
|
-
`(() => {
|
|
1757
|
-
const el = document.elementFromPoint(${x}, ${y});
|
|
1758
|
-
if (!el) return;
|
|
1759
|
-
const init = { bubbles: true, cancelable: true, composed: true, clientX: ${x}, clientY: ${y} };
|
|
1760
|
-
try { el.dispatchEvent(new PointerEvent("pointerover", init)); } catch {}
|
|
1761
|
-
try { el.dispatchEvent(new PointerEvent("pointerenter", { ...init, bubbles: false })); } catch {}
|
|
1762
|
-
try { el.dispatchEvent(new MouseEvent("mouseover", init)); } catch {}
|
|
1763
|
-
try { el.dispatchEvent(new MouseEvent("mouseenter", { ...init, bubbles: false })); } catch {}
|
|
1764
|
-
try { el.dispatchEvent(new MouseEvent("mousemove", init)); } catch {}
|
|
1765
|
-
})()`
|
|
1766
|
-
);
|
|
1767
|
-
} else {
|
|
1768
|
-
return yield* new DriverError({
|
|
1769
|
-
message: "hover() is not supported on this driver/platform"
|
|
1770
|
-
});
|
|
1771
|
-
}
|
|
1772
|
-
yield* afterMutation();
|
|
1773
|
-
}),
|
|
1774
|
-
/**
|
|
1775
|
-
* Atomic 1-round-trip form fill: on web/DOM channels, waits for actionability,
|
|
1776
|
-
* focuses, clears, sets the React/Vue-safe value, verifies the value survived
|
|
1777
|
-
* React re-render/remount, and retries up to 3x. For contenteditable editors
|
|
1778
|
-
* (TipTap/ProseMirror/Lexical/Slate) or stubborn controlled inputs, falls back
|
|
1779
|
-
* seamlessly to native tap + SelectAll + Backspace + keyboard input.
|
|
1780
|
-
*/
|
|
1781
|
-
fill: (selector, text, opts) => Effect4.gen(function* () {
|
|
1782
|
-
const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
|
|
1783
|
-
const fillStart = Date.now();
|
|
1784
|
-
const domChannel = driver.domChannel;
|
|
1785
|
-
if (!isSystemUISelector(selector) && !isRelativeSelectorLike2(selector) && domChannel?.isConnected() && domChannel.fillDom) {
|
|
1786
|
-
const fillAttempt = yield* Effect4.either(
|
|
1787
|
-
Effect4.tryPromise({
|
|
1788
|
-
try: () => domChannel.fillDom(selector, text, { timeoutMs: timeout }),
|
|
1789
|
-
catch: (e) => new DriverError({ message: `DOM fill failed: ${e}` })
|
|
1790
|
-
})
|
|
1791
|
-
);
|
|
1792
|
-
if (fillAttempt._tag === "Right" && fillAttempt.right) {
|
|
1793
|
-
yield* afterMutation();
|
|
1794
|
-
return;
|
|
1795
|
-
}
|
|
1796
|
-
const remaining = Math.max(50, timeout - (Date.now() - fillStart));
|
|
1797
|
-
const fallbackEl = yield* Effect4.either(
|
|
1798
|
-
waitForActionElement(
|
|
1799
|
-
driver,
|
|
1800
|
-
selector,
|
|
1801
|
-
parse,
|
|
1802
|
-
{
|
|
1803
|
-
...defaults,
|
|
1804
|
-
...opts,
|
|
1805
|
-
timeout: Math.min(remaining, 1500),
|
|
1806
|
-
platform: opts?.platform ?? config.platform
|
|
1807
|
-
},
|
|
1808
|
-
cache
|
|
1809
|
-
)
|
|
1810
|
-
);
|
|
1811
|
-
if (fallbackEl._tag === "Right") {
|
|
1812
|
-
const { x: x2, y: y2 } = centerOf(fallbackEl.right);
|
|
1813
|
-
yield* driver.tapAtCoordinate(x2, y2);
|
|
1814
|
-
const selectAllKey = process.platform === "darwin" ? "Meta+a" : "Control+a";
|
|
1815
|
-
yield* Effect4.either(driver.pressKey(selectAllKey));
|
|
1816
|
-
yield* Effect4.either(driver.pressKey("Backspace"));
|
|
1817
|
-
if (text.length > 0) {
|
|
1818
|
-
yield* driver.inputText(text);
|
|
1819
|
-
}
|
|
1820
|
-
yield* afterMutation();
|
|
1821
|
-
return;
|
|
1822
|
-
}
|
|
1823
|
-
const actionDiag = yield* Effect4.tryPromise({
|
|
1824
|
-
try: () => domChannel.evaluate(buildDomActionabilityDiagScript(selector)),
|
|
1825
|
-
catch: () => null
|
|
1826
|
-
}).pipe(Effect4.catchAll(() => Effect4.succeed(null)));
|
|
1827
|
-
if (actionDiag?.found && actionDiag.obstructedBy) {
|
|
1828
|
-
return yield* new ElementNotFoundError({
|
|
1829
|
-
message: `Element is covered by ${actionDiag.obstructedBy} (not fillable within ${timeout}ms) \u2014 selector: ${formatSelector(selector)}`,
|
|
1830
|
-
selector,
|
|
1831
|
-
timeoutMs: timeout
|
|
1832
|
-
});
|
|
1833
|
-
}
|
|
1834
|
-
if (actionDiag?.found && actionDiag.visible && actionDiag.enabled === false) {
|
|
1835
|
-
return yield* new ElementNotFoundError({
|
|
1836
|
-
message: `Element is disabled (not fillable within ${timeout}ms) \u2014 selector: ${formatSelector(selector)}`,
|
|
1837
|
-
selector,
|
|
1838
|
-
timeoutMs: timeout
|
|
1839
|
-
});
|
|
1840
|
-
}
|
|
1841
|
-
return yield* new ElementNotFoundError({
|
|
1842
|
-
message: `Element not fillable within ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
|
|
1843
|
-
selector,
|
|
1844
|
-
timeoutMs: timeout
|
|
1845
|
-
});
|
|
1846
|
-
}
|
|
1847
|
-
const element = yield* waitForActionElement(
|
|
1848
|
-
driver,
|
|
1849
|
-
selector,
|
|
1850
|
-
parse,
|
|
1851
|
-
{ ...defaults, ...opts, platform: opts?.platform ?? config.platform },
|
|
1852
|
-
cache
|
|
1853
|
-
);
|
|
1854
|
-
const { x, y } = centerOf(element);
|
|
1855
|
-
yield* driver.tapAtCoordinate(x, y);
|
|
1856
|
-
yield* driver.inputText(text);
|
|
1857
|
-
yield* afterMutation();
|
|
1858
|
-
}),
|
|
1859
|
-
pressKey: (key) => Effect4.gen(function* () {
|
|
1860
|
-
yield* driver.pressKey(key);
|
|
1861
|
-
cache.invalidate();
|
|
1862
|
-
}),
|
|
1863
|
-
hideKeyboard: () => Effect4.gen(function* () {
|
|
1864
|
-
yield* driver.hideKeyboard();
|
|
1865
|
-
cache.invalidate();
|
|
1866
|
-
}),
|
|
1867
|
-
dismissKeyboard: (opts) => Effect4.gen(function* () {
|
|
1868
|
-
const strategy = opts?.strategy ?? DEFAULT_DISMISS_KEYBOARD_STRATEGY;
|
|
1869
|
-
if (strategy === "driver") {
|
|
1870
|
-
return yield* dismissKeyboardWithDriver();
|
|
1871
|
-
}
|
|
1872
|
-
if (strategy === "back") {
|
|
1873
|
-
return yield* dismissKeyboardWithBack();
|
|
1874
|
-
}
|
|
1875
|
-
const platform = (yield* driver.getDeviceInfo()).platform;
|
|
1876
|
-
const hideKeyboardResult = yield* Effect4.either(driver.hideKeyboard());
|
|
1877
|
-
if (hideKeyboardResult._tag === "Right") {
|
|
1878
|
-
yield* afterMutation();
|
|
1879
|
-
return;
|
|
1880
|
-
}
|
|
1881
|
-
if (platform === "android") {
|
|
1882
|
-
const backResult = yield* Effect4.either(driver.back());
|
|
1883
|
-
if (backResult._tag === "Right") {
|
|
1884
|
-
yield* afterMutation();
|
|
1885
|
-
return;
|
|
1886
|
-
}
|
|
1887
|
-
return yield* new DriverError({
|
|
1888
|
-
message: `dismissKeyboard() failed with strategy "auto" on android. hideKeyboard(): ${hideKeyboardResult.left.message}. back(): ${backResult.left.message}`
|
|
1889
|
-
});
|
|
1890
|
-
}
|
|
1891
|
-
return yield* new DriverError({
|
|
1892
|
-
message: `dismissKeyboard() failed with strategy "auto" on ${platform}. hideKeyboard(): ${hideKeyboardResult.left.message}`
|
|
1893
|
-
});
|
|
1894
|
-
}),
|
|
1895
|
-
swipe: (direction, opts) => swipeEffect(direction, opts),
|
|
1896
|
-
scroll: (direction) => scrollEffect(direction),
|
|
1897
|
-
scrollUntilVisible: (selector, opts) => Effect4.gen(function* () {
|
|
1898
|
-
const searchDirection = opts?.direction ?? DEFAULT_SCROLL_SEARCH_DIRECTION;
|
|
1899
|
-
const gestureDirection = gestureDirectionForSearch(searchDirection);
|
|
1900
|
-
const maxScrolls = Math.max(0, opts?.maxScrolls ?? DEFAULT_MAX_SCROLLS);
|
|
1901
|
-
const totalTimeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
|
|
1902
|
-
const deadline = Date.now() + totalTimeout;
|
|
1903
|
-
let scrollCount = 0;
|
|
1904
|
-
while (scrollCount <= maxScrolls && Date.now() <= deadline) {
|
|
1905
|
-
const found = yield* probeVisible(selector, opts);
|
|
1906
|
-
if (found) {
|
|
1907
|
-
return;
|
|
1908
|
-
}
|
|
1909
|
-
if (scrollCount === maxScrolls) {
|
|
1910
|
-
break;
|
|
1911
|
-
}
|
|
1912
|
-
yield* scrollEffect(gestureDirection);
|
|
1913
|
-
scrollCount += 1;
|
|
1914
|
-
}
|
|
1915
|
-
return yield* new ElementNotFoundError({
|
|
1916
|
-
message: `Element not found after ${scrollCount} scroll(s) toward ${searchDirection} \u2014 selector: ${formatSelector(selector)}`,
|
|
1917
|
-
selector,
|
|
1918
|
-
timeoutMs: totalTimeout
|
|
1919
|
-
});
|
|
1920
|
-
}),
|
|
1921
|
-
backUntilVisible: (selector, opts) => Effect4.gen(function* () {
|
|
1922
|
-
const maxBacks = Math.max(0, opts?.maxBacks ?? DEFAULT_MAX_BACKS);
|
|
1923
|
-
const totalTimeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
|
|
1924
|
-
const deadline = Date.now() + totalTimeout;
|
|
1925
|
-
let backCount = 0;
|
|
1926
|
-
while (backCount <= maxBacks && Date.now() <= deadline) {
|
|
1927
|
-
const found = yield* probeVisible(selector, opts);
|
|
1928
|
-
if (found) {
|
|
1929
|
-
return;
|
|
1930
|
-
}
|
|
1931
|
-
if (backCount === maxBacks) {
|
|
1932
|
-
break;
|
|
1933
|
-
}
|
|
1934
|
-
const backResult = yield* Effect4.either(driver.back());
|
|
1935
|
-
if (backResult._tag === "Left") {
|
|
1936
|
-
return yield* new DriverError({
|
|
1937
|
-
message: `backUntilVisible() failed on back attempt ${backCount + 1}: ${backResult.left.message}`
|
|
1938
|
-
});
|
|
1939
|
-
}
|
|
1940
|
-
yield* afterMutation();
|
|
1941
|
-
backCount += 1;
|
|
1942
|
-
}
|
|
1943
|
-
return yield* new ElementNotFoundError({
|
|
1944
|
-
message: `Element not found after ${backCount} back action(s) \u2014 selector: ${formatSelector(selector)}. If this screen uses an in-app close or back control, tap that element instead of relying on system back.`,
|
|
1945
|
-
selector,
|
|
1946
|
-
timeoutMs: totalTimeout
|
|
1947
|
-
});
|
|
1948
|
-
}),
|
|
1949
|
-
pinch: (selector, opts) => scaleGesture("pinch", selector, opts),
|
|
1950
|
-
zoom: (selector, opts) => scaleGesture("zoom", selector, opts),
|
|
1951
|
-
multiTouch: (sequences) => Effect4.gen(function* () {
|
|
1952
|
-
if (!driver.multiTouch) {
|
|
1953
|
-
return yield* new DriverError({
|
|
1954
|
-
message: "multiTouch() is only supported on mobile platforms (Android/iOS)"
|
|
1955
|
-
});
|
|
1956
|
-
}
|
|
1957
|
-
yield* driver.multiTouch(sequences);
|
|
1958
|
-
yield* afterMutation();
|
|
1959
|
-
}),
|
|
1960
|
-
...createAssertions()
|
|
1961
|
-
};
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
|
-
// src/api/storybook.ts
|
|
1965
|
-
function assertSafeStorybookToken(group, key, value) {
|
|
1966
|
-
if (/[;:=]/.test(key)) {
|
|
1967
|
-
throw new DriverError({
|
|
1968
|
-
message: `openStory() ${group} key "${key}" contains unsupported Storybook query characters (;, :, =).`
|
|
1969
|
-
});
|
|
1970
|
-
}
|
|
1971
|
-
if (typeof value === "string" && /[;:]/.test(value)) {
|
|
1972
|
-
throw new DriverError({
|
|
1973
|
-
message: `openStory() ${group}.${key} contains unsupported Storybook query characters (; or :).`
|
|
1974
|
-
});
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
function encodeStorybookValue(value) {
|
|
1978
|
-
if (value === null) {
|
|
1979
|
-
return "!null";
|
|
1980
|
-
}
|
|
1981
|
-
return String(value);
|
|
1982
|
-
}
|
|
1983
|
-
function encodeStorybookEntries(group, entries) {
|
|
1984
|
-
if (!entries) {
|
|
1985
|
-
return void 0;
|
|
1986
|
-
}
|
|
1987
|
-
const pairs = Object.entries(entries);
|
|
1988
|
-
if (pairs.length === 0) {
|
|
1989
|
-
return void 0;
|
|
1990
|
-
}
|
|
1991
|
-
return pairs.map(([key, value]) => {
|
|
1992
|
-
assertSafeStorybookToken(group, key, value);
|
|
1993
|
-
return `${key}:${encodeStorybookValue(value)}`;
|
|
1994
|
-
}).join(";");
|
|
1995
|
-
}
|
|
1996
|
-
function buildStorybookUrl(storyId, options, runtime) {
|
|
1997
|
-
const trimmedStoryId = storyId.trim();
|
|
1998
|
-
if (!trimmedStoryId) {
|
|
1999
|
-
throw new DriverError({ message: "openStory() requires a non-empty Storybook story ID." });
|
|
2000
|
-
}
|
|
2001
|
-
const baseUrl = options?.baseUrl ?? runtime.storybook?.url ?? runtime.appBaseUrl;
|
|
2002
|
-
if (!baseUrl) {
|
|
2003
|
-
throw new DriverError({
|
|
2004
|
-
message: "openStory() requires apps.web.url, execution.web.storybook.url, or options.baseUrl."
|
|
2005
|
-
});
|
|
2006
|
-
}
|
|
2007
|
-
let url;
|
|
2008
|
-
try {
|
|
2009
|
-
url = new URL(runtime.storybook?.iframePath ?? "/iframe.html", baseUrl);
|
|
2010
|
-
} catch (error) {
|
|
2011
|
-
throw new DriverError({
|
|
2012
|
-
message: `openStory() could not build a Storybook URL from "${baseUrl}": ${error instanceof Error ? error.message : String(error)}`
|
|
2013
|
-
});
|
|
2014
|
-
}
|
|
2015
|
-
url.searchParams.set("id", trimmedStoryId);
|
|
2016
|
-
url.searchParams.set("viewMode", options?.viewMode ?? "story");
|
|
2017
|
-
const args = encodeStorybookEntries("args", options?.args);
|
|
2018
|
-
if (args) {
|
|
2019
|
-
url.searchParams.set("args", args);
|
|
2020
|
-
}
|
|
2021
|
-
const globals = encodeStorybookEntries("globals", options?.globals);
|
|
2022
|
-
if (globals) {
|
|
2023
|
-
url.searchParams.set("globals", globals);
|
|
2024
|
-
}
|
|
2025
|
-
return url.toString();
|
|
2026
|
-
}
|
|
2027
|
-
|
|
2028
|
-
// src/api/expect.ts
|
|
2029
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
2030
|
-
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
2031
|
-
import { dirname, resolve as resolvePath } from "path";
|
|
2032
|
-
import { Effect as Effect5 } from "effect";
|
|
2033
|
-
function selectorToCss(sel) {
|
|
2034
|
-
if (typeof sel === "string") return sel;
|
|
2035
|
-
if (typeof sel === "object" && sel !== null && "css" in sel && sel.css) return sel.css;
|
|
2036
|
-
if (typeof sel === "object" && sel !== null && "testID" in sel && sel.testID)
|
|
2037
|
-
return `[data-testid="${sel.testID}"]`;
|
|
2038
|
-
if (typeof sel === "object" && sel !== null && "accessibilityLabel" in sel && sel.accessibilityLabel)
|
|
2039
|
-
return `[aria-label="${sel.accessibilityLabel}"]`;
|
|
2040
|
-
return "";
|
|
2041
|
-
}
|
|
2042
|
-
function deepEqual(a, b) {
|
|
2043
|
-
if (Object.is(a, b)) return true;
|
|
2044
|
-
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") return false;
|
|
2045
|
-
if (a instanceof RegExp && b instanceof RegExp)
|
|
2046
|
-
return a.source === b.source && a.flags === b.flags;
|
|
2047
|
-
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
|
2048
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
2049
|
-
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
|
|
2050
|
-
for (let i = 0; i < a.length; i++) {
|
|
2051
|
-
if (!deepEqual(a[i], b[i])) return false;
|
|
2052
|
-
}
|
|
2053
|
-
return true;
|
|
2054
|
-
}
|
|
2055
|
-
const aKeys = Object.keys(a);
|
|
2056
|
-
const bKeys = Object.keys(b);
|
|
2057
|
-
if (aKeys.length !== bKeys.length) return false;
|
|
2058
|
-
for (const k of aKeys) {
|
|
2059
|
-
if (!Object.prototype.hasOwnProperty.call(b, k) || !deepEqual(a[k], b[k])) {
|
|
2060
|
-
return false;
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
|
-
return true;
|
|
2064
|
-
}
|
|
2065
|
-
var retryScope = new AsyncLocalStorage();
|
|
2066
|
-
var defaultRetryIntervals = [50, 100, 250, 500];
|
|
2067
|
-
function normalizeAriaSnapshot(snapshot) {
|
|
2068
|
-
const lines = snapshot.replaceAll("\r\n", "\n").trimEnd().split("\n");
|
|
2069
|
-
while (lines[0]?.trim() === "" && lines.length > 1) lines.shift();
|
|
2070
|
-
const indentation = lines.reduce(
|
|
2071
|
-
(minimum, line) => line.trim() ? Math.min(minimum, /^ */.exec(line)[0].length) : minimum,
|
|
2072
|
-
Infinity
|
|
2073
|
-
);
|
|
2074
|
-
return lines.map((line) => line.slice(indentation)).join("\n");
|
|
2075
|
-
}
|
|
2076
|
-
async function retryAssertion(check, timeout, intervals = defaultRetryIntervals) {
|
|
2077
|
-
if (!Number.isFinite(timeout) || timeout < 0 || intervals.some((ms) => !Number.isFinite(ms) || ms < 0)) {
|
|
2078
|
-
throw new RangeError("Assertion timeout and intervals must be finite, non-negative numbers");
|
|
2079
|
-
}
|
|
2080
|
-
if (intervals.length === 0) intervals = defaultRetryIntervals;
|
|
2081
|
-
let lastFailure;
|
|
2082
|
-
let expired = false;
|
|
2083
|
-
let delayTimer;
|
|
2084
|
-
let timeoutTimer;
|
|
2085
|
-
const deadline = new Promise((_, reject) => {
|
|
2086
|
-
timeoutTimer = setTimeout(() => {
|
|
2087
|
-
expired = true;
|
|
2088
|
-
const detail = lastFailure instanceof Error ? lastFailure.message : String(lastFailure);
|
|
2089
|
-
reject(
|
|
2090
|
-
new Error(
|
|
2091
|
-
`Assertion timed out after ${timeout}ms${lastFailure === void 0 ? "" : `: ${detail}`}`,
|
|
2092
|
-
{ cause: lastFailure }
|
|
2093
|
-
)
|
|
2094
|
-
);
|
|
2095
|
-
}, timeout);
|
|
2096
|
-
});
|
|
2097
|
-
const attempts = async () => {
|
|
2098
|
-
for (let attempt = 0; ; attempt++) {
|
|
2099
|
-
if (expired) return;
|
|
2100
|
-
try {
|
|
2101
|
-
await retryScope.run(true, check);
|
|
2102
|
-
return;
|
|
2103
|
-
} catch (error) {
|
|
2104
|
-
if (expired) return;
|
|
2105
|
-
lastFailure = error;
|
|
2106
|
-
const interval = intervals[Math.min(attempt, intervals.length - 1)];
|
|
2107
|
-
await new Promise((resolve2) => {
|
|
2108
|
-
delayTimer = setTimeout(resolve2, interval);
|
|
2109
|
-
});
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
};
|
|
2113
|
-
try {
|
|
2114
|
-
await Promise.race([deadline, attempts()]);
|
|
2115
|
-
} finally {
|
|
2116
|
-
clearTimeout(timeoutTimer);
|
|
2117
|
-
clearTimeout(delayTimer);
|
|
2118
|
-
}
|
|
2119
|
-
}
|
|
2120
|
-
function createPromiseExpect(driver, config, recorder, flowContext, visualRegression) {
|
|
2121
|
-
const ctx = flowContext ?? {
|
|
2122
|
-
flowFilePath: "",
|
|
2123
|
-
flowName: "unknown",
|
|
2124
|
-
platform: "web"
|
|
2125
|
-
};
|
|
2126
|
-
const coord = createCoordinator(driver, config);
|
|
2127
|
-
const defaultTimeout = config.defaults?.timeout ?? 5e3;
|
|
2128
|
-
const run2 = (effect) => Effect5.runPromise(effect);
|
|
2129
|
-
const recordSoft = async (action) => {
|
|
2130
|
-
if (!ctx.recordSoftFailure || retryScope.getStore()) return action();
|
|
2131
|
-
try {
|
|
2132
|
-
await action();
|
|
2133
|
-
} catch (error) {
|
|
2134
|
-
ctx.recordSoftFailure(error);
|
|
2135
|
-
}
|
|
2136
|
-
};
|
|
2137
|
-
const recordStep = (command, action, selector) => recorder && !retryScope.getStore() ? recorder.runStep(command, action, { selector, captureScreenshot: false }) : action();
|
|
2138
|
-
const runSelectorStep = (command, selector, action) => recordStep(command, action, selector);
|
|
2139
|
-
const runSoftSelectorStep = (command, selector, action) => recordSoft(() => runSelectorStep(command, selector, action));
|
|
2140
|
-
const buildNegatedExpectation = (selector, runStep) => ({
|
|
2141
|
-
toBeVisible: (opts) => runStep("expect.not.toBeVisible", selector, () => run2(coord.assertHidden(selector, opts))),
|
|
2142
|
-
toBeHidden: (opts) => runStep(
|
|
2143
|
-
"expect.not.toBeHidden",
|
|
2144
|
-
selector,
|
|
2145
|
-
() => run2(coord.assertVisible(selector, opts)).then(() => {
|
|
2146
|
-
})
|
|
2147
|
-
),
|
|
2148
|
-
toHaveText: (expected, opts) => runStep(
|
|
2149
|
-
`expect.not.toHaveText(${JSON.stringify(expected)})`,
|
|
2150
|
-
selector,
|
|
2151
|
-
() => run2(coord.assertText(selector, expected, opts, true))
|
|
2152
|
-
),
|
|
2153
|
-
toMatchText: (pattern, opts) => runStep(
|
|
2154
|
-
`expect.not.toMatchText(${pattern})`,
|
|
2155
|
-
selector,
|
|
2156
|
-
() => run2(coord.assertMatchesText(selector, pattern, opts, true))
|
|
2157
|
-
),
|
|
2158
|
-
toHaveValue: (expected, opts) => runStep(
|
|
2159
|
-
`expect.not.toHaveValue(${JSON.stringify(expected)})`,
|
|
2160
|
-
selector,
|
|
2161
|
-
() => run2(coord.assertValue(selector, expected, opts, true))
|
|
2162
|
-
),
|
|
2163
|
-
toHaveAttribute: (name, value, opts) => runStep(
|
|
2164
|
-
`expect.not.toHaveAttribute(${JSON.stringify(name)})`,
|
|
2165
|
-
selector,
|
|
2166
|
-
() => run2(coord.assertAttribute(selector, name, value, opts, true))
|
|
2167
|
-
),
|
|
2168
|
-
toBeEnabled: (opts) => runStep("expect.not.toBeEnabled", selector, () => run2(coord.assertDisabled(selector, opts))),
|
|
2169
|
-
toBeDisabled: (opts) => runStep("expect.not.toBeDisabled", selector, () => run2(coord.assertEnabled(selector, opts))),
|
|
2170
|
-
toContainText: (expected, opts) => runStep(
|
|
2171
|
-
`expect.not.toContainText(${JSON.stringify(expected)})`,
|
|
2172
|
-
selector,
|
|
2173
|
-
() => run2(coord.assertContainsText(selector, expected, opts, true))
|
|
2174
|
-
),
|
|
2175
|
-
toHaveCount: (expected, opts) => runStep(
|
|
2176
|
-
`expect.not.toHaveCount(${expected})`,
|
|
2177
|
-
selector,
|
|
2178
|
-
() => run2(coord.assertCount(selector, expected, opts, true))
|
|
2179
|
-
),
|
|
2180
|
-
toBeFocused: (opts) => runStep(
|
|
2181
|
-
"expect.not.toBeFocused",
|
|
2182
|
-
selector,
|
|
2183
|
-
() => run2(coord.assertFocused(selector, opts, true))
|
|
2184
|
-
),
|
|
2185
|
-
toHaveAccessibleName: (expected, opts) => runStep(
|
|
2186
|
-
`expect.not.toHaveAccessibleName(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2187
|
-
selector,
|
|
2188
|
-
() => run2(coord.assertAccessibleName(selector, expected, opts, true))
|
|
2189
|
-
),
|
|
2190
|
-
toHaveAccessibleDescription: (expected, opts) => runStep(
|
|
2191
|
-
`expect.not.toHaveAccessibleDescription(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2192
|
-
selector,
|
|
2193
|
-
() => run2(coord.assertAccessibleDescription(selector, expected, opts, true))
|
|
2194
|
-
)
|
|
2195
|
-
});
|
|
2196
|
-
const buildPollMatchers = (fn, opts, negate) => {
|
|
2197
|
-
const check = (label, predicate, describeFail) => recordStep(
|
|
2198
|
-
`expect.poll.${negate ? "not." : ""}${label}`,
|
|
2199
|
-
() => retryAssertion(
|
|
2200
|
-
async () => {
|
|
2201
|
-
const val = await fn();
|
|
2202
|
-
const ok = predicate(val);
|
|
2203
|
-
if (negate ? ok : !ok) {
|
|
2204
|
-
throw new Error(describeFail(val));
|
|
2205
|
-
}
|
|
2206
|
-
},
|
|
2207
|
-
opts?.timeout ?? defaultTimeout,
|
|
2208
|
-
opts?.intervals
|
|
2209
|
-
)
|
|
2210
|
-
);
|
|
2211
|
-
return {
|
|
2212
|
-
toBe: (expected) => check(
|
|
2213
|
-
`toBe(${JSON.stringify(expected)})`,
|
|
2214
|
-
(v) => Object.is(v, expected),
|
|
2215
|
-
(v) => negate ? `Expected polled value NOT to be ${JSON.stringify(expected)}` : `Expected polled value to be ${JSON.stringify(expected)}, received ${JSON.stringify(v)}`
|
|
2216
|
-
),
|
|
2217
|
-
toEqual: (expected) => check(
|
|
2218
|
-
`toEqual(${JSON.stringify(expected)})`,
|
|
2219
|
-
(v) => deepEqual(v, expected),
|
|
2220
|
-
(v) => negate ? `Expected polled value NOT to equal ${JSON.stringify(expected)}` : `Expected polled value to equal ${JSON.stringify(expected)}, received ${JSON.stringify(v)}`
|
|
2221
|
-
),
|
|
2222
|
-
toContain: (expected) => check(
|
|
2223
|
-
`toContain(${JSON.stringify(expected)})`,
|
|
2224
|
-
(v) => {
|
|
2225
|
-
if (typeof v === "string") return v.includes(String(expected));
|
|
2226
|
-
if (Array.isArray(v)) return v.some((item) => deepEqual(item, expected));
|
|
2227
|
-
return false;
|
|
2228
|
-
},
|
|
2229
|
-
(v) => negate ? `Expected polled value NOT to contain ${JSON.stringify(expected)}, received ${JSON.stringify(v)}` : `Expected polled value to contain ${JSON.stringify(expected)}, received ${JSON.stringify(v)}`
|
|
2230
|
-
),
|
|
2231
|
-
toMatch: (pattern) => check(
|
|
2232
|
-
`toMatch(${pattern instanceof RegExp ? String(pattern) : JSON.stringify(pattern)})`,
|
|
2233
|
-
(v) => {
|
|
2234
|
-
const str = String(v ?? "");
|
|
2235
|
-
return pattern instanceof RegExp ? pattern.test(str) : str.includes(pattern);
|
|
2236
|
-
},
|
|
2237
|
-
(v) => negate ? `Expected polled value NOT to match ${String(pattern)}, received ${JSON.stringify(v)}` : `Expected polled value to match ${String(pattern)}, received ${JSON.stringify(v)}`
|
|
2238
|
-
),
|
|
2239
|
-
toBeGreaterThan: (expected) => check(
|
|
2240
|
-
`toBeGreaterThan(${expected})`,
|
|
2241
|
-
(v) => typeof v === "number" && v > expected,
|
|
2242
|
-
(v) => negate ? `Expected polled value NOT to be > ${expected}, received ${String(v)}` : `Expected polled value > ${expected}, received ${String(v)}`
|
|
2243
|
-
),
|
|
2244
|
-
toBeLessThan: (expected) => check(
|
|
2245
|
-
`toBeLessThan(${expected})`,
|
|
2246
|
-
(v) => typeof v === "number" && v < expected,
|
|
2247
|
-
(v) => negate ? `Expected polled value NOT to be < ${expected}, received ${String(v)}` : `Expected polled value < ${expected}, received ${String(v)}`
|
|
2248
|
-
),
|
|
2249
|
-
toBeGreaterThanOrEqual: (expected) => check(
|
|
2250
|
-
`toBeGreaterThanOrEqual(${expected})`,
|
|
2251
|
-
(v) => typeof v === "number" && v >= expected,
|
|
2252
|
-
(v) => negate ? `Expected polled value NOT to be >= ${expected}, received ${String(v)}` : `Expected polled value >= ${expected}, received ${String(v)}`
|
|
2253
|
-
),
|
|
2254
|
-
toBeLessThanOrEqual: (expected) => check(
|
|
2255
|
-
`toBeLessThanOrEqual(${expected})`,
|
|
2256
|
-
(v) => typeof v === "number" && v <= expected,
|
|
2257
|
-
(v) => negate ? `Expected polled value NOT to be <= ${expected}, received ${String(v)}` : `Expected polled value <= ${expected}, received ${String(v)}`
|
|
2258
|
-
),
|
|
2259
|
-
toBeTruthy: () => check(
|
|
2260
|
-
"toBeTruthy",
|
|
2261
|
-
(v) => Boolean(v),
|
|
2262
|
-
(v) => negate ? `Expected polled value NOT to be truthy, received ${JSON.stringify(v)}` : `Expected polled value to be truthy, received ${JSON.stringify(v)}`
|
|
2263
|
-
),
|
|
2264
|
-
toBeFalsy: () => check(
|
|
2265
|
-
"toBeFalsy",
|
|
2266
|
-
(v) => !v,
|
|
2267
|
-
(v) => negate ? `Expected polled value NOT to be falsy, received ${JSON.stringify(v)}` : `Expected polled value to be falsy, received ${JSON.stringify(v)}`
|
|
2268
|
-
),
|
|
2269
|
-
toBeDefined: () => check(
|
|
2270
|
-
"toBeDefined",
|
|
2271
|
-
(v) => v !== void 0,
|
|
2272
|
-
() => negate ? `Expected polled value to be undefined` : `Expected polled value to be defined`
|
|
2273
|
-
),
|
|
2274
|
-
toBeUndefined: () => check(
|
|
2275
|
-
"toBeUndefined",
|
|
2276
|
-
(v) => v === void 0,
|
|
2277
|
-
(v) => negate ? `Expected polled value NOT to be undefined` : `Expected polled value to be undefined, received ${JSON.stringify(v)}`
|
|
2278
|
-
),
|
|
2279
|
-
toHaveLength: (expected) => check(
|
|
2280
|
-
`toHaveLength(${expected})`,
|
|
2281
|
-
(v) => v !== null && v !== void 0 && typeof v.length === "number" && v.length === expected,
|
|
2282
|
-
(v) => negate ? `Expected polled value NOT to have length ${expected}` : `Expected polled value to have length ${expected}, received ${JSON.stringify(v)}`
|
|
2283
|
-
)
|
|
2284
|
-
};
|
|
2285
|
-
};
|
|
2286
|
-
const buildSelectorExpectation = (selector, runStep) => ({
|
|
2287
|
-
toBeVisible: (opts) => runStep(
|
|
2288
|
-
"expect.toBeVisible",
|
|
2289
|
-
selector,
|
|
2290
|
-
() => run2(coord.assertVisible(selector, opts)).then(() => {
|
|
2291
|
-
})
|
|
2292
|
-
),
|
|
2293
|
-
toBeHidden: (opts) => runStep("expect.toBeHidden", selector, () => run2(coord.assertHidden(selector, opts))),
|
|
2294
|
-
toHaveText: (expected, opts) => runStep(
|
|
2295
|
-
`expect.toHaveText(${JSON.stringify(expected)})`,
|
|
2296
|
-
selector,
|
|
2297
|
-
() => run2(coord.assertText(selector, expected, opts))
|
|
2298
|
-
),
|
|
2299
|
-
toMatchText: (pattern, opts) => runStep(
|
|
2300
|
-
`expect.toMatchText(${pattern})`,
|
|
2301
|
-
selector,
|
|
2302
|
-
() => run2(coord.assertMatchesText(selector, pattern, opts))
|
|
2303
|
-
),
|
|
2304
|
-
toHaveValue: (expected, opts) => runStep(
|
|
2305
|
-
`expect.toHaveValue(${JSON.stringify(expected)})`,
|
|
2306
|
-
selector,
|
|
2307
|
-
() => run2(coord.assertValue(selector, expected, opts))
|
|
2308
|
-
),
|
|
2309
|
-
toHaveAttribute: (name, value, opts) => runStep(
|
|
2310
|
-
`expect.toHaveAttribute(${JSON.stringify(name)})`,
|
|
2311
|
-
selector,
|
|
2312
|
-
() => run2(coord.assertAttribute(selector, name, value, opts))
|
|
2313
|
-
),
|
|
2314
|
-
toBeEnabled: (opts) => runStep("expect.toBeEnabled", selector, () => run2(coord.assertEnabled(selector, opts))),
|
|
2315
|
-
toBeDisabled: (opts) => runStep("expect.toBeDisabled", selector, () => run2(coord.assertDisabled(selector, opts))),
|
|
2316
|
-
toContainText: (expected, opts) => runStep(
|
|
2317
|
-
`expect.toContainText(${JSON.stringify(expected)})`,
|
|
2318
|
-
selector,
|
|
2319
|
-
() => run2(coord.assertContainsText(selector, expected, opts))
|
|
2320
|
-
),
|
|
2321
|
-
toHaveCount: (expected, opts) => runStep(
|
|
2322
|
-
`expect.toHaveCount(${expected})`,
|
|
2323
|
-
selector,
|
|
2324
|
-
() => run2(coord.assertCount(selector, expected, opts))
|
|
2325
|
-
),
|
|
2326
|
-
toBeFocused: (opts) => runStep("expect.toBeFocused", selector, () => run2(coord.assertFocused(selector, opts))),
|
|
2327
|
-
toHaveAccessibleName: (expected, opts) => runStep(
|
|
2328
|
-
`expect.toHaveAccessibleName(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2329
|
-
selector,
|
|
2330
|
-
() => run2(coord.assertAccessibleName(selector, expected, opts))
|
|
2331
|
-
),
|
|
2332
|
-
toHaveAccessibleDescription: (expected, opts) => runStep(
|
|
2333
|
-
`expect.toHaveAccessibleDescription(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2334
|
-
selector,
|
|
2335
|
-
() => run2(coord.assertAccessibleDescription(selector, expected, opts))
|
|
2336
|
-
),
|
|
2337
|
-
not: buildNegatedExpectation(selector, runStep),
|
|
2338
|
-
toMatchAriaSnapshot: (expected, opts) => runStep("expect.toMatchAriaSnapshot", selector, async () => {
|
|
2339
|
-
if (!driver.getAriaSnapshot) {
|
|
2340
|
-
throw new Error(
|
|
2341
|
-
`toMatchAriaSnapshot() is not supported on ${ctx.platform} with the current driver`
|
|
2342
|
-
);
|
|
2343
|
-
}
|
|
2344
|
-
if (isRelativeSelector(selector))
|
|
2345
|
-
throw new Error("ARIA snapshots require a locator, not a relative selector");
|
|
2346
|
-
const timeout = opts?.timeout ?? defaultTimeout;
|
|
2347
|
-
const path = typeof expected === "string" ? void 0 : resolvePath(dirname(ctx.flowFilePath), expected.path);
|
|
2348
|
-
if (path && ctx.updateBaselines) {
|
|
2349
|
-
const actual = await run2(driver.getAriaSnapshot(selector, timeout));
|
|
2350
|
-
await mkdir(dirname(path), { recursive: true });
|
|
2351
|
-
await writeFile(path, `${normalizeAriaSnapshot(actual)}
|
|
2352
|
-
`, "utf8");
|
|
2353
|
-
return;
|
|
2354
|
-
}
|
|
2355
|
-
const baseline = normalizeAriaSnapshot(
|
|
2356
|
-
typeof expected === "string" ? expected : await readFile(path, "utf8")
|
|
2357
|
-
);
|
|
2358
|
-
await retryAssertion(
|
|
2359
|
-
async () => {
|
|
2360
|
-
const actual = normalizeAriaSnapshot(
|
|
2361
|
-
await run2(driver.getAriaSnapshot(selector, timeout))
|
|
2362
|
-
);
|
|
2363
|
-
if (actual !== baseline)
|
|
2364
|
-
throw new Error(
|
|
2365
|
-
`ARIA snapshot did not match.
|
|
2366
|
-
Expected:
|
|
2367
|
-
${baseline}
|
|
2368
|
-
Received:
|
|
2369
|
-
${actual}`
|
|
2370
|
-
);
|
|
2371
|
-
},
|
|
2372
|
-
timeout,
|
|
2373
|
-
opts?.intervals
|
|
2374
|
-
);
|
|
2375
|
-
}),
|
|
2376
|
-
toMatchScreenshot: (name, options) => runStep(
|
|
2377
|
-
`expect.toMatchScreenshot(${JSON.stringify(name)})`,
|
|
2378
|
-
selector,
|
|
2379
|
-
() => run2(
|
|
2380
|
-
coord.assertScreenshot(selector, name, ctx.flowFilePath, ctx.flowName, ctx.platform, {
|
|
2381
|
-
threshold: options?.threshold ?? visualRegression?.threshold,
|
|
2382
|
-
maxDiffPixelRatio: options?.maxDiffPixelRatio ?? visualRegression?.maxDiffPixelRatio,
|
|
2383
|
-
mask: [],
|
|
2384
|
-
updateBaselines: ctx.updateBaselines,
|
|
2385
|
-
baselinesDir: visualRegression?.baselinesDir
|
|
2386
|
-
})
|
|
2387
|
-
)
|
|
2388
|
-
),
|
|
2389
|
-
toPassAccessibilityAudit: (options) => {
|
|
2390
|
-
const excludeCss = options?.exclude?.map(selectorToCss).filter(Boolean) ?? [];
|
|
2391
|
-
const targetCss = selectorToCss(selector);
|
|
2392
|
-
return runStep(
|
|
2393
|
-
"expect.toPassAccessibilityAudit",
|
|
2394
|
-
selector,
|
|
2395
|
-
() => run2(
|
|
2396
|
-
coord.assertAccessibilityAudit(ctx.platform, {
|
|
2397
|
-
severity: options?.severity,
|
|
2398
|
-
rules: options?.rules,
|
|
2399
|
-
targetSelector: targetCss || void 0,
|
|
2400
|
-
excludeSelectors: excludeCss
|
|
2401
|
-
})
|
|
2402
|
-
)
|
|
2403
|
-
);
|
|
2404
|
-
},
|
|
2405
|
-
toHaveAccessibilityLabel: (expected) => runStep(
|
|
2406
|
-
`expect.toHaveAccessibilityLabel(${expected !== void 0 ? JSON.stringify(expected) : ""})`,
|
|
2407
|
-
selector,
|
|
2408
|
-
() => run2(coord.assertAccessibilityLabel(selector, expected))
|
|
2409
|
-
),
|
|
2410
|
-
toBeFocusable: () => runStep(
|
|
2411
|
-
"expect.toBeFocusable",
|
|
2412
|
-
selector,
|
|
2413
|
-
() => run2(coord.assertFocusable(selector, ctx.platform))
|
|
2414
|
-
),
|
|
2415
|
-
toHaveRole: (expected) => runStep(
|
|
2416
|
-
`expect.toHaveRole(${JSON.stringify(expected)})`,
|
|
2417
|
-
selector,
|
|
2418
|
-
() => run2(coord.assertRole(selector, expected, ctx.platform))
|
|
2419
|
-
),
|
|
2420
|
-
toHaveMinTouchTarget: (size = 44) => runStep(
|
|
2421
|
-
`expect.toHaveMinTouchTarget(${size})`,
|
|
2422
|
-
selector,
|
|
2423
|
-
() => run2(coord.assertMinTouchTarget(selector, size))
|
|
2424
|
-
)
|
|
2425
|
-
});
|
|
2426
|
-
const expectFn = ((selectorOrFn) => {
|
|
2427
|
-
if (typeof selectorOrFn !== "function") {
|
|
2428
|
-
return buildSelectorExpectation(selectorOrFn, runSelectorStep);
|
|
2429
|
-
}
|
|
2430
|
-
return {
|
|
2431
|
-
toPass: (opts) => recordStep(
|
|
2432
|
-
"expect.toPass",
|
|
2433
|
-
() => retryAssertion(selectorOrFn, opts?.timeout ?? defaultTimeout, opts?.intervals)
|
|
2434
|
-
)
|
|
2435
|
-
};
|
|
2436
|
-
});
|
|
2437
|
-
const toHaveURL = (expected, opts) => {
|
|
2438
|
-
const label = `expect.toHaveURL(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`;
|
|
2439
|
-
return recordStep(label, () => run2(coord.waitForURL(expected, opts)));
|
|
2440
|
-
};
|
|
2441
|
-
expectFn.toHaveURL = toHaveURL;
|
|
2442
|
-
expectFn.soft = Object.assign(
|
|
2443
|
-
(selector) => buildSelectorExpectation(selector, runSoftSelectorStep),
|
|
2444
|
-
{
|
|
2445
|
-
toHaveURL: (expected, opts) => recordSoft(() => toHaveURL(expected, opts))
|
|
2446
|
-
}
|
|
2447
|
-
);
|
|
2448
|
-
Object.defineProperty(expectFn, "not", {
|
|
2449
|
-
enumerable: true,
|
|
2450
|
-
value: {
|
|
2451
|
-
toHaveURL: (expected, opts) => {
|
|
2452
|
-
const label = `expect.not.toHaveURL(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`;
|
|
2453
|
-
return recordStep(label, () => run2(coord.waitForURL(expected, opts, true)));
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
});
|
|
2457
|
-
expectFn.poll = (fn, opts) => ({
|
|
2458
|
-
...buildPollMatchers(fn, opts, false),
|
|
2459
|
-
not: buildPollMatchers(fn, opts, true)
|
|
2460
|
-
});
|
|
2461
|
-
return expectFn;
|
|
2462
|
-
}
|
|
2463
|
-
|
|
2464
|
-
// src/api/app.ts
|
|
2465
|
-
import { Effect as Effect6 } from "effect";
|
|
2466
|
-
|
|
2467
|
-
// src/drivers/launch-options.ts
|
|
2468
|
-
function mergeRecord(base, override) {
|
|
2469
|
-
if (!base && !override) return void 0;
|
|
2470
|
-
return { ...base, ...override };
|
|
2471
|
-
}
|
|
2472
|
-
function stringifyLaunchValue(value) {
|
|
2473
|
-
if (typeof value === "string") return value;
|
|
2474
|
-
if (typeof value === "number" || typeof value === "boolean" || value == null) {
|
|
2475
|
-
return String(value);
|
|
2476
|
-
}
|
|
2477
|
-
return JSON.stringify(value);
|
|
2478
|
-
}
|
|
2479
|
-
function splitLocale(locale) {
|
|
2480
|
-
if (!locale) return {};
|
|
2481
|
-
const [language, ...rest] = locale.split(/[-_]/).filter(Boolean);
|
|
2482
|
-
if (!language || rest.length === 0) {
|
|
2483
|
-
return {};
|
|
2484
|
-
}
|
|
2485
|
-
return { language, remainder: rest.join("_") };
|
|
2486
|
-
}
|
|
2487
|
-
function resolveAndroidDeviceState(deviceState) {
|
|
2488
|
-
if (!deviceState) return {};
|
|
2489
|
-
const split = splitLocale(deviceState.locale);
|
|
2490
|
-
return {
|
|
2491
|
-
language: deviceState.language ?? split.language,
|
|
2492
|
-
locale: split.remainder ?? deviceState.locale,
|
|
2493
|
-
timeZone: deviceState.timeZone
|
|
2494
|
-
};
|
|
2495
|
-
}
|
|
2496
|
-
function resolveIOSDeviceState(deviceState) {
|
|
2497
|
-
if (!deviceState) return {};
|
|
2498
|
-
const split = splitLocale(deviceState.locale);
|
|
2499
|
-
const language = deviceState.language ?? split.language;
|
|
2500
|
-
const locale = deviceState.locale && split.remainder && language ? `${language}_${split.remainder}` : deviceState.locale && !split.remainder && language ? `${language}_${deviceState.locale}` : deviceState.locale?.replaceAll("-", "_");
|
|
2501
|
-
return {
|
|
2502
|
-
language,
|
|
2503
|
-
locale,
|
|
2504
|
-
timeZone: deviceState.timeZone
|
|
2505
|
-
};
|
|
2506
|
-
}
|
|
2507
|
-
function mergeLaunchOptions(base, override) {
|
|
2508
|
-
if (!base && !override) return void 0;
|
|
2509
|
-
return {
|
|
2510
|
-
...base,
|
|
2511
|
-
...override,
|
|
2512
|
-
launchArguments: mergeRecord(base?.launchArguments, override?.launchArguments),
|
|
2513
|
-
deviceState: mergeRecord(base?.deviceState, override?.deviceState)
|
|
2514
|
-
};
|
|
2515
|
-
}
|
|
2516
|
-
function hasLaunchDeviceState(deviceState) {
|
|
2517
|
-
return Boolean(deviceState?.language || deviceState?.locale || deviceState?.timeZone);
|
|
2518
|
-
}
|
|
2519
|
-
function deviceStateToAppiumCapabilities(platform, deviceState) {
|
|
2520
|
-
const normalizedState = platform === "android" ? resolveAndroidDeviceState(deviceState) : resolveIOSDeviceState(deviceState);
|
|
2521
|
-
if (!normalizedState.language && !normalizedState.locale && !normalizedState.timeZone) return {};
|
|
2522
|
-
if (platform === "android") {
|
|
2523
|
-
const hasLanguage = Boolean(normalizedState.language);
|
|
2524
|
-
const hasLocale = Boolean(normalizedState.locale);
|
|
2525
|
-
if (hasLanguage !== hasLocale) {
|
|
2526
|
-
throw new Error(
|
|
2527
|
-
"Appium Android deviceState requires both language and locale when either is provided."
|
|
2528
|
-
);
|
|
2529
|
-
}
|
|
2530
|
-
}
|
|
2531
|
-
const capabilities = {};
|
|
2532
|
-
if (normalizedState.language) {
|
|
2533
|
-
capabilities["appium:language"] = normalizedState.language;
|
|
2534
|
-
}
|
|
2535
|
-
if (normalizedState.locale) {
|
|
2536
|
-
capabilities["appium:locale"] = normalizedState.locale;
|
|
2537
|
-
}
|
|
2538
|
-
if (normalizedState.timeZone) {
|
|
2539
|
-
capabilities[platform === "ios" ? "appium:appTimeZone" : "appium:timeZone"] = normalizedState.timeZone;
|
|
2540
|
-
}
|
|
2541
|
-
return capabilities;
|
|
2542
|
-
}
|
|
2543
|
-
function buildIOSLaunchConfiguration(options) {
|
|
2544
|
-
if (!options) return void 0;
|
|
2545
|
-
const argumentsList = [];
|
|
2546
|
-
const environment = {};
|
|
2547
|
-
const normalizedState = resolveIOSDeviceState(options.deviceState);
|
|
2548
|
-
if (normalizedState.language) {
|
|
2549
|
-
argumentsList.push("-AppleLanguages", `(${normalizedState.language})`);
|
|
2550
|
-
}
|
|
2551
|
-
if (normalizedState.locale) {
|
|
2552
|
-
argumentsList.push("-AppleLocale", normalizedState.locale);
|
|
2553
|
-
}
|
|
2554
|
-
if (options.launchArguments) {
|
|
2555
|
-
for (const [key, value] of Object.entries(options.launchArguments)) {
|
|
2556
|
-
argumentsList.push(`-${key}`, stringifyLaunchValue(value));
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
if (normalizedState.timeZone) {
|
|
2560
|
-
environment.TZ = normalizedState.timeZone;
|
|
2561
|
-
}
|
|
2562
|
-
if (argumentsList.length === 0 && Object.keys(environment).length === 0) {
|
|
2563
|
-
return void 0;
|
|
2564
|
-
}
|
|
2565
|
-
return {
|
|
2566
|
-
arguments: argumentsList.length > 0 ? argumentsList : void 0,
|
|
2567
|
-
environment: Object.keys(environment).length > 0 ? environment : void 0
|
|
2568
|
-
};
|
|
2569
|
-
}
|
|
2570
|
-
|
|
2571
|
-
// src/api/app.ts
|
|
2572
|
-
var describeMatcher = (matcher) => typeof matcher === "string" ? matcher : matcher.toString();
|
|
2573
|
-
function formatEvaluateCommand(fn) {
|
|
2574
|
-
const raw = typeof fn === "string" ? fn : fn.toString();
|
|
2575
|
-
const compact = raw.replaceAll(/\s+/g, " ").trim();
|
|
2576
|
-
const snippet = compact.length > 72 ? `${compact.slice(0, 69)}...` : compact;
|
|
2577
|
-
return `evaluate(${snippet})`;
|
|
2578
|
-
}
|
|
2579
|
-
function parseSetCookieHeader(headerValue, originUrl) {
|
|
2580
|
-
const parts = headerValue.split(";").map((p) => p.trim());
|
|
2581
|
-
const first2 = parts[0];
|
|
2582
|
-
if (!first2) return null;
|
|
2583
|
-
const eqIdx = first2.indexOf("=");
|
|
2584
|
-
if (eqIdx <= 0) return null;
|
|
2585
|
-
const name = first2.slice(0, eqIdx).trim();
|
|
2586
|
-
const value = first2.slice(eqIdx + 1).trim();
|
|
2587
|
-
const cookie = {
|
|
2588
|
-
name,
|
|
2589
|
-
value,
|
|
2590
|
-
url: `${originUrl.origin}/`,
|
|
2591
|
-
path: "/"
|
|
2592
|
-
};
|
|
2593
|
-
for (const attr of parts.slice(1)) {
|
|
2594
|
-
const [rawK, ...rest] = attr.split("=");
|
|
2595
|
-
const k = (rawK ?? "").trim().toLowerCase();
|
|
2596
|
-
const v = rest.join("=").trim();
|
|
2597
|
-
if (k === "path" && v) cookie.path = v;
|
|
2598
|
-
else if (k === "domain" && v) {
|
|
2599
|
-
cookie.domain = v;
|
|
2600
|
-
delete cookie.url;
|
|
2601
|
-
} else if (k === "httponly") cookie.httpOnly = true;
|
|
2602
|
-
else if (k === "secure") cookie.secure = true;
|
|
2603
|
-
else if (k === "samesite") {
|
|
2604
|
-
const norm = v.toLowerCase();
|
|
2605
|
-
if (norm === "strict") cookie.sameSite = "Strict";
|
|
2606
|
-
else if (norm === "lax") cookie.sameSite = "Lax";
|
|
2607
|
-
else if (norm === "none") cookie.sameSite = "None";
|
|
2608
|
-
} else if (k === "max-age") {
|
|
2609
|
-
const sec = Number.parseInt(v, 10);
|
|
2610
|
-
if (Number.isFinite(sec)) cookie.expires = Math.floor(Date.now() / 1e3) + sec;
|
|
2611
|
-
} else if (k === "expires") {
|
|
2612
|
-
const ts = Date.parse(v);
|
|
2613
|
-
if (Number.isFinite(ts)) cookie.expires = Math.floor(ts / 1e3);
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
return cookie;
|
|
2617
|
-
}
|
|
2618
|
-
var RECORDED_RAW_PAGE_METHODS = /* @__PURE__ */ new Set([
|
|
2619
|
-
"goto",
|
|
2620
|
-
"reload",
|
|
2621
|
-
"click",
|
|
2622
|
-
"dblclick",
|
|
2623
|
-
"fill",
|
|
2624
|
-
"hover",
|
|
2625
|
-
"press",
|
|
2626
|
-
"type",
|
|
2627
|
-
"check",
|
|
2628
|
-
"uncheck",
|
|
2629
|
-
"selectOption",
|
|
2630
|
-
"setInputFiles",
|
|
2631
|
-
"waitForURL",
|
|
2632
|
-
"waitForResponse",
|
|
2633
|
-
"waitForSelector",
|
|
2634
|
-
"evaluate"
|
|
2635
|
-
]);
|
|
2636
|
-
function wrapRawPageWithStepRecording(rawPage, recorder) {
|
|
2637
|
-
if (!recorder || !rawPage || typeof rawPage !== "object") return rawPage;
|
|
2638
|
-
const candidate = rawPage;
|
|
2639
|
-
if (typeof candidate["goto"] !== "function" || typeof candidate["click"] !== "function") {
|
|
2640
|
-
return rawPage;
|
|
2641
|
-
}
|
|
2642
|
-
return new Proxy(candidate, {
|
|
2643
|
-
get(target, prop, receiver) {
|
|
2644
|
-
if (prop === "then") return void 0;
|
|
2645
|
-
const value = Reflect.get(target, prop, receiver);
|
|
2646
|
-
if (typeof value !== "function") return value;
|
|
2647
|
-
if (typeof prop === "string" && RECORDED_RAW_PAGE_METHODS.has(prop)) {
|
|
2648
|
-
return (...callArgs) => {
|
|
2649
|
-
const argHint = typeof callArgs[0] === "string" ? callArgs[0].length > 60 ? `${callArgs[0].slice(0, 57)}...` : callArgs[0] : void 0;
|
|
2650
|
-
const cmd = argHint ? `page.${prop}(${JSON.stringify(argHint)})` : `page.${prop}`;
|
|
2651
|
-
return recorder.runStep(cmd, () => Promise.resolve(value.apply(target, callArgs)), {
|
|
2652
|
-
captureScreenshot: false
|
|
2653
|
-
});
|
|
2654
|
-
};
|
|
2655
|
-
}
|
|
2656
|
-
return value.bind(target);
|
|
2657
|
-
}
|
|
2658
|
-
});
|
|
2659
|
-
}
|
|
2660
|
-
function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
2661
|
-
const coord = createCoordinator(driver, config);
|
|
2662
|
-
const platform = options.platform ?? (appId.startsWith("http://") || appId.startsWith("https://") ? "web" : void 0);
|
|
2663
|
-
const run2 = (effect) => Effect6.runPromise(effect);
|
|
2664
|
-
const unsupportedWebFeature = (feature) => Effect6.fail(new DriverError({ message: `${feature}() is only supported on the web platform` }));
|
|
2665
|
-
const optionalMethod = (name, method) => method ?? ((..._args) => unsupportedWebFeature(name));
|
|
2666
|
-
const unsupportedNetworkFeature = async (name) => {
|
|
2667
|
-
const target = platform ?? (await run2(driver.getDeviceInfo())).platform;
|
|
2668
|
-
throw new DriverError({
|
|
2669
|
-
message: `${name}() is not supported on ${target} with the current driver`
|
|
2670
|
-
});
|
|
2671
|
-
};
|
|
2672
|
-
const runStep = (command, action, opts) => recorder ? recorder.runStep(command, action, opts) : action();
|
|
2673
|
-
const runDeviceStep = (name, method, ...args) => runStep(name, async () => {
|
|
2674
|
-
if (!method) {
|
|
2675
|
-
const target = platform ?? (await run2(driver.getDeviceInfo())).platform;
|
|
2676
|
-
throw new DriverError({ message: `${name}() is not supported on ${target}` });
|
|
2677
|
-
}
|
|
2678
|
-
await run2(method(...args));
|
|
2679
|
-
});
|
|
2680
|
-
const runScreenshotStep = (command, action, opts) => recorder ? recorder.runScreenshotStep(command, action, opts) : action();
|
|
2681
|
-
const getCurrentUrl = async () => {
|
|
2682
|
-
if (driver.getUrl) {
|
|
2683
|
-
return run2(driver.getUrl());
|
|
2684
|
-
}
|
|
2685
|
-
return run2(
|
|
2686
|
-
driver.evaluate(
|
|
2687
|
-
"typeof window !== 'undefined' && window.location ? String(window.location.href || '') : ''"
|
|
2688
|
-
).pipe(Effect6.catchAll(() => Effect6.succeed("")))
|
|
2689
|
-
);
|
|
2690
|
-
};
|
|
2691
|
-
const resolveRequestUrl = async (rawUrl) => {
|
|
2692
|
-
if (rawUrl.startsWith("http://") || rawUrl.startsWith("https://")) {
|
|
2693
|
-
return new URL(rawUrl);
|
|
2694
|
-
}
|
|
2695
|
-
const pageUrl = await getCurrentUrl();
|
|
2696
|
-
const base = pageUrl && (pageUrl.startsWith("http://") || pageUrl.startsWith("https://")) ? pageUrl : appId.startsWith("http://") || appId.startsWith("https://") ? appId : "http://localhost";
|
|
2697
|
-
return new URL(rawUrl, base);
|
|
2698
|
-
};
|
|
2699
|
-
const performBrowserRequest = async (method, rawUrl, init) => {
|
|
2700
|
-
const targetUrl = await resolveRequestUrl(rawUrl);
|
|
2701
|
-
if (init?.query) {
|
|
2702
|
-
for (const [k, v] of Object.entries(init.query)) {
|
|
2703
|
-
if (v !== void 0) targetUrl.searchParams.set(k, String(v));
|
|
2704
|
-
}
|
|
2705
|
-
}
|
|
2706
|
-
const headers = { ...init?.headers };
|
|
2707
|
-
const hasCookieHeader = Object.keys(headers).some((k) => k.toLowerCase() === "cookie");
|
|
2708
|
-
if (!hasCookieHeader && driver.getCookies) {
|
|
2709
|
-
const cookies = await run2(driver.getCookies([targetUrl.toString()])).catch(() => []);
|
|
2710
|
-
if (cookies.length > 0) {
|
|
2711
|
-
headers["cookie"] = cookies.map((c) => `${c.name}=${c.value}`).join("; ");
|
|
2712
|
-
}
|
|
2713
|
-
}
|
|
2714
|
-
let requestBody;
|
|
2715
|
-
if (init?.body !== void 0) {
|
|
2716
|
-
if (typeof init.body === "string") {
|
|
2717
|
-
requestBody = init.body;
|
|
2718
|
-
} else {
|
|
2719
|
-
requestBody = JSON.stringify(init.body);
|
|
2720
|
-
if (!Object.keys(headers).some((k) => k.toLowerCase() === "content-type")) {
|
|
2721
|
-
headers["content-type"] = "application/json";
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2724
|
-
}
|
|
2725
|
-
const res = await fetch(targetUrl.toString(), {
|
|
2726
|
-
method,
|
|
2727
|
-
headers,
|
|
2728
|
-
...requestBody !== void 0 ? { body: requestBody } : {},
|
|
2729
|
-
...init?.signal ? { signal: init.signal } : {}
|
|
2730
|
-
});
|
|
2731
|
-
if (driver.setCookies) {
|
|
2732
|
-
const rawSetCookies = typeof res.headers.getSetCookie === "function" ? res.headers.getSetCookie() : res.headers.get("set-cookie") ? [res.headers.get("set-cookie")] : [];
|
|
2733
|
-
const parsedCookies = rawSetCookies.map((line) => parseSetCookieHeader(line, targetUrl)).filter((c) => c !== null);
|
|
2734
|
-
if (parsedCookies.length > 0) {
|
|
2735
|
-
await run2(driver.setCookies(parsedCookies)).catch(() => {
|
|
2736
|
-
});
|
|
2737
|
-
}
|
|
2738
|
-
}
|
|
2739
|
-
const rawText = await res.text();
|
|
2740
|
-
const contentType = res.headers.get("content-type") ?? "";
|
|
2741
|
-
let data = rawText;
|
|
2742
|
-
if (contentType.includes("application/json")) {
|
|
2743
|
-
try {
|
|
2744
|
-
data = JSON.parse(rawText);
|
|
2745
|
-
} catch {
|
|
2746
|
-
data = rawText;
|
|
2747
|
-
}
|
|
2748
|
-
} else if (rawText.trim().startsWith("{") || rawText.trim().startsWith("[")) {
|
|
2749
|
-
try {
|
|
2750
|
-
data = JSON.parse(rawText);
|
|
2751
|
-
} catch {
|
|
2752
|
-
data = rawText;
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
return {
|
|
2756
|
-
status: res.status,
|
|
2757
|
-
statusText: res.statusText,
|
|
2758
|
-
ok: res.ok,
|
|
2759
|
-
url: res.url || targetUrl.toString(),
|
|
2760
|
-
headers: res.headers,
|
|
2761
|
-
data,
|
|
2762
|
-
text: async () => rawText,
|
|
2763
|
-
json: async () => JSON.parse(rawText)
|
|
2764
|
-
};
|
|
2765
|
-
};
|
|
2766
|
-
const requestClient = {
|
|
2767
|
-
fetch: (url, init) => {
|
|
2768
|
-
const method = (init?.method ?? "GET").toUpperCase();
|
|
2769
|
-
return runStep(
|
|
2770
|
-
`request.${method}(${url})`,
|
|
2771
|
-
() => performBrowserRequest(method, url, init)
|
|
2772
|
-
);
|
|
2773
|
-
},
|
|
2774
|
-
get: (url, opts) => runStep(`request.GET(${url})`, () => performBrowserRequest("GET", url, opts)),
|
|
2775
|
-
post: (url, body, opts) => runStep(
|
|
2776
|
-
`request.POST(${url})`,
|
|
2777
|
-
() => performBrowserRequest("POST", url, { ...opts, body })
|
|
2778
|
-
),
|
|
2779
|
-
put: (url, body, opts) => runStep(
|
|
2780
|
-
`request.PUT(${url})`,
|
|
2781
|
-
() => performBrowserRequest("PUT", url, { ...opts, body })
|
|
2782
|
-
),
|
|
2783
|
-
patch: (url, body, opts) => runStep(
|
|
2784
|
-
`request.PATCH(${url})`,
|
|
2785
|
-
() => performBrowserRequest("PATCH", url, { ...opts, body })
|
|
2786
|
-
),
|
|
2787
|
-
delete: (url, opts) => runStep(`request.DELETE(${url})`, () => performBrowserRequest("DELETE", url, opts))
|
|
2788
|
-
};
|
|
2789
|
-
const appExpect = createPromiseExpect(
|
|
2790
|
-
driver,
|
|
2791
|
-
config,
|
|
2792
|
-
recorder,
|
|
2793
|
-
options.flowContext,
|
|
2794
|
-
options.visualRegression
|
|
2795
|
-
);
|
|
2796
|
-
const appObj = {
|
|
2797
|
-
setGeolocation: (point) => runDeviceStep("setGeolocation", driver.setGeolocation, point),
|
|
2798
|
-
setSystemTime: (time) => runDeviceStep("setSystemTime", driver.setSystemTime, time),
|
|
2799
|
-
grantPermission: (permission, opts) => runDeviceStep("grantPermission", driver.setPermission, appId, permission, "grant", opts),
|
|
2800
|
-
denyPermission: (permission, opts) => runDeviceStep("denyPermission", driver.setPermission, appId, permission, "deny", opts),
|
|
2801
|
-
setOrientation: (orientation) => runDeviceStep("setOrientation", driver.setOrientation, orientation),
|
|
2802
|
-
setBiometricEnrollment: (enabled) => runDeviceStep("setBiometricEnrollment", driver.setBiometricEnrollment, enabled),
|
|
2803
|
-
simulateBiometric: (opts) => runDeviceStep("simulateBiometric", driver.simulateBiometric, opts),
|
|
2804
|
-
sendPushNotification: (payload) => runDeviceStep("sendPushNotification", driver.sendPushNotification, appId, payload),
|
|
2805
|
-
tap: (selector, opts) => runStep("tap", () => run2(coord.tap(selector, opts)), { selector, captureScreenshot: true }),
|
|
2806
|
-
tapXY: (x, y) => runStep("tapXY", () => run2(coord.tapXY(x, y)), {
|
|
2807
|
-
selector: { point: { x, y } },
|
|
2808
|
-
captureScreenshot: true
|
|
2809
|
-
}),
|
|
2810
|
-
doubleTap: (selector, opts) => runStep("doubleTap", () => run2(coord.doubleTap(selector, opts)), {
|
|
2811
|
-
selector,
|
|
2812
|
-
captureScreenshot: true
|
|
2813
|
-
}),
|
|
2814
|
-
longPress: (selector, opts) => runStep("longPress", () => run2(coord.longPress(selector, opts?.duration, opts)), {
|
|
2815
|
-
selector,
|
|
2816
|
-
captureScreenshot: true
|
|
2817
|
-
}),
|
|
2818
|
-
longPressXY: (x, y, opts) => runStep("longPressXY", () => run2(coord.longPressXY(x, y, opts?.duration)), {
|
|
2819
|
-
selector: { point: { x, y } },
|
|
2820
|
-
captureScreenshot: true
|
|
2821
|
-
}),
|
|
2822
|
-
hover: (selector, opts) => runStep("hover", () => run2(coord.hover(selector, opts)), {
|
|
2823
|
-
selector,
|
|
2824
|
-
captureScreenshot: true
|
|
2825
|
-
}),
|
|
2826
|
-
inputText: (text) => runStep("inputText", () => run2(coord.inputText(text)), { captureScreenshot: true }),
|
|
2827
|
-
fill: (selector, value, opts) => runStep("fill", () => run2(coord.fill(selector, value, opts)), {
|
|
2828
|
-
selector,
|
|
2829
|
-
captureScreenshot: true
|
|
2830
|
-
}),
|
|
2831
|
-
pressKey: (key) => runStep(`pressKey(${key})`, () => run2(coord.pressKey(key)), { captureScreenshot: true }),
|
|
2832
|
-
hideKeyboard: () => runStep("hideKeyboard", () => run2(coord.hideKeyboard()), { captureScreenshot: true }),
|
|
2833
|
-
dismissKeyboard: (opts) => runStep(
|
|
2834
|
-
`dismissKeyboard(${opts?.strategy ?? "auto"})`,
|
|
2835
|
-
() => run2(coord.dismissKeyboard(opts)),
|
|
2836
|
-
{
|
|
2837
|
-
selector: { strategy: opts?.strategy ?? "auto" },
|
|
2838
|
-
captureScreenshot: true
|
|
2839
|
-
}
|
|
2840
|
-
),
|
|
2841
|
-
swipe: (direction, opts) => runStep(`swipe(${direction})`, () => run2(coord.swipe(direction, opts)), {
|
|
2842
|
-
captureScreenshot: true
|
|
2843
|
-
}),
|
|
2844
|
-
scroll: (direction) => runStep(`scroll(${direction})`, () => run2(coord.scroll(direction)), {
|
|
2845
|
-
captureScreenshot: true
|
|
2846
|
-
}),
|
|
2847
|
-
scrollUntilVisible: (selector, opts) => runStep(
|
|
2848
|
-
`scrollUntilVisible(${opts?.direction ?? "down"})`,
|
|
2849
|
-
() => run2(coord.scrollUntilVisible(selector, opts)),
|
|
2850
|
-
{
|
|
2851
|
-
selector: {
|
|
2852
|
-
target: selector,
|
|
2853
|
-
...opts,
|
|
2854
|
-
direction: opts?.direction ?? "down",
|
|
2855
|
-
maxScrolls: opts?.maxScrolls ?? 5
|
|
2856
|
-
},
|
|
2857
|
-
captureScreenshot: true
|
|
2858
|
-
}
|
|
2859
|
-
),
|
|
2860
|
-
backUntilVisible: (selector, opts) => runStep(
|
|
2861
|
-
`backUntilVisible(${opts?.maxBacks ?? 3})`,
|
|
2862
|
-
() => run2(coord.backUntilVisible(selector, opts)),
|
|
2863
|
-
{
|
|
2864
|
-
selector: {
|
|
2865
|
-
target: selector,
|
|
2866
|
-
...opts,
|
|
2867
|
-
maxBacks: opts?.maxBacks ?? 3
|
|
2868
|
-
},
|
|
2869
|
-
captureScreenshot: true
|
|
2870
|
-
}
|
|
2871
|
-
),
|
|
2872
|
-
launch: (opts) => {
|
|
2873
|
-
const mergedLaunchOptions = mergeLaunchOptions(options.launchOptions, opts);
|
|
2874
|
-
return runStep("launch", () => run2(driver.launchApp(appId, mergedLaunchOptions)), {
|
|
2875
|
-
selector: mergedLaunchOptions,
|
|
2876
|
-
captureScreenshot: true
|
|
2877
|
-
});
|
|
2878
|
-
},
|
|
2879
|
-
stop: () => runStep("stop", () => run2(driver.stopApp(appId)), { captureScreenshot: true }),
|
|
2880
|
-
kill: () => runStep("kill", () => run2(driver.killApp(appId)), { captureScreenshot: true }),
|
|
2881
|
-
clearState: () => runStep("clearState", () => run2(driver.clearAppState(appId)), { captureScreenshot: true }),
|
|
2882
|
-
openLink: (url) => runStep("openLink", () => run2(driver.openLink(url)), {
|
|
2883
|
-
selector: { url },
|
|
2884
|
-
captureScreenshot: true
|
|
2885
|
-
}),
|
|
2886
|
-
openStory: (storyId, opts) => runStep(
|
|
2887
|
-
`openStory(${storyId})`,
|
|
2888
|
-
async () => {
|
|
2889
|
-
if (platform !== "web") {
|
|
2890
|
-
await run2(unsupportedWebFeature("openStory"));
|
|
2891
|
-
return;
|
|
2892
|
-
}
|
|
2893
|
-
const url = buildStorybookUrl(storyId, opts, {
|
|
2894
|
-
appBaseUrl: appId,
|
|
2895
|
-
storybook: options.storybook
|
|
2896
|
-
});
|
|
2897
|
-
await run2(driver.openLink(url));
|
|
2898
|
-
},
|
|
2899
|
-
{
|
|
2900
|
-
selector: {
|
|
2901
|
-
storyId,
|
|
2902
|
-
viewMode: opts?.viewMode ?? "story",
|
|
2903
|
-
args: opts?.args,
|
|
2904
|
-
globals: opts?.globals,
|
|
2905
|
-
baseUrl: opts?.baseUrl
|
|
2906
|
-
},
|
|
2907
|
-
captureScreenshot: true
|
|
2908
|
-
}
|
|
2909
|
-
),
|
|
2910
|
-
back: () => runStep("back", () => run2(driver.back()), { captureScreenshot: true }),
|
|
2911
|
-
reload: (opts) => runStep(
|
|
2912
|
-
"reload",
|
|
2913
|
-
async () => {
|
|
2914
|
-
if (driver.reload) {
|
|
2915
|
-
await run2(driver.reload(opts));
|
|
2916
|
-
return;
|
|
2917
|
-
}
|
|
2918
|
-
if (driver.domChannel?.reload) {
|
|
2919
|
-
await driver.domChannel.reload();
|
|
2920
|
-
return;
|
|
2921
|
-
}
|
|
2922
|
-
await run2(driver.evaluate("window.location.reload()"));
|
|
2923
|
-
},
|
|
2924
|
-
{ captureScreenshot: true }
|
|
2925
|
-
),
|
|
2926
|
-
url: () => runStep("url", () => getCurrentUrl()),
|
|
2927
|
-
waitForURL: (expected, opts) => runStep(
|
|
2928
|
-
`waitForURL(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2929
|
-
() => run2(coord.waitForURL(expected, opts))
|
|
2930
|
-
),
|
|
2931
|
-
waitForResponse: (matcher, opts) => runStep(
|
|
2932
|
-
`waitForResponse(${typeof matcher === "function" ? "<predicate>" : describeMatcher(matcher)})`,
|
|
2933
|
-
() => run2(optionalMethod("waitForResponse", driver.waitForResponse)(matcher, opts))
|
|
2934
|
-
),
|
|
2935
|
-
takeScreenshot: (name) => runScreenshotStep(
|
|
2936
|
-
name ? `takeScreenshot(${name})` : "takeScreenshot",
|
|
2937
|
-
() => run2(driver.takeScreenshot()),
|
|
2938
|
-
{ name }
|
|
2939
|
-
),
|
|
2940
|
-
evaluate: (fn, ...args) => runStep(
|
|
2941
|
-
formatEvaluateCommand(fn),
|
|
2942
|
-
() => run2(driver.evaluate(fn, ...args))
|
|
2943
|
-
),
|
|
2944
|
-
mockNetwork: (matcher, response) => runStep(
|
|
2945
|
-
"mockNetwork",
|
|
2946
|
-
() => driver.mockNetwork ? run2(driver.mockNetwork(matcher, response)) : unsupportedNetworkFeature("mockNetwork"),
|
|
2947
|
-
{
|
|
2948
|
-
selector: { matcher: describeMatcher(matcher), response }
|
|
2949
|
-
}
|
|
2950
|
-
),
|
|
2951
|
-
blockNetwork: (matcher) => runStep(
|
|
2952
|
-
"blockNetwork",
|
|
2953
|
-
() => driver.blockNetwork ? run2(driver.blockNetwork(matcher)) : unsupportedNetworkFeature("blockNetwork"),
|
|
2954
|
-
{
|
|
2955
|
-
selector: { matcher: describeMatcher(matcher) }
|
|
2956
|
-
}
|
|
2957
|
-
),
|
|
2958
|
-
clearNetworkMocks: () => runStep(
|
|
2959
|
-
"clearNetworkMocks",
|
|
2960
|
-
() => driver.clearNetworkMocks ? run2(driver.clearNetworkMocks()) : unsupportedNetworkFeature("clearNetworkMocks")
|
|
2961
|
-
),
|
|
2962
|
-
setNetworkConditions: (conditions) => runStep(
|
|
2963
|
-
"setNetworkConditions",
|
|
2964
|
-
() => run2(optionalMethod("setNetworkConditions", driver.setNetworkConditions)(conditions)),
|
|
2965
|
-
{ selector: conditions }
|
|
2966
|
-
),
|
|
2967
|
-
setOffline: (offline) => runStep(
|
|
2968
|
-
`setOffline(${offline})`,
|
|
2969
|
-
() => run2(optionalMethod("setOffline", driver.setNetworkConditions)({ offline })),
|
|
2970
|
-
{ selector: { offline } }
|
|
2971
|
-
),
|
|
2972
|
-
saveCookies: (path) => runStep("saveCookies", () => run2(optionalMethod("saveCookies", driver.saveCookies)(path)), {
|
|
2973
|
-
selector: { path }
|
|
2974
|
-
}),
|
|
2975
|
-
loadCookies: (path) => runStep("loadCookies", () => run2(optionalMethod("loadCookies", driver.loadCookies)(path)), {
|
|
2976
|
-
selector: { path }
|
|
2977
|
-
}),
|
|
2978
|
-
getCookies: (urls) => runStep("getCookies", () => run2(optionalMethod("getCookies", driver.getCookies)(urls))),
|
|
2979
|
-
setCookies: (cookies) => runStep("setCookies", () => run2(optionalMethod("setCookies", driver.setCookies)(cookies)), {
|
|
2980
|
-
selector: { count: cookies.length }
|
|
2981
|
-
}),
|
|
2982
|
-
clearCookies: () => runStep("clearCookies", () => run2(optionalMethod("clearCookies", driver.clearCookies)())),
|
|
2983
|
-
saveAuthState: (path) => runStep(
|
|
2984
|
-
"saveAuthState",
|
|
2985
|
-
() => run2(optionalMethod("saveAuthState", driver.saveAuthState)(path)),
|
|
2986
|
-
{ selector: { path } }
|
|
2987
|
-
),
|
|
2988
|
-
loadAuthState: (path) => runStep(
|
|
2989
|
-
"loadAuthState",
|
|
2990
|
-
() => run2(optionalMethod("loadAuthState", driver.loadAuthState)(path)),
|
|
2991
|
-
{ selector: { path } }
|
|
2992
|
-
),
|
|
2993
|
-
downloadFile: (path) => runStep(
|
|
2994
|
-
"downloadFile",
|
|
2995
|
-
() => run2(optionalMethod("downloadFile", driver.downloadFile)(path)),
|
|
2996
|
-
{ selector: { path } }
|
|
2997
|
-
),
|
|
2998
|
-
uploadFile: (selector, path) => runStep(
|
|
2999
|
-
"uploadFile",
|
|
3000
|
-
() => run2(optionalMethod("uploadFile", driver.uploadFile)(selector, path)),
|
|
3001
|
-
{
|
|
3002
|
-
selector: { target: selector, path },
|
|
3003
|
-
captureScreenshot: true
|
|
3004
|
-
}
|
|
3005
|
-
),
|
|
3006
|
-
newTab: (url) => runStep("newTab", () => run2(optionalMethod("newTab", driver.newTab)(url)), {
|
|
3007
|
-
selector: url ? { url } : void 0,
|
|
3008
|
-
captureScreenshot: true
|
|
3009
|
-
}),
|
|
3010
|
-
switchToTab: (index) => runStep(
|
|
3011
|
-
`switchToTab(${index})`,
|
|
3012
|
-
() => run2(optionalMethod("switchToTab", driver.switchToTab)(index)),
|
|
3013
|
-
{
|
|
3014
|
-
selector: { index },
|
|
3015
|
-
captureScreenshot: true
|
|
3016
|
-
}
|
|
3017
|
-
),
|
|
3018
|
-
closeTab: () => runStep("closeTab", () => run2(optionalMethod("closeTab", driver.closeTab)()), {
|
|
3019
|
-
captureScreenshot: true
|
|
3020
|
-
}),
|
|
3021
|
-
getTabIds: () => runStep("getTabIds", () => run2(optionalMethod("getTabIds", driver.getTabIds)())),
|
|
3022
|
-
getConsoleLogs: () => runStep(
|
|
3023
|
-
"getConsoleLogs",
|
|
3024
|
-
() => run2(optionalMethod("getConsoleLogs", driver.getConsoleLogs)())
|
|
3025
|
-
),
|
|
3026
|
-
getJSErrors: () => runStep("getJSErrors", () => run2(optionalMethod("getJSErrors", driver.getJSErrors)())),
|
|
3027
|
-
getHAR: () => runStep("getHAR", () => run2(optionalMethod("getHAR", driver.getHAR)())),
|
|
3028
|
-
request: requestClient,
|
|
3029
|
-
newContext: (ctxOpts) => runStep(
|
|
3030
|
-
"newContext",
|
|
3031
|
-
async () => {
|
|
3032
|
-
const created = await run2(
|
|
3033
|
-
optionalMethod("newContext", driver.createIsolatedContext)(ctxOpts)
|
|
3034
|
-
);
|
|
3035
|
-
let closed = false;
|
|
3036
|
-
const safeClose = async () => {
|
|
3037
|
-
if (closed) return;
|
|
3038
|
-
closed = true;
|
|
3039
|
-
await created.close();
|
|
3040
|
-
};
|
|
3041
|
-
options.onRegisterCleanup?.(safeClose);
|
|
3042
|
-
const childDriver = created.driver;
|
|
3043
|
-
const childApp = createPromiseApp(childDriver, appId, config, recorder, options);
|
|
3044
|
-
const childExpect = createPromiseExpect(
|
|
3045
|
-
childDriver,
|
|
3046
|
-
config,
|
|
3047
|
-
recorder,
|
|
3048
|
-
options.flowContext,
|
|
3049
|
-
options.visualRegression
|
|
3050
|
-
);
|
|
3051
|
-
return { app: childApp, expect: childExpect, close: safeClose };
|
|
3052
|
-
},
|
|
3053
|
-
{ selector: ctxOpts }
|
|
3054
|
-
),
|
|
3055
|
-
frame: (frameSelector) => {
|
|
3056
|
-
const scoped = (sel) => inFrame(frameSelector, sel);
|
|
3057
|
-
return {
|
|
3058
|
-
tap: (sel, opts) => appObj.tap(scoped(sel), opts),
|
|
3059
|
-
doubleTap: (sel, opts) => appObj.doubleTap(scoped(sel), opts),
|
|
3060
|
-
longPress: (sel, opts) => appObj.longPress(scoped(sel), opts),
|
|
3061
|
-
hover: (sel, opts) => appObj.hover(scoped(sel), opts),
|
|
3062
|
-
fill: (sel, value, opts) => appObj.fill(scoped(sel), value, opts),
|
|
3063
|
-
uploadFile: (sel, path) => appObj.uploadFile(scoped(sel), path),
|
|
3064
|
-
getText: (sel, opts) => appObj.getText(scoped(sel), opts),
|
|
3065
|
-
getAttribute: (sel, name, opts) => appObj.getAttribute(scoped(sel), name, opts),
|
|
3066
|
-
isVisible: (sel, opts) => appObj.isVisible(scoped(sel), opts),
|
|
3067
|
-
isEnabled: (sel, opts) => appObj.isEnabled(scoped(sel), opts),
|
|
3068
|
-
count: (sel, opts) => appObj.count(scoped(sel), opts),
|
|
3069
|
-
expect: (sel) => appExpect(scoped(sel))
|
|
3070
|
-
};
|
|
3071
|
-
},
|
|
3072
|
-
getPage: () => {
|
|
3073
|
-
if (!driver.getRawPage) {
|
|
3074
|
-
throw new DriverError({
|
|
3075
|
-
message: "getPage() is only available when running with a browser driver that exposes a raw page."
|
|
3076
|
-
});
|
|
3077
|
-
}
|
|
3078
|
-
return wrapRawPageWithStepRecording(driver.getRawPage(), recorder);
|
|
3079
|
-
},
|
|
3080
|
-
cdp: () => {
|
|
3081
|
-
const raw = driver.getCdpSession?.();
|
|
3082
|
-
if (!raw) {
|
|
3083
|
-
throw new DriverError({
|
|
3084
|
-
message: "app.cdp() is only available on Chromium web drivers (Direct CDP or Playwright Chromium)."
|
|
3085
|
-
});
|
|
3086
|
-
}
|
|
3087
|
-
return {
|
|
3088
|
-
send: (method, params) => runStep(`cdp.${method}`, () => raw.send(method, params), {
|
|
3089
|
-
selector: params
|
|
3090
|
-
}),
|
|
3091
|
-
on: (event, listener) => raw.on(event, listener),
|
|
3092
|
-
get sessionId() {
|
|
3093
|
-
return raw.sessionId;
|
|
3094
|
-
},
|
|
3095
|
-
get browserContextId() {
|
|
3096
|
-
return raw.browserContextId;
|
|
3097
|
-
}
|
|
3098
|
-
};
|
|
3099
|
-
},
|
|
3100
|
-
enableVirtualAuthenticator: (opts) => runStep(
|
|
3101
|
-
"enableVirtualAuthenticator",
|
|
3102
|
-
() => run2(
|
|
3103
|
-
optionalMethod("enableVirtualAuthenticator", driver.enableVirtualAuthenticator)(opts)
|
|
3104
|
-
),
|
|
3105
|
-
{ selector: opts }
|
|
3106
|
-
),
|
|
3107
|
-
removeVirtualAuthenticator: (authenticatorId) => runStep(
|
|
3108
|
-
"removeVirtualAuthenticator",
|
|
3109
|
-
() => run2(
|
|
3110
|
-
optionalMethod(
|
|
3111
|
-
"removeVirtualAuthenticator",
|
|
3112
|
-
driver.removeVirtualAuthenticator
|
|
3113
|
-
)(authenticatorId)
|
|
3114
|
-
)
|
|
3115
|
-
),
|
|
3116
|
-
getVirtualCredentials: (authenticatorId) => runStep(
|
|
3117
|
-
"getVirtualCredentials",
|
|
3118
|
-
() => run2(optionalMethod("getVirtualCredentials", driver.getVirtualCredentials)(authenticatorId))
|
|
3119
|
-
),
|
|
3120
|
-
addVirtualCredential: (credential, authenticatorId) => runStep(
|
|
3121
|
-
"addVirtualCredential",
|
|
3122
|
-
() => run2(
|
|
3123
|
-
optionalMethod("addVirtualCredential", driver.addVirtualCredential)(
|
|
3124
|
-
credential,
|
|
3125
|
-
authenticatorId
|
|
3126
|
-
)
|
|
3127
|
-
),
|
|
3128
|
-
{ selector: { credentialId: credential.credentialId, rpId: credential.rpId } }
|
|
3129
|
-
),
|
|
3130
|
-
clearVirtualCredentials: (authenticatorId) => runStep(
|
|
3131
|
-
"clearVirtualCredentials",
|
|
3132
|
-
() => run2(
|
|
3133
|
-
optionalMethod(
|
|
3134
|
-
"clearVirtualCredentials",
|
|
3135
|
-
driver.clearVirtualCredentials
|
|
3136
|
-
)(authenticatorId)
|
|
3137
|
-
)
|
|
3138
|
-
),
|
|
3139
|
-
pinch: (selector, opts) => runStep("pinch", () => run2(coord.pinch(selector, opts)), {
|
|
3140
|
-
selector,
|
|
3141
|
-
captureScreenshot: true
|
|
3142
|
-
}),
|
|
3143
|
-
zoom: (selector, opts) => runStep("zoom", () => run2(coord.zoom(selector, opts)), {
|
|
3144
|
-
selector,
|
|
3145
|
-
captureScreenshot: true
|
|
3146
|
-
}),
|
|
3147
|
-
multiTouch: (sequences) => runStep("multiTouch", () => run2(coord.multiTouch(sequences)), { captureScreenshot: true }),
|
|
3148
|
-
getText: (selector, opts) => runStep("getText", () => run2(coord.getText(selector, opts)), { selector }),
|
|
3149
|
-
getAttribute: (selector, name, opts) => runStep(`getAttribute(${name})`, () => run2(coord.getAttribute(selector, name, opts)), {
|
|
3150
|
-
selector
|
|
3151
|
-
}),
|
|
3152
|
-
isVisible: (selector, opts) => {
|
|
3153
|
-
const timeout = opts?.timeout ?? 1e3;
|
|
3154
|
-
return run2(
|
|
3155
|
-
Effect6.gen(function* () {
|
|
3156
|
-
const result = yield* Effect6.either(
|
|
3157
|
-
waitForElement(
|
|
3158
|
-
driver,
|
|
3159
|
-
selector,
|
|
3160
|
-
config.parse,
|
|
3161
|
-
{ timeout, pollInterval: 100 },
|
|
3162
|
-
void 0
|
|
3163
|
-
)
|
|
3164
|
-
);
|
|
3165
|
-
return result._tag === "Right";
|
|
3166
|
-
})
|
|
3167
|
-
);
|
|
3168
|
-
},
|
|
3169
|
-
isEnabled: (selector, opts) => runStep("isEnabled", () => run2(coord.isElementEnabled(selector, opts)), { selector }),
|
|
3170
|
-
count: (selector, opts) => runStep("count", () => run2(coord.count(selector, opts)), { selector }),
|
|
3171
|
-
// Web-first bridge & fast state helpers
|
|
3172
|
-
waitForIdle: (opts) => runStep("waitForIdle", async () => {
|
|
3173
|
-
if (driver.domChannel?.waitForIdle) {
|
|
3174
|
-
await driver.domChannel.waitForIdle(opts);
|
|
3175
|
-
}
|
|
3176
|
-
}),
|
|
3177
|
-
setStorage: (entries) => runStep("setStorage", async () => {
|
|
3178
|
-
if (driver.domChannel?.setStorage) {
|
|
3179
|
-
await driver.domChannel.setStorage(entries);
|
|
3180
|
-
return;
|
|
3181
|
-
}
|
|
3182
|
-
const serialized = JSON.stringify(entries);
|
|
3183
|
-
await run2(
|
|
3184
|
-
driver.evaluate(
|
|
3185
|
-
`((payload) => {
|
|
3186
|
-
if (payload.localStorage) {
|
|
3187
|
-
for (const [k, v] of Object.entries(payload.localStorage)) {
|
|
3188
|
-
window.localStorage.setItem(k, v);
|
|
3189
|
-
}
|
|
3190
|
-
}
|
|
3191
|
-
if (payload.sessionStorage) {
|
|
3192
|
-
for (const [k, v] of Object.entries(payload.sessionStorage)) {
|
|
3193
|
-
window.sessionStorage.setItem(k, v);
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
if (payload.cookies) {
|
|
3197
|
-
for (const c of payload.cookies) {
|
|
3198
|
-
const path = c.path ? '; path=' + c.path : '; path=/';
|
|
3199
|
-
const domain = c.domain ? '; domain=' + c.domain : '';
|
|
3200
|
-
document.cookie = encodeURIComponent(c.name) + '=' + encodeURIComponent(c.value) + path + domain;
|
|
3201
|
-
}
|
|
3202
|
-
}
|
|
3203
|
-
})(${serialized})`
|
|
3204
|
-
)
|
|
3205
|
-
);
|
|
3206
|
-
}),
|
|
3207
|
-
clearStorage: (opts) => runStep("clearStorage", async () => {
|
|
3208
|
-
if (driver.domChannel?.clearStorage) {
|
|
3209
|
-
await driver.domChannel.clearStorage(opts);
|
|
3210
|
-
return;
|
|
3211
|
-
}
|
|
3212
|
-
const serialized = JSON.stringify(opts ?? {});
|
|
3213
|
-
await run2(
|
|
3214
|
-
driver.evaluate(
|
|
3215
|
-
`((clearOpts) => {
|
|
3216
|
-
if (clearOpts.localStorage !== false) {
|
|
3217
|
-
try { window.localStorage.clear(); } catch {}
|
|
3218
|
-
}
|
|
3219
|
-
if (clearOpts.sessionStorage !== false) {
|
|
3220
|
-
try { window.sessionStorage.clear(); } catch {}
|
|
3221
|
-
}
|
|
3222
|
-
})(${serialized})`
|
|
3223
|
-
)
|
|
3224
|
-
);
|
|
3225
|
-
}),
|
|
3226
|
-
resetFast: () => runStep("resetFast", async () => {
|
|
3227
|
-
if (driver.resetFast) {
|
|
3228
|
-
await run2(driver.resetFast());
|
|
3229
|
-
return;
|
|
3230
|
-
}
|
|
3231
|
-
if (driver.domChannel?.clearStorage) {
|
|
3232
|
-
await driver.domChannel.clearStorage({
|
|
3233
|
-
localStorage: true,
|
|
3234
|
-
sessionStorage: true,
|
|
3235
|
-
cookies: true,
|
|
3236
|
-
indexedDB: true,
|
|
3237
|
-
capacitorPreferences: true
|
|
3238
|
-
});
|
|
3239
|
-
if (driver.domChannel.reload) {
|
|
3240
|
-
await driver.domChannel.reload();
|
|
3241
|
-
}
|
|
3242
|
-
return;
|
|
3243
|
-
}
|
|
3244
|
-
await run2(driver.clearAppState(appId));
|
|
3245
|
-
}),
|
|
3246
|
-
// WebView / hybrid context switching (low-level escape hatches)
|
|
3247
|
-
getContexts: () => runStep(
|
|
3248
|
-
"getContexts",
|
|
3249
|
-
() => run2((driver.getContexts ?? (() => Effect6.succeed(["NATIVE_APP"])))())
|
|
3250
|
-
),
|
|
3251
|
-
getCurrentContext: () => runStep(
|
|
3252
|
-
"getCurrentContext",
|
|
3253
|
-
() => run2((driver.getCurrentContext ?? (() => Effect6.succeed("NATIVE_APP")))())
|
|
3254
|
-
),
|
|
3255
|
-
switchToContext: (contextId) => runStep(
|
|
3256
|
-
`switchToContext(${contextId})`,
|
|
3257
|
-
() => run2((driver.setContext ?? ((_id) => Effect6.void))(contextId))
|
|
3258
|
-
),
|
|
3259
|
-
switchToWebView: () => runStep("switchToWebView", async () => {
|
|
3260
|
-
const contexts = await run2(
|
|
3261
|
-
(driver.getContexts ?? (() => Effect6.succeed(["NATIVE_APP"])))()
|
|
3262
|
-
);
|
|
3263
|
-
const webview = contexts.find((c) => c.startsWith("WEBVIEW_"));
|
|
3264
|
-
if (!webview) {
|
|
3265
|
-
throw new DriverError({
|
|
3266
|
-
message: `No WebView context found. Available contexts: ${contexts.join(", ")}`
|
|
3267
|
-
});
|
|
3268
|
-
}
|
|
3269
|
-
await run2((driver.setContext ?? ((_id) => Effect6.void))(webview));
|
|
3270
|
-
}),
|
|
3271
|
-
switchToNativeApp: () => runStep(
|
|
3272
|
-
"switchToNativeApp",
|
|
3273
|
-
() => run2((driver.setContext ?? ((_id) => Effect6.void))("NATIVE_APP"))
|
|
3274
|
-
)
|
|
3275
|
-
};
|
|
3276
|
-
return appObj;
|
|
3277
|
-
}
|
|
2
|
+
createAndroidWebViewCdpChannel,
|
|
3
|
+
createCompositeDomChannel,
|
|
4
|
+
createWebKitInspectorChannel
|
|
5
|
+
} from "./chunk-WS2TVNMY.js";
|
|
6
|
+
import {
|
|
7
|
+
adbClearApp,
|
|
8
|
+
adbForceStop,
|
|
9
|
+
adbForward,
|
|
10
|
+
adbInstall,
|
|
11
|
+
adbLaunchApp,
|
|
12
|
+
adbOpenLink,
|
|
13
|
+
adbResetNetwork,
|
|
14
|
+
adbSetAirplaneMode,
|
|
15
|
+
adbSetCustomNetwork,
|
|
16
|
+
adbSetData,
|
|
17
|
+
adbSetNetworkProfile,
|
|
18
|
+
adbSetWifi,
|
|
19
|
+
adbShell,
|
|
20
|
+
findADB
|
|
21
|
+
} from "./chunk-2AFWVHQK.js";
|
|
22
|
+
import {
|
|
23
|
+
installedUrlSchemesOnSimulator,
|
|
24
|
+
launchOnSimulator,
|
|
25
|
+
launchWithUrlOnSimulator,
|
|
26
|
+
pfctlResetNetwork,
|
|
27
|
+
pfctlSetOffline,
|
|
28
|
+
pfctlSetThrottle,
|
|
29
|
+
resetSimulatorKeychain,
|
|
30
|
+
terminateOnSimulator
|
|
31
|
+
} from "./chunk-WV3ALL3H.js";
|
|
32
|
+
import {
|
|
33
|
+
getHealthyWarmDaemon,
|
|
34
|
+
registerWarmDaemon
|
|
35
|
+
} from "./chunk-Z6K4QQAR.js";
|
|
36
|
+
import {
|
|
37
|
+
allocateFreePort,
|
|
38
|
+
allocatePort,
|
|
39
|
+
releasePort
|
|
40
|
+
} from "./chunk-JPZCZHL4.js";
|
|
41
|
+
import {
|
|
42
|
+
hasLaunchDeviceState,
|
|
43
|
+
splitGraphemes
|
|
44
|
+
} from "./chunk-6PTUVG6A.js";
|
|
45
|
+
import {
|
|
46
|
+
DriverError,
|
|
47
|
+
buildDomFillScript,
|
|
48
|
+
buildDomQueryScript,
|
|
49
|
+
buildDomScrollIntoViewScript,
|
|
50
|
+
buildDomTapScript,
|
|
51
|
+
buildDomWaitForHiddenScript,
|
|
52
|
+
buildDomWaitForMatchScript,
|
|
53
|
+
buildDomWaitForSelectorScript
|
|
54
|
+
} from "./chunk-SGZMO456.js";
|
|
3278
55
|
|
|
3279
56
|
// src/drivers/playwright-parser.ts
|
|
3280
57
|
function rawNodeToElement(node) {
|
|
@@ -3305,7 +82,7 @@ function parseWebHierarchy(json) {
|
|
|
3305
82
|
}
|
|
3306
83
|
|
|
3307
84
|
// src/drivers/raw-driver.ts
|
|
3308
|
-
import { Context, Effect
|
|
85
|
+
import { Context, Effect } from "effect";
|
|
3309
86
|
var RawDriver = class extends Context.Tag("RawDriver")() {
|
|
3310
87
|
};
|
|
3311
88
|
|
|
@@ -3313,10 +90,10 @@ var RawDriver = class extends Context.Tag("RawDriver")() {
|
|
|
3313
90
|
import { spawn } from "child_process";
|
|
3314
91
|
import { createHash } from "crypto";
|
|
3315
92
|
import { mkdtempSync, rmSync } from "fs";
|
|
3316
|
-
import { readFile
|
|
93
|
+
import { readFile, writeFile } from "fs/promises";
|
|
3317
94
|
import { tmpdir } from "os";
|
|
3318
95
|
import { join } from "path";
|
|
3319
|
-
import { Effect as
|
|
96
|
+
import { Effect as Effect3, Layer } from "effect";
|
|
3320
97
|
import {
|
|
3321
98
|
chromium,
|
|
3322
99
|
firefox,
|
|
@@ -3325,9 +102,9 @@ import {
|
|
|
3325
102
|
|
|
3326
103
|
// src/drivers/device-controls.ts
|
|
3327
104
|
import { execFileSync } from "child_process";
|
|
3328
|
-
import { Effect as
|
|
105
|
+
import { Effect as Effect2 } from "effect";
|
|
3329
106
|
function deviceEffect(operation, action) {
|
|
3330
|
-
return
|
|
107
|
+
return Effect2.tryPromise({
|
|
3331
108
|
try: async () => action(),
|
|
3332
109
|
catch: (error) => new DriverError({
|
|
3333
110
|
message: `${operation} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -3718,23 +495,23 @@ function resolvePlaywrightLocator(root, selector) {
|
|
|
3718
495
|
return locator;
|
|
3719
496
|
}
|
|
3720
497
|
function makePlaywrightDriver(config) {
|
|
3721
|
-
return
|
|
498
|
+
return Effect3.gen(function* () {
|
|
3722
499
|
const browserName = config.browser ?? "chromium";
|
|
3723
500
|
const ownsBrowser = !config.sharedBrowser && !config.cdpEndpoint && !config.wsEndpoint && !config.warmBrowser;
|
|
3724
|
-
const browser = config.sharedBrowser ? config.sharedBrowser : config.wsEndpoint ? yield*
|
|
501
|
+
const browser = config.sharedBrowser ? config.sharedBrowser : config.wsEndpoint ? yield* Effect3.tryPromise({
|
|
3725
502
|
try: () => browserLaunchers[browserName].connect(config.wsEndpoint),
|
|
3726
503
|
catch: (e) => new DriverError({
|
|
3727
504
|
message: `Failed to connect to remote Playwright server (${config.wsEndpoint}): ${e}`
|
|
3728
505
|
})
|
|
3729
|
-
}) : config.cdpEndpoint ? yield*
|
|
506
|
+
}) : config.cdpEndpoint ? yield* Effect3.tryPromise({
|
|
3730
507
|
try: () => chromium.connectOverCDP(config.cdpEndpoint),
|
|
3731
508
|
catch: (e) => new DriverError({
|
|
3732
509
|
message: `Failed to connect to browser over CDP (${config.cdpEndpoint}): ${e}`
|
|
3733
510
|
})
|
|
3734
|
-
}) : config.warmBrowser && browserName === "chromium" ? yield*
|
|
511
|
+
}) : config.warmBrowser && browserName === "chromium" ? yield* Effect3.tryPromise({
|
|
3735
512
|
try: async () => (await ensureWarmBrowserDaemon(config)).browser,
|
|
3736
513
|
catch: (e) => new DriverError({ message: `Failed to connect to warm Chromium daemon: ${e}` })
|
|
3737
|
-
}) : yield*
|
|
514
|
+
}) : yield* Effect3.tryPromise({
|
|
3738
515
|
try: () => browserLaunchers[browserName].launch({
|
|
3739
516
|
headless: config.headless ?? true,
|
|
3740
517
|
...config.channel ? { channel: config.channel } : {},
|
|
@@ -3761,6 +538,7 @@ function makePlaywrightDriver(config) {
|
|
|
3761
538
|
let harPages = /* @__PURE__ */ new Map();
|
|
3762
539
|
let queuedDownloads = [];
|
|
3763
540
|
let downloadWaiters = [];
|
|
541
|
+
let dialogHandler = null;
|
|
3764
542
|
const attachedPages = /* @__PURE__ */ new WeakSet();
|
|
3765
543
|
const resetWebDiagnostics = () => {
|
|
3766
544
|
consoleLogs = [];
|
|
@@ -3971,6 +749,34 @@ function makePlaywrightDriver(config) {
|
|
|
3971
749
|
debugLog("download", getTabId(activePage), download.suggestedFilename(), download.url());
|
|
3972
750
|
flushDownload(download);
|
|
3973
751
|
});
|
|
752
|
+
activePage.on("dialog", (dialog) => {
|
|
753
|
+
const activeHandler = dialogHandler;
|
|
754
|
+
if (!activeHandler) return;
|
|
755
|
+
let handled = false;
|
|
756
|
+
const info = {
|
|
757
|
+
type: dialog.type(),
|
|
758
|
+
message: dialog.message(),
|
|
759
|
+
defaultValue: dialog.defaultValue(),
|
|
760
|
+
accept: async (promptText) => {
|
|
761
|
+
if (handled) return;
|
|
762
|
+
handled = true;
|
|
763
|
+
await dialog.accept(promptText);
|
|
764
|
+
},
|
|
765
|
+
dismiss: async () => {
|
|
766
|
+
if (handled) return;
|
|
767
|
+
handled = true;
|
|
768
|
+
await dialog.dismiss();
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
void Promise.resolve(activeHandler(info)).catch(() => {
|
|
772
|
+
}).finally(() => {
|
|
773
|
+
if (!handled) {
|
|
774
|
+
handled = true;
|
|
775
|
+
void dialog.dismiss().catch(() => {
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
});
|
|
3974
780
|
if (config.recordHar !== false) {
|
|
3975
781
|
activePage.on("requestfinished", (request) => {
|
|
3976
782
|
void recordRequestFinished(activePage, request).catch(() => {
|
|
@@ -4211,7 +1017,7 @@ function makePlaywrightDriver(config) {
|
|
|
4211
1017
|
updateHarPage(page);
|
|
4212
1018
|
debugLog("beginFlow", flowName);
|
|
4213
1019
|
};
|
|
4214
|
-
yield*
|
|
1020
|
+
yield* Effect3.tryPromise({
|
|
4215
1021
|
try: () => createContextAndPage(config.storageState),
|
|
4216
1022
|
catch: (e) => new DriverError({ message: `Failed to create page: ${e}` })
|
|
4217
1023
|
});
|
|
@@ -4255,11 +1061,11 @@ function makePlaywrightDriver(config) {
|
|
|
4255
1061
|
let coveragePage;
|
|
4256
1062
|
const service = {
|
|
4257
1063
|
...domChannel ? { domChannel } : {},
|
|
4258
|
-
beginFlow: (flowName) =>
|
|
1064
|
+
beginFlow: (flowName) => Effect3.tryPromise({
|
|
4259
1065
|
try: () => beginFlow(flowName),
|
|
4260
1066
|
catch: (e) => new DriverError({ message: `Failed to prepare flow ${flowName}: ${e}` })
|
|
4261
1067
|
}),
|
|
4262
|
-
dumpHierarchy: () =>
|
|
1068
|
+
dumpHierarchy: () => Effect3.tryPromise({
|
|
4263
1069
|
try: async () => {
|
|
4264
1070
|
const tree = await page.evaluate(`
|
|
4265
1071
|
(function() {
|
|
@@ -4294,17 +1100,17 @@ function makePlaywrightDriver(config) {
|
|
|
4294
1100
|
},
|
|
4295
1101
|
catch: (e) => new DriverError({ message: `Failed to dump hierarchy: ${e}` })
|
|
4296
1102
|
}),
|
|
4297
|
-
tapAtCoordinate: (x, y) =>
|
|
1103
|
+
tapAtCoordinate: (x, y) => Effect3.tryPromise({
|
|
4298
1104
|
try: async () => {
|
|
4299
1105
|
await page.mouse.click(x, y);
|
|
4300
1106
|
},
|
|
4301
1107
|
catch: (e) => new DriverError({ message: `Failed to tap at (${x}, ${y}): ${e}` })
|
|
4302
1108
|
}),
|
|
4303
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
1109
|
+
doubleTapAtCoordinate: (x, y) => Effect3.tryPromise({
|
|
4304
1110
|
try: () => page.mouse.dblclick(x, y),
|
|
4305
1111
|
catch: (e) => new DriverError({ message: `Failed to double tap at (${x}, ${y}): ${e}` })
|
|
4306
1112
|
}),
|
|
4307
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
1113
|
+
longPressAtCoordinate: (x, y, duration) => Effect3.tryPromise({
|
|
4308
1114
|
try: async () => {
|
|
4309
1115
|
await page.mouse.move(x, y);
|
|
4310
1116
|
await page.mouse.down();
|
|
@@ -4313,7 +1119,7 @@ function makePlaywrightDriver(config) {
|
|
|
4313
1119
|
},
|
|
4314
1120
|
catch: (e) => new DriverError({ message: `Failed to long press at (${x}, ${y}): ${e}` })
|
|
4315
1121
|
}),
|
|
4316
|
-
swipe: (startX, startY, endX, endY, duration) =>
|
|
1122
|
+
swipe: (startX, startY, endX, endY, duration) => Effect3.tryPromise({
|
|
4317
1123
|
try: async () => {
|
|
4318
1124
|
await page.evaluate(`
|
|
4319
1125
|
(function() {
|
|
@@ -4350,23 +1156,23 @@ function makePlaywrightDriver(config) {
|
|
|
4350
1156
|
},
|
|
4351
1157
|
catch: (e) => new DriverError({ message: `Failed to swipe: ${e}` })
|
|
4352
1158
|
}),
|
|
4353
|
-
inputText: (text) =>
|
|
1159
|
+
inputText: (text) => Effect3.tryPromise({
|
|
4354
1160
|
try: () => page.keyboard.insertText(text),
|
|
4355
1161
|
catch: (e) => new DriverError({ message: `Failed to input text: ${e}` })
|
|
4356
1162
|
}),
|
|
4357
|
-
pressKey: (key) =>
|
|
1163
|
+
pressKey: (key) => Effect3.tryPromise({
|
|
4358
1164
|
try: () => page.keyboard.press(key),
|
|
4359
1165
|
catch: (e) => new DriverError({ message: `Failed to press key ${key}: ${e}` })
|
|
4360
1166
|
}),
|
|
4361
|
-
hideKeyboard: () =>
|
|
4362
|
-
takeScreenshot: () =>
|
|
1167
|
+
hideKeyboard: () => Effect3.void,
|
|
1168
|
+
takeScreenshot: () => Effect3.tryPromise({
|
|
4363
1169
|
try: async () => {
|
|
4364
1170
|
const buffer = await page.screenshot();
|
|
4365
1171
|
return new Uint8Array(buffer);
|
|
4366
1172
|
},
|
|
4367
1173
|
catch: (e) => new DriverError({ message: `Failed to take screenshot: ${e}` })
|
|
4368
1174
|
}),
|
|
4369
|
-
getDeviceInfo: () =>
|
|
1175
|
+
getDeviceInfo: () => Effect3.tryPromise({
|
|
4370
1176
|
try: async () => {
|
|
4371
1177
|
const viewport = page.viewportSize() ?? { width: 1280, height: 720 };
|
|
4372
1178
|
return {
|
|
@@ -4381,7 +1187,7 @@ function makePlaywrightDriver(config) {
|
|
|
4381
1187
|
},
|
|
4382
1188
|
catch: (e) => new DriverError({ message: `Failed to get device info: ${e}` })
|
|
4383
1189
|
}),
|
|
4384
|
-
launchApp: (url, opts) =>
|
|
1190
|
+
launchApp: (url, opts) => Effect3.tryPromise({
|
|
4385
1191
|
try: async () => {
|
|
4386
1192
|
const targetUrl = opts?.deepLink || url || config.baseUrl || "about:blank";
|
|
4387
1193
|
if (opts?.clearState) {
|
|
@@ -4402,7 +1208,7 @@ function makePlaywrightDriver(config) {
|
|
|
4402
1208
|
},
|
|
4403
1209
|
catch: (e) => new DriverError({ message: `Failed to navigate to ${url}: ${e}` })
|
|
4404
1210
|
}),
|
|
4405
|
-
stopApp: (_id) =>
|
|
1211
|
+
stopApp: (_id) => Effect3.tryPromise({
|
|
4406
1212
|
try: async () => {
|
|
4407
1213
|
await page.goto("about:blank");
|
|
4408
1214
|
updateHarPage(page);
|
|
@@ -4410,7 +1216,7 @@ function makePlaywrightDriver(config) {
|
|
|
4410
1216
|
},
|
|
4411
1217
|
catch: (e) => new DriverError({ message: `Failed to stop app: ${e}` })
|
|
4412
1218
|
}),
|
|
4413
|
-
killApp: (_id) =>
|
|
1219
|
+
killApp: (_id) => Effect3.tryPromise({
|
|
4414
1220
|
try: async () => {
|
|
4415
1221
|
const prefetched = prefetchedSlotPromise;
|
|
4416
1222
|
prefetchedSlotPromise = void 0;
|
|
@@ -4433,14 +1239,14 @@ function makePlaywrightDriver(config) {
|
|
|
4433
1239
|
},
|
|
4434
1240
|
catch: (e) => new DriverError({ message: `Failed to kill app: ${e}` })
|
|
4435
1241
|
}),
|
|
4436
|
-
clearAppState: (_id) =>
|
|
1242
|
+
clearAppState: (_id) => Effect3.tryPromise({
|
|
4437
1243
|
try: async () => {
|
|
4438
1244
|
await clearStorage();
|
|
4439
1245
|
debugLog("clearAppState");
|
|
4440
1246
|
},
|
|
4441
1247
|
catch: (e) => new DriverError({ message: `Failed to clear app state: ${e}` })
|
|
4442
1248
|
}),
|
|
4443
|
-
openLink: (url) =>
|
|
1249
|
+
openLink: (url) => Effect3.tryPromise({
|
|
4444
1250
|
try: async () => {
|
|
4445
1251
|
await page.goto(url, config.waitUntil ? { waitUntil: config.waitUntil } : void 0);
|
|
4446
1252
|
updateHarPage(page);
|
|
@@ -4449,7 +1255,7 @@ function makePlaywrightDriver(config) {
|
|
|
4449
1255
|
},
|
|
4450
1256
|
catch: (e) => new DriverError({ message: `Failed to open link ${url}: ${e}` })
|
|
4451
1257
|
}),
|
|
4452
|
-
back: () =>
|
|
1258
|
+
back: () => Effect3.tryPromise({
|
|
4453
1259
|
try: async () => {
|
|
4454
1260
|
await page.goBack();
|
|
4455
1261
|
updateHarPage(page);
|
|
@@ -4457,7 +1263,7 @@ function makePlaywrightDriver(config) {
|
|
|
4457
1263
|
},
|
|
4458
1264
|
catch: (e) => new DriverError({ message: `Failed to go back: ${e}` })
|
|
4459
1265
|
}),
|
|
4460
|
-
reload: (reloadOpts) =>
|
|
1266
|
+
reload: (reloadOpts) => Effect3.tryPromise({
|
|
4461
1267
|
try: async () => {
|
|
4462
1268
|
const waitUntil = reloadOpts?.waitUntil ?? config.waitUntil;
|
|
4463
1269
|
await page.reload(waitUntil ? { waitUntil } : void 0);
|
|
@@ -4466,14 +1272,14 @@ function makePlaywrightDriver(config) {
|
|
|
4466
1272
|
},
|
|
4467
1273
|
catch: (e) => new DriverError({ message: `Failed to reload page: ${e}` })
|
|
4468
1274
|
}),
|
|
4469
|
-
hoverAtCoordinate: (x, y) =>
|
|
1275
|
+
hoverAtCoordinate: (x, y) => Effect3.tryPromise({
|
|
4470
1276
|
try: async () => {
|
|
4471
1277
|
await page.mouse.move(x, y);
|
|
4472
1278
|
},
|
|
4473
1279
|
catch: (e) => new DriverError({ message: `Failed to hover at (${x}, ${y}): ${e}` })
|
|
4474
1280
|
}),
|
|
4475
|
-
getUrl: () =>
|
|
4476
|
-
evaluate: (script, ...args) =>
|
|
1281
|
+
getUrl: () => Effect3.sync(() => currentPageUrl(page)),
|
|
1282
|
+
evaluate: (script, ...args) => Effect3.tryPromise({
|
|
4477
1283
|
try: () => evaluateOnPage(page, script, args),
|
|
4478
1284
|
catch: (e) => new DriverError({ message: `Evaluate failed: ${e}` })
|
|
4479
1285
|
}),
|
|
@@ -4561,7 +1367,7 @@ function makePlaywrightDriver(config) {
|
|
|
4561
1367
|
}
|
|
4562
1368
|
};
|
|
4563
1369
|
},
|
|
4564
|
-
enableVirtualAuthenticator: (opts) =>
|
|
1370
|
+
enableVirtualAuthenticator: (opts) => Effect3.tryPromise({
|
|
4565
1371
|
try: async () => {
|
|
4566
1372
|
const attached = await attachVirtualAuthenticatorOn(context, page, opts);
|
|
4567
1373
|
activeAuthenticatorId = attached.authenticatorId;
|
|
@@ -4570,7 +1376,7 @@ function makePlaywrightDriver(config) {
|
|
|
4570
1376
|
},
|
|
4571
1377
|
catch: (e) => e instanceof DriverError ? e : new DriverError({ message: `Failed to enable virtual authenticator: ${e}` })
|
|
4572
1378
|
}),
|
|
4573
|
-
removeVirtualAuthenticator: (authenticatorId) =>
|
|
1379
|
+
removeVirtualAuthenticator: (authenticatorId) => Effect3.tryPromise({
|
|
4574
1380
|
try: async () => {
|
|
4575
1381
|
const id = authenticatorId ?? activeAuthenticatorId;
|
|
4576
1382
|
if (!id) return;
|
|
@@ -4581,7 +1387,7 @@ function makePlaywrightDriver(config) {
|
|
|
4581
1387
|
},
|
|
4582
1388
|
catch: (e) => new DriverError({ message: `Failed to remove virtual authenticator: ${e}` })
|
|
4583
1389
|
}),
|
|
4584
|
-
getVirtualCredentials: (authenticatorId) =>
|
|
1390
|
+
getVirtualCredentials: (authenticatorId) => Effect3.tryPromise({
|
|
4585
1391
|
try: async () => {
|
|
4586
1392
|
const id = authenticatorId ?? activeAuthenticatorId;
|
|
4587
1393
|
if (!id) return [];
|
|
@@ -4593,7 +1399,7 @@ function makePlaywrightDriver(config) {
|
|
|
4593
1399
|
},
|
|
4594
1400
|
catch: (e) => new DriverError({ message: `Failed to read virtual credentials: ${e}` })
|
|
4595
1401
|
}),
|
|
4596
|
-
addVirtualCredential: (credential, authenticatorId) =>
|
|
1402
|
+
addVirtualCredential: (credential, authenticatorId) => Effect3.tryPromise({
|
|
4597
1403
|
try: async () => {
|
|
4598
1404
|
if (browserName !== "chromium") {
|
|
4599
1405
|
throw new DriverError({
|
|
@@ -4623,7 +1429,7 @@ function makePlaywrightDriver(config) {
|
|
|
4623
1429
|
},
|
|
4624
1430
|
catch: (e) => e instanceof DriverError ? e : new DriverError({ message: `Failed to import virtual credential: ${e}` })
|
|
4625
1431
|
}),
|
|
4626
|
-
clearVirtualCredentials: (authenticatorId) =>
|
|
1432
|
+
clearVirtualCredentials: (authenticatorId) => Effect3.tryPromise({
|
|
4627
1433
|
try: async () => {
|
|
4628
1434
|
const id = authenticatorId ?? activeAuthenticatorId;
|
|
4629
1435
|
if (!id) return;
|
|
@@ -4633,7 +1439,7 @@ function makePlaywrightDriver(config) {
|
|
|
4633
1439
|
},
|
|
4634
1440
|
catch: (e) => new DriverError({ message: `Failed to clear virtual credentials: ${e}` })
|
|
4635
1441
|
}),
|
|
4636
|
-
mockNetwork: (matcher, response) =>
|
|
1442
|
+
mockNetwork: (matcher, response) => Effect3.tryPromise({
|
|
4637
1443
|
try: async () => {
|
|
4638
1444
|
buildMockResponse(response);
|
|
4639
1445
|
const definition = { kind: "mock", matcher, response };
|
|
@@ -4643,7 +1449,7 @@ function makePlaywrightDriver(config) {
|
|
|
4643
1449
|
},
|
|
4644
1450
|
catch: (e) => new DriverError({ message: `Failed to mock network route: ${e}` })
|
|
4645
1451
|
}),
|
|
4646
|
-
blockNetwork: (matcher) =>
|
|
1452
|
+
blockNetwork: (matcher) => Effect3.tryPromise({
|
|
4647
1453
|
try: async () => {
|
|
4648
1454
|
const definition = { kind: "block", matcher };
|
|
4649
1455
|
routeDefinitions.push(definition);
|
|
@@ -4652,7 +1458,7 @@ function makePlaywrightDriver(config) {
|
|
|
4652
1458
|
},
|
|
4653
1459
|
catch: (e) => new DriverError({ message: `Failed to block network route: ${e}` })
|
|
4654
1460
|
}),
|
|
4655
|
-
clearNetworkMocks: () =>
|
|
1461
|
+
clearNetworkMocks: () => Effect3.tryPromise({
|
|
4656
1462
|
try: async () => {
|
|
4657
1463
|
for (const appliedRoute of appliedRoutes) {
|
|
4658
1464
|
await context.unroute(appliedRoute.matcher, appliedRoute.handler);
|
|
@@ -4663,7 +1469,7 @@ function makePlaywrightDriver(config) {
|
|
|
4663
1469
|
},
|
|
4664
1470
|
catch: (e) => new DriverError({ message: `Failed to clear network mocks: ${e}` })
|
|
4665
1471
|
}),
|
|
4666
|
-
setNetworkConditions: (conditions) =>
|
|
1472
|
+
setNetworkConditions: (conditions) => Effect3.tryPromise({
|
|
4667
1473
|
try: async () => {
|
|
4668
1474
|
currentNetworkConditions = { ...conditions };
|
|
4669
1475
|
await applyNetworkConditions();
|
|
@@ -4671,17 +1477,17 @@ function makePlaywrightDriver(config) {
|
|
|
4671
1477
|
},
|
|
4672
1478
|
catch: (e) => new DriverError({ message: `Failed to set network conditions: ${e}` })
|
|
4673
1479
|
}),
|
|
4674
|
-
saveCookies: (path) =>
|
|
1480
|
+
saveCookies: (path) => Effect3.tryPromise({
|
|
4675
1481
|
try: async () => {
|
|
4676
1482
|
const cookies = await context.cookies();
|
|
4677
|
-
await
|
|
1483
|
+
await writeFile(path, JSON.stringify(cookies, null, 2), "utf8");
|
|
4678
1484
|
debugLog("saveCookies", path);
|
|
4679
1485
|
},
|
|
4680
1486
|
catch: (e) => new DriverError({ message: `Failed to save cookies to ${path}: ${e}` })
|
|
4681
1487
|
}),
|
|
4682
|
-
loadCookies: (path) =>
|
|
1488
|
+
loadCookies: (path) => Effect3.tryPromise({
|
|
4683
1489
|
try: async () => {
|
|
4684
|
-
const contents = await
|
|
1490
|
+
const contents = await readFile(path, "utf8");
|
|
4685
1491
|
const cookies = JSON.parse(contents);
|
|
4686
1492
|
if (!Array.isArray(cookies)) {
|
|
4687
1493
|
throw new Error("Cookie file must contain an array of cookies.");
|
|
@@ -4691,27 +1497,27 @@ function makePlaywrightDriver(config) {
|
|
|
4691
1497
|
},
|
|
4692
1498
|
catch: (e) => new DriverError({ message: `Failed to load cookies from ${path}: ${e}` })
|
|
4693
1499
|
}),
|
|
4694
|
-
getCookies: (urls) =>
|
|
1500
|
+
getCookies: (urls) => Effect3.tryPromise({
|
|
4695
1501
|
try: async () => {
|
|
4696
1502
|
const cookies = await (urls && urls.length > 0 ? context.cookies(urls) : context.cookies());
|
|
4697
1503
|
return cookies;
|
|
4698
1504
|
},
|
|
4699
1505
|
catch: (e) => new DriverError({ message: `Failed to read cookies: ${e}` })
|
|
4700
1506
|
}),
|
|
4701
|
-
setCookies: (cookies) =>
|
|
1507
|
+
setCookies: (cookies) => Effect3.tryPromise({
|
|
4702
1508
|
try: async () => {
|
|
4703
1509
|
if (cookies.length === 0) return;
|
|
4704
1510
|
await context.addCookies(cookies);
|
|
4705
1511
|
},
|
|
4706
1512
|
catch: (e) => new DriverError({ message: `Failed to set cookies: ${e}` })
|
|
4707
1513
|
}),
|
|
4708
|
-
clearCookies: () =>
|
|
1514
|
+
clearCookies: () => Effect3.tryPromise({
|
|
4709
1515
|
try: async () => {
|
|
4710
1516
|
await context.clearCookies();
|
|
4711
1517
|
},
|
|
4712
1518
|
catch: (e) => new DriverError({ message: `Failed to clear cookies: ${e}` })
|
|
4713
1519
|
}),
|
|
4714
|
-
waitForResponse: (matcher, waitOpts) =>
|
|
1520
|
+
waitForResponse: (matcher, waitOpts) => Effect3.tryPromise({
|
|
4715
1521
|
try: async () => {
|
|
4716
1522
|
const timeout = waitOpts?.timeout ?? 15e3;
|
|
4717
1523
|
const matches = (res) => {
|
|
@@ -4769,9 +1575,9 @@ function makePlaywrightDriver(config) {
|
|
|
4769
1575
|
},
|
|
4770
1576
|
catch: (e) => new DriverError({ message: `waitForResponse() failed: ${e}` })
|
|
4771
1577
|
}),
|
|
4772
|
-
createIsolatedContext: (ctxOpts) =>
|
|
1578
|
+
createIsolatedContext: (ctxOpts) => Effect3.tryPromise({
|
|
4773
1579
|
try: async () => {
|
|
4774
|
-
const childDriver = await
|
|
1580
|
+
const childDriver = await Effect3.runPromise(
|
|
4775
1581
|
makePlaywrightDriver({
|
|
4776
1582
|
...config,
|
|
4777
1583
|
sharedBrowser: browser,
|
|
@@ -4782,26 +1588,26 @@ function makePlaywrightDriver(config) {
|
|
|
4782
1588
|
})
|
|
4783
1589
|
);
|
|
4784
1590
|
if (ctxOpts?.url) {
|
|
4785
|
-
await
|
|
1591
|
+
await Effect3.runPromise(childDriver.openLink(ctxOpts.url));
|
|
4786
1592
|
}
|
|
4787
1593
|
return {
|
|
4788
1594
|
driver: childDriver,
|
|
4789
1595
|
close: async () => {
|
|
4790
|
-
await
|
|
1596
|
+
await Effect3.runPromise(childDriver.killApp("isolated-context")).catch(() => {
|
|
4791
1597
|
});
|
|
4792
1598
|
}
|
|
4793
1599
|
};
|
|
4794
1600
|
},
|
|
4795
1601
|
catch: (e) => new DriverError({ message: `createIsolatedContext() failed: ${e}` })
|
|
4796
1602
|
}),
|
|
4797
|
-
saveAuthState: (path) =>
|
|
1603
|
+
saveAuthState: (path) => Effect3.tryPromise({
|
|
4798
1604
|
try: async () => {
|
|
4799
1605
|
await context.storageState({ path });
|
|
4800
1606
|
debugLog("saveAuthState", path);
|
|
4801
1607
|
},
|
|
4802
1608
|
catch: (e) => new DriverError({ message: `Failed to save auth state to ${path}: ${e}` })
|
|
4803
1609
|
}),
|
|
4804
|
-
loadAuthState: (path) =>
|
|
1610
|
+
loadAuthState: (path) => Effect3.tryPromise({
|
|
4805
1611
|
try: async () => {
|
|
4806
1612
|
await replaceContext(path);
|
|
4807
1613
|
updateHarPage(page);
|
|
@@ -4809,7 +1615,7 @@ function makePlaywrightDriver(config) {
|
|
|
4809
1615
|
},
|
|
4810
1616
|
catch: (e) => new DriverError({ message: `Failed to load auth state from ${path}: ${e}` })
|
|
4811
1617
|
}),
|
|
4812
|
-
downloadFile: (path) =>
|
|
1618
|
+
downloadFile: (path) => Effect3.tryPromise({
|
|
4813
1619
|
try: async () => {
|
|
4814
1620
|
const download = await nextDownload();
|
|
4815
1621
|
await download.saveAs(path);
|
|
@@ -4817,7 +1623,109 @@ function makePlaywrightDriver(config) {
|
|
|
4817
1623
|
},
|
|
4818
1624
|
catch: (e) => new DriverError({ message: `Failed to download file to ${path}: ${e}` })
|
|
4819
1625
|
}),
|
|
4820
|
-
|
|
1626
|
+
dragAndDrop: (fromX, fromY, toX, toY, steps = 10) => Effect3.tryPromise({
|
|
1627
|
+
try: async () => {
|
|
1628
|
+
await page.mouse.move(fromX, fromY);
|
|
1629
|
+
await page.mouse.down();
|
|
1630
|
+
await page.mouse.move(toX, toY, { steps: Math.max(1, Math.round(steps)) });
|
|
1631
|
+
await page.mouse.up();
|
|
1632
|
+
},
|
|
1633
|
+
catch: (e) => new DriverError({ message: `Failed to dragAndDrop: ${e}` })
|
|
1634
|
+
}),
|
|
1635
|
+
setViewport: (viewport) => Effect3.tryPromise({
|
|
1636
|
+
try: async () => {
|
|
1637
|
+
await page.setViewportSize({ width: viewport.width, height: viewport.height });
|
|
1638
|
+
},
|
|
1639
|
+
catch: (e) => new DriverError({ message: `Failed to set viewport: ${e}` })
|
|
1640
|
+
}),
|
|
1641
|
+
setEmulation: (emulationOpts) => Effect3.tryPromise({
|
|
1642
|
+
try: async () => {
|
|
1643
|
+
if (emulationOpts.colorScheme !== void 0 || emulationOpts.reducedMotion !== void 0) {
|
|
1644
|
+
await page.emulateMedia({
|
|
1645
|
+
...emulationOpts.colorScheme !== void 0 ? { colorScheme: emulationOpts.colorScheme } : {},
|
|
1646
|
+
...emulationOpts.reducedMotion !== void 0 ? { reducedMotion: emulationOpts.reducedMotion } : {}
|
|
1647
|
+
});
|
|
1648
|
+
}
|
|
1649
|
+
if (browserName === "chromium" && (emulationOpts.locale !== void 0 || emulationOpts.timezoneId !== void 0)) {
|
|
1650
|
+
const session = await ensureCdpSession();
|
|
1651
|
+
if (emulationOpts.locale !== void 0) {
|
|
1652
|
+
await session.send("Emulation.setLocaleOverride", { locale: emulationOpts.locale }).catch(() => {
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
if (emulationOpts.timezoneId !== void 0) {
|
|
1656
|
+
await session.send("Emulation.setTimezoneOverride", { timezoneId: emulationOpts.timezoneId }).catch(() => {
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
},
|
|
1661
|
+
catch: (e) => new DriverError({ message: `Failed to set emulation: ${e}` })
|
|
1662
|
+
}),
|
|
1663
|
+
setDialogHandler: (handler) => Effect3.sync(() => {
|
|
1664
|
+
dialogHandler = handler;
|
|
1665
|
+
}),
|
|
1666
|
+
getClipboard: () => Effect3.tryPromise({
|
|
1667
|
+
try: async () => {
|
|
1668
|
+
if (browserName === "chromium") {
|
|
1669
|
+
await context.grantPermissions(["clipboard-read", "clipboard-write"]).catch(() => {
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
const val = await page.evaluate(`(async () => {
|
|
1673
|
+
if (navigator.clipboard && typeof navigator.clipboard.readText === "function") {
|
|
1674
|
+
try { return await navigator.clipboard.readText(); } catch {}
|
|
1675
|
+
}
|
|
1676
|
+
return typeof window.__spanaClipboardText === "string" ? window.__spanaClipboardText : "";
|
|
1677
|
+
})()`);
|
|
1678
|
+
return typeof val === "string" ? val : "";
|
|
1679
|
+
},
|
|
1680
|
+
catch: (e) => new DriverError({ message: `Failed to read clipboard: ${e}` })
|
|
1681
|
+
}),
|
|
1682
|
+
setClipboard: (text) => Effect3.tryPromise({
|
|
1683
|
+
try: async () => {
|
|
1684
|
+
if (browserName === "chromium") {
|
|
1685
|
+
await context.grantPermissions(["clipboard-read", "clipboard-write"]).catch(() => {
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
const encoded = JSON.stringify(text);
|
|
1689
|
+
await page.evaluate(`(async (txt) => {
|
|
1690
|
+
window.__spanaClipboardText = txt;
|
|
1691
|
+
if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
|
|
1692
|
+
try { await navigator.clipboard.writeText(txt); } catch {}
|
|
1693
|
+
}
|
|
1694
|
+
})(${encoded})`);
|
|
1695
|
+
},
|
|
1696
|
+
catch: (e) => new DriverError({ message: `Failed to write clipboard: ${e}` })
|
|
1697
|
+
}),
|
|
1698
|
+
waitForDownload: (triggerFn, dlOpts) => Effect3.tryPromise({
|
|
1699
|
+
try: async () => {
|
|
1700
|
+
const timeout = dlOpts?.timeout ?? 15e3;
|
|
1701
|
+
const downloadPromise = page.waitForEvent("download", { timeout });
|
|
1702
|
+
await triggerFn();
|
|
1703
|
+
const download = await downloadPromise;
|
|
1704
|
+
const filePath = await download.path() ?? join(tmpdir(), download.suggestedFilename());
|
|
1705
|
+
return {
|
|
1706
|
+
suggestedFilename: download.suggestedFilename(),
|
|
1707
|
+
path: filePath,
|
|
1708
|
+
url: download.url(),
|
|
1709
|
+
text: async () => {
|
|
1710
|
+
const actualPath = await download.path();
|
|
1711
|
+
if (!actualPath) {
|
|
1712
|
+
throw new Error("Download path unavailable (remote browser?)");
|
|
1713
|
+
}
|
|
1714
|
+
return readFile(actualPath, "utf8");
|
|
1715
|
+
},
|
|
1716
|
+
bytes: async () => {
|
|
1717
|
+
const actualPath = await download.path();
|
|
1718
|
+
if (!actualPath) {
|
|
1719
|
+
throw new Error("Download path unavailable (remote browser?)");
|
|
1720
|
+
}
|
|
1721
|
+
return new Uint8Array(await readFile(actualPath));
|
|
1722
|
+
},
|
|
1723
|
+
saveAs: (destPath) => download.saveAs(destPath)
|
|
1724
|
+
};
|
|
1725
|
+
},
|
|
1726
|
+
catch: (e) => new DriverError({ message: `waitForDownload() failed: ${e}` })
|
|
1727
|
+
}),
|
|
1728
|
+
uploadFile: (selector, path) => Effect3.tryPromise({
|
|
4821
1729
|
try: async () => {
|
|
4822
1730
|
await setInputFiles(selector, path);
|
|
4823
1731
|
debugLog("uploadFile", Array.isArray(path) ? path.join(", ") : path);
|
|
@@ -4826,7 +1734,7 @@ function makePlaywrightDriver(config) {
|
|
|
4826
1734
|
message: `Failed to upload file ${Array.isArray(path) ? path.join(", ") : path}: ${e}`
|
|
4827
1735
|
})
|
|
4828
1736
|
}),
|
|
4829
|
-
newTab: (url) =>
|
|
1737
|
+
newTab: (url) => Effect3.tryPromise({
|
|
4830
1738
|
try: async () => {
|
|
4831
1739
|
const nextPage = await context.newPage();
|
|
4832
1740
|
attachPageDiagnostics(nextPage);
|
|
@@ -4841,7 +1749,7 @@ function makePlaywrightDriver(config) {
|
|
|
4841
1749
|
},
|
|
4842
1750
|
catch: (e) => new DriverError({ message: `Failed to open a new tab: ${e}` })
|
|
4843
1751
|
}),
|
|
4844
|
-
switchToTab: (index) =>
|
|
1752
|
+
switchToTab: (index) => Effect3.tryPromise({
|
|
4845
1753
|
try: async () => {
|
|
4846
1754
|
const openPages = context.pages();
|
|
4847
1755
|
const nextPage = openPages[index];
|
|
@@ -4857,7 +1765,7 @@ function makePlaywrightDriver(config) {
|
|
|
4857
1765
|
},
|
|
4858
1766
|
catch: (e) => new DriverError({ message: `Failed to switch tabs: ${e}` })
|
|
4859
1767
|
}),
|
|
4860
|
-
closeTab: () =>
|
|
1768
|
+
closeTab: () => Effect3.tryPromise({
|
|
4861
1769
|
try: async () => {
|
|
4862
1770
|
const openPages = context.pages();
|
|
4863
1771
|
if (openPages.length <= 1) {
|
|
@@ -4877,14 +1785,14 @@ function makePlaywrightDriver(config) {
|
|
|
4877
1785
|
},
|
|
4878
1786
|
catch: (e) => new DriverError({ message: `Failed to close the current tab: ${e}` })
|
|
4879
1787
|
}),
|
|
4880
|
-
getTabIds: () =>
|
|
1788
|
+
getTabIds: () => Effect3.sync(() => {
|
|
4881
1789
|
const ids = context.pages().map((openPage) => getTabId(openPage));
|
|
4882
1790
|
debugLog("getTabIds", ids.join(", "));
|
|
4883
1791
|
return ids;
|
|
4884
1792
|
}),
|
|
4885
|
-
getConsoleLogs: () =>
|
|
4886
|
-
getJSErrors: () =>
|
|
4887
|
-
getHAR: () =>
|
|
1793
|
+
getConsoleLogs: () => Effect3.succeed([...consoleLogs]),
|
|
1794
|
+
getJSErrors: () => Effect3.succeed([...jsErrors]),
|
|
1795
|
+
getHAR: () => Effect3.sync(() => ({
|
|
4888
1796
|
log: {
|
|
4889
1797
|
version: "1.2",
|
|
4890
1798
|
creator: {
|
|
@@ -4904,7 +1812,7 @@ function makePlaywrightDriver(config) {
|
|
|
4904
1812
|
}
|
|
4905
1813
|
|
|
4906
1814
|
// src/drivers/uiautomator2/driver.ts
|
|
4907
|
-
import { Effect as
|
|
1815
|
+
import { Effect as Effect4 } from "effect";
|
|
4908
1816
|
|
|
4909
1817
|
// src/drivers/uiautomator2/client.ts
|
|
4910
1818
|
var UiAutomator2Client = class {
|
|
@@ -5251,7 +2159,7 @@ var UiAutomator2Client = class {
|
|
|
5251
2159
|
|
|
5252
2160
|
// src/drivers/uiautomator2/driver.ts
|
|
5253
2161
|
function createUiAutomator2Driver(host, port, serial, packageName, driverOptions) {
|
|
5254
|
-
return
|
|
2162
|
+
return Effect4.gen(function* () {
|
|
5255
2163
|
const client = new UiAutomator2Client(host, port);
|
|
5256
2164
|
let currentContext = "NATIVE_APP";
|
|
5257
2165
|
let hasLaunchedOnce = false;
|
|
@@ -5275,7 +2183,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5275
2183
|
if (driverOptions?.domChannel) channels.push(driverOptions.domChannel);
|
|
5276
2184
|
if (cdpChannel) channels.push(cdpChannel);
|
|
5277
2185
|
const domChannel = channels.length === 0 ? void 0 : channels.length === 1 ? channels[0] : createCompositeDomChannel(channels);
|
|
5278
|
-
yield*
|
|
2186
|
+
yield* Effect4.tryPromise({
|
|
5279
2187
|
try: () => client.createSession(packageName),
|
|
5280
2188
|
catch: (e) => new DriverError({
|
|
5281
2189
|
message: `Failed to create UiAutomator2 session: ${e}`
|
|
@@ -5291,70 +2199,70 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5291
2199
|
// -----------------------------------------------------------------------
|
|
5292
2200
|
// Hierarchy
|
|
5293
2201
|
// -----------------------------------------------------------------------
|
|
5294
|
-
dumpHierarchy: () =>
|
|
2202
|
+
dumpHierarchy: () => Effect4.tryPromise({
|
|
5295
2203
|
try: () => client.getSource(),
|
|
5296
2204
|
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
5297
2205
|
}),
|
|
5298
2206
|
// -----------------------------------------------------------------------
|
|
5299
2207
|
// Coordinate-level actions
|
|
5300
2208
|
// -----------------------------------------------------------------------
|
|
5301
|
-
tapAtCoordinate: (x, y) =>
|
|
2209
|
+
tapAtCoordinate: (x, y) => Effect4.tryPromise({
|
|
5302
2210
|
try: () => client.performTap(x, y),
|
|
5303
2211
|
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
5304
2212
|
}),
|
|
5305
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
2213
|
+
doubleTapAtCoordinate: (x, y) => Effect4.tryPromise({
|
|
5306
2214
|
try: async () => {
|
|
5307
2215
|
await client.performTap(x, y);
|
|
5308
2216
|
await client.performTap(x, y);
|
|
5309
2217
|
},
|
|
5310
2218
|
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
5311
2219
|
}),
|
|
5312
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
2220
|
+
longPressAtCoordinate: (x, y, duration) => Effect4.tryPromise({
|
|
5313
2221
|
try: () => client.performLongPress(x, y, duration),
|
|
5314
2222
|
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
5315
2223
|
}),
|
|
5316
|
-
swipe: (sx, sy, ex, ey, dur) =>
|
|
2224
|
+
swipe: (sx, sy, ex, ey, dur) => Effect4.tryPromise({
|
|
5317
2225
|
try: () => client.performSwipe(sx, sy, ex, ey, dur),
|
|
5318
2226
|
catch: (e) => new DriverError({ message: `Swipe failed: ${e}` })
|
|
5319
2227
|
}),
|
|
5320
|
-
pinch: (cx, cy, scale, duration) =>
|
|
2228
|
+
pinch: (cx, cy, scale, duration) => Effect4.tryPromise({
|
|
5321
2229
|
try: () => client.performPinch(cx, cy, scale, duration),
|
|
5322
2230
|
catch: (e) => new DriverError({ message: `Pinch failed: ${e}` })
|
|
5323
2231
|
}),
|
|
5324
|
-
zoom: (cx, cy, scale, duration) =>
|
|
2232
|
+
zoom: (cx, cy, scale, duration) => Effect4.tryPromise({
|
|
5325
2233
|
try: () => client.performZoom(cx, cy, scale, duration),
|
|
5326
2234
|
catch: (e) => new DriverError({ message: `Zoom failed: ${e}` })
|
|
5327
2235
|
}),
|
|
5328
|
-
multiTouch: (sequences) =>
|
|
2236
|
+
multiTouch: (sequences) => Effect4.tryPromise({
|
|
5329
2237
|
try: () => client.performMultiTouch(sequences),
|
|
5330
2238
|
catch: (e) => new DriverError({ message: `Multi-touch failed: ${e}` })
|
|
5331
2239
|
}),
|
|
5332
2240
|
// -----------------------------------------------------------------------
|
|
5333
2241
|
// Text input
|
|
5334
2242
|
// -----------------------------------------------------------------------
|
|
5335
|
-
inputText: (text) =>
|
|
2243
|
+
inputText: (text) => Effect4.tryPromise({
|
|
5336
2244
|
try: () => client.sendKeys(text),
|
|
5337
2245
|
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
5338
2246
|
}),
|
|
5339
|
-
pressKey: (key) =>
|
|
2247
|
+
pressKey: (key) => Effect4.tryPromise({
|
|
5340
2248
|
try: () => client.pressKeyCode(parseInt(key, 10) || 0),
|
|
5341
2249
|
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
5342
2250
|
}),
|
|
5343
|
-
hideKeyboard: () =>
|
|
2251
|
+
hideKeyboard: () => Effect4.tryPromise({
|
|
5344
2252
|
try: () => client.hideKeyboard(),
|
|
5345
2253
|
catch: (e) => new DriverError({ message: `Hide keyboard failed: ${e}` })
|
|
5346
2254
|
}),
|
|
5347
2255
|
// -----------------------------------------------------------------------
|
|
5348
2256
|
// Queries
|
|
5349
2257
|
// -----------------------------------------------------------------------
|
|
5350
|
-
takeScreenshot: () =>
|
|
2258
|
+
takeScreenshot: () => Effect4.tryPromise({
|
|
5351
2259
|
try: async () => {
|
|
5352
2260
|
const base64 = await client.getScreenshot();
|
|
5353
2261
|
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
5354
2262
|
},
|
|
5355
2263
|
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
5356
2264
|
}),
|
|
5357
|
-
getDeviceInfo: () =>
|
|
2265
|
+
getDeviceInfo: () => Effect4.tryPromise({
|
|
5358
2266
|
try: async () => {
|
|
5359
2267
|
const size = await client.getWindowSize();
|
|
5360
2268
|
return {
|
|
@@ -5372,7 +2280,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5372
2280
|
// -----------------------------------------------------------------------
|
|
5373
2281
|
// App lifecycle
|
|
5374
2282
|
// -----------------------------------------------------------------------
|
|
5375
|
-
launchApp: (bundleId, opts) =>
|
|
2283
|
+
launchApp: (bundleId, opts) => Effect4.tryPromise({
|
|
5376
2284
|
try: async () => {
|
|
5377
2285
|
const canFastReset = hasLaunchedOnce && driverOptions?.fastWebViewReset !== false && domChannel?.isConnected() && !opts?.deepLink && !opts?.clearKeychain && !hasLaunchDeviceState(opts?.deviceState) && !(opts?.launchArguments && Object.keys(opts.launchArguments).length > 0);
|
|
5378
2286
|
if (canFastReset) {
|
|
@@ -5441,13 +2349,13 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5441
2349
|
},
|
|
5442
2350
|
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
5443
2351
|
}),
|
|
5444
|
-
stopApp: (bundleId) =>
|
|
2352
|
+
stopApp: (bundleId) => Effect4.tryPromise({
|
|
5445
2353
|
try: async () => {
|
|
5446
2354
|
adbForceStop(serial, bundleId);
|
|
5447
2355
|
},
|
|
5448
2356
|
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
5449
2357
|
}),
|
|
5450
|
-
killApp: (bundleId) =>
|
|
2358
|
+
killApp: (bundleId) => Effect4.tryPromise({
|
|
5451
2359
|
try: async () => {
|
|
5452
2360
|
await domChannel?.disconnect().catch(() => {
|
|
5453
2361
|
});
|
|
@@ -5456,7 +2364,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5456
2364
|
},
|
|
5457
2365
|
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
5458
2366
|
}),
|
|
5459
|
-
clearAppState: (bundleId) =>
|
|
2367
|
+
clearAppState: (bundleId) => Effect4.tryPromise({
|
|
5460
2368
|
try: async () => {
|
|
5461
2369
|
if (domChannel?.isConnected() && domChannel.clearStorage) {
|
|
5462
2370
|
await domChannel.clearStorage({
|
|
@@ -5476,7 +2384,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5476
2384
|
},
|
|
5477
2385
|
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
5478
2386
|
}),
|
|
5479
|
-
resetFast: () =>
|
|
2387
|
+
resetFast: () => Effect4.tryPromise({
|
|
5480
2388
|
try: async () => {
|
|
5481
2389
|
if (!domChannel) {
|
|
5482
2390
|
throw new Error("resetFast() requires a connected DOM channel (spana-bridge or CDP)");
|
|
@@ -5506,14 +2414,14 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5506
2414
|
// -----------------------------------------------------------------------
|
|
5507
2415
|
// Navigation
|
|
5508
2416
|
// -----------------------------------------------------------------------
|
|
5509
|
-
openLink: (url) =>
|
|
2417
|
+
openLink: (url) => Effect4.tryPromise({
|
|
5510
2418
|
try: async () => {
|
|
5511
2419
|
adbOpenLink(serial, url, packageName);
|
|
5512
2420
|
await new Promise((resolve2) => setTimeout(resolve2, 1e3));
|
|
5513
2421
|
},
|
|
5514
2422
|
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
5515
2423
|
}),
|
|
5516
|
-
back: () =>
|
|
2424
|
+
back: () => Effect4.tryPromise({
|
|
5517
2425
|
// KEYCODE_BACK = 4
|
|
5518
2426
|
try: () => client.pressKeyCode(4),
|
|
5519
2427
|
catch: (e) => new DriverError({ message: `Back failed: ${e}` })
|
|
@@ -5522,7 +2430,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5522
2430
|
// Direct DOM evaluation via spana-bridge or Android WebView CDP,
|
|
5523
2431
|
// falling back to UiAutomator2 /execute/sync when no DOM channel attaches.
|
|
5524
2432
|
// -----------------------------------------------------------------------
|
|
5525
|
-
evaluate: (script, ...args) =>
|
|
2433
|
+
evaluate: (script, ...args) => Effect4.tryPromise({
|
|
5526
2434
|
try: async () => {
|
|
5527
2435
|
if (domChannel) {
|
|
5528
2436
|
try {
|
|
@@ -5548,7 +2456,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5548
2456
|
},
|
|
5549
2457
|
catch: (e) => new DriverError({ message: `evaluate() failed: ${e}` })
|
|
5550
2458
|
}),
|
|
5551
|
-
getContexts: () =>
|
|
2459
|
+
getContexts: () => Effect4.tryPromise({
|
|
5552
2460
|
try: async () => {
|
|
5553
2461
|
const contexts = /* @__PURE__ */ new Set(["NATIVE_APP"]);
|
|
5554
2462
|
if (domChannel?.listTargets) {
|
|
@@ -5571,7 +2479,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5571
2479
|
},
|
|
5572
2480
|
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
5573
2481
|
}),
|
|
5574
|
-
getCurrentContext: () =>
|
|
2482
|
+
getCurrentContext: () => Effect4.tryPromise({
|
|
5575
2483
|
try: async () => {
|
|
5576
2484
|
if (currentContext !== "NATIVE_APP") return currentContext;
|
|
5577
2485
|
if (typeof client.getCurrentContext === "function") {
|
|
@@ -5585,7 +2493,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5585
2493
|
},
|
|
5586
2494
|
catch: (e) => new DriverError({ message: `getCurrentContext failed: ${e}` })
|
|
5587
2495
|
}),
|
|
5588
|
-
setContext: (contextId) =>
|
|
2496
|
+
setContext: (contextId) => Effect4.tryPromise({
|
|
5589
2497
|
try: async () => {
|
|
5590
2498
|
if (contextId === "NATIVE_APP") {
|
|
5591
2499
|
currentContext = "NATIVE_APP";
|
|
@@ -5611,7 +2519,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5611
2519
|
},
|
|
5612
2520
|
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
5613
2521
|
}),
|
|
5614
|
-
mockNetwork: (matcher, response) =>
|
|
2522
|
+
mockNetwork: (matcher, response) => Effect4.tryPromise({
|
|
5615
2523
|
try: async () => {
|
|
5616
2524
|
if (!domChannel?.mockNetwork) {
|
|
5617
2525
|
throw new Error(
|
|
@@ -5622,7 +2530,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5622
2530
|
},
|
|
5623
2531
|
catch: (e) => new DriverError({ message: `mockNetwork failed: ${e}` })
|
|
5624
2532
|
}),
|
|
5625
|
-
blockNetwork: (matcher) =>
|
|
2533
|
+
blockNetwork: (matcher) => Effect4.tryPromise({
|
|
5626
2534
|
try: async () => {
|
|
5627
2535
|
if (!domChannel?.blockNetwork) {
|
|
5628
2536
|
throw new Error(
|
|
@@ -5633,7 +2541,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5633
2541
|
},
|
|
5634
2542
|
catch: (e) => new DriverError({ message: `blockNetwork failed: ${e}` })
|
|
5635
2543
|
}),
|
|
5636
|
-
clearNetworkMocks: () =>
|
|
2544
|
+
clearNetworkMocks: () => Effect4.tryPromise({
|
|
5637
2545
|
try: async () => {
|
|
5638
2546
|
if (domChannel?.clearNetworkMocks) {
|
|
5639
2547
|
await domChannel.clearNetworkMocks();
|
|
@@ -5641,18 +2549,18 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5641
2549
|
},
|
|
5642
2550
|
catch: (e) => new DriverError({ message: `clearNetworkMocks failed: ${e}` })
|
|
5643
2551
|
}),
|
|
5644
|
-
getConsoleLogs: () =>
|
|
2552
|
+
getConsoleLogs: () => Effect4.tryPromise({
|
|
5645
2553
|
try: async () => domChannel?.getConsoleLogs ? domChannel.getConsoleLogs() : [],
|
|
5646
2554
|
catch: (e) => new DriverError({ message: `getConsoleLogs failed: ${e}` })
|
|
5647
2555
|
}),
|
|
5648
|
-
getJSErrors: () =>
|
|
2556
|
+
getJSErrors: () => Effect4.tryPromise({
|
|
5649
2557
|
try: async () => domChannel?.getJSErrors ? domChannel.getJSErrors() : [],
|
|
5650
2558
|
catch: (e) => new DriverError({ message: `getJSErrors failed: ${e}` })
|
|
5651
2559
|
}),
|
|
5652
2560
|
// -----------------------------------------------------------------------
|
|
5653
2561
|
// Network conditions
|
|
5654
2562
|
// -----------------------------------------------------------------------
|
|
5655
|
-
setNetworkConditions: (conditions) =>
|
|
2563
|
+
setNetworkConditions: (conditions) => Effect4.tryPromise({
|
|
5656
2564
|
try: async () => {
|
|
5657
2565
|
const isEmulator = serial.startsWith("emulator-");
|
|
5658
2566
|
const resolved = resolveNetworkConditions(conditions);
|
|
@@ -5899,7 +2807,7 @@ function parseAndroidHierarchy(xml) {
|
|
|
5899
2807
|
}
|
|
5900
2808
|
|
|
5901
2809
|
// src/drivers/wda/driver.ts
|
|
5902
|
-
import { Effect as
|
|
2810
|
+
import { Effect as Effect5 } from "effect";
|
|
5903
2811
|
|
|
5904
2812
|
// src/drivers/wda/client.ts
|
|
5905
2813
|
var WDAClient = class {
|
|
@@ -6337,7 +3245,7 @@ function isSessionError(error) {
|
|
|
6337
3245
|
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);
|
|
6338
3246
|
}
|
|
6339
3247
|
function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth = 100, driverOptions) {
|
|
6340
|
-
return
|
|
3248
|
+
return Effect5.gen(function* () {
|
|
6341
3249
|
const client = new WDAClient(host, port);
|
|
6342
3250
|
let currentContext = "NATIVE_APP";
|
|
6343
3251
|
let hasLaunchedOnce = false;
|
|
@@ -6458,23 +3366,23 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6458
3366
|
let reusedWarmSession = false;
|
|
6459
3367
|
if (driverOptions?.warmSessionId && typeof client.attachSession === "function") {
|
|
6460
3368
|
client.attachSession(driverOptions.warmSessionId);
|
|
6461
|
-
const alive = yield*
|
|
3369
|
+
const alive = yield* Effect5.tryPromise({
|
|
6462
3370
|
try: () => client.isSessionAlive(),
|
|
6463
3371
|
catch: () => false
|
|
6464
|
-
}).pipe(
|
|
3372
|
+
}).pipe(Effect5.catchAll(() => Effect5.succeed(false)));
|
|
6465
3373
|
reusedWarmSession = alive;
|
|
6466
3374
|
}
|
|
6467
3375
|
if (!reusedWarmSession) {
|
|
6468
|
-
const createdId = yield*
|
|
3376
|
+
const createdId = yield* Effect5.tryPromise({
|
|
6469
3377
|
try: () => createSessionWithRetry(bundleId || void 0),
|
|
6470
3378
|
catch: (e) => new DriverError({ message: `Failed to create WDA session: ${e}` })
|
|
6471
3379
|
});
|
|
6472
3380
|
driverOptions?.onSessionCreated?.(createdId);
|
|
6473
|
-
yield*
|
|
3381
|
+
yield* Effect5.tryPromise({
|
|
6474
3382
|
try: () => client.disableQuiescence(),
|
|
6475
3383
|
catch: (e) => new DriverError({ message: `Failed to disable quiescence: ${e}` })
|
|
6476
3384
|
});
|
|
6477
|
-
yield*
|
|
3385
|
+
yield* Effect5.tryPromise({
|
|
6478
3386
|
try: () => client.setSnapshotMaxDepth(snapshotMaxDepth),
|
|
6479
3387
|
catch: (e) => new DriverError({ message: `Failed to set snapshot depth: ${e}` })
|
|
6480
3388
|
});
|
|
@@ -6491,27 +3399,27 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6491
3399
|
// -----------------------------------------------------------------------
|
|
6492
3400
|
// Hierarchy
|
|
6493
3401
|
// -----------------------------------------------------------------------
|
|
6494
|
-
dumpHierarchy: () =>
|
|
3402
|
+
dumpHierarchy: () => Effect5.tryPromise({
|
|
6495
3403
|
try: () => withSessionRecovery(() => client.getSource()),
|
|
6496
3404
|
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
6497
3405
|
}),
|
|
6498
3406
|
// -----------------------------------------------------------------------
|
|
6499
3407
|
// Coordinate-level actions
|
|
6500
3408
|
// -----------------------------------------------------------------------
|
|
6501
|
-
tapAtCoordinate: (x, y) =>
|
|
3409
|
+
tapAtCoordinate: (x, y) => Effect5.tryPromise({
|
|
6502
3410
|
try: () => withSessionRecovery(() => client.tap(x, y)),
|
|
6503
3411
|
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
6504
3412
|
}),
|
|
6505
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
3413
|
+
doubleTapAtCoordinate: (x, y) => Effect5.tryPromise({
|
|
6506
3414
|
try: () => withSessionRecovery(() => client.doubleTap(x, y)),
|
|
6507
3415
|
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
6508
3416
|
}),
|
|
6509
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
3417
|
+
longPressAtCoordinate: (x, y, duration) => Effect5.tryPromise({
|
|
6510
3418
|
// duration arrives in ms (spana convention) → convert to seconds for WDA
|
|
6511
3419
|
try: () => withSessionRecovery(() => client.longPress(x, y, msToSec(duration))),
|
|
6512
3420
|
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
6513
3421
|
}),
|
|
6514
|
-
swipe: (sx, sy, ex, ey, dur) =>
|
|
3422
|
+
swipe: (sx, sy, ex, ey, dur) => Effect5.tryPromise({
|
|
6515
3423
|
// dur arrives in ms → convert to seconds for WDA.
|
|
6516
3424
|
// Clamp Y to avoid iOS system gesture zones (home indicator / App Switcher).
|
|
6517
3425
|
try: async () => {
|
|
@@ -6529,26 +3437,26 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6529
3437
|
},
|
|
6530
3438
|
catch: (e) => new DriverError({ message: `Swipe failed: ${e}` })
|
|
6531
3439
|
}),
|
|
6532
|
-
pinch: (cx, cy, scale, duration) =>
|
|
3440
|
+
pinch: (cx, cy, scale, duration) => Effect5.tryPromise({
|
|
6533
3441
|
try: () => withSessionRecovery(() => client.pinch(cx, cy, scale, msToSec(duration))),
|
|
6534
3442
|
catch: (e) => new DriverError({ message: `Pinch failed: ${e}` })
|
|
6535
3443
|
}),
|
|
6536
|
-
zoom: (cx, cy, scale, duration) =>
|
|
3444
|
+
zoom: (cx, cy, scale, duration) => Effect5.tryPromise({
|
|
6537
3445
|
try: () => withSessionRecovery(() => client.zoom(cx, cy, scale, msToSec(duration))),
|
|
6538
3446
|
catch: (e) => new DriverError({ message: `Zoom failed: ${e}` })
|
|
6539
3447
|
}),
|
|
6540
|
-
multiTouch: (sequences) =>
|
|
3448
|
+
multiTouch: (sequences) => Effect5.tryPromise({
|
|
6541
3449
|
try: () => withSessionRecovery(() => client.multiTouch(sequences)),
|
|
6542
3450
|
catch: (e) => new DriverError({ message: `Multi-touch failed: ${e}` })
|
|
6543
3451
|
}),
|
|
6544
3452
|
// -----------------------------------------------------------------------
|
|
6545
3453
|
// Text input
|
|
6546
3454
|
// -----------------------------------------------------------------------
|
|
6547
|
-
inputText: (text) =>
|
|
3455
|
+
inputText: (text) => Effect5.tryPromise({
|
|
6548
3456
|
try: () => withSessionRecovery(() => client.sendKeys(text)),
|
|
6549
3457
|
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
6550
3458
|
}),
|
|
6551
|
-
pressKey: (key) =>
|
|
3459
|
+
pressKey: (key) => Effect5.tryPromise({
|
|
6552
3460
|
// WDA uses named hardware buttons; map common names, fall back to home
|
|
6553
3461
|
try: async () => {
|
|
6554
3462
|
const buttonMap = {
|
|
@@ -6563,7 +3471,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6563
3471
|
},
|
|
6564
3472
|
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
6565
3473
|
}),
|
|
6566
|
-
hideKeyboard: () =>
|
|
3474
|
+
hideKeyboard: () => Effect5.tryPromise({
|
|
6567
3475
|
// Dismiss keyboard by tapping above the keyboard area.
|
|
6568
3476
|
// The previous approach (pressHome) backgrounds the app on iOS.
|
|
6569
3477
|
try: async () => {
|
|
@@ -6576,11 +3484,11 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6576
3484
|
// -----------------------------------------------------------------------
|
|
6577
3485
|
// Queries
|
|
6578
3486
|
// -----------------------------------------------------------------------
|
|
6579
|
-
takeScreenshot: () =>
|
|
3487
|
+
takeScreenshot: () => Effect5.tryPromise({
|
|
6580
3488
|
try: () => withSessionRecovery(() => client.getScreenshot()),
|
|
6581
3489
|
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
6582
3490
|
}),
|
|
6583
|
-
getDeviceInfo: () =>
|
|
3491
|
+
getDeviceInfo: () => Effect5.tryPromise({
|
|
6584
3492
|
try: async () => {
|
|
6585
3493
|
const size = await withSessionRecovery(() => client.getWindowSize());
|
|
6586
3494
|
return {
|
|
@@ -6598,7 +3506,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6598
3506
|
// -----------------------------------------------------------------------
|
|
6599
3507
|
// App lifecycle
|
|
6600
3508
|
// -----------------------------------------------------------------------
|
|
6601
|
-
launchApp: (appBundleId, opts) =>
|
|
3509
|
+
launchApp: (appBundleId, opts) => Effect5.tryPromise({
|
|
6602
3510
|
try: async () => {
|
|
6603
3511
|
const canFastReset = hasLaunchedOnce && driverOptions?.fastWebViewReset !== false && domChannel.isConnected() && !opts?.deepLink && !opts?.clearKeychain && !hasLaunchDeviceState(opts?.deviceState) && !(opts?.launchArguments && Object.keys(opts.launchArguments).length > 0);
|
|
6604
3512
|
if (canFastReset) {
|
|
@@ -6682,7 +3590,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6682
3590
|
},
|
|
6683
3591
|
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
6684
3592
|
}),
|
|
6685
|
-
stopApp: (appBundleId) =>
|
|
3593
|
+
stopApp: (appBundleId) => Effect5.tryPromise({
|
|
6686
3594
|
try: () => {
|
|
6687
3595
|
if (simulatorUdid) {
|
|
6688
3596
|
terminateOnSimulator(simulatorUdid, appBundleId);
|
|
@@ -6692,7 +3600,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6692
3600
|
},
|
|
6693
3601
|
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
6694
3602
|
}),
|
|
6695
|
-
killApp: (appBundleId) =>
|
|
3603
|
+
killApp: (appBundleId) => Effect5.tryPromise({
|
|
6696
3604
|
try: async () => {
|
|
6697
3605
|
await domChannel.disconnect().catch(() => {
|
|
6698
3606
|
});
|
|
@@ -6705,7 +3613,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6705
3613
|
},
|
|
6706
3614
|
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
6707
3615
|
}),
|
|
6708
|
-
clearAppState: (appBundleId) =>
|
|
3616
|
+
clearAppState: (appBundleId) => Effect5.tryPromise({
|
|
6709
3617
|
try: async () => {
|
|
6710
3618
|
if (domChannel.isConnected() && domChannel.clearStorage) {
|
|
6711
3619
|
await domChannel.clearStorage({
|
|
@@ -6728,7 +3636,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6728
3636
|
},
|
|
6729
3637
|
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
6730
3638
|
}),
|
|
6731
|
-
resetFast: () =>
|
|
3639
|
+
resetFast: () => Effect5.tryPromise({
|
|
6732
3640
|
try: async () => {
|
|
6733
3641
|
if (domChannel.clearStorage) {
|
|
6734
3642
|
await domChannel.clearStorage({
|
|
@@ -6755,7 +3663,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6755
3663
|
// -----------------------------------------------------------------------
|
|
6756
3664
|
// Navigation
|
|
6757
3665
|
// -----------------------------------------------------------------------
|
|
6758
|
-
openLink: (url) =>
|
|
3666
|
+
openLink: (url) => Effect5.tryPromise({
|
|
6759
3667
|
try: async () => {
|
|
6760
3668
|
if (simulatorUdid) {
|
|
6761
3669
|
await openSimulatorUrl(url);
|
|
@@ -6765,7 +3673,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6765
3673
|
},
|
|
6766
3674
|
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
6767
3675
|
}),
|
|
6768
|
-
back: () =>
|
|
3676
|
+
back: () => Effect5.tryPromise({
|
|
6769
3677
|
// iOS has no hardware back button; pressing home is the closest
|
|
6770
3678
|
// equivalent for dismissing the current context.
|
|
6771
3679
|
try: () => client.pressHome(),
|
|
@@ -6775,13 +3683,13 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6775
3683
|
// Direct DOM evaluation via spana-bridge or WebKit Remote Inspector
|
|
6776
3684
|
// (no Appium required)
|
|
6777
3685
|
// -----------------------------------------------------------------------
|
|
6778
|
-
evaluate: (script, ...args) =>
|
|
3686
|
+
evaluate: (script, ...args) => Effect5.tryPromise({
|
|
6779
3687
|
try: () => domChannel.evaluate(script, ...args),
|
|
6780
3688
|
catch: (e) => new DriverError({
|
|
6781
3689
|
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.`
|
|
6782
3690
|
})
|
|
6783
3691
|
}),
|
|
6784
|
-
getContexts: () =>
|
|
3692
|
+
getContexts: () => Effect5.tryPromise({
|
|
6785
3693
|
try: async () => {
|
|
6786
3694
|
const contexts = ["NATIVE_APP"];
|
|
6787
3695
|
if (domChannel.listTargets) {
|
|
@@ -6800,8 +3708,8 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6800
3708
|
},
|
|
6801
3709
|
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
6802
3710
|
}),
|
|
6803
|
-
getCurrentContext: () =>
|
|
6804
|
-
setContext: (contextId) =>
|
|
3711
|
+
getCurrentContext: () => Effect5.succeed(currentContext),
|
|
3712
|
+
setContext: (contextId) => Effect5.tryPromise({
|
|
6805
3713
|
try: async () => {
|
|
6806
3714
|
if (contextId === "NATIVE_APP") {
|
|
6807
3715
|
currentContext = "NATIVE_APP";
|
|
@@ -6821,7 +3729,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6821
3729
|
},
|
|
6822
3730
|
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
6823
3731
|
}),
|
|
6824
|
-
mockNetwork: (matcher, response) =>
|
|
3732
|
+
mockNetwork: (matcher, response) => Effect5.tryPromise({
|
|
6825
3733
|
try: async () => {
|
|
6826
3734
|
if (!domChannel.mockNetwork) {
|
|
6827
3735
|
throw new Error(
|
|
@@ -6832,7 +3740,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6832
3740
|
},
|
|
6833
3741
|
catch: (e) => new DriverError({ message: `mockNetwork failed: ${e}` })
|
|
6834
3742
|
}),
|
|
6835
|
-
blockNetwork: (matcher) =>
|
|
3743
|
+
blockNetwork: (matcher) => Effect5.tryPromise({
|
|
6836
3744
|
try: async () => {
|
|
6837
3745
|
if (!domChannel.blockNetwork) {
|
|
6838
3746
|
throw new Error(
|
|
@@ -6843,7 +3751,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6843
3751
|
},
|
|
6844
3752
|
catch: (e) => new DriverError({ message: `blockNetwork failed: ${e}` })
|
|
6845
3753
|
}),
|
|
6846
|
-
clearNetworkMocks: () =>
|
|
3754
|
+
clearNetworkMocks: () => Effect5.tryPromise({
|
|
6847
3755
|
try: async () => {
|
|
6848
3756
|
if (domChannel.clearNetworkMocks) {
|
|
6849
3757
|
await domChannel.clearNetworkMocks();
|
|
@@ -6851,18 +3759,18 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6851
3759
|
},
|
|
6852
3760
|
catch: (e) => new DriverError({ message: `clearNetworkMocks failed: ${e}` })
|
|
6853
3761
|
}),
|
|
6854
|
-
getConsoleLogs: () =>
|
|
3762
|
+
getConsoleLogs: () => Effect5.tryPromise({
|
|
6855
3763
|
try: async () => domChannel.getConsoleLogs ? domChannel.getConsoleLogs() : [],
|
|
6856
3764
|
catch: (e) => new DriverError({ message: `getConsoleLogs failed: ${e}` })
|
|
6857
3765
|
}),
|
|
6858
|
-
getJSErrors: () =>
|
|
3766
|
+
getJSErrors: () => Effect5.tryPromise({
|
|
6859
3767
|
try: async () => domChannel.getJSErrors ? domChannel.getJSErrors() : [],
|
|
6860
3768
|
catch: (e) => new DriverError({ message: `getJSErrors failed: ${e}` })
|
|
6861
3769
|
}),
|
|
6862
3770
|
// -----------------------------------------------------------------------
|
|
6863
3771
|
// Network simulation
|
|
6864
3772
|
// -----------------------------------------------------------------------
|
|
6865
|
-
setNetworkConditions: (conditions) =>
|
|
3773
|
+
setNetworkConditions: (conditions) => Effect5.tryPromise({
|
|
6866
3774
|
try: async () => {
|
|
6867
3775
|
if (!simulatorUdid) {
|
|
6868
3776
|
throw new DriverError({
|
|
@@ -6985,7 +3893,7 @@ function parseIOSHierarchy(xml) {
|
|
|
6985
3893
|
}
|
|
6986
3894
|
|
|
6987
3895
|
// src/drivers/electron.ts
|
|
6988
|
-
import { Effect as
|
|
3896
|
+
import { Effect as Effect6 } from "effect";
|
|
6989
3897
|
import {
|
|
6990
3898
|
_electron,
|
|
6991
3899
|
chromium as chromium2
|
|
@@ -7029,7 +3937,7 @@ var CLEAR_STORAGE_SCRIPT2 = `
|
|
|
7029
3937
|
})();
|
|
7030
3938
|
`;
|
|
7031
3939
|
function makeElectronDriver(options) {
|
|
7032
|
-
return
|
|
3940
|
+
return Effect6.gen(function* () {
|
|
7033
3941
|
let electronApp;
|
|
7034
3942
|
let cdpBrowser;
|
|
7035
3943
|
let context;
|
|
@@ -7053,13 +3961,13 @@ function makeElectronDriver(options) {
|
|
|
7053
3961
|
const resolvedCdpUrl = options.cdpUrl ?? (options.cdpPort && !options.entry && !options.executablePath ? `http://127.0.0.1:${options.cdpPort}` : void 0);
|
|
7054
3962
|
if (resolvedCdpUrl) {
|
|
7055
3963
|
const connect = options.connectOverCDP ?? chromium2.connectOverCDP.bind(chromium2);
|
|
7056
|
-
cdpBrowser = yield*
|
|
3964
|
+
cdpBrowser = yield* Effect6.tryPromise({
|
|
7057
3965
|
try: () => connect(resolvedCdpUrl),
|
|
7058
3966
|
catch: (e) => new DriverError({
|
|
7059
3967
|
message: `Failed to connect to Electron over CDP (${resolvedCdpUrl}): ${e}`
|
|
7060
3968
|
})
|
|
7061
3969
|
});
|
|
7062
|
-
page = yield*
|
|
3970
|
+
page = yield* Effect6.tryPromise({
|
|
7063
3971
|
try: async () => {
|
|
7064
3972
|
const contexts = cdpBrowser.contexts();
|
|
7065
3973
|
context = contexts[0];
|
|
@@ -7084,7 +3992,7 @@ function makeElectronDriver(options) {
|
|
|
7084
3992
|
});
|
|
7085
3993
|
}
|
|
7086
3994
|
const launcher = options.launchElectron ?? _electron.launch.bind(_electron);
|
|
7087
|
-
electronApp = yield*
|
|
3995
|
+
electronApp = yield* Effect6.tryPromise({
|
|
7088
3996
|
try: () => launcher({
|
|
7089
3997
|
...options.executablePath ? { executablePath: options.executablePath } : {},
|
|
7090
3998
|
...launchArgs.length > 0 ? { args: launchArgs } : {},
|
|
@@ -7093,7 +4001,7 @@ function makeElectronDriver(options) {
|
|
|
7093
4001
|
}),
|
|
7094
4002
|
catch: (e) => new DriverError({ message: `Failed to launch Electron app: ${e}` })
|
|
7095
4003
|
});
|
|
7096
|
-
page = yield*
|
|
4004
|
+
page = yield* Effect6.tryPromise({
|
|
7097
4005
|
try: async () => {
|
|
7098
4006
|
const win = await electronApp.firstWindow();
|
|
7099
4007
|
context = electronApp.context();
|
|
@@ -7123,26 +4031,26 @@ function makeElectronDriver(options) {
|
|
|
7123
4031
|
};
|
|
7124
4032
|
const service = {
|
|
7125
4033
|
domChannel,
|
|
7126
|
-
beginFlow: () =>
|
|
4034
|
+
beginFlow: () => Effect6.sync(() => {
|
|
7127
4035
|
consoleLogs.length = 0;
|
|
7128
4036
|
jsErrors.length = 0;
|
|
7129
4037
|
}),
|
|
7130
|
-
dumpHierarchy: () =>
|
|
4038
|
+
dumpHierarchy: () => Effect6.tryPromise({
|
|
7131
4039
|
try: async () => {
|
|
7132
4040
|
const tree = await page.evaluate(DOM_HIERARCHY_WALK_SCRIPT);
|
|
7133
4041
|
return JSON.stringify(tree);
|
|
7134
4042
|
},
|
|
7135
4043
|
catch: (e) => new DriverError({ message: `Electron dumpHierarchy failed: ${e}` })
|
|
7136
4044
|
}),
|
|
7137
|
-
tapAtCoordinate: (x, y) =>
|
|
4045
|
+
tapAtCoordinate: (x, y) => Effect6.tryPromise({
|
|
7138
4046
|
try: () => page.mouse.click(x, y),
|
|
7139
4047
|
catch: (e) => new DriverError({ message: `Electron tap failed at (${x}, ${y}): ${e}` })
|
|
7140
4048
|
}),
|
|
7141
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
4049
|
+
doubleTapAtCoordinate: (x, y) => Effect6.tryPromise({
|
|
7142
4050
|
try: () => page.mouse.dblclick(x, y),
|
|
7143
4051
|
catch: (e) => new DriverError({ message: `Electron doubleTap failed at (${x}, ${y}): ${e}` })
|
|
7144
4052
|
}),
|
|
7145
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
4053
|
+
longPressAtCoordinate: (x, y, duration) => Effect6.tryPromise({
|
|
7146
4054
|
try: async () => {
|
|
7147
4055
|
await page.mouse.move(x, y);
|
|
7148
4056
|
await page.mouse.down();
|
|
@@ -7151,7 +4059,7 @@ function makeElectronDriver(options) {
|
|
|
7151
4059
|
},
|
|
7152
4060
|
catch: (e) => new DriverError({ message: `Electron longPress failed: ${e}` })
|
|
7153
4061
|
}),
|
|
7154
|
-
swipe: (startX, startY, endX, endY, duration) =>
|
|
4062
|
+
swipe: (startX, startY, endX, endY, duration) => Effect6.tryPromise({
|
|
7155
4063
|
try: async () => {
|
|
7156
4064
|
await page.mouse.move(startX, startY);
|
|
7157
4065
|
await page.mouse.wheel(startX - endX, startY - endY);
|
|
@@ -7159,20 +4067,20 @@ function makeElectronDriver(options) {
|
|
|
7159
4067
|
},
|
|
7160
4068
|
catch: (e) => new DriverError({ message: `Electron swipe failed: ${e}` })
|
|
7161
4069
|
}),
|
|
7162
|
-
inputText: (text) =>
|
|
4070
|
+
inputText: (text) => Effect6.tryPromise({
|
|
7163
4071
|
try: () => page.keyboard.insertText(text),
|
|
7164
4072
|
catch: (e) => new DriverError({ message: `Electron inputText failed: ${e}` })
|
|
7165
4073
|
}),
|
|
7166
|
-
pressKey: (key) =>
|
|
4074
|
+
pressKey: (key) => Effect6.tryPromise({
|
|
7167
4075
|
try: () => page.keyboard.press(key),
|
|
7168
4076
|
catch: (e) => new DriverError({ message: `Electron pressKey failed: ${e}` })
|
|
7169
4077
|
}),
|
|
7170
|
-
hideKeyboard: () =>
|
|
7171
|
-
takeScreenshot: () =>
|
|
4078
|
+
hideKeyboard: () => Effect6.void,
|
|
4079
|
+
takeScreenshot: () => Effect6.tryPromise({
|
|
7172
4080
|
try: async () => new Uint8Array(await page.screenshot()),
|
|
7173
4081
|
catch: (e) => new DriverError({ message: `Electron screenshot failed: ${e}` })
|
|
7174
4082
|
}),
|
|
7175
|
-
getDeviceInfo: () =>
|
|
4083
|
+
getDeviceInfo: () => Effect6.tryPromise({
|
|
7176
4084
|
try: async () => {
|
|
7177
4085
|
const viewport = page.viewportSize() ?? { width: 1280, height: 800 };
|
|
7178
4086
|
return {
|
|
@@ -7187,7 +4095,7 @@ function makeElectronDriver(options) {
|
|
|
7187
4095
|
},
|
|
7188
4096
|
catch: (e) => new DriverError({ message: `Electron getDeviceInfo failed: ${e}` })
|
|
7189
4097
|
}),
|
|
7190
|
-
launchApp: (appRef, opts) =>
|
|
4098
|
+
launchApp: (appRef, opts) => Effect6.tryPromise({
|
|
7191
4099
|
try: async () => {
|
|
7192
4100
|
if (opts?.clearState) {
|
|
7193
4101
|
await clearStorageAndCookies();
|
|
@@ -7199,8 +4107,8 @@ function makeElectronDriver(options) {
|
|
|
7199
4107
|
},
|
|
7200
4108
|
catch: (e) => new DriverError({ message: `Electron launchApp failed: ${e}` })
|
|
7201
4109
|
}),
|
|
7202
|
-
stopApp: () =>
|
|
7203
|
-
killApp: () =>
|
|
4110
|
+
stopApp: () => Effect6.void,
|
|
4111
|
+
killApp: () => Effect6.tryPromise({
|
|
7204
4112
|
try: async () => {
|
|
7205
4113
|
await domChannel?.disconnect().catch(() => {
|
|
7206
4114
|
});
|
|
@@ -7212,32 +4120,32 @@ function makeElectronDriver(options) {
|
|
|
7212
4120
|
},
|
|
7213
4121
|
catch: (e) => new DriverError({ message: `Electron killApp failed: ${e}` })
|
|
7214
4122
|
}),
|
|
7215
|
-
clearAppState: () =>
|
|
4123
|
+
clearAppState: () => Effect6.tryPromise({
|
|
7216
4124
|
try: async () => {
|
|
7217
4125
|
await clearStorageAndCookies();
|
|
7218
4126
|
},
|
|
7219
4127
|
catch: (e) => new DriverError({ message: `Electron clearAppState failed: ${e}` })
|
|
7220
4128
|
}),
|
|
7221
|
-
resetFast: () =>
|
|
4129
|
+
resetFast: () => Effect6.tryPromise({
|
|
7222
4130
|
try: async () => {
|
|
7223
4131
|
await clearStorageAndCookies();
|
|
7224
4132
|
await page.reload();
|
|
7225
4133
|
},
|
|
7226
4134
|
catch: (e) => new DriverError({ message: `Electron resetFast failed: ${e}` })
|
|
7227
4135
|
}),
|
|
7228
|
-
openLink: (url) =>
|
|
4136
|
+
openLink: (url) => Effect6.tryPromise({
|
|
7229
4137
|
try: async () => {
|
|
7230
4138
|
await page.goto(url);
|
|
7231
4139
|
},
|
|
7232
4140
|
catch: (e) => new DriverError({ message: `Electron openLink failed: ${e}` })
|
|
7233
4141
|
}),
|
|
7234
|
-
back: () =>
|
|
4142
|
+
back: () => Effect6.tryPromise({
|
|
7235
4143
|
try: async () => {
|
|
7236
4144
|
await page.goBack();
|
|
7237
4145
|
},
|
|
7238
4146
|
catch: (e) => new DriverError({ message: `Electron back failed: ${e}` })
|
|
7239
4147
|
}),
|
|
7240
|
-
evaluate: (script, ...args) =>
|
|
4148
|
+
evaluate: (script, ...args) => Effect6.tryPromise({
|
|
7241
4149
|
try: async () => {
|
|
7242
4150
|
if (domChannel?.isConnected()) {
|
|
7243
4151
|
return await domChannel.evaluate(script, ...args);
|
|
@@ -7255,7 +4163,7 @@ function makeElectronDriver(options) {
|
|
|
7255
4163
|
},
|
|
7256
4164
|
catch: (e) => new DriverError({ message: `Electron evaluate failed: ${e}` })
|
|
7257
4165
|
}),
|
|
7258
|
-
mockNetwork: (matcher, response) =>
|
|
4166
|
+
mockNetwork: (matcher, response) => Effect6.tryPromise({
|
|
7259
4167
|
try: async () => {
|
|
7260
4168
|
if (!context) throw new Error("No Electron BrowserContext available");
|
|
7261
4169
|
await context.route(matcher, async (route) => {
|
|
@@ -7270,7 +4178,7 @@ function makeElectronDriver(options) {
|
|
|
7270
4178
|
},
|
|
7271
4179
|
catch: (e) => new DriverError({ message: `Electron mockNetwork failed: ${e}` })
|
|
7272
4180
|
}),
|
|
7273
|
-
blockNetwork: (matcher) =>
|
|
4181
|
+
blockNetwork: (matcher) => Effect6.tryPromise({
|
|
7274
4182
|
try: async () => {
|
|
7275
4183
|
if (!context) throw new Error("No Electron BrowserContext available");
|
|
7276
4184
|
await context.route(matcher, async (route) => {
|
|
@@ -7280,7 +4188,7 @@ function makeElectronDriver(options) {
|
|
|
7280
4188
|
},
|
|
7281
4189
|
catch: (e) => new DriverError({ message: `Electron blockNetwork failed: ${e}` })
|
|
7282
4190
|
}),
|
|
7283
|
-
clearNetworkMocks: () =>
|
|
4191
|
+
clearNetworkMocks: () => Effect6.tryPromise({
|
|
7284
4192
|
try: async () => {
|
|
7285
4193
|
if (!context) return;
|
|
7286
4194
|
for (const entry of appliedRoutes) {
|
|
@@ -7291,8 +4199,8 @@ function makeElectronDriver(options) {
|
|
|
7291
4199
|
},
|
|
7292
4200
|
catch: (e) => new DriverError({ message: `Electron clearNetworkMocks failed: ${e}` })
|
|
7293
4201
|
}),
|
|
7294
|
-
getConsoleLogs: () =>
|
|
7295
|
-
getJSErrors: () =>
|
|
4202
|
+
getConsoleLogs: () => Effect6.succeed([...consoleLogs]),
|
|
4203
|
+
getJSErrors: () => Effect6.succeed([...jsErrors])
|
|
7296
4204
|
};
|
|
7297
4205
|
return service;
|
|
7298
4206
|
});
|
|
@@ -7302,14 +4210,14 @@ function makeElectronDriver(options) {
|
|
|
7302
4210
|
import { execFileSync as execFileSync2, spawn as spawn2 } from "child_process";
|
|
7303
4211
|
import { existsSync, readdirSync } from "fs";
|
|
7304
4212
|
import { createRequire } from "module";
|
|
7305
|
-
import { dirname
|
|
4213
|
+
import { dirname, resolve, join as join2 } from "path";
|
|
7306
4214
|
import { fileURLToPath } from "url";
|
|
7307
4215
|
var __dirname2 = fileURLToPath(new URL(".", import.meta.url));
|
|
7308
4216
|
var require2 = createRequire(import.meta.url);
|
|
7309
4217
|
function resolveOptionalPackageDir(packageName, subpath) {
|
|
7310
4218
|
try {
|
|
7311
4219
|
const packageJsonPath = require2.resolve(`${packageName}/package.json`);
|
|
7312
|
-
return resolve(
|
|
4220
|
+
return resolve(dirname(packageJsonPath), subpath);
|
|
7313
4221
|
} catch {
|
|
7314
4222
|
return null;
|
|
7315
4223
|
}
|
|
@@ -7452,34 +4360,6 @@ async function setupUiAutomator2(serial, hostPort, options = {}) {
|
|
|
7452
4360
|
}
|
|
7453
4361
|
|
|
7454
4362
|
export {
|
|
7455
|
-
mergeLaunchOptions,
|
|
7456
|
-
hasLaunchDeviceState,
|
|
7457
|
-
deviceStateToAppiumCapabilities,
|
|
7458
|
-
buildIOSLaunchConfiguration,
|
|
7459
|
-
byRole,
|
|
7460
|
-
byCss,
|
|
7461
|
-
or,
|
|
7462
|
-
within,
|
|
7463
|
-
inFrame,
|
|
7464
|
-
nth,
|
|
7465
|
-
first,
|
|
7466
|
-
last,
|
|
7467
|
-
filterSelector,
|
|
7468
|
-
systemUI,
|
|
7469
|
-
isSystemUISelector,
|
|
7470
|
-
isTestIDSelector,
|
|
7471
|
-
isComposableDomSelector,
|
|
7472
|
-
splitGraphemes,
|
|
7473
|
-
flattenElements,
|
|
7474
|
-
invalidateWebViewFrameCache,
|
|
7475
|
-
findWebViewFrame,
|
|
7476
|
-
domRectToScreenBounds,
|
|
7477
|
-
isOffscreenInViewport,
|
|
7478
|
-
resolveElementAcrossChannels,
|
|
7479
|
-
createCoordinator,
|
|
7480
|
-
buildStorybookUrl,
|
|
7481
|
-
createPromiseExpect,
|
|
7482
|
-
createPromiseApp,
|
|
7483
4363
|
parseWebHierarchy,
|
|
7484
4364
|
deviceEffect,
|
|
7485
4365
|
resolveNetworkConditions,
|
|
@@ -7495,4 +4375,4 @@ export {
|
|
|
7495
4375
|
makeElectronDriver,
|
|
7496
4376
|
setupUiAutomator2
|
|
7497
4377
|
};
|
|
7498
|
-
//# sourceMappingURL=chunk-
|
|
4378
|
+
//# sourceMappingURL=chunk-FXBWACUT.js.map
|