spana-test 0.1.0 → 0.2.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.
Files changed (120) hide show
  1. package/.agents/skills/spana-testing/SKILL.md +4 -1
  2. package/README.md +277 -86
  3. package/dist/agent/index.d.ts +34 -5
  4. package/dist/agent/index.js +14 -10
  5. package/dist/{chunk-RK4Z6C7M.js → chunk-3YR4GUGE.js} +3 -2
  6. package/dist/chunk-3YR4GUGE.js.map +1 -0
  7. package/dist/{chunk-WIJYK22K.js → chunk-AEKDFFPJ.js} +2 -2
  8. package/dist/chunk-BF37W5EG.js +125 -0
  9. package/dist/chunk-BF37W5EG.js.map +1 -0
  10. package/dist/chunk-EXLUY7KT.js +21 -0
  11. package/dist/chunk-EXLUY7KT.js.map +1 -0
  12. package/dist/chunk-FNDOEMOL.js +62 -0
  13. package/dist/chunk-FNDOEMOL.js.map +1 -0
  14. package/dist/chunk-HWFDXIXR.js +183 -0
  15. package/dist/chunk-HWFDXIXR.js.map +1 -0
  16. package/dist/chunk-IJIASIX5.js +314 -0
  17. package/dist/chunk-IJIASIX5.js.map +1 -0
  18. package/dist/chunk-KJPHH2TW.js +168 -0
  19. package/dist/chunk-KJPHH2TW.js.map +1 -0
  20. package/dist/{chunk-RJ5VPHVX.js → chunk-L7MFJF46.js} +16 -6
  21. package/dist/chunk-L7MFJF46.js.map +1 -0
  22. package/dist/{chunk-5XO6S7AI.js → chunk-MRH7SK52.js} +4 -4
  23. package/dist/chunk-MRH7SK52.js.map +1 -0
  24. package/dist/{chunk-53MUJUJY.js → chunk-P7JQRLP4.js} +5 -4
  25. package/dist/{chunk-53MUJUJY.js.map → chunk-P7JQRLP4.js.map} +1 -1
  26. package/dist/chunk-S2XNAKSO.js +1087 -0
  27. package/dist/chunk-S2XNAKSO.js.map +1 -0
  28. package/dist/{chunk-VDWWIVM6.js → chunk-S4R4OR7T.js} +108 -53
  29. package/dist/chunk-S4R4OR7T.js.map +1 -0
  30. package/dist/{chunk-V62HFH6E.js → chunk-SFBRFB2N.js} +14 -6
  31. package/dist/chunk-SFBRFB2N.js.map +1 -0
  32. package/dist/{chunk-PWEOJKUF.js → chunk-VNYF5BHX.js} +28 -7
  33. package/dist/chunk-VNYF5BHX.js.map +1 -0
  34. package/dist/chunk-WBU34APM.js +38 -0
  35. package/dist/chunk-WBU34APM.js.map +1 -0
  36. package/dist/{chunk-CKJQX73M.js → chunk-WQ4GXUUE.js} +921 -352
  37. package/dist/chunk-WQ4GXUUE.js.map +1 -0
  38. package/dist/chunk-YBZCOQXJ.js +311 -0
  39. package/dist/chunk-YBZCOQXJ.js.map +1 -0
  40. package/dist/cli.js +316 -40
  41. package/dist/cli.js.map +1 -1
  42. package/dist/{compiler-G75RIIYS.js → compiler-74VGKZO6.js} +2 -2
  43. package/dist/{compiler-G75RIIYS.js.map → compiler-74VGKZO6.js.map} +1 -1
  44. package/dist/config-loader-BJJ3IJJ7.js +9 -0
  45. package/dist/{console-FV4RJPO4.js → console-XWKUTP3D.js} +39 -7
  46. package/dist/console-XWKUTP3D.js.map +1 -0
  47. package/dist/{config-Dg9O0rcQ.d.ts → coordinator-BbUjvvnX.d.ts} +165 -1
  48. package/dist/{discover-RWBKI5IB.js → discover-KZKXHZZA.js} +3 -3
  49. package/dist/doctor-command-T2UX5RV5.js +732 -0
  50. package/dist/doctor-command-T2UX5RV5.js.map +1 -0
  51. package/dist/{element-CGteXiXB.d.ts → element-DZ0HyJ3C.d.ts} +2 -0
  52. package/dist/{flow-D-_tlLpp.d.ts → flow-BUC9Mf8W.d.ts} +38 -9
  53. package/dist/gherkin/steps.d.ts +2 -2
  54. package/dist/{html-JP2HBIJQ.js → html-GE6Q4DCG.js} +23 -3
  55. package/dist/html-GE6Q4DCG.js.map +1 -0
  56. package/dist/index.d.ts +171 -3
  57. package/dist/index.js +6 -3
  58. package/dist/index.js.map +1 -1
  59. package/dist/{init-command-CELKL2CX.js → init-command-GVMRXIMY.js} +37 -21
  60. package/dist/init-command-GVMRXIMY.js.map +1 -0
  61. package/dist/init-flow-command-R76AXF4Z.js +34 -0
  62. package/dist/init-flow-command-R76AXF4Z.js.map +1 -0
  63. package/dist/{installer-R6NX7BYQ.js → installer-YZJ4DV3F.js} +4 -2
  64. package/dist/{ios-ZZU6DHH7.js → ios-ZW6XVNLG.js} +4 -2
  65. package/dist/json-KS67BZYU.js +39 -0
  66. package/dist/json-KS67BZYU.js.map +1 -0
  67. package/dist/{junit-UDY5JG22.js → junit-HLC62MK6.js} +2 -2
  68. package/dist/junit-HLC62MK6.js.map +1 -0
  69. package/dist/provider-A57C3MU6.js +12 -0
  70. package/dist/{redact-IDA3C4UH.js → redact-U72BUBBR.js} +2 -2
  71. package/dist/{redact-IDA3C4UH.js.map → redact-U72BUBBR.js.map} +1 -1
  72. package/dist/{runner-QEF6PJOE.js → runner-UXNHVVGG.js} +2 -2
  73. package/dist/{server-MMK7PZIH.js → server-W7OA3DDN.js} +49 -24
  74. package/dist/server-W7OA3DDN.js.map +1 -0
  75. package/dist/session-TMNOKYLG.js +17 -0
  76. package/dist/{studio-command-CDVPREMG.js → studio-command-6VHTHDUK.js} +2 -2
  77. package/dist/{test-command-SB5KYPQI.js → test-command-AHMOZLV4.js} +1280 -357
  78. package/dist/test-command-AHMOZLV4.js.map +1 -0
  79. package/dist/validator-35624P7S.js +20 -0
  80. package/package.json +1 -1
  81. package/studio-dist/assets/index-DC6DIXfl.js +188 -0
  82. package/studio-dist/assets/index-DDKsnBwD.css +1 -0
  83. package/studio-dist/index.html +2 -2
  84. package/dist/chunk-5XO6S7AI.js.map +0 -1
  85. package/dist/chunk-BZRLA4Z3.js +0 -82
  86. package/dist/chunk-BZRLA4Z3.js.map +0 -1
  87. package/dist/chunk-CKJQX73M.js.map +0 -1
  88. package/dist/chunk-PANFRTIU.js +0 -310
  89. package/dist/chunk-PANFRTIU.js.map +0 -1
  90. package/dist/chunk-PWEOJKUF.js.map +0 -1
  91. package/dist/chunk-RJ5VPHVX.js.map +0 -1
  92. package/dist/chunk-RK4Z6C7M.js.map +0 -1
  93. package/dist/chunk-U564GCO2.js +0 -259
  94. package/dist/chunk-U564GCO2.js.map +0 -1
  95. package/dist/chunk-V62HFH6E.js.map +0 -1
  96. package/dist/chunk-VDWWIVM6.js.map +0 -1
  97. package/dist/config-loader-JJ5RPP53.js +0 -9
  98. package/dist/console-FV4RJPO4.js.map +0 -1
  99. package/dist/html-JP2HBIJQ.js.map +0 -1
  100. package/dist/init-command-CELKL2CX.js.map +0 -1
  101. package/dist/json-JMRPUVY2.js +0 -20
  102. package/dist/json-JMRPUVY2.js.map +0 -1
  103. package/dist/junit-UDY5JG22.js.map +0 -1
  104. package/dist/provider-CUWPULGC.js +0 -10
  105. package/dist/server-MMK7PZIH.js.map +0 -1
  106. package/dist/session-FBJABNXL.js +0 -16
  107. package/dist/test-command-SB5KYPQI.js.map +0 -1
  108. package/dist/validator-CFQ55NUQ.js +0 -13
  109. package/studio-dist/assets/index-CPdpC9i-.css +0 -1
  110. package/studio-dist/assets/index-L1Wd0vop.js +0 -183
  111. /package/dist/{chunk-WIJYK22K.js.map → chunk-AEKDFFPJ.js.map} +0 -0
  112. /package/dist/{config-loader-JJ5RPP53.js.map → config-loader-BJJ3IJJ7.js.map} +0 -0
  113. /package/dist/{discover-RWBKI5IB.js.map → discover-KZKXHZZA.js.map} +0 -0
  114. /package/dist/{installer-R6NX7BYQ.js.map → installer-YZJ4DV3F.js.map} +0 -0
  115. /package/dist/{ios-ZZU6DHH7.js.map → ios-ZW6XVNLG.js.map} +0 -0
  116. /package/dist/{provider-CUWPULGC.js.map → provider-A57C3MU6.js.map} +0 -0
  117. /package/dist/{runner-QEF6PJOE.js.map → runner-UXNHVVGG.js.map} +0 -0
  118. /package/dist/{session-FBJABNXL.js.map → session-TMNOKYLG.js.map} +0 -0
  119. /package/dist/{studio-command-CDVPREMG.js.map → studio-command-6VHTHDUK.js.map} +0 -0
  120. /package/dist/{validator-CFQ55NUQ.js.map → validator-35624P7S.js.map} +0 -0
@@ -0,0 +1,1087 @@
1
+ // src/errors.ts
2
+ import { Schema } from "effect";
3
+ var ElementNotFoundError = class extends Schema.TaggedError()(
4
+ "ElementNotFoundError",
5
+ {
6
+ message: Schema.String,
7
+ selector: Schema.Unknown,
8
+ timeoutMs: Schema.optional(Schema.Number)
9
+ }
10
+ ) {
11
+ };
12
+ var TextMismatchError = class extends Schema.TaggedError()(
13
+ "TextMismatchError",
14
+ {
15
+ message: Schema.String,
16
+ expected: Schema.String,
17
+ actual: Schema.optional(Schema.String),
18
+ selector: Schema.Unknown
19
+ }
20
+ ) {
21
+ };
22
+ var TimeoutError = class extends Schema.TaggedError()(
23
+ "TimeoutError",
24
+ {
25
+ message: Schema.String,
26
+ operation: Schema.String,
27
+ timeoutMs: Schema.Number
28
+ }
29
+ ) {
30
+ };
31
+ var WaitTimeoutError = class extends Schema.TaggedError()(
32
+ "WaitTimeoutError",
33
+ {
34
+ message: Schema.String,
35
+ selector: Schema.Unknown,
36
+ timeoutMs: Schema.Number
37
+ }
38
+ ) {
39
+ };
40
+ var DriverError = class extends Schema.TaggedError()(
41
+ "DriverError",
42
+ {
43
+ message: Schema.String,
44
+ command: Schema.optional(Schema.String),
45
+ exitCode: Schema.optional(Schema.Number),
46
+ stdout: Schema.optional(Schema.String),
47
+ stderr: Schema.optional(Schema.String)
48
+ }
49
+ ) {
50
+ };
51
+ var DeviceDisconnectedError = class extends Schema.TaggedError()(
52
+ "DeviceDisconnectedError",
53
+ {
54
+ message: Schema.String,
55
+ deviceId: Schema.optional(Schema.String),
56
+ platform: Schema.optional(Schema.String)
57
+ }
58
+ ) {
59
+ };
60
+ var AppCrashedError = class extends Schema.TaggedError()(
61
+ "AppCrashedError",
62
+ {
63
+ message: Schema.String,
64
+ appId: Schema.optional(Schema.String),
65
+ platform: Schema.optional(Schema.String)
66
+ }
67
+ ) {
68
+ };
69
+ var AppNotInstalledError = class extends Schema.TaggedError()(
70
+ "AppNotInstalledError",
71
+ {
72
+ message: Schema.String,
73
+ appId: Schema.String,
74
+ platform: Schema.optional(Schema.String)
75
+ }
76
+ ) {
77
+ };
78
+ var FlowSyntaxError = class extends Schema.TaggedError()(
79
+ "FlowSyntaxError",
80
+ {
81
+ message: Schema.String,
82
+ filePath: Schema.String
83
+ }
84
+ ) {
85
+ };
86
+ var DeviceNotFoundError = class extends Schema.TaggedError()(
87
+ "DeviceNotFoundError",
88
+ {
89
+ message: Schema.String,
90
+ platform: Schema.optional(Schema.String),
91
+ deviceId: Schema.optional(Schema.String)
92
+ }
93
+ ) {
94
+ };
95
+ var ConfigError = class extends Schema.TaggedError()(
96
+ "ConfigError",
97
+ {
98
+ message: Schema.String,
99
+ filePath: Schema.optional(Schema.String)
100
+ }
101
+ ) {
102
+ };
103
+
104
+ // src/schemas/selector.ts
105
+ import { Schema as Schema2 } from "effect";
106
+ var TestIDSelector = Schema2.Struct({ testID: Schema2.String });
107
+ var TextSelector = Schema2.Struct({ text: Schema2.String });
108
+ var AccessibilityLabelSelector = Schema2.Struct({ accessibilityLabel: Schema2.String });
109
+ var PointSelector = Schema2.Struct({
110
+ point: Schema2.Struct({ x: Schema2.Number, y: Schema2.Number })
111
+ });
112
+ var Selector = Schema2.Union(
113
+ Schema2.String,
114
+ TestIDSelector,
115
+ TextSelector,
116
+ AccessibilityLabelSelector,
117
+ PointSelector
118
+ );
119
+ function isRelativeSelector(sel) {
120
+ return typeof sel === "object" && sel !== null && "selector" in sel;
121
+ }
122
+
123
+ // src/smart/element-matcher.ts
124
+ function flattenElements(root) {
125
+ const result = [];
126
+ const stack = [root];
127
+ while (stack.length > 0) {
128
+ const node = stack.pop();
129
+ result.push(node);
130
+ if (node.children) {
131
+ for (let i = node.children.length - 1; i >= 0; i--) {
132
+ stack.push(node.children[i]);
133
+ }
134
+ }
135
+ }
136
+ return result;
137
+ }
138
+ function matchesSelector(element, selector) {
139
+ if (typeof selector === "string") {
140
+ return element.text?.toLowerCase().includes(selector.toLowerCase()) ?? false;
141
+ }
142
+ if ("testID" in selector) {
143
+ return element.id === selector.testID;
144
+ }
145
+ if ("text" in selector) {
146
+ return element.text?.toLowerCase().includes(selector.text.toLowerCase()) ?? false;
147
+ }
148
+ if ("accessibilityLabel" in selector) {
149
+ return element.accessibilityLabel === selector.accessibilityLabel;
150
+ }
151
+ if ("point" in selector) {
152
+ const { x, y } = selector.point;
153
+ const b = element.bounds;
154
+ return x >= b.x && x <= b.x + b.width && y >= b.y && y <= b.y + b.height;
155
+ }
156
+ return false;
157
+ }
158
+ function findElements(root, selector) {
159
+ return flattenElements(root).filter((el) => matchesSelector(el, selector));
160
+ }
161
+ function isProbablyOnScreen(element) {
162
+ const centerX = element.bounds.x + element.bounds.width / 2;
163
+ const centerY = element.bounds.y + element.bounds.height / 2;
164
+ return element.bounds.width > 0 && element.bounds.height > 0 && centerX >= 0 && centerY >= 0;
165
+ }
166
+ function findPathToElement(root, target) {
167
+ const stack = [{ element: root, ancestors: [] }];
168
+ while (stack.length > 0) {
169
+ const current = stack.pop();
170
+ if (current.element === target) {
171
+ return current;
172
+ }
173
+ const children = current.element.children;
174
+ if (!children) {
175
+ continue;
176
+ }
177
+ for (let index = children.length - 1; index >= 0; index -= 1) {
178
+ const child = children[index];
179
+ stack.push({
180
+ element: child,
181
+ ancestors: [...current.ancestors, current.element]
182
+ });
183
+ }
184
+ }
185
+ return void 0;
186
+ }
187
+ function isActionable(element) {
188
+ return element.visible !== false && element.enabled !== false && element.clickable === true && isProbablyOnScreen(element);
189
+ }
190
+ function resolveActionTarget(root, element) {
191
+ const path = findPathToElement(root, element);
192
+ if (!path) {
193
+ return element;
194
+ }
195
+ const candidates = [path.element, ...path.ancestors.toReversed()];
196
+ return candidates.find(isActionable) ?? element;
197
+ }
198
+ function findElement(root, selector) {
199
+ const matches = findElements(root, selector).filter((el) => el.visible !== false);
200
+ if (matches.length === 0) return void 0;
201
+ const visibleMatches = matches.filter(isProbablyOnScreen);
202
+ if (visibleMatches.length === 0) return void 0;
203
+ const clickable = visibleMatches.filter((el) => el.clickable);
204
+ if (clickable.length > 0) return clickable[clickable.length - 1];
205
+ return visibleMatches[visibleMatches.length - 1];
206
+ }
207
+ function centerOf(element) {
208
+ return {
209
+ x: Math.round(element.bounds.x + element.bounds.width / 2),
210
+ y: Math.round(element.bounds.y + element.bounds.height / 2)
211
+ };
212
+ }
213
+ function formatSelector(sel) {
214
+ if (isRelativeSelector(sel)) {
215
+ const parts = [formatSimpleSelector(sel.selector)];
216
+ if (sel.below) parts.push(`below ${formatSimpleSelector(sel.below)}`);
217
+ if (sel.above) parts.push(`above ${formatSimpleSelector(sel.above)}`);
218
+ if (sel.leftOf) parts.push(`leftOf ${formatSimpleSelector(sel.leftOf)}`);
219
+ if (sel.rightOf) parts.push(`rightOf ${formatSimpleSelector(sel.rightOf)}`);
220
+ if (sel.childOf) parts.push(`childOf ${formatSimpleSelector(sel.childOf)}`);
221
+ return parts.join(" ");
222
+ }
223
+ return formatSimpleSelector(sel);
224
+ }
225
+ function formatSimpleSelector(sel) {
226
+ if (typeof sel === "string") return `"${sel}"`;
227
+ if ("testID" in sel) return `testID: "${sel.testID}"`;
228
+ if ("text" in sel) return `text: "${sel.text}"`;
229
+ if ("accessibilityLabel" in sel) return `accessibilityLabel: "${sel.accessibilityLabel}"`;
230
+ if ("point" in sel) return `point: (${sel.point.x}, ${sel.point.y})`;
231
+ return JSON.stringify(sel);
232
+ }
233
+ function findElementExtended(root, selector) {
234
+ if (!isRelativeSelector(selector)) {
235
+ return findElement(root, selector);
236
+ }
237
+ return findRelativeElement(root, selector);
238
+ }
239
+ function findActionElementExtended(root, selector) {
240
+ const match = findElementExtended(root, selector);
241
+ return match ? resolveActionTarget(root, match) : void 0;
242
+ }
243
+ function findRelativeElement(root, rel) {
244
+ const all = flattenElements(root).filter((el) => el.visible !== false && isProbablyOnScreen(el));
245
+ let candidates = all.filter((el) => matchesSelector(el, rel.selector));
246
+ if (candidates.length === 0) return void 0;
247
+ if (rel.below) {
248
+ const anchor = findElement(root, rel.below);
249
+ if (!anchor) return void 0;
250
+ const anchorBottom = anchor.bounds.y + anchor.bounds.height;
251
+ candidates = candidates.filter((el) => el.bounds.y >= anchorBottom);
252
+ candidates.sort((a, b) => a.bounds.y - b.bounds.y);
253
+ }
254
+ if (rel.above) {
255
+ const anchor = findElement(root, rel.above);
256
+ if (!anchor) return void 0;
257
+ const anchorTop = anchor.bounds.y;
258
+ candidates = candidates.filter((el) => el.bounds.y + el.bounds.height <= anchorTop);
259
+ candidates.sort((a, b) => b.bounds.y - a.bounds.y);
260
+ }
261
+ if (rel.leftOf) {
262
+ const anchor = findElement(root, rel.leftOf);
263
+ if (!anchor) return void 0;
264
+ const anchorLeft = anchor.bounds.x;
265
+ candidates = candidates.filter((el) => el.bounds.x + el.bounds.width <= anchorLeft);
266
+ candidates.sort((a, b) => b.bounds.x - a.bounds.x);
267
+ }
268
+ if (rel.rightOf) {
269
+ const anchor = findElement(root, rel.rightOf);
270
+ if (!anchor) return void 0;
271
+ const anchorRight = anchor.bounds.x + anchor.bounds.width;
272
+ candidates = candidates.filter((el) => el.bounds.x >= anchorRight);
273
+ candidates.sort((a, b) => a.bounds.x - b.bounds.x);
274
+ }
275
+ if (rel.childOf) {
276
+ const parent = findElement(root, rel.childOf);
277
+ if (!parent) return void 0;
278
+ const descendants = flattenElements(parent);
279
+ const descendantSet = new Set(descendants);
280
+ candidates = candidates.filter((el) => descendantSet.has(el) && el !== parent);
281
+ }
282
+ return candidates[0];
283
+ }
284
+
285
+ // src/smart/coordinator.ts
286
+ import { Duration as Duration2, Effect as Effect3 } from "effect";
287
+
288
+ // src/core/graphemes.ts
289
+ function splitGraphemes(text) {
290
+ if (text.length === 0) {
291
+ return [];
292
+ }
293
+ const Segmenter = globalThis.Intl?.Segmenter;
294
+ if (!Segmenter) {
295
+ return Array.from(text);
296
+ }
297
+ return Array.from(
298
+ new Segmenter(void 0, { granularity: "grapheme" }).segment(text),
299
+ (part) => part.segment
300
+ );
301
+ }
302
+
303
+ // src/smart/auto-wait.ts
304
+ import { Duration, Effect } from "effect";
305
+
306
+ // src/smart/diagnostics.ts
307
+ function diagnoseElementNotFound(root, selector) {
308
+ const allElements = flattenElements(root);
309
+ const totalElements = allElements.length;
310
+ const suggestions = [];
311
+ const simpleSelector = isRelativeSelector(selector) ? selector.selector : selector;
312
+ const matchingButHidden = allElements.filter(
313
+ (el) => matchesSelector(el, simpleSelector) && el.visible === false
314
+ );
315
+ if (matchingButHidden.length > 0) {
316
+ return {
317
+ reason: "not-visible",
318
+ suggestions: [
319
+ `Element matches selector but has visible=false (${matchingButHidden.length} match(es))`
320
+ ],
321
+ totalElements
322
+ };
323
+ }
324
+ const matchingButOffScreen = allElements.filter(
325
+ (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)
326
+ );
327
+ if (matchingButOffScreen.length > 0) {
328
+ return {
329
+ reason: "off-screen",
330
+ suggestions: [
331
+ `Element matches selector but is off-screen or has zero size (${matchingButOffScreen.length} match(es))`
332
+ ],
333
+ totalElements
334
+ };
335
+ }
336
+ const matchingButDisabled = allElements.filter(
337
+ (el) => matchesSelector(el, simpleSelector) && el.visible !== false && el.enabled === false
338
+ );
339
+ if (matchingButDisabled.length > 0) {
340
+ return {
341
+ reason: "not-interactive",
342
+ suggestions: [`Element matches selector but is disabled (enabled=false)`],
343
+ totalElements
344
+ };
345
+ }
346
+ if (typeof simpleSelector === "string") {
347
+ const similar = findSimilarByText(allElements, simpleSelector);
348
+ suggestions.push(...similar);
349
+ } else if ("testID" in simpleSelector && simpleSelector.testID) {
350
+ const similar = findSimilarByTestID(allElements, simpleSelector.testID);
351
+ suggestions.push(...similar);
352
+ } else if ("text" in simpleSelector && simpleSelector.text) {
353
+ const similar = findSimilarByText(allElements, simpleSelector.text);
354
+ suggestions.push(...similar);
355
+ }
356
+ return { reason: "not-found", suggestions, totalElements };
357
+ }
358
+ function findSimilarByTestID(elements, targetId) {
359
+ const lower = targetId.toLowerCase();
360
+ const prefix = lower.slice(0, Math.max(3, Math.floor(lower.length / 2)));
361
+ return elements.filter((el) => el.id && el.id.toLowerCase().includes(prefix)).slice(0, 3).map((el) => `Did you mean testID "${el.id}"?`);
362
+ }
363
+ function findSimilarByText(elements, targetText) {
364
+ const lower = targetText.toLowerCase();
365
+ const prefix = lower.slice(0, 3);
366
+ return elements.filter((el) => {
367
+ if (!el.text) return false;
368
+ const elLower = el.text.toLowerCase();
369
+ return elLower.includes(prefix) || lower.includes(elLower.slice(0, 3));
370
+ }).filter((el) => el.visible !== false).slice(0, 3).map((el) => `Did you mean text "${el.text}"?`);
371
+ }
372
+ function formatDiagnostic(diag) {
373
+ const parts = [];
374
+ if (diag.reason === "not-visible") {
375
+ parts.push("Element exists but is not visible.");
376
+ } else if (diag.reason === "off-screen") {
377
+ parts.push("Element exists but is off-screen or has zero size. Try scrolling to it.");
378
+ } else if (diag.reason === "not-interactive") {
379
+ parts.push("Element exists but is disabled (not interactive).");
380
+ }
381
+ if (diag.suggestions.length > 0) {
382
+ parts.push(...diag.suggestions);
383
+ }
384
+ parts.push(`(${diag.totalElements} elements in hierarchy)`);
385
+ return parts.join("\n");
386
+ }
387
+
388
+ // src/smart/auto-wait.ts
389
+ var DEFAULT_TIMEOUT = 5e3;
390
+ var DEFAULT_POLL_INTERVAL = 200;
391
+ var DEFAULT_INITIAL_POLL_INTERVAL = 50;
392
+ var DEFAULT_SETTLE_TIMEOUT = 0;
393
+ function getHierarchy(driver, parse, cache) {
394
+ if (cache) return cache.get(driver, parse);
395
+ return Effect.gen(function* () {
396
+ const raw = yield* driver.dumpHierarchy();
397
+ return parse(raw);
398
+ });
399
+ }
400
+ function nextInterval(elapsed, timeout, initial, max) {
401
+ if (initial >= max) return max;
402
+ const rampDuration = timeout / 2;
403
+ const progress = Math.min(elapsed / rampDuration, 1);
404
+ return Math.round(initial + (max - initial) * progress);
405
+ }
406
+ function waitForResolvedElement(driver, selector, parse, resolveElement, opts, cache) {
407
+ const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
408
+ const pollInterval = opts?.pollInterval ?? DEFAULT_POLL_INTERVAL;
409
+ const initialPollInterval = opts?.initialPollInterval ?? DEFAULT_INITIAL_POLL_INTERVAL;
410
+ const settleTimeout = opts?.settleTimeout ?? DEFAULT_SETTLE_TIMEOUT;
411
+ return Effect.gen(function* () {
412
+ const start = Date.now();
413
+ let isFirstPoll = true;
414
+ while (Date.now() - start < timeout) {
415
+ if (!isFirstPoll && cache) cache.invalidate();
416
+ isFirstPoll = false;
417
+ const root = yield* getHierarchy(driver, parse, cache);
418
+ const element = resolveElement(root, selector);
419
+ if (element) {
420
+ if (settleTimeout > 0) {
421
+ yield* Effect.sleep(Duration.millis(settleTimeout));
422
+ if (cache) cache.invalidate();
423
+ const settledRoot = yield* getHierarchy(driver, parse, cache);
424
+ const settledElement = resolveElement(settledRoot, selector);
425
+ if (settledElement) return settledElement;
426
+ } else {
427
+ return element;
428
+ }
429
+ }
430
+ const elapsed = Date.now() - start;
431
+ const interval = nextInterval(elapsed, timeout, initialPollInterval, pollInterval);
432
+ yield* Effect.sleep(Duration.millis(interval));
433
+ }
434
+ if (cache) cache.invalidate();
435
+ const diagRoot = yield* getHierarchy(driver, parse, cache);
436
+ const diagnostic = diagnoseElementNotFound(diagRoot, selector);
437
+ const diagMessage = formatDiagnostic(diagnostic);
438
+ return yield* new ElementNotFoundError({
439
+ message: `Element not found within ${timeout}ms \u2014 selector: ${formatSelector(selector)}
440
+ ${diagMessage}`,
441
+ selector,
442
+ timeoutMs: timeout
443
+ });
444
+ });
445
+ }
446
+ function waitForElement(driver, selector, parse, opts, cache) {
447
+ return waitForResolvedElement(driver, selector, parse, findElementExtended, opts, cache);
448
+ }
449
+ function waitForActionElement(driver, selector, parse, opts, cache) {
450
+ return waitForResolvedElement(driver, selector, parse, findActionElementExtended, opts, cache);
451
+ }
452
+ function waitForNotVisible(driver, selector, parse, opts, cache) {
453
+ const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
454
+ const pollInterval = opts?.pollInterval ?? DEFAULT_POLL_INTERVAL;
455
+ const initialPollInterval = opts?.initialPollInterval ?? DEFAULT_INITIAL_POLL_INTERVAL;
456
+ return Effect.gen(function* () {
457
+ const start = Date.now();
458
+ let isFirstPoll = true;
459
+ while (Date.now() - start < timeout) {
460
+ if (!isFirstPoll && cache) cache.invalidate();
461
+ isFirstPoll = false;
462
+ const root = yield* getHierarchy(driver, parse, cache);
463
+ const element = findElementExtended(root, selector);
464
+ if (!element) return;
465
+ const elapsed = Date.now() - start;
466
+ const interval = nextInterval(elapsed, timeout, initialPollInterval, pollInterval);
467
+ yield* Effect.sleep(Duration.millis(interval));
468
+ }
469
+ return yield* new WaitTimeoutError({
470
+ message: `Element still visible after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
471
+ selector,
472
+ timeoutMs: timeout
473
+ });
474
+ });
475
+ }
476
+
477
+ // src/smart/hierarchy-cache.ts
478
+ import { Effect as Effect2 } from "effect";
479
+ var DEFAULT_CACHE_TTL = 100;
480
+ function createHierarchyCache(config) {
481
+ const ttl = config?.hierarchyCacheTtl ?? DEFAULT_CACHE_TTL;
482
+ let cachedRoot;
483
+ let cachedAt = 0;
484
+ return {
485
+ get(driver, parse) {
486
+ return Effect2.gen(function* () {
487
+ const now = Date.now();
488
+ if (ttl > 0 && cachedRoot && now - cachedAt < ttl) {
489
+ return cachedRoot;
490
+ }
491
+ const raw = yield* driver.dumpHierarchy();
492
+ const root = parse(raw);
493
+ if (ttl > 0) {
494
+ cachedRoot = root;
495
+ cachedAt = Date.now();
496
+ }
497
+ return root;
498
+ });
499
+ },
500
+ invalidate() {
501
+ cachedRoot = void 0;
502
+ cachedAt = 0;
503
+ }
504
+ };
505
+ }
506
+
507
+ // src/smart/coordinator.ts
508
+ var DEFAULT_SCROLL_SEARCH_DIRECTION = "down";
509
+ var DEFAULT_MAX_SCROLLS = 5;
510
+ var DEFAULT_DISMISS_KEYBOARD_STRATEGY = "auto";
511
+ var DEFAULT_MAX_BACKS = 3;
512
+ function computeSwipeCoords(direction, screenW, screenH, offsetFraction) {
513
+ const cx = screenW / 2;
514
+ const cy = screenH / 2;
515
+ const offset = Math.min(screenW, screenH) * offsetFraction;
516
+ return {
517
+ up: { startX: cx, startY: cy + offset, endX: cx, endY: cy - offset },
518
+ down: { startX: cx, startY: cy - offset, endX: cx, endY: cy + offset },
519
+ left: { startX: cx + offset, startY: cy, endX: cx - offset, endY: cy },
520
+ right: { startX: cx - offset, startY: cy, endX: cx + offset, endY: cy }
521
+ }[direction];
522
+ }
523
+ function createCoordinator(driver, config) {
524
+ const { parse, defaults } = config;
525
+ const cacheConfig = {
526
+ hierarchyCacheTtl: config.hierarchyCacheTtl
527
+ };
528
+ const cache = createHierarchyCache(cacheConfig);
529
+ const idleWait = () => {
530
+ const ms = config.waitForIdleTimeout;
531
+ return ms && ms > 0 ? Effect3.sleep(Duration2.millis(ms)) : Effect3.void;
532
+ };
533
+ const afterMutation = () => Effect3.gen(function* () {
534
+ cache.invalidate();
535
+ yield* idleWait();
536
+ });
537
+ const screenH = config.screenHeight ?? 1920;
538
+ const safeMinY = screenH * 0.15;
539
+ const safeMaxY = screenH * 0.85;
540
+ const clampY = (y) => Math.max(safeMinY, Math.min(safeMaxY, y));
541
+ const swipeEffect = (direction, opts) => Effect3.gen(function* () {
542
+ const w = config.screenWidth ?? 1080;
543
+ const h = config.screenHeight ?? 1920;
544
+ const coords = computeSwipeCoords(direction, w, h, 0.2);
545
+ yield* driver.swipe(
546
+ coords.startX,
547
+ clampY(coords.startY),
548
+ coords.endX,
549
+ clampY(coords.endY),
550
+ opts?.duration ?? 300
551
+ );
552
+ yield* afterMutation();
553
+ });
554
+ const scrollEffect = (direction) => Effect3.gen(function* () {
555
+ const w = config.screenWidth ?? 1080;
556
+ const h = config.screenHeight ?? 1920;
557
+ const coords = computeSwipeCoords(direction, w, h, 0.3);
558
+ yield* driver.swipe(
559
+ coords.startX,
560
+ clampY(coords.startY),
561
+ coords.endX,
562
+ clampY(coords.endY),
563
+ 500
564
+ );
565
+ yield* Effect3.promise(() => new Promise((r) => setTimeout(r, 300)));
566
+ yield* afterMutation();
567
+ });
568
+ const probeVisible = (selector, opts) => Effect3.gen(function* () {
569
+ cache.invalidate();
570
+ const probeTimeout = opts?.probeTimeout ?? 1;
571
+ const result = yield* Effect3.either(
572
+ waitForElement(
573
+ driver,
574
+ selector,
575
+ parse,
576
+ { ...defaults, ...opts, timeout: probeTimeout },
577
+ cache
578
+ )
579
+ );
580
+ if (result._tag === "Right") {
581
+ return true;
582
+ }
583
+ if (result.left._tag === "ElementNotFoundError" || result.left._tag === "WaitTimeoutError") {
584
+ return false;
585
+ }
586
+ return yield* result.left;
587
+ });
588
+ const gestureDirectionForSearch = (direction) => {
589
+ const directionMap = {
590
+ up: "down",
591
+ down: "up",
592
+ left: "right",
593
+ right: "left"
594
+ };
595
+ return directionMap[direction];
596
+ };
597
+ const pollUntilMatch = (selector, opts, check, formatError) => Effect3.gen(function* () {
598
+ const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
599
+ const pollInterval = opts?.pollInterval ?? defaults?.pollInterval ?? 200;
600
+ const start = Date.now();
601
+ let lastActual;
602
+ while (Date.now() - start < timeout) {
603
+ if (cache) cache.invalidate();
604
+ const raw = yield* driver.dumpHierarchy();
605
+ const root = parse(raw);
606
+ const element = findElementExtended(root, selector);
607
+ if (element) {
608
+ const result = check(element);
609
+ if (result.matched) return;
610
+ lastActual = result.actual;
611
+ }
612
+ yield* Effect3.sleep(Duration2.millis(pollInterval));
613
+ }
614
+ const err = formatError(lastActual, timeout);
615
+ return yield* new TextMismatchError({
616
+ message: err.message,
617
+ expected: err.expected,
618
+ actual: lastActual,
619
+ selector
620
+ });
621
+ });
622
+ const dismissKeyboardWithDriver = () => Effect3.gen(function* () {
623
+ yield* driver.hideKeyboard();
624
+ yield* afterMutation();
625
+ });
626
+ const dismissKeyboardWithBack = () => Effect3.gen(function* () {
627
+ yield* driver.back();
628
+ yield* afterMutation();
629
+ });
630
+ return {
631
+ tap: (selector, opts) => Effect3.gen(function* () {
632
+ const element = yield* waitForActionElement(
633
+ driver,
634
+ selector,
635
+ parse,
636
+ { ...defaults, ...opts },
637
+ cache
638
+ );
639
+ const { x, y } = centerOf(element);
640
+ yield* driver.tapAtCoordinate(x, y);
641
+ yield* afterMutation();
642
+ }),
643
+ tapXY: (x, y) => Effect3.gen(function* () {
644
+ yield* driver.tapAtCoordinate(x, y);
645
+ yield* afterMutation();
646
+ }),
647
+ doubleTap: (selector, opts) => Effect3.gen(function* () {
648
+ const element = yield* waitForActionElement(
649
+ driver,
650
+ selector,
651
+ parse,
652
+ { ...defaults, ...opts },
653
+ cache
654
+ );
655
+ const { x, y } = centerOf(element);
656
+ yield* driver.tapAtCoordinate(x, y);
657
+ yield* Effect3.promise(() => new Promise((r) => setTimeout(r, 200)));
658
+ yield* driver.tapAtCoordinate(x, y);
659
+ yield* afterMutation();
660
+ }),
661
+ longPress: (selector, duration = 1e3, opts) => Effect3.gen(function* () {
662
+ const element = yield* waitForActionElement(
663
+ driver,
664
+ selector,
665
+ parse,
666
+ { ...defaults, ...opts },
667
+ cache
668
+ );
669
+ const { x, y } = centerOf(element);
670
+ yield* driver.longPressAtCoordinate(x, y, duration);
671
+ yield* afterMutation();
672
+ }),
673
+ longPressXY: (x, y, duration = 1e3) => Effect3.gen(function* () {
674
+ yield* driver.longPressAtCoordinate(x, y, duration);
675
+ yield* afterMutation();
676
+ }),
677
+ inputText: (text) => Effect3.gen(function* () {
678
+ const delay = config.typingDelay;
679
+ if (delay && delay > 0) {
680
+ for (const segment of splitGraphemes(text)) {
681
+ yield* driver.inputText(segment);
682
+ yield* Effect3.sleep(Duration2.millis(delay));
683
+ }
684
+ } else {
685
+ yield* driver.inputText(text);
686
+ }
687
+ yield* afterMutation();
688
+ }),
689
+ pressKey: (key) => Effect3.gen(function* () {
690
+ yield* driver.pressKey(key);
691
+ cache.invalidate();
692
+ }),
693
+ hideKeyboard: () => Effect3.gen(function* () {
694
+ yield* driver.hideKeyboard();
695
+ cache.invalidate();
696
+ }),
697
+ dismissKeyboard: (opts) => Effect3.gen(function* () {
698
+ const strategy = opts?.strategy ?? DEFAULT_DISMISS_KEYBOARD_STRATEGY;
699
+ if (strategy === "driver") {
700
+ return yield* dismissKeyboardWithDriver();
701
+ }
702
+ if (strategy === "back") {
703
+ return yield* dismissKeyboardWithBack();
704
+ }
705
+ const platform = (yield* driver.getDeviceInfo()).platform;
706
+ const hideKeyboardResult = yield* Effect3.either(driver.hideKeyboard());
707
+ if (hideKeyboardResult._tag === "Right") {
708
+ yield* afterMutation();
709
+ return;
710
+ }
711
+ if (platform === "android") {
712
+ const backResult = yield* Effect3.either(driver.back());
713
+ if (backResult._tag === "Right") {
714
+ yield* afterMutation();
715
+ return;
716
+ }
717
+ return yield* new DriverError({
718
+ message: `dismissKeyboard() failed with strategy "auto" on android. hideKeyboard(): ${hideKeyboardResult.left.message}. back(): ${backResult.left.message}`
719
+ });
720
+ }
721
+ return yield* new DriverError({
722
+ message: `dismissKeyboard() failed with strategy "auto" on ${platform}. hideKeyboard(): ${hideKeyboardResult.left.message}`
723
+ });
724
+ }),
725
+ swipe: (direction, opts) => swipeEffect(direction, opts),
726
+ scroll: (direction) => scrollEffect(direction),
727
+ scrollUntilVisible: (selector, opts) => Effect3.gen(function* () {
728
+ const searchDirection = opts?.direction ?? DEFAULT_SCROLL_SEARCH_DIRECTION;
729
+ const gestureDirection = gestureDirectionForSearch(searchDirection);
730
+ const maxScrolls = Math.max(0, opts?.maxScrolls ?? DEFAULT_MAX_SCROLLS);
731
+ const totalTimeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
732
+ const deadline = Date.now() + totalTimeout;
733
+ let scrollCount = 0;
734
+ while (scrollCount <= maxScrolls && Date.now() <= deadline) {
735
+ const found = yield* probeVisible(selector, opts);
736
+ if (found) {
737
+ return;
738
+ }
739
+ if (scrollCount === maxScrolls) {
740
+ break;
741
+ }
742
+ yield* scrollEffect(gestureDirection);
743
+ scrollCount += 1;
744
+ }
745
+ return yield* new ElementNotFoundError({
746
+ message: `Element not found after ${scrollCount} scroll(s) toward ${searchDirection} \u2014 selector: ${formatSelector(selector)}`,
747
+ selector,
748
+ timeoutMs: totalTimeout
749
+ });
750
+ }),
751
+ backUntilVisible: (selector, opts) => Effect3.gen(function* () {
752
+ const maxBacks = Math.max(0, opts?.maxBacks ?? DEFAULT_MAX_BACKS);
753
+ const totalTimeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
754
+ const deadline = Date.now() + totalTimeout;
755
+ let backCount = 0;
756
+ while (backCount <= maxBacks && Date.now() <= deadline) {
757
+ const found = yield* probeVisible(selector, opts);
758
+ if (found) {
759
+ return;
760
+ }
761
+ if (backCount === maxBacks) {
762
+ break;
763
+ }
764
+ const backResult = yield* Effect3.either(driver.back());
765
+ if (backResult._tag === "Left") {
766
+ return yield* new DriverError({
767
+ message: `backUntilVisible() failed on back attempt ${backCount + 1}: ${backResult.left.message}`
768
+ });
769
+ }
770
+ yield* afterMutation();
771
+ backCount += 1;
772
+ }
773
+ return yield* new ElementNotFoundError({
774
+ 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.`,
775
+ selector,
776
+ timeoutMs: totalTimeout
777
+ });
778
+ }),
779
+ pinch: (selector, opts) => Effect3.gen(function* () {
780
+ const element = yield* waitForActionElement(
781
+ driver,
782
+ selector,
783
+ parse,
784
+ { ...defaults, ...opts },
785
+ cache
786
+ );
787
+ const { x, y } = centerOf(element);
788
+ const scale = opts?.scale ?? 0.5;
789
+ const duration = opts?.duration ?? 1500;
790
+ if (!driver.pinch) {
791
+ return yield* new DriverError({
792
+ message: "pinch() is only supported on mobile platforms (Android/iOS)"
793
+ });
794
+ }
795
+ yield* driver.pinch(x, y, scale, duration);
796
+ yield* afterMutation();
797
+ }),
798
+ zoom: (selector, opts) => Effect3.gen(function* () {
799
+ const element = yield* waitForActionElement(
800
+ driver,
801
+ selector,
802
+ parse,
803
+ { ...defaults, ...opts },
804
+ cache
805
+ );
806
+ const { x, y } = centerOf(element);
807
+ const scale = opts?.scale ?? 0.5;
808
+ const duration = opts?.duration ?? 1500;
809
+ if (!driver.zoom) {
810
+ return yield* new DriverError({
811
+ message: "zoom() is only supported on mobile platforms (Android/iOS)"
812
+ });
813
+ }
814
+ yield* driver.zoom(x, y, scale, duration);
815
+ yield* afterMutation();
816
+ }),
817
+ multiTouch: (sequences) => Effect3.gen(function* () {
818
+ if (!driver.multiTouch) {
819
+ return yield* new DriverError({
820
+ message: "multiTouch() is only supported on mobile platforms (Android/iOS)"
821
+ });
822
+ }
823
+ yield* driver.multiTouch(sequences);
824
+ yield* afterMutation();
825
+ }),
826
+ assertVisible: (selector, opts) => waitForElement(driver, selector, parse, { ...defaults, ...opts }, cache),
827
+ assertHidden: (selector, opts) => waitForNotVisible(driver, selector, parse, { ...defaults, ...opts }, cache),
828
+ assertText: (selector, expected, opts) => pollUntilMatch(
829
+ selector,
830
+ opts,
831
+ (el) => ({ matched: el.text === expected, actual: el.text }),
832
+ (actual, timeout) => ({
833
+ message: `Expected text "${expected}" but got "${actual ?? "(no text)"}" after ${timeout}ms`,
834
+ expected
835
+ })
836
+ ),
837
+ assertContainsText: (selector, expected, opts) => pollUntilMatch(
838
+ selector,
839
+ opts,
840
+ (el) => {
841
+ const actual = el.text ?? "";
842
+ return {
843
+ matched: actual.toLowerCase().includes(expected.toLowerCase()),
844
+ actual: el.text
845
+ };
846
+ },
847
+ (actual, timeout) => ({
848
+ message: `Expected text to contain "${expected}" but got "${actual ?? "(no text)"}" after ${timeout}ms`,
849
+ expected
850
+ })
851
+ ),
852
+ assertEnabled: (selector, opts) => Effect3.gen(function* () {
853
+ const element = yield* waitForElement(
854
+ driver,
855
+ selector,
856
+ parse,
857
+ { ...defaults, ...opts },
858
+ cache
859
+ );
860
+ if (element.enabled === false) {
861
+ return yield* new TextMismatchError({
862
+ message: `Expected element to be enabled but it is disabled \u2014 selector: ${formatSelector(selector)}`,
863
+ expected: "enabled",
864
+ actual: "disabled",
865
+ selector
866
+ });
867
+ }
868
+ }),
869
+ assertDisabled: (selector, opts) => Effect3.gen(function* () {
870
+ const element = yield* waitForElement(
871
+ driver,
872
+ selector,
873
+ parse,
874
+ { ...defaults, ...opts },
875
+ cache
876
+ );
877
+ if (element.enabled !== false) {
878
+ return yield* new TextMismatchError({
879
+ message: `Expected element to be disabled but it is enabled \u2014 selector: ${formatSelector(selector)}`,
880
+ expected: "disabled",
881
+ actual: "enabled",
882
+ selector
883
+ });
884
+ }
885
+ }),
886
+ getText: (selector, opts) => Effect3.gen(function* () {
887
+ const element = yield* waitForElement(
888
+ driver,
889
+ selector,
890
+ parse,
891
+ { ...defaults, ...opts },
892
+ cache
893
+ );
894
+ return element.text ?? "";
895
+ }),
896
+ isElementEnabled: (selector, opts) => Effect3.gen(function* () {
897
+ const element = yield* waitForElement(
898
+ driver,
899
+ selector,
900
+ parse,
901
+ { ...defaults, ...opts },
902
+ cache
903
+ );
904
+ return element.enabled !== false;
905
+ }),
906
+ assertValue: (selector, expected, opts) => {
907
+ const expectedStr = String(expected);
908
+ return pollUntilMatch(
909
+ selector,
910
+ opts,
911
+ (el) => {
912
+ const actual = el.value ?? "";
913
+ return { matched: actual === expectedStr, actual };
914
+ },
915
+ (actual, timeout) => ({
916
+ message: `Expected value "${expectedStr}" but got "${actual ?? "(no value)"}" after ${timeout}ms`,
917
+ expected: expectedStr
918
+ })
919
+ );
920
+ },
921
+ assertAttribute: (selector, name, expectedValue, opts) => pollUntilMatch(
922
+ selector,
923
+ opts,
924
+ (el) => {
925
+ const actual = el.attributes?.[name];
926
+ if (expectedValue === void 0) {
927
+ return { matched: actual !== void 0, actual };
928
+ }
929
+ return { matched: actual === expectedValue, actual };
930
+ },
931
+ (actual, timeout) => expectedValue === void 0 ? {
932
+ message: `Expected attribute "${name}" to exist but it was not found after ${timeout}ms`,
933
+ expected: name
934
+ } : {
935
+ message: `Expected attribute "${name}" to be "${expectedValue}" but got "${actual ?? "(not found)"}" after ${timeout}ms`,
936
+ expected: expectedValue
937
+ }
938
+ ),
939
+ assertMatchesText: (selector, pattern, opts) => pollUntilMatch(
940
+ selector,
941
+ opts,
942
+ (el) => {
943
+ const actual = el.text ?? "";
944
+ return { matched: pattern.test(actual), actual };
945
+ },
946
+ (actual, timeout) => ({
947
+ message: `Expected text to match ${pattern} but got "${actual ?? "(no text)"}" after ${timeout}ms`,
948
+ expected: String(pattern)
949
+ })
950
+ ),
951
+ getAttribute: (selector, name, opts) => Effect3.gen(function* () {
952
+ const element = yield* waitForElement(
953
+ driver,
954
+ selector,
955
+ parse,
956
+ { ...defaults, ...opts },
957
+ cache
958
+ );
959
+ return element.attributes?.[name];
960
+ })
961
+ };
962
+ }
963
+
964
+ // src/drivers/raw-driver.ts
965
+ import { Context, Effect as Effect4 } from "effect";
966
+ var RawDriver = class extends Context.Tag("RawDriver")() {
967
+ };
968
+ function appendDriverLog(logs, message) {
969
+ logs.push(`[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}`);
970
+ }
971
+ function wrapLoggedMethod(logs, methodName, fn) {
972
+ return (...args) => {
973
+ const startedAt = Date.now();
974
+ appendDriverLog(logs, `${methodName} started`);
975
+ return fn(...args).pipe(
976
+ Effect4.tap(
977
+ () => Effect4.sync(() => {
978
+ appendDriverLog(logs, `${methodName} succeeded (${Date.now() - startedAt}ms)`);
979
+ })
980
+ ),
981
+ Effect4.tapError(
982
+ (error) => Effect4.sync(() => {
983
+ appendDriverLog(
984
+ logs,
985
+ `${methodName} failed (${Date.now() - startedAt}ms): ${error.message}`
986
+ );
987
+ })
988
+ )
989
+ );
990
+ };
991
+ }
992
+ function wrapOptionalMethod(logs, methodName, fn) {
993
+ return fn ? wrapLoggedMethod(logs, methodName, fn) : void 0;
994
+ }
995
+ function wrapEvaluateMethod(logs, fn) {
996
+ return (script, ...args) => wrapLoggedMethod(logs, "evaluate", fn)(script, ...args);
997
+ }
998
+ function withBufferedDriverLogs(driver) {
999
+ const logs = [];
1000
+ return {
1001
+ ...driver,
1002
+ beginFlow: (flowName) => {
1003
+ logs.length = 0;
1004
+ appendDriverLog(logs, `beginFlow ${flowName}`);
1005
+ const startedAt = Date.now();
1006
+ const effect = driver.beginFlow ? driver.beginFlow(flowName) : Effect4.void;
1007
+ return effect.pipe(
1008
+ Effect4.tap(
1009
+ () => Effect4.sync(() => {
1010
+ appendDriverLog(logs, `beginFlow ready (${Date.now() - startedAt}ms)`);
1011
+ })
1012
+ ),
1013
+ Effect4.tapError(
1014
+ (error) => Effect4.sync(() => {
1015
+ appendDriverLog(
1016
+ logs,
1017
+ `beginFlow failed (${Date.now() - startedAt}ms): ${error.message}`
1018
+ );
1019
+ })
1020
+ )
1021
+ );
1022
+ },
1023
+ getDriverLogs: () => Effect4.succeed([...logs]),
1024
+ dumpHierarchy: wrapLoggedMethod(logs, "dumpHierarchy", driver.dumpHierarchy),
1025
+ tapAtCoordinate: wrapLoggedMethod(logs, "tapAtCoordinate", driver.tapAtCoordinate),
1026
+ doubleTapAtCoordinate: wrapLoggedMethod(
1027
+ logs,
1028
+ "doubleTapAtCoordinate",
1029
+ driver.doubleTapAtCoordinate
1030
+ ),
1031
+ longPressAtCoordinate: wrapLoggedMethod(
1032
+ logs,
1033
+ "longPressAtCoordinate",
1034
+ driver.longPressAtCoordinate
1035
+ ),
1036
+ swipe: wrapLoggedMethod(logs, "swipe", driver.swipe),
1037
+ pinch: wrapOptionalMethod(logs, "pinch", driver.pinch),
1038
+ zoom: wrapOptionalMethod(logs, "zoom", driver.zoom),
1039
+ multiTouch: wrapOptionalMethod(logs, "multiTouch", driver.multiTouch),
1040
+ inputText: wrapLoggedMethod(logs, "inputText", driver.inputText),
1041
+ pressKey: wrapLoggedMethod(logs, "pressKey", driver.pressKey),
1042
+ hideKeyboard: wrapLoggedMethod(logs, "hideKeyboard", driver.hideKeyboard),
1043
+ takeScreenshot: wrapLoggedMethod(logs, "takeScreenshot", driver.takeScreenshot),
1044
+ getDeviceInfo: wrapLoggedMethod(logs, "getDeviceInfo", driver.getDeviceInfo),
1045
+ launchApp: wrapLoggedMethod(logs, "launchApp", driver.launchApp),
1046
+ stopApp: wrapLoggedMethod(logs, "stopApp", driver.stopApp),
1047
+ killApp: wrapLoggedMethod(logs, "killApp", driver.killApp),
1048
+ clearAppState: wrapLoggedMethod(logs, "clearAppState", driver.clearAppState),
1049
+ openLink: wrapLoggedMethod(logs, "openLink", driver.openLink),
1050
+ back: wrapLoggedMethod(logs, "back", driver.back),
1051
+ evaluate: wrapEvaluateMethod(logs, driver.evaluate),
1052
+ getContexts: wrapOptionalMethod(logs, "getContexts", driver.getContexts),
1053
+ getCurrentContext: wrapOptionalMethod(logs, "getCurrentContext", driver.getCurrentContext),
1054
+ setContext: wrapOptionalMethod(logs, "setContext", driver.setContext),
1055
+ mockNetwork: wrapOptionalMethod(logs, "mockNetwork", driver.mockNetwork),
1056
+ blockNetwork: wrapOptionalMethod(logs, "blockNetwork", driver.blockNetwork),
1057
+ clearNetworkMocks: wrapOptionalMethod(logs, "clearNetworkMocks", driver.clearNetworkMocks),
1058
+ setNetworkConditions: wrapOptionalMethod(
1059
+ logs,
1060
+ "setNetworkConditions",
1061
+ driver.setNetworkConditions
1062
+ ),
1063
+ saveCookies: wrapOptionalMethod(logs, "saveCookies", driver.saveCookies),
1064
+ loadCookies: wrapOptionalMethod(logs, "loadCookies", driver.loadCookies),
1065
+ saveAuthState: wrapOptionalMethod(logs, "saveAuthState", driver.saveAuthState),
1066
+ loadAuthState: wrapOptionalMethod(logs, "loadAuthState", driver.loadAuthState),
1067
+ downloadFile: wrapOptionalMethod(logs, "downloadFile", driver.downloadFile),
1068
+ uploadFile: wrapOptionalMethod(logs, "uploadFile", driver.uploadFile),
1069
+ newTab: wrapOptionalMethod(logs, "newTab", driver.newTab),
1070
+ switchToTab: wrapOptionalMethod(logs, "switchToTab", driver.switchToTab),
1071
+ closeTab: wrapOptionalMethod(logs, "closeTab", driver.closeTab),
1072
+ getTabIds: wrapOptionalMethod(logs, "getTabIds", driver.getTabIds),
1073
+ getConsoleLogs: wrapOptionalMethod(logs, "getConsoleLogs", driver.getConsoleLogs),
1074
+ getJSErrors: wrapOptionalMethod(logs, "getJSErrors", driver.getJSErrors),
1075
+ getHAR: wrapOptionalMethod(logs, "getHAR", driver.getHAR)
1076
+ };
1077
+ }
1078
+
1079
+ export {
1080
+ DriverError,
1081
+ splitGraphemes,
1082
+ flattenElements,
1083
+ waitForElement,
1084
+ createCoordinator,
1085
+ withBufferedDriverLogs
1086
+ };
1087
+ //# sourceMappingURL=chunk-S2XNAKSO.js.map