@letsrunit/playwright 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.
package/dist/index.js CHANGED
@@ -1227,21 +1227,32 @@ async function formatHtml(page) {
1227
1227
  }
1228
1228
 
1229
1229
  // src/fuzzy-locator.ts
1230
+ function debug(...args) {
1231
+ if (process.env.LETSRUNIT_DEBUG_FUZZY_LOCATOR === "1") {
1232
+ console.log("[fuzzyLocator]", ...args);
1233
+ }
1234
+ }
1230
1235
  async function fuzzyLocator(page, selector) {
1236
+ debug("input selector:", selector);
1231
1237
  const primary = page.locator(selector);
1232
1238
  const candidates = [
1233
- tryRelaxNameToHasText(page, selector),
1234
- tryTagInsteadOfRole(page, selector),
1235
- tryRoleNameProximity(page, selector),
1236
- tryFieldAlternative(page, selector),
1237
- tryAsField(page, selector)
1239
+ { name: "relaxNameToHasText", locator: tryRelaxNameToHasText(page, selector) },
1240
+ { name: "tagInsteadOfRole", locator: tryTagInsteadOfRole(page, selector) },
1241
+ { name: "roleNameProximity", locator: tryRoleNameProximity(page, selector) },
1242
+ { name: "fieldAlternative", locator: tryFieldAlternative(page, selector) },
1243
+ { name: "asField", locator: tryAsField(page, selector) }
1238
1244
  ];
1239
1245
  let combined = primary;
1246
+ const enabled = [];
1240
1247
  for (const candidate of candidates) {
1241
- if (!candidate) continue;
1242
- combined = combined.or(candidate);
1248
+ if (!candidate.locator) continue;
1249
+ enabled.push(candidate.name);
1250
+ combined = combined.or(candidate.locator);
1243
1251
  }
1244
- return combined.first();
1252
+ debug("enabled fallbacks:", enabled.length ? enabled.join(", ") : "(none)");
1253
+ const result = combined.first();
1254
+ debug("returning locator:", result.toString());
1255
+ return result;
1245
1256
  }
1246
1257
  function tryRelaxNameToHasText(page, selector) {
1247
1258
  const matchAnyNameFull = selector.match(/^(role=.*)\[name="([^"]+)"i?](.*)$/i);