spana-test 0.8.0 → 0.9.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 (55) hide show
  1. package/dist/agent/index.d.ts +2 -2
  2. package/dist/agent/index.js +5 -5
  3. package/dist/{app-CgbLADmF.d.ts → app-DSh1ejLh.d.ts} +97 -22
  4. package/dist/{chunk-NS2HLJO4.js → chunk-2KRVN4WN.js} +3 -3
  5. package/dist/{chunk-AJCSETN6.js → chunk-3UVSUVHW.js} +619 -174
  6. package/dist/chunk-3UVSUVHW.js.map +1 -0
  7. package/dist/{chunk-3FXDOTFI.js → chunk-ALPQES3J.js} +187 -36
  8. package/dist/chunk-ALPQES3J.js.map +1 -0
  9. package/dist/{chunk-PMXSU5MS.js → chunk-FP6PVHHR.js} +2 -2
  10. package/dist/{chunk-WKVU24B6.js → chunk-IGTK5MHB.js} +4 -4
  11. package/dist/{chunk-2T4K7BJ3.js → chunk-JZZ2W2XH.js} +3 -2
  12. package/dist/chunk-JZZ2W2XH.js.map +1 -0
  13. package/dist/{chunk-SNL4X67N.js → chunk-UEWZ2EXL.js} +352 -111
  14. package/dist/chunk-UEWZ2EXL.js.map +1 -0
  15. package/dist/{chunk-QP4MDUBY.js → chunk-VP6V4XEJ.js} +2 -2
  16. package/dist/{chunk-RKYKRGHB.js → chunk-Z6K4QQAR.js} +128 -6
  17. package/dist/chunk-Z6K4QQAR.js.map +1 -0
  18. package/dist/cli.js +9 -9
  19. package/dist/config-loader-F5YAY7RP.js +9 -0
  20. package/dist/{daemon-manager-DDYQITPD.js → daemon-manager-2EQDVUVM.js} +8 -2
  21. package/dist/{doctor-command-HEQQOYUR.js → doctor-command-YTCQ2SC7.js} +4 -4
  22. package/dist/{flow-Md5xLwbX.d.ts → flow-CSMwD9Fh.d.ts} +1 -1
  23. package/dist/gherkin/steps.d.ts +2 -2
  24. package/dist/index.d.ts +38 -8
  25. package/dist/index.js +25 -9
  26. package/dist/index.js.map +1 -1
  27. package/dist/{installer-IYGMG7LS.js → installer-5UHTYQTB.js} +3 -3
  28. package/dist/{server-JPNH33MX.js → server-4YLBAZEM.js} +6 -6
  29. package/dist/{server-4PEREPHY.js → server-IS4K5FCT.js} +2 -2
  30. package/dist/{session-D9e30RVS.d.ts → session-CgvT-Oso.d.ts} +3 -1
  31. package/dist/{session-V4PYJXNB.js → session-K7FCRKOC.js} +6 -6
  32. package/dist/{studio-command-JOIFCOHC.js → studio-command-RFPV2DS7.js} +2 -2
  33. package/dist/{test-command-JCO2HPYI.js → test-command-UEJG5AI6.js} +11 -9
  34. package/dist/test-command-UEJG5AI6.js.map +1 -0
  35. package/native/win32-x64/spana_native.dll +0 -0
  36. package/package.json +1 -1
  37. package/dist/chunk-2T4K7BJ3.js.map +0 -1
  38. package/dist/chunk-3FXDOTFI.js.map +0 -1
  39. package/dist/chunk-AJCSETN6.js.map +0 -1
  40. package/dist/chunk-RKYKRGHB.js.map +0 -1
  41. package/dist/chunk-SNL4X67N.js.map +0 -1
  42. package/dist/config-loader-5FU45FXK.js +0 -9
  43. package/dist/test-command-JCO2HPYI.js.map +0 -1
  44. /package/dist/{chunk-NS2HLJO4.js.map → chunk-2KRVN4WN.js.map} +0 -0
  45. /package/dist/{chunk-PMXSU5MS.js.map → chunk-FP6PVHHR.js.map} +0 -0
  46. /package/dist/{chunk-WKVU24B6.js.map → chunk-IGTK5MHB.js.map} +0 -0
  47. /package/dist/{chunk-QP4MDUBY.js.map → chunk-VP6V4XEJ.js.map} +0 -0
  48. /package/dist/{config-loader-5FU45FXK.js.map → config-loader-F5YAY7RP.js.map} +0 -0
  49. /package/dist/{daemon-manager-DDYQITPD.js.map → daemon-manager-2EQDVUVM.js.map} +0 -0
  50. /package/dist/{doctor-command-HEQQOYUR.js.map → doctor-command-YTCQ2SC7.js.map} +0 -0
  51. /package/dist/{installer-IYGMG7LS.js.map → installer-5UHTYQTB.js.map} +0 -0
  52. /package/dist/{server-JPNH33MX.js.map → server-4YLBAZEM.js.map} +0 -0
  53. /package/dist/{server-4PEREPHY.js.map → server-IS4K5FCT.js.map} +0 -0
  54. /package/dist/{session-V4PYJXNB.js.map → session-K7FCRKOC.js.map} +0 -0
  55. /package/dist/{studio-command-JOIFCOHC.js.map → studio-command-RFPV2DS7.js.map} +0 -0
@@ -3,6 +3,7 @@ import {
3
3
  ElementNotFoundError,
4
4
  TextMismatchError,
5
5
  WaitTimeoutError,
6
+ buildDomActionabilityDiagScript,
6
7
  buildDomFillScript,
7
8
  buildDomQueryScript,
8
9
  buildDomScrollIntoViewScript,
@@ -14,11 +15,11 @@ import {
14
15
  createCompositeDomChannel,
15
16
  createWebKitInspectorChannel,
16
17
  domMatchToElement
17
- } from "./chunk-SNL4X67N.js";
18
+ } from "./chunk-UEWZ2EXL.js";
18
19
  import {
19
20
  getHealthyWarmDaemon,
20
21
  registerWarmDaemon
21
- } from "./chunk-RKYKRGHB.js";
22
+ } from "./chunk-Z6K4QQAR.js";
22
23
  import {
23
24
  installedUrlSchemesOnSimulator,
24
25
  launchOnSimulator,
@@ -65,7 +66,9 @@ var _AccessibilityLabelSelectorSchema = Schema.Struct({
65
66
  var _RoleSelectorSchema = Schema.Struct({
66
67
  role: Schema.String,
67
68
  name: Schema.optional(Schema.String),
68
- exact: Schema.optional(Schema.Boolean)
69
+ exact: Schema.optional(Schema.Boolean),
70
+ level: Schema.optional(Schema.Number),
71
+ includeHidden: Schema.optional(Schema.Boolean)
69
72
  });
70
73
  var _CssSelectorSchema = Schema.Struct({
71
74
  css: Schema.String
@@ -100,6 +103,17 @@ function byRole(role, nameOrOpts, opts) {
100
103
  function byCss(css, opts) {
101
104
  return { css, ...opts };
102
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
+ }
103
117
  function within(parent, child) {
104
118
  const obj = toObjectSelector(child);
105
119
  if ("point" in obj) return obj;
@@ -146,7 +160,7 @@ function isTestIDSelector(sel) {
146
160
  }
147
161
  function isComposableDomSelector(sel) {
148
162
  if (typeof sel !== "object" || sel === null || isRelativeSelector(sel)) return false;
149
- return "role" in sel || "css" in sel || "within" in sel || "frame" in sel || "hasText" in sel || "hasNotText" in sel || "nth" in sel || "first" in sel || "last" in sel;
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;
150
164
  }
151
165
 
152
166
  // src/smart/element-matcher.ts
@@ -187,6 +201,8 @@ function matchesSelector(element, selector) {
187
201
  }
188
202
  } else if ("css" in selector) {
189
203
  baseMatch = false;
204
+ } else if ("anyOf" in selector && Array.isArray(selector.anyOf)) {
205
+ baseMatch = selector.anyOf.some((branch) => matchesSelector(element, branch));
190
206
  } else if ("point" in selector) {
191
207
  const { x, y } = selector.point;
192
208
  const b = element.bounds;
@@ -203,6 +219,14 @@ function matchesSelector(element, selector) {
203
219
  const bad = selector.hasNotText instanceof RegExp ? selector.hasNotText.test(text) : text.toLowerCase().includes(selector.hasNotText.toLowerCase());
204
220
  if (bad) return false;
205
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
+ }
206
230
  }
207
231
  return true;
208
232
  }
@@ -289,8 +313,16 @@ function formatSimpleSelector(sel) {
289
313
  else if ("text" in sel) base = `text: "${sel.text}"`;
290
314
  else if ("accessibilityLabel" in sel) base = `accessibilityLabel: "${sel.accessibilityLabel}"`;
291
315
  else if ("role" in sel) {
292
- base = sel.name !== void 0 ? `role: "${sel.role}", name: ${sel.name instanceof RegExp ? sel.name.toString() : JSON.stringify(sel.name)}` : `role: "${sel.role}"`;
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(", ");
293
324
  } else if ("css" in sel) base = `css: "${sel.css}"`;
325
+ else if ("anyOf" in sel) base = `or(${sel.anyOf.map(formatSimpleSelector).join(", ")})`;
294
326
  else if ("point" in sel) return `point: (${sel.point.x}, ${sel.point.y})`;
295
327
  else return JSON.stringify(sel);
296
328
  const mods = [];
@@ -306,6 +338,8 @@ function formatSimpleSelector(sel) {
306
338
  `hasNotText(${sel.hasNotText instanceof RegExp ? sel.hasNotText.toString() : JSON.stringify(sel.hasNotText)})`
307
339
  );
308
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)})`);
309
343
  if (sel.first) mods.push("first");
310
344
  else if (sel.last) mods.push("last");
311
345
  else if (sel.nth !== void 0) mods.push(`nth(${sel.nth})`);
@@ -679,7 +713,8 @@ function waitForResolvedAcrossChannels(driver, selector, parse, forAction, opts,
679
713
  timeoutMs: timeout,
680
714
  forAction,
681
715
  failFastWhenIdle: opts?.failFastWhenIdle,
682
- idleQuietMs: opts?.idleQuietMs
716
+ idleQuietMs: opts?.idleQuietMs,
717
+ ...opts?.actionStableFrames !== void 0 ? { stableFrames: opts.actionStableFrames } : {}
683
718
  }),
684
719
  catch: () => null
685
720
  }).pipe(Effect2.catchAll(() => Effect2.succeed(null)));
@@ -692,7 +727,27 @@ function waitForResolvedAcrossChannels(driver, selector, parse, forAction, opts,
692
727
  domMatch: match
693
728
  };
694
729
  }
695
- if (Array.isArray(reactiveMatches) && reactiveMatches.length === 0 && (opts?.failFastWhenIdle || Date.now() - start >= timeout)) {
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
+ }
696
751
  if (cache) cache.invalidate();
697
752
  const diagRoot2 = yield* getHierarchy(driver, parse, cache);
698
753
  const diagnostic2 = diagnoseElementNotFound(diagRoot2, selector);
@@ -736,7 +791,8 @@ ${diagMessage2}`,
736
791
  timeoutMs: Math.min(remaining, opts?.platform === "web" ? remaining : 1e3),
737
792
  forAction,
738
793
  failFastWhenIdle: opts?.failFastWhenIdle,
739
- idleQuietMs: opts?.idleQuietMs
794
+ idleQuietMs: opts?.idleQuietMs,
795
+ ...opts?.actionStableFrames !== void 0 ? { stableFrames: opts.actionStableFrames } : {}
740
796
  }),
741
797
  catch: () => null
742
798
  }).pipe(Effect2.catchAll(() => Effect2.succeed(null)));
@@ -970,7 +1026,24 @@ function createCoordinator(driver, config) {
970
1026
  };
971
1027
  return directionMap[direction];
972
1028
  };
973
- const pollUntilMatch = (selector, opts, check, formatError, domMatchSpec) => Effect4.gen(function* () {
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* () {
974
1047
  const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
975
1048
  const pollInterval = opts?.pollInterval ?? defaults?.pollInterval ?? 200;
976
1049
  const start = Date.now();
@@ -980,6 +1053,7 @@ function createCoordinator(driver, config) {
980
1053
  const reactive = yield* Effect4.tryPromise({
981
1054
  try: () => domChannel.waitForMatch(selector, {
982
1055
  ...domMatchSpec,
1056
+ ...negate ? { negate: true } : {},
983
1057
  timeoutMs: timeout
984
1058
  }),
985
1059
  catch: () => null
@@ -1005,7 +1079,7 @@ function createCoordinator(driver, config) {
1005
1079
  const element = resolved?.element;
1006
1080
  if (element) {
1007
1081
  const result = check(element);
1008
- if (result.matched) return;
1082
+ if (negate ? !result.matched : result.matched) return;
1009
1083
  lastActual = result.actual;
1010
1084
  }
1011
1085
  yield* Effect4.sleep(Duration2.millis(pollInterval));
@@ -1069,32 +1143,45 @@ function createCoordinator(driver, config) {
1069
1143
  const createAssertions = () => ({
1070
1144
  assertVisible: (selector, opts) => waitForElement(driver, selector, parse, { ...defaults, ...opts }, cache),
1071
1145
  assertHidden: (selector, opts) => waitForNotVisible(driver, selector, parse, { ...defaults, ...opts }, cache),
1072
- assertText: (selector, expected, opts) => pollUntilMatch(
1073
- selector,
1074
- opts,
1075
- (el) => ({ matched: el.text === expected, actual: el.text }),
1076
- (actual, timeout) => ({
1077
- message: `Expected text "${expected}" but got "${actual ?? "(no text)"}" after ${timeout}ms`,
1078
- expected
1079
- }),
1080
- { kind: "text", expected }
1081
- ),
1082
- assertContainsText: (selector, expected, opts) => pollUntilMatch(
1083
- selector,
1084
- opts,
1085
- (el) => {
1086
- const actual = el.text ?? "";
1087
- return {
1088
- matched: actual.toLowerCase().includes(expected.toLowerCase()),
1089
- actual: el.text
1090
- };
1091
- },
1092
- (actual, timeout) => ({
1093
- message: `Expected text to contain "${expected}" but got "${actual ?? "(no text)"}" after ${timeout}ms`,
1094
- expected
1095
- }),
1096
- { kind: "containsText", expected }
1097
- ),
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
+ },
1098
1185
  assertEnabled: (selector, opts) => assertEnabledState(selector, true, opts),
1099
1186
  assertDisabled: (selector, opts) => assertEnabledState(selector, false, opts),
1100
1187
  getText: (selector, opts) => Effect4.gen(function* () {
@@ -1102,22 +1189,45 @@ function createCoordinator(driver, config) {
1102
1189
  driver,
1103
1190
  selector,
1104
1191
  parse,
1105
- { ...defaults, ...opts },
1192
+ { ...defaults, ...opts, platform: opts?.platform ?? config.platform },
1106
1193
  cache
1107
1194
  );
1108
- return element.text ?? "";
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;
1109
1219
  }),
1110
1220
  isElementEnabled: (selector, opts) => Effect4.gen(function* () {
1111
1221
  const element = yield* waitForElement(
1112
1222
  driver,
1113
1223
  selector,
1114
1224
  parse,
1115
- { ...defaults, ...opts },
1225
+ { ...defaults, ...opts, platform: opts?.platform ?? config.platform },
1116
1226
  cache
1117
1227
  );
1118
1228
  return element.enabled !== false;
1119
1229
  }),
1120
- assertValue: (selector, expected, opts) => {
1230
+ assertValue: (selector, expected, opts, negate = false) => {
1121
1231
  const expectedStr = String(expected);
1122
1232
  return pollUntilMatch(
1123
1233
  selector,
@@ -1127,13 +1237,14 @@ function createCoordinator(driver, config) {
1127
1237
  return { matched: actual === expectedStr, actual };
1128
1238
  },
1129
1239
  (actual, timeout) => ({
1130
- message: `Expected value "${expectedStr}" but got "${actual ?? "(no value)"}" after ${timeout}ms`,
1131
- expected: expectedStr
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
1132
1242
  }),
1133
- { kind: "value", expected: expectedStr }
1243
+ { kind: "value", expected: expectedStr },
1244
+ negate
1134
1245
  );
1135
1246
  },
1136
- assertAttribute: (selector, name, expectedValue, opts) => pollUntilMatch(
1247
+ assertAttribute: (selector, name, expectedValue, opts, negate = false) => pollUntilMatch(
1137
1248
  selector,
1138
1249
  opts,
1139
1250
  (el) => {
@@ -1143,34 +1254,66 @@ function createCoordinator(driver, config) {
1143
1254
  }
1144
1255
  return { matched: actual === expectedValue, actual };
1145
1256
  },
1146
- (actual, timeout) => expectedValue === void 0 ? {
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 ? {
1147
1264
  message: `Expected attribute "${name}" to exist but it was not found after ${timeout}ms`,
1148
1265
  expected: name
1149
1266
  } : {
1150
1267
  message: `Expected attribute "${name}" to be "${expectedValue}" but got "${actual ?? "(not found)"}" after ${timeout}ms`,
1151
1268
  expected: expectedValue
1152
1269
  },
1153
- { kind: "attribute", attributeName: name, expected: expectedValue }
1270
+ { kind: "attribute", attributeName: name, expected: expectedValue },
1271
+ negate
1154
1272
  ),
1155
- assertMatchesText: (selector, pattern, opts) => pollUntilMatch(
1273
+ assertMatchesText: (selector, pattern, opts, negate = false) => pollUntilMatch(
1156
1274
  selector,
1157
1275
  opts,
1158
1276
  (el) => {
1159
- const actual = el.text ?? "";
1277
+ const actual = normalizeWhitespace(el.textContent ?? el.text ?? "");
1160
1278
  return { matched: pattern.test(actual), actual };
1161
1279
  },
1162
1280
  (actual, timeout) => ({
1163
- message: `Expected text to match ${pattern} but got "${actual ?? "(no text)"}" after ${timeout}ms`,
1164
- expected: String(pattern)
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)
1165
1283
  }),
1166
- { kind: "matchesText", patternSource: pattern.source, patternFlags: pattern.flags }
1284
+ { kind: "matchesText", patternSource: pattern.source, patternFlags: pattern.flags },
1285
+ negate
1167
1286
  ),
1168
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
+ }
1169
1312
  const element = yield* waitForElement(
1170
1313
  driver,
1171
1314
  selector,
1172
1315
  parse,
1173
- { ...defaults, ...opts },
1316
+ { ...defaults, ...opts, platform: opts?.platform ?? config.platform },
1174
1317
  cache
1175
1318
  );
1176
1319
  return element.attributes?.[name];
@@ -1251,7 +1394,7 @@ function createCoordinator(driver, config) {
1251
1394
  },
1252
1395
  { kind: "accessibilityLabel", expected }
1253
1396
  ),
1254
- assertAccessibleName: (selector, expected, opts) => pollUntilMatch(
1397
+ assertAccessibleName: (selector, expected, opts, negate = false) => pollUntilMatch(
1255
1398
  selector,
1256
1399
  opts,
1257
1400
  (el) => {
@@ -1260,16 +1403,36 @@ function createCoordinator(driver, config) {
1260
1403
  return { matched, actual };
1261
1404
  },
1262
1405
  (actual, timeout) => ({
1263
- message: `Expected accessible name ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got "${actual ?? "(none)"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
1264
- expected: String(expected)
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)
1265
1408
  }),
1266
1409
  expected instanceof RegExp ? {
1267
1410
  kind: "accessibleName",
1268
1411
  patternSource: expected.source,
1269
1412
  patternFlags: expected.flags
1270
- } : { kind: "accessibleName", expected }
1413
+ } : { kind: "accessibleName", expected },
1414
+ negate
1271
1415
  ),
1272
- assertFocused: (selector, opts) => pollUntilMatch(
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(
1273
1436
  selector,
1274
1437
  opts,
1275
1438
  (el) => ({
@@ -1277,12 +1440,13 @@ function createCoordinator(driver, config) {
1277
1440
  actual: el.focused ? "focused" : "not focused"
1278
1441
  }),
1279
1442
  (actual, timeout) => ({
1280
- message: `Expected element to be focused but it was "${actual ?? "not focused"}" after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
1281
- expected: "focused"
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"
1282
1445
  }),
1283
- { kind: "focused" }
1446
+ { kind: "focused" },
1447
+ negate
1284
1448
  ),
1285
- assertCount: (selector, expectedCount, opts) => Effect4.gen(function* () {
1449
+ assertCount: (selector, expectedCount, opts, negate = false) => Effect4.gen(function* () {
1286
1450
  const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
1287
1451
  const pollInterval = opts?.pollInterval ?? defaults?.pollInterval ?? 200;
1288
1452
  const start = Date.now();
@@ -1293,6 +1457,7 @@ function createCoordinator(driver, config) {
1293
1457
  try: () => domChannel.waitForMatch(selector, {
1294
1458
  kind: "count",
1295
1459
  expectedCount,
1460
+ ...negate ? { negate: true } : {},
1296
1461
  timeoutMs: timeout
1297
1462
  }),
1298
1463
  catch: () => null
@@ -1300,8 +1465,8 @@ function createCoordinator(driver, config) {
1300
1465
  if (reactive) {
1301
1466
  if (reactive.matched) return;
1302
1467
  return yield* new TextMismatchError({
1303
- message: `Expected count ${expectedCount} but got ${reactive.actual ?? "0"} after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
1304
- expected: String(expectedCount),
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),
1305
1470
  actual: reactive.actual ?? "0",
1306
1471
  selector
1307
1472
  });
@@ -1317,7 +1482,7 @@ function createCoordinator(driver, config) {
1317
1482
  if (matches) {
1318
1483
  const count2 = matches.filter((m) => m.visible).length;
1319
1484
  lastCount = count2;
1320
- if (count2 === expectedCount) return;
1485
+ if (negate ? count2 !== expectedCount : count2 === expectedCount) return;
1321
1486
  yield* Effect4.sleep(Duration2.millis(pollInterval));
1322
1487
  continue;
1323
1488
  }
@@ -1328,17 +1493,17 @@ function createCoordinator(driver, config) {
1328
1493
  (el) => el.visible !== false
1329
1494
  ).length;
1330
1495
  lastCount = count;
1331
- if (count === expectedCount) return;
1496
+ if (negate ? count !== expectedCount : count === expectedCount) return;
1332
1497
  yield* Effect4.sleep(Duration2.millis(pollInterval));
1333
1498
  }
1334
1499
  return yield* new TextMismatchError({
1335
- message: `Expected count ${expectedCount} but got ${lastCount >= 0 ? lastCount : 0} after ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
1336
- expected: String(expectedCount),
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),
1337
1502
  actual: String(lastCount >= 0 ? lastCount : 0),
1338
1503
  selector
1339
1504
  });
1340
1505
  }),
1341
- waitForURL: (expected, opts) => Effect4.gen(function* () {
1506
+ waitForURL: (expected, opts, negate = false) => Effect4.gen(function* () {
1342
1507
  const timeout = opts?.timeout ?? defaults?.timeout ?? 5e3;
1343
1508
  const pollInterval = opts?.pollInterval ?? defaults?.pollInterval ?? 100;
1344
1509
  const start = Date.now();
@@ -1350,6 +1515,7 @@ function createCoordinator(driver, config) {
1350
1515
  try: () => domChannel.waitForMatch("", {
1351
1516
  kind: "url",
1352
1517
  ...expected instanceof RegExp ? { patternSource: expected.source, patternFlags: expected.flags } : { expected },
1518
+ ...negate ? { negate: true } : {},
1353
1519
  timeoutMs: timeout
1354
1520
  }),
1355
1521
  catch: () => null
@@ -1357,8 +1523,8 @@ function createCoordinator(driver, config) {
1357
1523
  if (reactive) {
1358
1524
  if (reactive.matched) return;
1359
1525
  return yield* new TextMismatchError({
1360
- message: `Expected URL ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got ${JSON.stringify(reactive.actual ?? "")} after ${timeout}ms`,
1361
- expected: String(expected),
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),
1362
1528
  actual: reactive.actual ?? "",
1363
1529
  selector: "url"
1364
1530
  });
@@ -1369,12 +1535,12 @@ function createCoordinator(driver, config) {
1369
1535
  "typeof window !== 'undefined' && window.location ? window.location.href : ''"
1370
1536
  ).pipe(Effect4.catchAll(() => Effect4.succeed("")));
1371
1537
  lastUrl = url;
1372
- if (matchesUrl(url)) return;
1538
+ if (negate ? !matchesUrl(url) : matchesUrl(url)) return;
1373
1539
  yield* Effect4.sleep(Duration2.millis(pollInterval));
1374
1540
  }
1375
1541
  return yield* new TextMismatchError({
1376
- message: `Expected URL ${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)} but got ${JSON.stringify(lastUrl)} after ${timeout}ms`,
1377
- expected: String(expected),
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),
1378
1544
  actual: lastUrl,
1379
1545
  selector: "url"
1380
1546
  });
@@ -1528,7 +1694,7 @@ function createCoordinator(driver, config) {
1528
1694
  driver,
1529
1695
  selector,
1530
1696
  parse,
1531
- { ...defaults, ...opts },
1697
+ { ...defaults, ...opts, platform: opts?.platform ?? config.platform },
1532
1698
  cache
1533
1699
  );
1534
1700
  const { x, y } = centerOf(element);
@@ -1542,7 +1708,7 @@ function createCoordinator(driver, config) {
1542
1708
  driver,
1543
1709
  selector,
1544
1710
  parse,
1545
- { ...defaults, ...opts },
1711
+ { ...defaults, ...opts, platform: opts?.platform ?? config.platform },
1546
1712
  cache
1547
1713
  );
1548
1714
  const { x, y } = centerOf(element);
@@ -1617,11 +1783,13 @@ function createCoordinator(driver, config) {
1617
1783
  const fillStart = Date.now();
1618
1784
  const domChannel = driver.domChannel;
1619
1785
  if (!isSystemUISelector(selector) && !isRelativeSelectorLike2(selector) && domChannel?.isConnected() && domChannel.fillDom) {
1620
- const filled = yield* Effect4.tryPromise({
1621
- try: () => domChannel.fillDom(selector, text, { timeoutMs: timeout }),
1622
- catch: (e) => new DriverError({ message: `DOM fill failed: ${e}` })
1623
- });
1624
- if (filled) {
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) {
1625
1793
  yield* afterMutation();
1626
1794
  return;
1627
1795
  }
@@ -1652,6 +1820,24 @@ function createCoordinator(driver, config) {
1652
1820
  yield* afterMutation();
1653
1821
  return;
1654
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
+ }
1655
1841
  return yield* new ElementNotFoundError({
1656
1842
  message: `Element not fillable within ${timeout}ms \u2014 selector: ${formatSelector(selector)}`,
1657
1843
  selector,
@@ -1850,6 +2036,50 @@ function selectorToCss(sel) {
1850
2036
  return `[aria-label="${sel.accessibilityLabel}"]`;
1851
2037
  return "";
1852
2038
  }
2039
+ function deepEqual(a, b) {
2040
+ if (Object.is(a, b)) return true;
2041
+ if (a === null || b === null || typeof a !== "object" || typeof b !== "object") return false;
2042
+ if (a instanceof RegExp && b instanceof RegExp)
2043
+ return a.source === b.source && a.flags === b.flags;
2044
+ if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
2045
+ if (Array.isArray(a) || Array.isArray(b)) {
2046
+ if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
2047
+ for (let i = 0; i < a.length; i++) {
2048
+ if (!deepEqual(a[i], b[i])) return false;
2049
+ }
2050
+ return true;
2051
+ }
2052
+ const aKeys = Object.keys(a);
2053
+ const bKeys = Object.keys(b);
2054
+ if (aKeys.length !== bKeys.length) return false;
2055
+ for (const k of aKeys) {
2056
+ if (!Object.prototype.hasOwnProperty.call(b, k) || !deepEqual(a[k], b[k])) {
2057
+ return false;
2058
+ }
2059
+ }
2060
+ return true;
2061
+ }
2062
+ async function retryUntilPass(fn, opts, defaultTimeout) {
2063
+ const timeout = opts?.timeout ?? defaultTimeout;
2064
+ const intervals = opts?.intervals && opts.intervals.length > 0 ? opts.intervals : [50, 100, 250, 500];
2065
+ const deadline = Date.now() + timeout;
2066
+ let attempt = 0;
2067
+ let lastError;
2068
+ while (true) {
2069
+ try {
2070
+ await fn();
2071
+ return;
2072
+ } catch (err) {
2073
+ lastError = err;
2074
+ const remaining = deadline - Date.now();
2075
+ if (remaining <= 0) break;
2076
+ const delay = intervals[Math.min(attempt, intervals.length - 1)] ?? 250;
2077
+ attempt += 1;
2078
+ await new Promise((r) => setTimeout(r, Math.min(delay, remaining)));
2079
+ }
2080
+ }
2081
+ throw lastError instanceof Error ? lastError : new Error(`expect(fn).toPass() timed out after ${timeout}ms: ${String(lastError)}`);
2082
+ }
1853
2083
  function createPromiseExpect(driver, config, recorder, flowContext, visualRegression) {
1854
2084
  const ctx = flowContext ?? {
1855
2085
  flowFilePath: "",
@@ -1857,110 +2087,283 @@ function createPromiseExpect(driver, config, recorder, flowContext, visualRegres
1857
2087
  platform: "web"
1858
2088
  };
1859
2089
  const coord = createCoordinator(driver, config);
2090
+ const defaultTimeout = config.defaults?.timeout ?? 5e3;
1860
2091
  const run = (effect) => Effect5.runPromise(effect);
1861
2092
  const runStep = (command, selector, action) => recorder ? recorder.runStep(command, action, { selector, captureScreenshot: false }) : action();
1862
- const expectFn = ((selector) => ({
1863
- toBeVisible: (opts) => runStep(
1864
- "expect.toBeVisible",
2093
+ const runPageStep = (command, action) => recorder ? recorder.runStep(command, action, { captureScreenshot: false }) : action();
2094
+ const buildNegatedExpectation = (selector) => ({
2095
+ toBeVisible: (opts) => runStep("expect.not.toBeVisible", selector, () => run(coord.assertHidden(selector, opts))),
2096
+ toBeHidden: (opts) => runStep(
2097
+ "expect.not.toBeHidden",
1865
2098
  selector,
1866
2099
  () => run(coord.assertVisible(selector, opts)).then(() => {
1867
2100
  })
1868
2101
  ),
1869
- toBeHidden: (opts) => runStep("expect.toBeHidden", selector, () => run(coord.assertHidden(selector, opts))),
1870
2102
  toHaveText: (expected, opts) => runStep(
1871
- `expect.toHaveText(${JSON.stringify(expected)})`,
2103
+ `expect.not.toHaveText(${JSON.stringify(expected)})`,
1872
2104
  selector,
1873
- () => run(coord.assertText(selector, expected, opts))
2105
+ () => run(coord.assertText(selector, expected, opts, true))
1874
2106
  ),
1875
2107
  toMatchText: (pattern, opts) => runStep(
1876
- `expect.toMatchText(${pattern})`,
2108
+ `expect.not.toMatchText(${pattern})`,
1877
2109
  selector,
1878
- () => run(coord.assertMatchesText(selector, pattern, opts))
2110
+ () => run(coord.assertMatchesText(selector, pattern, opts, true))
1879
2111
  ),
1880
2112
  toHaveValue: (expected, opts) => runStep(
1881
- `expect.toHaveValue(${JSON.stringify(expected)})`,
2113
+ `expect.not.toHaveValue(${JSON.stringify(expected)})`,
1882
2114
  selector,
1883
- () => run(coord.assertValue(selector, expected, opts))
2115
+ () => run(coord.assertValue(selector, expected, opts, true))
1884
2116
  ),
1885
2117
  toHaveAttribute: (name, value, opts) => runStep(
1886
- `expect.toHaveAttribute(${JSON.stringify(name)})`,
2118
+ `expect.not.toHaveAttribute(${JSON.stringify(name)})`,
1887
2119
  selector,
1888
- () => run(coord.assertAttribute(selector, name, value, opts))
2120
+ () => run(coord.assertAttribute(selector, name, value, opts, true))
1889
2121
  ),
1890
- toBeEnabled: (opts) => runStep("expect.toBeEnabled", selector, () => run(coord.assertEnabled(selector, opts))),
1891
- toBeDisabled: (opts) => runStep("expect.toBeDisabled", selector, () => run(coord.assertDisabled(selector, opts))),
2122
+ toBeEnabled: (opts) => runStep("expect.not.toBeEnabled", selector, () => run(coord.assertDisabled(selector, opts))),
2123
+ toBeDisabled: (opts) => runStep("expect.not.toBeDisabled", selector, () => run(coord.assertEnabled(selector, opts))),
1892
2124
  toContainText: (expected, opts) => runStep(
1893
- `expect.toContainText(${JSON.stringify(expected)})`,
2125
+ `expect.not.toContainText(${JSON.stringify(expected)})`,
1894
2126
  selector,
1895
- () => run(coord.assertContainsText(selector, expected, opts))
2127
+ () => run(coord.assertContainsText(selector, expected, opts, true))
1896
2128
  ),
1897
2129
  toHaveCount: (expected, opts) => runStep(
1898
- `expect.toHaveCount(${expected})`,
2130
+ `expect.not.toHaveCount(${expected})`,
2131
+ selector,
2132
+ () => run(coord.assertCount(selector, expected, opts, true))
2133
+ ),
2134
+ toBeFocused: (opts) => runStep(
2135
+ "expect.not.toBeFocused",
1899
2136
  selector,
1900
- () => run(coord.assertCount(selector, expected, opts))
2137
+ () => run(coord.assertFocused(selector, opts, true))
1901
2138
  ),
1902
- toBeFocused: (opts) => runStep("expect.toBeFocused", selector, () => run(coord.assertFocused(selector, opts))),
1903
2139
  toHaveAccessibleName: (expected, opts) => runStep(
1904
- `expect.toHaveAccessibleName(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
2140
+ `expect.not.toHaveAccessibleName(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
1905
2141
  selector,
1906
- () => run(coord.assertAccessibleName(selector, expected, opts))
2142
+ () => run(coord.assertAccessibleName(selector, expected, opts, true))
1907
2143
  ),
1908
- toMatchScreenshot: (name, options) => runStep(
1909
- `expect.toMatchScreenshot(${JSON.stringify(name)})`,
2144
+ toHaveAccessibleDescription: (expected, opts) => runStep(
2145
+ `expect.not.toHaveAccessibleDescription(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
1910
2146
  selector,
1911
- () => run(
1912
- coord.assertScreenshot(selector, name, ctx.flowFilePath, ctx.flowName, ctx.platform, {
1913
- threshold: options?.threshold ?? visualRegression?.threshold,
1914
- maxDiffPixelRatio: options?.maxDiffPixelRatio ?? visualRegression?.maxDiffPixelRatio,
1915
- mask: [],
1916
- updateBaselines: ctx.updateBaselines,
1917
- baselinesDir: visualRegression?.baselinesDir
1918
- })
2147
+ () => run(coord.assertAccessibleDescription(selector, expected, opts, true))
2148
+ )
2149
+ });
2150
+ const buildPollMatchers = (fn, opts, negate) => {
2151
+ const check = (label, predicate, describeFail) => runPageStep(
2152
+ `expect.poll.${negate ? "not." : ""}${label}`,
2153
+ () => retryUntilPass(
2154
+ async () => {
2155
+ const val = await fn();
2156
+ const ok = predicate(val);
2157
+ if (negate ? ok : !ok) {
2158
+ throw new Error(describeFail(val));
2159
+ }
2160
+ },
2161
+ opts,
2162
+ defaultTimeout
1919
2163
  )
1920
- ),
1921
- toPassAccessibilityAudit: (options) => {
1922
- const excludeCss = options?.exclude?.map(selectorToCss).filter(Boolean) ?? [];
1923
- const targetCss = selectorToCss(selector);
1924
- return runStep(
1925
- "expect.toPassAccessibilityAudit",
2164
+ );
2165
+ return {
2166
+ toBe: (expected) => check(
2167
+ `toBe(${JSON.stringify(expected)})`,
2168
+ (v) => Object.is(v, expected),
2169
+ (v) => negate ? `Expected polled value NOT to be ${JSON.stringify(expected)}` : `Expected polled value to be ${JSON.stringify(expected)}, received ${JSON.stringify(v)}`
2170
+ ),
2171
+ toEqual: (expected) => check(
2172
+ `toEqual(${JSON.stringify(expected)})`,
2173
+ (v) => deepEqual(v, expected),
2174
+ (v) => negate ? `Expected polled value NOT to equal ${JSON.stringify(expected)}` : `Expected polled value to equal ${JSON.stringify(expected)}, received ${JSON.stringify(v)}`
2175
+ ),
2176
+ toContain: (expected) => check(
2177
+ `toContain(${JSON.stringify(expected)})`,
2178
+ (v) => {
2179
+ if (typeof v === "string") return v.includes(String(expected));
2180
+ if (Array.isArray(v)) return v.some((item) => deepEqual(item, expected));
2181
+ return false;
2182
+ },
2183
+ (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)}`
2184
+ ),
2185
+ toMatch: (pattern) => check(
2186
+ `toMatch(${pattern instanceof RegExp ? String(pattern) : JSON.stringify(pattern)})`,
2187
+ (v) => {
2188
+ const str = String(v ?? "");
2189
+ return pattern instanceof RegExp ? pattern.test(str) : str.includes(pattern);
2190
+ },
2191
+ (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)}`
2192
+ ),
2193
+ toBeGreaterThan: (expected) => check(
2194
+ `toBeGreaterThan(${expected})`,
2195
+ (v) => typeof v === "number" && v > expected,
2196
+ (v) => negate ? `Expected polled value NOT to be > ${expected}, received ${String(v)}` : `Expected polled value > ${expected}, received ${String(v)}`
2197
+ ),
2198
+ toBeLessThan: (expected) => check(
2199
+ `toBeLessThan(${expected})`,
2200
+ (v) => typeof v === "number" && v < expected,
2201
+ (v) => negate ? `Expected polled value NOT to be < ${expected}, received ${String(v)}` : `Expected polled value < ${expected}, received ${String(v)}`
2202
+ ),
2203
+ toBeGreaterThanOrEqual: (expected) => check(
2204
+ `toBeGreaterThanOrEqual(${expected})`,
2205
+ (v) => typeof v === "number" && v >= expected,
2206
+ (v) => negate ? `Expected polled value NOT to be >= ${expected}, received ${String(v)}` : `Expected polled value >= ${expected}, received ${String(v)}`
2207
+ ),
2208
+ toBeLessThanOrEqual: (expected) => check(
2209
+ `toBeLessThanOrEqual(${expected})`,
2210
+ (v) => typeof v === "number" && v <= expected,
2211
+ (v) => negate ? `Expected polled value NOT to be <= ${expected}, received ${String(v)}` : `Expected polled value <= ${expected}, received ${String(v)}`
2212
+ ),
2213
+ toBeTruthy: () => check(
2214
+ "toBeTruthy",
2215
+ (v) => Boolean(v),
2216
+ (v) => negate ? `Expected polled value NOT to be truthy, received ${JSON.stringify(v)}` : `Expected polled value to be truthy, received ${JSON.stringify(v)}`
2217
+ ),
2218
+ toBeFalsy: () => check(
2219
+ "toBeFalsy",
2220
+ (v) => !v,
2221
+ (v) => negate ? `Expected polled value NOT to be falsy, received ${JSON.stringify(v)}` : `Expected polled value to be falsy, received ${JSON.stringify(v)}`
2222
+ ),
2223
+ toBeDefined: () => check(
2224
+ "toBeDefined",
2225
+ (v) => v !== void 0,
2226
+ () => negate ? `Expected polled value to be undefined` : `Expected polled value to be defined`
2227
+ ),
2228
+ toBeUndefined: () => check(
2229
+ "toBeUndefined",
2230
+ (v) => v === void 0,
2231
+ (v) => negate ? `Expected polled value NOT to be undefined` : `Expected polled value to be undefined, received ${JSON.stringify(v)}`
2232
+ ),
2233
+ toHaveLength: (expected) => check(
2234
+ `toHaveLength(${expected})`,
2235
+ (v) => v !== null && v !== void 0 && typeof v.length === "number" && v.length === expected,
2236
+ (v) => negate ? `Expected polled value NOT to have length ${expected}` : `Expected polled value to have length ${expected}, received ${JSON.stringify(v)}`
2237
+ )
2238
+ };
2239
+ };
2240
+ const expectFn = ((selectorOrFn) => {
2241
+ if (typeof selectorOrFn === "function") {
2242
+ return {
2243
+ toPass: (opts) => runPageStep("expect.toPass", () => retryUntilPass(selectorOrFn, opts, defaultTimeout))
2244
+ };
2245
+ }
2246
+ const selector = selectorOrFn;
2247
+ return {
2248
+ toBeVisible: (opts) => runStep(
2249
+ "expect.toBeVisible",
2250
+ selector,
2251
+ () => run(coord.assertVisible(selector, opts)).then(() => {
2252
+ })
2253
+ ),
2254
+ toBeHidden: (opts) => runStep("expect.toBeHidden", selector, () => run(coord.assertHidden(selector, opts))),
2255
+ toHaveText: (expected, opts) => runStep(
2256
+ `expect.toHaveText(${JSON.stringify(expected)})`,
2257
+ selector,
2258
+ () => run(coord.assertText(selector, expected, opts))
2259
+ ),
2260
+ toMatchText: (pattern, opts) => runStep(
2261
+ `expect.toMatchText(${pattern})`,
2262
+ selector,
2263
+ () => run(coord.assertMatchesText(selector, pattern, opts))
2264
+ ),
2265
+ toHaveValue: (expected, opts) => runStep(
2266
+ `expect.toHaveValue(${JSON.stringify(expected)})`,
2267
+ selector,
2268
+ () => run(coord.assertValue(selector, expected, opts))
2269
+ ),
2270
+ toHaveAttribute: (name, value, opts) => runStep(
2271
+ `expect.toHaveAttribute(${JSON.stringify(name)})`,
2272
+ selector,
2273
+ () => run(coord.assertAttribute(selector, name, value, opts))
2274
+ ),
2275
+ toBeEnabled: (opts) => runStep("expect.toBeEnabled", selector, () => run(coord.assertEnabled(selector, opts))),
2276
+ toBeDisabled: (opts) => runStep("expect.toBeDisabled", selector, () => run(coord.assertDisabled(selector, opts))),
2277
+ toContainText: (expected, opts) => runStep(
2278
+ `expect.toContainText(${JSON.stringify(expected)})`,
2279
+ selector,
2280
+ () => run(coord.assertContainsText(selector, expected, opts))
2281
+ ),
2282
+ toHaveCount: (expected, opts) => runStep(
2283
+ `expect.toHaveCount(${expected})`,
2284
+ selector,
2285
+ () => run(coord.assertCount(selector, expected, opts))
2286
+ ),
2287
+ toBeFocused: (opts) => runStep("expect.toBeFocused", selector, () => run(coord.assertFocused(selector, opts))),
2288
+ toHaveAccessibleName: (expected, opts) => runStep(
2289
+ `expect.toHaveAccessibleName(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
2290
+ selector,
2291
+ () => run(coord.assertAccessibleName(selector, expected, opts))
2292
+ ),
2293
+ toHaveAccessibleDescription: (expected, opts) => runStep(
2294
+ `expect.toHaveAccessibleDescription(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
2295
+ selector,
2296
+ () => run(coord.assertAccessibleDescription(selector, expected, opts))
2297
+ ),
2298
+ not: buildNegatedExpectation(selector),
2299
+ toMatchScreenshot: (name, options) => runStep(
2300
+ `expect.toMatchScreenshot(${JSON.stringify(name)})`,
1926
2301
  selector,
1927
2302
  () => run(
1928
- coord.assertAccessibilityAudit(ctx.platform, {
1929
- severity: options?.severity,
1930
- rules: options?.rules,
1931
- targetSelector: targetCss || void 0,
1932
- excludeSelectors: excludeCss
2303
+ coord.assertScreenshot(selector, name, ctx.flowFilePath, ctx.flowName, ctx.platform, {
2304
+ threshold: options?.threshold ?? visualRegression?.threshold,
2305
+ maxDiffPixelRatio: options?.maxDiffPixelRatio ?? visualRegression?.maxDiffPixelRatio,
2306
+ mask: [],
2307
+ updateBaselines: ctx.updateBaselines,
2308
+ baselinesDir: visualRegression?.baselinesDir
1933
2309
  })
1934
2310
  )
1935
- );
1936
- },
1937
- toHaveAccessibilityLabel: (expected) => runStep(
1938
- `expect.toHaveAccessibilityLabel(${expected !== void 0 ? JSON.stringify(expected) : ""})`,
1939
- selector,
1940
- () => run(coord.assertAccessibilityLabel(selector, expected))
1941
- ),
1942
- toBeFocusable: () => runStep(
1943
- "expect.toBeFocusable",
1944
- selector,
1945
- () => run(coord.assertFocusable(selector, ctx.platform))
1946
- ),
1947
- toHaveRole: (expected) => runStep(
1948
- `expect.toHaveRole(${JSON.stringify(expected)})`,
1949
- selector,
1950
- () => run(coord.assertRole(selector, expected, ctx.platform))
1951
- ),
1952
- toHaveMinTouchTarget: (size = 44) => runStep(
1953
- `expect.toHaveMinTouchTarget(${size})`,
1954
- selector,
1955
- () => run(coord.assertMinTouchTarget(selector, size))
1956
- )
1957
- }));
2311
+ ),
2312
+ toPassAccessibilityAudit: (options) => {
2313
+ const excludeCss = options?.exclude?.map(selectorToCss).filter(Boolean) ?? [];
2314
+ const targetCss = selectorToCss(selector);
2315
+ return runStep(
2316
+ "expect.toPassAccessibilityAudit",
2317
+ selector,
2318
+ () => run(
2319
+ coord.assertAccessibilityAudit(ctx.platform, {
2320
+ severity: options?.severity,
2321
+ rules: options?.rules,
2322
+ targetSelector: targetCss || void 0,
2323
+ excludeSelectors: excludeCss
2324
+ })
2325
+ )
2326
+ );
2327
+ },
2328
+ toHaveAccessibilityLabel: (expected) => runStep(
2329
+ `expect.toHaveAccessibilityLabel(${expected !== void 0 ? JSON.stringify(expected) : ""})`,
2330
+ selector,
2331
+ () => run(coord.assertAccessibilityLabel(selector, expected))
2332
+ ),
2333
+ toBeFocusable: () => runStep(
2334
+ "expect.toBeFocusable",
2335
+ selector,
2336
+ () => run(coord.assertFocusable(selector, ctx.platform))
2337
+ ),
2338
+ toHaveRole: (expected) => runStep(
2339
+ `expect.toHaveRole(${JSON.stringify(expected)})`,
2340
+ selector,
2341
+ () => run(coord.assertRole(selector, expected, ctx.platform))
2342
+ ),
2343
+ toHaveMinTouchTarget: (size = 44) => runStep(
2344
+ `expect.toHaveMinTouchTarget(${size})`,
2345
+ selector,
2346
+ () => run(coord.assertMinTouchTarget(selector, size))
2347
+ )
2348
+ };
2349
+ });
1958
2350
  expectFn.toHaveURL = (expected, opts) => {
1959
2351
  const label = `expect.toHaveURL(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`;
1960
- return recorder ? recorder.runStep(label, () => run(coord.waitForURL(expected, opts)), {
1961
- captureScreenshot: false
1962
- }) : run(coord.waitForURL(expected, opts));
2352
+ return runPageStep(label, () => run(coord.waitForURL(expected, opts)));
1963
2353
  };
2354
+ Object.defineProperty(expectFn, "not", {
2355
+ enumerable: true,
2356
+ value: {
2357
+ toHaveURL: (expected, opts) => {
2358
+ const label = `expect.not.toHaveURL(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`;
2359
+ return runPageStep(label, () => run(coord.waitForURL(expected, opts, true)));
2360
+ }
2361
+ }
2362
+ });
2363
+ expectFn.poll = (fn, opts) => ({
2364
+ ...buildPollMatchers(fn, opts, false),
2365
+ not: buildPollMatchers(fn, opts, true)
2366
+ });
1964
2367
  return expectFn;
1965
2368
  }
1966
2369
 
@@ -2547,6 +2950,7 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
2547
2950
  getAttribute: (sel, name, opts) => appObj.getAttribute(scoped(sel), name, opts),
2548
2951
  isVisible: (sel, opts) => appObj.isVisible(scoped(sel), opts),
2549
2952
  isEnabled: (sel, opts) => appObj.isEnabled(scoped(sel), opts),
2953
+ count: (sel, opts) => appObj.count(scoped(sel), opts),
2550
2954
  expect: (sel) => appExpect(scoped(sel))
2551
2955
  };
2552
2956
  },
@@ -2648,6 +3052,7 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
2648
3052
  );
2649
3053
  },
2650
3054
  isEnabled: (selector, opts) => runStep("isEnabled", () => run(coord.isElementEnabled(selector, opts)), { selector }),
3055
+ count: (selector, opts) => runStep("count", () => run(coord.count(selector, opts)), { selector }),
2651
3056
  // Web-first bridge & fast state helpers
2652
3057
  waitForIdle: (opts) => runStep("waitForIdle", async () => {
2653
3058
  if (driver.domChannel?.waitForIdle) {
@@ -3065,12 +3470,17 @@ function resolvePlaywrightLocator(root, selector) {
3065
3470
  scope = resolvePlaywrightLocator(scope, selector.within);
3066
3471
  }
3067
3472
  let locator;
3068
- if ("css" in selector) {
3473
+ if ("anyOf" in selector) {
3474
+ const branches = selector.anyOf.map((branch) => resolvePlaywrightLocator(scope, branch));
3475
+ locator = branches.reduce((acc, next) => acc.or(next));
3476
+ } else if ("css" in selector) {
3069
3477
  locator = scope.locator(selector.css);
3070
3478
  } else if ("role" in selector) {
3071
3479
  locator = scope.getByRole(selector.role, {
3072
3480
  ...selector.name !== void 0 ? { name: selector.name } : {},
3073
- ...selector.exact !== void 0 ? { exact: selector.exact } : {}
3481
+ ...selector.exact !== void 0 ? { exact: selector.exact } : {},
3482
+ ...selector.level !== void 0 ? { level: selector.level } : {},
3483
+ ...selector.includeHidden !== void 0 ? { includeHidden: selector.includeHidden } : {}
3074
3484
  });
3075
3485
  } else if ("testID" in selector) {
3076
3486
  locator = scope.getByTestId(selector.testID);
@@ -3085,6 +3495,12 @@ function resolvePlaywrightLocator(root, selector) {
3085
3495
  if (selector.hasNotText !== void 0) {
3086
3496
  locator = locator.filter({ hasNotText: selector.hasNotText });
3087
3497
  }
3498
+ if (selector.has !== void 0) {
3499
+ locator = locator.filter({ has: resolvePlaywrightLocator(scope, selector.has) });
3500
+ }
3501
+ if (selector.hasNot !== void 0) {
3502
+ locator = locator.filter({ hasNot: resolvePlaywrightLocator(scope, selector.hasNot) });
3503
+ }
3088
3504
  if (selector.first) {
3089
3505
  locator = locator.first();
3090
3506
  } else if (selector.last) {
@@ -4035,30 +4451,58 @@ function makePlaywrightDriver(config) {
4035
4451
  waitForResponse: (matcher, waitOpts) => Effect8.tryPromise({
4036
4452
  try: async () => {
4037
4453
  const timeout = waitOpts?.timeout ?? 15e3;
4038
- const response = await page.waitForResponse(
4039
- (res) => {
4040
- const info = {
4041
- url: res.url(),
4042
- status: res.status(),
4043
- statusText: res.statusText(),
4044
- headers: res.headers(),
4045
- method: res.request().method()
4046
- };
4047
- if (typeof matcher === "function") return matcher(info);
4048
- if (matcher instanceof RegExp) return matcher.test(info.url);
4049
- return info.url.includes(matcher);
4050
- },
4051
- { timeout }
4052
- );
4053
- return {
4054
- url: response.url(),
4055
- status: response.status(),
4056
- statusText: response.statusText(),
4057
- headers: response.headers(),
4058
- method: response.request().method(),
4059
- body: () => response.text(),
4060
- json: () => response.json()
4454
+ const matches = (res) => {
4455
+ const info = {
4456
+ url: res.url(),
4457
+ status: res.status(),
4458
+ statusText: res.statusText(),
4459
+ headers: res.headers(),
4460
+ method: res.request().method(),
4461
+ body: () => res.text(),
4462
+ json: () => res.json()
4463
+ };
4464
+ const ok = typeof matcher === "function" ? matcher(info) : matcher instanceof RegExp ? matcher.test(info.url) : info.url.includes(matcher);
4465
+ return ok ? info : null;
4061
4466
  };
4467
+ return await new Promise((resolve2, reject) => {
4468
+ const watchedPages = /* @__PURE__ */ new Set();
4469
+ let settled = false;
4470
+ const onResponse = (res) => {
4471
+ if (settled) return;
4472
+ const hit = matches(res);
4473
+ if (hit) {
4474
+ cleanup();
4475
+ resolve2(hit);
4476
+ }
4477
+ };
4478
+ const attachPage = (p) => {
4479
+ if (watchedPages.has(p)) return;
4480
+ watchedPages.add(p);
4481
+ p.on("response", onResponse);
4482
+ };
4483
+ const onNewPage = (p) => {
4484
+ if (!settled) attachPage(p);
4485
+ };
4486
+ const cleanup = () => {
4487
+ if (settled) return;
4488
+ settled = true;
4489
+ clearTimeout(timer);
4490
+ context.off("page", onNewPage);
4491
+ for (const p of watchedPages) {
4492
+ p.off("response", onResponse);
4493
+ }
4494
+ watchedPages.clear();
4495
+ };
4496
+ const timer = setTimeout(() => {
4497
+ cleanup();
4498
+ reject(new Error(`Timed out waiting for response after ${timeout}ms`));
4499
+ }, timeout);
4500
+ for (const existingPage of context.pages()) {
4501
+ attachPage(existingPage);
4502
+ }
4503
+ attachPage(page);
4504
+ context.on("page", onNewPage);
4505
+ });
4062
4506
  },
4063
4507
  catch: (e) => new DriverError({ message: `waitForResponse() failed: ${e}` })
4064
4508
  }),
@@ -6725,6 +7169,7 @@ export {
6725
7169
  buildIOSLaunchConfiguration,
6726
7170
  byRole,
6727
7171
  byCss,
7172
+ or,
6728
7173
  within,
6729
7174
  inFrame,
6730
7175
  nth,
@@ -6760,4 +7205,4 @@ export {
6760
7205
  makeElectronDriver,
6761
7206
  setupUiAutomator2
6762
7207
  };
6763
- //# sourceMappingURL=chunk-AJCSETN6.js.map
7208
+ //# sourceMappingURL=chunk-3UVSUVHW.js.map