@cutleryapp/agent 1.0.40 → 1.0.42

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.
@@ -175,7 +175,14 @@ class TestExecutor {
175
175
  await page.fill(fieldLabel, value);
176
176
  }
177
177
  else {
178
- await tryFill(page, fieldLabel, value);
178
+ // Check if it's a date/birth field and use date-aware fill
179
+ const isDateField = /date|birth|dob/i.test(fieldLabel);
180
+ if (isDateField) {
181
+ await tryFillDate(page, fieldLabel, value);
182
+ }
183
+ else {
184
+ await tryFill(page, fieldLabel, value);
185
+ }
179
186
  }
180
187
  handled = true;
181
188
  }
@@ -334,14 +341,36 @@ class TestExecutor {
334
341
  const optionValue = selMatch[1].trim();
335
342
  const fieldLabel = selMatch[2].trim();
336
343
  let selHandled = false;
337
- // 1. Native <select> — fastest for actual <select> elements
338
- try {
339
- const fieldLoc = page.getByLabel(new RegExp(fieldLabel, 'i')).first();
340
- await fieldLoc.selectOption({ label: optionValue }, { timeout: 800 });
341
- selHandled = true;
344
+ // 1. Native <select> — try by label, name, id
345
+ if (!selHandled) {
346
+ const fieldRe = new RegExp(fieldLabel.replace(/[\s_-]+/g, '[\\s_-]*'), 'i');
347
+ const selectLocators = [
348
+ page.getByLabel(fieldRe),
349
+ page.locator(`select[name*="${fieldLabel}" i]`),
350
+ page.locator(`select[id*="${fieldLabel}" i]`),
351
+ page.locator(`select[data-test*="${fieldLabel}" i]`),
352
+ ];
353
+ for (const loc of selectLocators) {
354
+ try {
355
+ const el = loc.first();
356
+ const tag = await el.evaluate((n) => n.tagName.toLowerCase()).catch(() => '');
357
+ if (tag !== 'select')
358
+ continue; // only drive actual <select> elements
359
+ // Try matching by label text, then by value
360
+ const matched = await Promise.any([
361
+ el.selectOption({ label: optionValue }, { timeout: 1000 }),
362
+ el.selectOption({ value: optionValue }, { timeout: 1000 }),
363
+ el.selectOption(optionValue, { timeout: 1000 }),
364
+ ]).then(() => true).catch(() => false);
365
+ if (matched) {
366
+ selHandled = true;
367
+ break;
368
+ }
369
+ }
370
+ catch { /* next */ }
371
+ }
342
372
  }
343
- catch { /* not a native select */ }
344
- // 2. Radio / checkbox label click — do this BEFORE autocomplete so radio buttons
373
+ // 2. Radio / checkbox label click before autocomplete so radio buttons
345
374
  // are handled in <100ms instead of waiting through autocomplete timeouts
346
375
  if (!selHandled) {
347
376
  try {
@@ -367,6 +396,14 @@ class TestExecutor {
367
396
  await page.locator(`[role="option"]:has-text("${optionValue}"), [class*="option"]:has-text("${optionValue}")`).first().click({ timeout: 1000 });
368
397
  selHandled = true;
369
398
  }
399
+ catch { /* try text input fallback */ }
400
+ }
401
+ // 5. Text input / textarea fallback — handles "Select X in Y" where Y is a textarea
402
+ if (!selHandled) {
403
+ try {
404
+ await tryFill(page, fieldLabel, optionValue);
405
+ selHandled = true;
406
+ }
370
407
  catch { /* fall to AI */ }
371
408
  }
372
409
  if (selHandled)
@@ -1146,6 +1183,68 @@ async function tryClickScoped(page, nameRe, target, scope) {
1146
1183
  catch { }
1147
1184
  return false;
1148
1185
  }
1186
+ /** Parse a date string in any common format and return {day, month, year} */
1187
+ function parseDate(value) {
1188
+ // Formats: DD/MM/YYYY, MM/DD/YYYY, YYYY-MM-DD, DD-MM-YYYY, DD Mon YYYY, etc.
1189
+ const patterns = [
1190
+ /^(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})$/, // DD/MM/YYYY or MM/DD/YYYY
1191
+ /^(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})$/, // YYYY-MM-DD
1192
+ ];
1193
+ for (const p of patterns) {
1194
+ const m = value.match(p);
1195
+ if (m) {
1196
+ const [, a, b, c] = m;
1197
+ // Heuristic: if first group is 4 digits → YYYY-MM-DD
1198
+ const [year, month, day] = a.length === 4 ? [a, b, c] : [c, b, a];
1199
+ const iso = `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;
1200
+ return { iso, day: day.padStart(2, '0'), month: month.padStart(2, '0'), year };
1201
+ }
1202
+ }
1203
+ return null;
1204
+ }
1205
+ /** Fill a date field — handles input[type=date], calendar pickers, and plain text inputs */
1206
+ async function tryFillDate(page, label, value) {
1207
+ const labelRe = new RegExp(escapeRegex(label), 'i');
1208
+ const parsed = parseDate(value);
1209
+ // Strategy 1: input[type="date"] — needs YYYY-MM-DD format
1210
+ if (parsed) {
1211
+ const dateInputSelectors = [
1212
+ `input[type="date"]`,
1213
+ `input[type="datetime-local"]`,
1214
+ ];
1215
+ for (const sel of dateInputSelectors) {
1216
+ try {
1217
+ const loc = page.locator(sel).first();
1218
+ if (await loc.isVisible({ timeout: 400 })) {
1219
+ await loc.fill(parsed.iso, { timeout: 1000 });
1220
+ return;
1221
+ }
1222
+ }
1223
+ catch { /* try next */ }
1224
+ }
1225
+ }
1226
+ // Strategy 2: plain text input — type the value as-is, dismiss any calendar that opens
1227
+ try {
1228
+ const input = await Promise.any([
1229
+ page.getByLabel(labelRe).first().elementHandle({ timeout: 500 }),
1230
+ page.getByPlaceholder(labelRe).first().elementHandle({ timeout: 500 }),
1231
+ page.getByRole('textbox', { name: labelRe }).first().elementHandle({ timeout: 500 }),
1232
+ ]);
1233
+ if (input) {
1234
+ await input.click();
1235
+ await page.keyboard.press('Escape'); // close any calendar that opened
1236
+ await page.waitForTimeout(150);
1237
+ await input.click({ clickCount: 3 }); // select all existing text
1238
+ await page.keyboard.type(value, { delay: 30 });
1239
+ await page.keyboard.press('Escape'); // close calendar again after typing
1240
+ await page.keyboard.press('Tab'); // commit the value
1241
+ return;
1242
+ }
1243
+ }
1244
+ catch { /* fall through */ }
1245
+ // Strategy 3: fallback to regular fill
1246
+ await tryFill(page, label, value);
1247
+ }
1149
1248
  async function tryFill(page, label, value) {
1150
1249
  const labelRe = new RegExp(escapeRegex(label), "i");
1151
1250
  const variants = labelVariants(label);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cutleryapp/agent",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "Local agent that connects your machine to the Cutlery QA platform and runs UI tests via Playwright",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {