@cutleryapp/agent 1.0.41 → 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
  }
@@ -1176,6 +1183,68 @@ async function tryClickScoped(page, nameRe, target, scope) {
1176
1183
  catch { }
1177
1184
  return false;
1178
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
+ }
1179
1248
  async function tryFill(page, label, value) {
1180
1249
  const labelRe = new RegExp(escapeRegex(label), "i");
1181
1250
  const variants = labelVariants(label);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cutleryapp/agent",
3
- "version": "1.0.41",
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": {