lazyscout 0.4.1 → 0.4.4
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
|
@@ -268,6 +268,222 @@ function isBlockedLabel(keywords, ...labels) {
|
|
|
268
268
|
return keywords.some((keyword) => keyword && haystack.includes(keyword.toLowerCase()));
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
// ../../packages/core/dist/patterns/catalog.js
|
|
272
|
+
var INPUT_TYPE_PATTERN = {
|
|
273
|
+
text: "text-input",
|
|
274
|
+
email: "text-input",
|
|
275
|
+
password: "text-input",
|
|
276
|
+
search: "text-input",
|
|
277
|
+
tel: "text-input",
|
|
278
|
+
url: "text-input",
|
|
279
|
+
number: "number-input",
|
|
280
|
+
range: "slider",
|
|
281
|
+
date: "date-input",
|
|
282
|
+
"datetime-local": "date-input",
|
|
283
|
+
month: "date-input",
|
|
284
|
+
week: "date-input",
|
|
285
|
+
time: "date-input",
|
|
286
|
+
checkbox: "checkbox",
|
|
287
|
+
radio: "radio",
|
|
288
|
+
file: "file-upload"
|
|
289
|
+
};
|
|
290
|
+
var ROLE_PATTERN = {
|
|
291
|
+
tab: "tab",
|
|
292
|
+
switch: "switch",
|
|
293
|
+
slider: "slider",
|
|
294
|
+
checkbox: "checkbox",
|
|
295
|
+
radio: "radio",
|
|
296
|
+
combobox: "combobox",
|
|
297
|
+
listbox: "select",
|
|
298
|
+
menu: "menu",
|
|
299
|
+
menubar: "menu",
|
|
300
|
+
menuitem: "menu",
|
|
301
|
+
link: "link",
|
|
302
|
+
searchbox: "text-input",
|
|
303
|
+
textbox: "text-input",
|
|
304
|
+
spinbutton: "number-input",
|
|
305
|
+
grid: "table",
|
|
306
|
+
table: "table",
|
|
307
|
+
navigation: "navigation"
|
|
308
|
+
};
|
|
309
|
+
var RULES = [
|
|
310
|
+
{
|
|
311
|
+
pattern: "tab",
|
|
312
|
+
evidence: () => 'role="tab"',
|
|
313
|
+
when: (element) => element.role === "tab"
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
pattern: "dialog-opener",
|
|
317
|
+
evidence: (element) => element.hasPopup === "dialog" ? 'aria-haspopup="dialog"' : `data-toggle="${element.hasPopup ?? "modal"}"`,
|
|
318
|
+
when: (element) => element.hasPopup === "dialog" || element.hasPopup === "modal" || element.hasPopup === "drawer"
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
pattern: "menu",
|
|
322
|
+
evidence: (element) => element.role?.startsWith("menuitem") || element.role === "menu" || element.role === "menubar" ? `role="${element.role}"` : `aria-haspopup="${element.hasPopup}"`,
|
|
323
|
+
when: (element) => Boolean(element.role?.startsWith("menuitem")) || element.role === "menu" || element.role === "menubar" || element.hasPopup === "menu" || element.hasPopup === "listbox" || element.hasPopup === "dropdown"
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
pattern: "accordion",
|
|
327
|
+
evidence: (element) => element.tagName === "summary" ? "<summary>" : "aria-expanded",
|
|
328
|
+
when: (element) => element.tagName === "summary" || element.expanded !== void 0
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
pattern: "file-upload",
|
|
332
|
+
evidence: () => 'input type="file"',
|
|
333
|
+
when: (element) => element.inputType === "file"
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
pattern: "switch",
|
|
337
|
+
evidence: () => 'role="switch"',
|
|
338
|
+
when: (element) => element.role === "switch"
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
pattern: "select",
|
|
342
|
+
evidence: () => "<select>",
|
|
343
|
+
when: (element) => element.tagName === "select"
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
pattern: "combobox",
|
|
347
|
+
evidence: () => 'role="combobox"',
|
|
348
|
+
when: (element) => element.role === "combobox"
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
pattern: "submit",
|
|
352
|
+
evidence: (element) => `type="${element.inputType ?? "submit"}"`,
|
|
353
|
+
when: (element) => element.inputType === "submit" || (element.tagName === "button" || element.role === "button") && element.context?.container === "form"
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
pattern: "pagination",
|
|
357
|
+
evidence: () => 'rel="next"/"prev"',
|
|
358
|
+
when: (element) => element.kind === "link" && /^(next|prev|previous|\d{1,3}|»|«|›|‹)$/i.test(element.accessibleName.trim())
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
pattern: "link",
|
|
362
|
+
evidence: () => "<a href>",
|
|
363
|
+
when: (element) => element.kind === "link" || element.role === "link"
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
pattern: "table",
|
|
367
|
+
evidence: () => 'role="grid"',
|
|
368
|
+
when: (element) => element.role === "grid" || element.role === "table"
|
|
369
|
+
}
|
|
370
|
+
];
|
|
371
|
+
function matchPattern(element) {
|
|
372
|
+
for (const rule of RULES) {
|
|
373
|
+
if (rule.when(element))
|
|
374
|
+
return { pattern: rule.pattern, evidence: rule.evidence(element) };
|
|
375
|
+
}
|
|
376
|
+
if (element.inputType && INPUT_TYPE_PATTERN[element.inputType]) {
|
|
377
|
+
return { pattern: INPUT_TYPE_PATTERN[element.inputType], evidence: `input type="${element.inputType}"` };
|
|
378
|
+
}
|
|
379
|
+
if (element.kind === "textarea")
|
|
380
|
+
return { pattern: "text-input", evidence: "<textarea>" };
|
|
381
|
+
if (element.role && ROLE_PATTERN[element.role]) {
|
|
382
|
+
return { pattern: ROLE_PATTERN[element.role], evidence: `role="${element.role}"` };
|
|
383
|
+
}
|
|
384
|
+
if (element.tagName === "button")
|
|
385
|
+
return { pattern: "button", evidence: "<button>" };
|
|
386
|
+
if (element.role === "button")
|
|
387
|
+
return { pattern: "button", evidence: 'role="button"' };
|
|
388
|
+
if (element.inputType === "button" || element.inputType === "reset") {
|
|
389
|
+
return { pattern: "button", evidence: `input type="${element.inputType}"` };
|
|
390
|
+
}
|
|
391
|
+
return { pattern: "unknown", evidence: `tag="${element.tagName}" role="${element.role || "none"}"` };
|
|
392
|
+
}
|
|
393
|
+
function classifyRisk(element, blockedKeywords = []) {
|
|
394
|
+
const labels = [element.accessibleName, element.text, element.name, element.id, element.ariaLabel];
|
|
395
|
+
if (isUnsafeAutoClick(...labels))
|
|
396
|
+
return "session-ending";
|
|
397
|
+
if (element.destructive || isBlockedLabel(blockedKeywords, ...labels))
|
|
398
|
+
return "destructive";
|
|
399
|
+
if (matchPattern(element).pattern === "unknown")
|
|
400
|
+
return "needs-review";
|
|
401
|
+
return "safe";
|
|
402
|
+
}
|
|
403
|
+
function elementIdentity(element, pattern) {
|
|
404
|
+
const locator3 = element.testId && `${element.testIdAttribute ?? "data-testid"}=${element.testId}` || element.id && `#${element.id}` || element.role && element.accessibleName && `${element.role}:${element.accessibleName}` || element.name && `[name=${element.name}]` || element.cssSelector || element.accessibleName;
|
|
405
|
+
return `${pattern}|${element.context?.containerSelector ?? ""}|${locator3}`;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// ../../packages/core/dist/patterns/coverage.js
|
|
409
|
+
var CoverageTracker = class {
|
|
410
|
+
entries = /* @__PURE__ */ new Map();
|
|
411
|
+
modalStates = 0;
|
|
412
|
+
casesGenerated = 0;
|
|
413
|
+
casesDeduplicated = 0;
|
|
414
|
+
/** Register an element as discovered. Safe to call repeatedly. */
|
|
415
|
+
discover(element, stateId2) {
|
|
416
|
+
const pattern = element.uiPattern ?? matchPattern(element).pattern;
|
|
417
|
+
const id2 = element.elementId ?? elementIdentity(element, pattern);
|
|
418
|
+
if (!this.entries.has(id2)) {
|
|
419
|
+
this.entries.set(id2, {
|
|
420
|
+
elementId: id2,
|
|
421
|
+
pattern,
|
|
422
|
+
reason: element.disabled ? "disabled" : pattern === "unknown" ? "unknown-pattern" : "skipped-limit",
|
|
423
|
+
stateId: stateId2,
|
|
424
|
+
locator: element.cssSelector,
|
|
425
|
+
name: element.accessibleName || element.name || element.id
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
return id2;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Record the outcome for an element. `tested` is terminal — a later skip for
|
|
432
|
+
* the same element cannot downgrade it.
|
|
433
|
+
*/
|
|
434
|
+
record(elementId, reason, detail) {
|
|
435
|
+
const entry = this.entries.get(elementId);
|
|
436
|
+
if (!entry)
|
|
437
|
+
return;
|
|
438
|
+
if (entry.reason === "tested" && reason !== "tested")
|
|
439
|
+
return;
|
|
440
|
+
entry.reason = reason;
|
|
441
|
+
if (detail)
|
|
442
|
+
entry.detail = detail;
|
|
443
|
+
}
|
|
444
|
+
countModalState() {
|
|
445
|
+
this.modalStates += 1;
|
|
446
|
+
}
|
|
447
|
+
countCase(deduplicated = false) {
|
|
448
|
+
if (deduplicated)
|
|
449
|
+
this.casesDeduplicated += 1;
|
|
450
|
+
else
|
|
451
|
+
this.casesGenerated += 1;
|
|
452
|
+
}
|
|
453
|
+
report() {
|
|
454
|
+
return buildCoverageReport([...this.entries.values()], {
|
|
455
|
+
modalStates: this.modalStates,
|
|
456
|
+
casesGenerated: this.casesGenerated,
|
|
457
|
+
casesDeduplicated: this.casesDeduplicated
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
var BLOCKED = ["blocked-destructive", "blocked-session-ending", "blocked-filter"];
|
|
462
|
+
var SKIPPED = ["skipped-limit", "skipped-duplicate", "not-visible", "disabled", "failed"];
|
|
463
|
+
function buildCoverageReport(entries, totals = {}) {
|
|
464
|
+
const byPattern = /* @__PURE__ */ new Map();
|
|
465
|
+
for (const entry of entries) {
|
|
466
|
+
const bucket = byPattern.get(entry.pattern) ?? { discovered: 0, tested: 0 };
|
|
467
|
+
bucket.discovered += 1;
|
|
468
|
+
if (entry.reason === "tested")
|
|
469
|
+
bucket.tested += 1;
|
|
470
|
+
byPattern.set(entry.pattern, bucket);
|
|
471
|
+
}
|
|
472
|
+
return {
|
|
473
|
+
elementsDiscovered: entries.length,
|
|
474
|
+
knownPatterns: entries.filter((entry) => entry.pattern !== "unknown").length,
|
|
475
|
+
tested: entries.filter((entry) => entry.reason === "tested").length,
|
|
476
|
+
skipped: entries.filter((entry) => SKIPPED.includes(entry.reason)).length,
|
|
477
|
+
blocked: entries.filter((entry) => BLOCKED.includes(entry.reason)).length,
|
|
478
|
+
unknown: entries.filter((entry) => entry.reason === "unknown-pattern").length,
|
|
479
|
+
modalStates: totals.modalStates ?? 0,
|
|
480
|
+
casesGenerated: totals.casesGenerated ?? 0,
|
|
481
|
+
casesDeduplicated: totals.casesDeduplicated ?? 0,
|
|
482
|
+
byPattern: [...byPattern.entries()].map(([pattern, bucket]) => ({ pattern, ...bucket })).sort((left, right) => right.discovered - left.discovered),
|
|
483
|
+
entries
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
|
|
271
487
|
// ../../packages/core/dist/testcase/describeStep.js
|
|
272
488
|
function describeTarget(target) {
|
|
273
489
|
const name = target.name || target.label || target.text || target.placeholder;
|
|
@@ -331,13 +547,44 @@ function collectPageData() {
|
|
|
331
547
|
const value = el.getAttribute(name);
|
|
332
548
|
return value && value.trim() ? value.trim() : void 0;
|
|
333
549
|
}
|
|
550
|
+
function renderedText(el) {
|
|
551
|
+
let text = "";
|
|
552
|
+
const walk = (node) => {
|
|
553
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
554
|
+
text += node.textContent ?? "";
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
558
|
+
return;
|
|
559
|
+
const element = node;
|
|
560
|
+
const style = window.getComputedStyle(element);
|
|
561
|
+
if (style.display === "none" || style.visibility === "hidden")
|
|
562
|
+
return;
|
|
563
|
+
if (element instanceof HTMLImageElement) {
|
|
564
|
+
const alt = element.getAttribute("alt");
|
|
565
|
+
if (alt)
|
|
566
|
+
text += ` ${alt} `;
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
const inline = style.display === "inline" || style.display === "contents";
|
|
570
|
+
if (!inline)
|
|
571
|
+
text += " ";
|
|
572
|
+
for (const child of Array.from(element.childNodes))
|
|
573
|
+
walk(child);
|
|
574
|
+
if (!inline)
|
|
575
|
+
text += " ";
|
|
576
|
+
};
|
|
577
|
+
for (const child of Array.from(el.childNodes))
|
|
578
|
+
walk(child);
|
|
579
|
+
return text;
|
|
580
|
+
}
|
|
334
581
|
function accessibleName(el) {
|
|
335
582
|
const ariaLabel = cleanText(el.getAttribute("aria-label"));
|
|
336
583
|
if (ariaLabel)
|
|
337
584
|
return ariaLabel;
|
|
338
585
|
const labelledBy = el.getAttribute("aria-labelledby");
|
|
339
586
|
if (labelledBy) {
|
|
340
|
-
const text = labelledBy.split(/\s+/).map((
|
|
587
|
+
const text = labelledBy.split(/\s+/).map((id2) => cleanText(document.getElementById(id2)?.textContent)).filter(Boolean).join(" ");
|
|
341
588
|
if (text)
|
|
342
589
|
return text;
|
|
343
590
|
}
|
|
@@ -365,7 +612,7 @@ function collectPageData() {
|
|
|
365
612
|
return cleanText(el.value);
|
|
366
613
|
return cleanText(el.getAttribute("name"));
|
|
367
614
|
}
|
|
368
|
-
const ownText = cleanText(el
|
|
615
|
+
const ownText = cleanText(renderedText(el));
|
|
369
616
|
if (ownText)
|
|
370
617
|
return ownText;
|
|
371
618
|
const image = el.querySelector("img[alt]");
|
|
@@ -398,6 +645,50 @@ function collectPageData() {
|
|
|
398
645
|
}
|
|
399
646
|
return parts.join(" > ");
|
|
400
647
|
}
|
|
648
|
+
const TEST_ID_ATTRIBUTES = ["data-testid", "data-test-id", "data-test", "data-qa", "data-cy"];
|
|
649
|
+
function testIdOf(el) {
|
|
650
|
+
for (const attribute2 of TEST_ID_ATTRIBUTES) {
|
|
651
|
+
const value = attr(el, attribute2);
|
|
652
|
+
if (value)
|
|
653
|
+
return { attribute: attribute2, value };
|
|
654
|
+
}
|
|
655
|
+
return void 0;
|
|
656
|
+
}
|
|
657
|
+
function ariaFlag(el, name) {
|
|
658
|
+
const value = el.getAttribute(name);
|
|
659
|
+
return value === null ? void 0 : value === "true";
|
|
660
|
+
}
|
|
661
|
+
function relationOf(el) {
|
|
662
|
+
const relation = {
|
|
663
|
+
controls: attr(el, "aria-controls"),
|
|
664
|
+
labelledBy: attr(el, "aria-labelledby"),
|
|
665
|
+
describedBy: attr(el, "aria-describedby"),
|
|
666
|
+
owns: attr(el, "aria-owns"),
|
|
667
|
+
target: attr(el, "data-target") || attr(el, "data-bs-target") || attr(el, "data-modal") || attr(el, "data-drawer")
|
|
668
|
+
};
|
|
669
|
+
return Object.values(relation).some(Boolean) ? relation : void 0;
|
|
670
|
+
}
|
|
671
|
+
const CONTAINERS = [
|
|
672
|
+
["dialog", '[role="dialog"], [role="alertdialog"], dialog, [aria-modal="true"]'],
|
|
673
|
+
["tab-panel", '[role="tabpanel"]'],
|
|
674
|
+
["menu", '[role="menu"], [role="listbox"]'],
|
|
675
|
+
["table-row", 'tr, [role="row"]'],
|
|
676
|
+
["form", "form"],
|
|
677
|
+
["card", '[class*="card" i], article']
|
|
678
|
+
];
|
|
679
|
+
function contextOf(el) {
|
|
680
|
+
for (const [container, selector] of CONTAINERS) {
|
|
681
|
+
const found = el.closest(selector);
|
|
682
|
+
if (!found)
|
|
683
|
+
continue;
|
|
684
|
+
return {
|
|
685
|
+
container,
|
|
686
|
+
containerSelector: cssSelector(found),
|
|
687
|
+
containerName: accessibleName(found) || cleanText(found.querySelector("h1, h2, h3, legend, caption")?.textContent) || void 0
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
return { container: "page" };
|
|
691
|
+
}
|
|
401
692
|
function inputRole(input) {
|
|
402
693
|
switch (input.type) {
|
|
403
694
|
case "checkbox":
|
|
@@ -450,8 +741,23 @@ function collectPageData() {
|
|
|
450
741
|
inputType,
|
|
451
742
|
placeholder: attr(el, "placeholder"),
|
|
452
743
|
name: attr(el, "name"),
|
|
453
|
-
testId:
|
|
744
|
+
testId: testIdOf(el)?.value,
|
|
745
|
+
// Kept so the generator matches the attribute the page really uses
|
|
746
|
+
// instead of rewriting it to Playwright's default `data-testid`.
|
|
747
|
+
testIdAttribute: testIdOf(el)?.attribute,
|
|
454
748
|
id: el.id || void 0,
|
|
749
|
+
ariaLabel: attr(el, "aria-label"),
|
|
750
|
+
describedBy: attr(el, "aria-describedby"),
|
|
751
|
+
visible: true,
|
|
752
|
+
readOnly: el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement ? el.readOnly : void 0,
|
|
753
|
+
checked: el instanceof HTMLInputElement && (el.type === "checkbox" || el.type === "radio") ? el.checked : ariaFlag(el, "aria-checked"),
|
|
754
|
+
expanded: ariaFlag(el, "aria-expanded"),
|
|
755
|
+
selected: ariaFlag(el, "aria-selected"),
|
|
756
|
+
multiple: el instanceof HTMLSelectElement || el instanceof HTMLInputElement ? el.multiple : void 0,
|
|
757
|
+
accept: el instanceof HTMLInputElement && el.type === "file" ? attr(el, "accept") : void 0,
|
|
758
|
+
hasPopup: attr(el, "aria-haspopup") || attr(el, "data-toggle") || attr(el, "data-bs-toggle"),
|
|
759
|
+
relation: relationOf(el),
|
|
760
|
+
context: contextOf(el),
|
|
455
761
|
href: el instanceof HTMLAnchorElement ? el.href : void 0,
|
|
456
762
|
options,
|
|
457
763
|
required,
|
|
@@ -522,6 +828,33 @@ function collectPageData() {
|
|
|
522
828
|
}
|
|
523
829
|
const BUTTON_SELECTOR = 'button, input[type="submit"], input[type="button"], input[type="reset"], [role="button"]';
|
|
524
830
|
const INPUT_SELECTOR = 'input:not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="hidden"]):not([type="image"])';
|
|
831
|
+
const WIDGET_SELECTOR = [
|
|
832
|
+
'[role="tab"]',
|
|
833
|
+
'[role="switch"]',
|
|
834
|
+
'[role="slider"]',
|
|
835
|
+
'[role="menuitem"]',
|
|
836
|
+
'[role="menuitemcheckbox"]',
|
|
837
|
+
'[role="menuitemradio"]',
|
|
838
|
+
'[role="option"]',
|
|
839
|
+
'[role="combobox"]',
|
|
840
|
+
'[role="checkbox"]',
|
|
841
|
+
'[role="radio"]',
|
|
842
|
+
'[role="link"]',
|
|
843
|
+
'[role="treeitem"]',
|
|
844
|
+
"summary",
|
|
845
|
+
"[aria-expanded]",
|
|
846
|
+
"[aria-haspopup]",
|
|
847
|
+
"[aria-controls]",
|
|
848
|
+
"[data-toggle]",
|
|
849
|
+
"[data-bs-toggle]",
|
|
850
|
+
"[data-target]",
|
|
851
|
+
"[data-bs-target]",
|
|
852
|
+
"[data-modal]",
|
|
853
|
+
"[data-drawer]",
|
|
854
|
+
"[data-tab]",
|
|
855
|
+
"[onclick]",
|
|
856
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
857
|
+
].join(", ");
|
|
525
858
|
const forms = Array.from(document.querySelectorAll("form")).slice(0, 20).map((form) => {
|
|
526
859
|
const fields = Array.from(form.querySelectorAll(INPUT_SELECTOR + ", textarea, select")).filter(isCollectable).slice(0, 40).map((el) => {
|
|
527
860
|
const kind = el.tagName === "TEXTAREA" ? "textarea" : el.tagName === "SELECT" ? "select" : "input";
|
|
@@ -547,6 +880,8 @@ function collectPageData() {
|
|
|
547
880
|
inputs: collect(INPUT_SELECTOR, "input", "textbox"),
|
|
548
881
|
textareas: collect("textarea", "textarea", "textbox"),
|
|
549
882
|
selects: collect("select", "select", "combobox"),
|
|
883
|
+
// Everything interactive that the native groups above do not already cover.
|
|
884
|
+
widgets: Array.from(document.querySelectorAll(WIDGET_SELECTOR)).filter(isCollectable).filter((el) => !el.matches(`a[href], ${BUTTON_SELECTOR}, ${INPUT_SELECTOR}, textarea, select`)).slice(0, MAX_PER_GROUP).map((el) => toRawElement(el, "button", attr(el, "role") || "generic")),
|
|
550
885
|
forms,
|
|
551
886
|
visibleDialogs: Array.from(document.querySelectorAll('[role="dialog"], dialog[open], [aria-modal="true"], .modal-backdrop:not(.hidden), .modal:not(.hidden), .drawer:not(.hidden)')).filter(isCollectable).map((element) => accessibleName(element) || cleanText(element.querySelector("h1, h2, h3")?.textContent) || cleanText(element.textContent).slice(0, 120)).filter(Boolean).slice(0, 20),
|
|
552
887
|
interactions: Array.from(document.querySelectorAll('[role="tab"], [role="tablist"] [aria-controls], [aria-expanded], [aria-haspopup], [data-toggle], [data-bs-toggle], [data-modal], [data-drawer], [data-tab], details[data-accordion], select')).filter(isCollectable).map((element) => {
|
|
@@ -559,13 +894,18 @@ function collectPageData() {
|
|
|
559
894
|
const dataTab = element.hasAttribute("data-tab");
|
|
560
895
|
const accordion = element.matches("details[data-accordion]");
|
|
561
896
|
const kind = role === "tab" || dataTab ? "tab" : dataDrawer ? "drawer" : popup === "dialog" || toggle === "modal" || dataModal ? "dialog" : popup === "menu" || popup === "listbox" || toggle === "dropdown" ? "dropdown" : accordion ? "accordion" : element instanceof HTMLSelectElement ? "dropdown" : element.matches("[aria-expanded]") ? "accordion" : "dialog";
|
|
897
|
+
const controls = element.getAttribute("aria-controls");
|
|
898
|
+
const targetSelector = element.getAttribute("data-target") || element.getAttribute("data-bs-target") || element.getAttribute("data-modal") || element.getAttribute("data-drawer");
|
|
899
|
+
const clickable = element.tagName === "DETAILS" ? element.querySelector("summary") ?? element : element;
|
|
562
900
|
return {
|
|
563
901
|
kind,
|
|
564
902
|
name: accessibleName(element),
|
|
565
903
|
role,
|
|
566
|
-
cssSelector: cssSelector(
|
|
904
|
+
cssSelector: cssSelector(clickable),
|
|
567
905
|
expanded: expanded === null ? void 0 : expanded === "true",
|
|
568
|
-
visible: true
|
|
906
|
+
visible: true,
|
|
907
|
+
controlsSelector: controls ? `#${CSS.escape(controls)}` : targetSelector || void 0,
|
|
908
|
+
evidence: role === "tab" ? 'role="tab"' : popup ? `aria-haspopup="${popup}"` : toggle ? `data-toggle="${toggle}"` : dataModal ? "data-modal" : dataDrawer ? "data-drawer" : accordion ? "details[data-accordion]" : expanded !== null ? "aria-expanded" : "<select>"
|
|
569
909
|
};
|
|
570
910
|
}).filter((item) => item.name).slice(0, 40),
|
|
571
911
|
stateContent: Array.from(document.querySelectorAll('[aria-live], [data-state], [data-testid*="state" i]')).filter(isCollectable).map((element) => cleanText(element.textContent)).filter(Boolean).slice(0, 30),
|
|
@@ -578,10 +918,18 @@ function collectPageData() {
|
|
|
578
918
|
|
|
579
919
|
// ../../packages/explorer/dist/mapToPageModel.js
|
|
580
920
|
function toUIElement(raw, keywords) {
|
|
581
|
-
|
|
921
|
+
const base2 = {
|
|
582
922
|
...raw,
|
|
583
923
|
destructive: isBlockedLabel(keywords, raw.accessibleName, raw.text, raw.name, raw.id)
|
|
584
924
|
};
|
|
925
|
+
const { pattern, evidence } = matchPattern(base2);
|
|
926
|
+
return {
|
|
927
|
+
...base2,
|
|
928
|
+
uiPattern: pattern,
|
|
929
|
+
patternEvidence: evidence,
|
|
930
|
+
risk: classifyRisk(base2, keywords),
|
|
931
|
+
elementId: elementIdentity(base2, pattern)
|
|
932
|
+
};
|
|
585
933
|
}
|
|
586
934
|
function toFormInfo(raw, keywords) {
|
|
587
935
|
return {
|
|
@@ -601,7 +949,8 @@ function mapToPageModel(raw, meta, blockedKeywords = []) {
|
|
|
601
949
|
const inputs = raw.inputs.map(toElement);
|
|
602
950
|
const textareas = raw.textareas.map(toElement);
|
|
603
951
|
const selects = raw.selects.map(toElement);
|
|
604
|
-
const
|
|
952
|
+
const widgets = (raw.widgets ?? []).map(toElement);
|
|
953
|
+
const controls = [...links, ...buttons, ...inputs, ...textareas, ...selects, ...widgets];
|
|
605
954
|
const state = createPageState(raw, meta.finalUrl, controls);
|
|
606
955
|
return {
|
|
607
956
|
url: meta.url,
|
|
@@ -745,6 +1094,7 @@ var DEFAULT_CONFIG = {
|
|
|
745
1094
|
limits: DEFAULT_LIMITS,
|
|
746
1095
|
continueAfterLogin: true
|
|
747
1096
|
};
|
|
1097
|
+
var MAX_MODAL_DEPTH = 3;
|
|
748
1098
|
async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions = {}) {
|
|
749
1099
|
const config2 = {
|
|
750
1100
|
...DEFAULT_CONFIG,
|
|
@@ -801,7 +1151,32 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
801
1151
|
let totalActionsFailed = 0;
|
|
802
1152
|
let totalActionsRetried = 0;
|
|
803
1153
|
let urlsSkippedByScope = 0;
|
|
1154
|
+
let modalStatesDiscovered = 0;
|
|
804
1155
|
let endReason = "queue-exhausted";
|
|
1156
|
+
const transitions = [];
|
|
1157
|
+
const coverage = new CoverageTracker();
|
|
1158
|
+
function recordTransition(from, action, before, after, result, durationMs) {
|
|
1159
|
+
const beforeText = new Set(from.stateContent);
|
|
1160
|
+
const afterText = after.state?.stateContent ?? [];
|
|
1161
|
+
transitions.push({
|
|
1162
|
+
sourceStateId: from.id,
|
|
1163
|
+
destinationStateId: after.state?.id,
|
|
1164
|
+
actionId: action.id,
|
|
1165
|
+
actionType: action.type,
|
|
1166
|
+
targetLocator: action.selector,
|
|
1167
|
+
urlBefore: before.url,
|
|
1168
|
+
urlAfter: after.url,
|
|
1169
|
+
fingerprintBefore: before.fingerprint,
|
|
1170
|
+
fingerprintAfter: after.state?.fingerprint ?? before.fingerprint,
|
|
1171
|
+
result,
|
|
1172
|
+
visibleDialogsAfter: after.state?.visibleDialogs,
|
|
1173
|
+
headingsAfter: after.state?.headings,
|
|
1174
|
+
addedText: afterText.filter((text) => !beforeText.has(text)).slice(0, 10),
|
|
1175
|
+
removedText: from.stateContent.filter((text) => !afterText.includes(text)).slice(0, 10),
|
|
1176
|
+
validationMessagesAfter: after.state?.validationMessages,
|
|
1177
|
+
durationMs
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
805
1180
|
function isWithinScope(url) {
|
|
806
1181
|
if (!config2.scopePath)
|
|
807
1182
|
return true;
|
|
@@ -816,20 +1191,53 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
816
1191
|
function isSessionEnding(name, text) {
|
|
817
1192
|
return isSessionEndingLabel(name, text);
|
|
818
1193
|
}
|
|
819
|
-
async function discoverNavigationRegions(page) {
|
|
1194
|
+
async function discoverNavigationRegions(page, currentState) {
|
|
820
1195
|
const candidates = [];
|
|
821
1196
|
try {
|
|
822
1197
|
const navItems = await page.evaluate(() => {
|
|
1198
|
+
const renderedText = (element) => {
|
|
1199
|
+
let text = "";
|
|
1200
|
+
const walk = (node) => {
|
|
1201
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
1202
|
+
text += node.textContent ?? "";
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
1205
|
+
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
1206
|
+
return;
|
|
1207
|
+
const child = node;
|
|
1208
|
+
const style = window.getComputedStyle(child);
|
|
1209
|
+
if (style.visibility === "hidden")
|
|
1210
|
+
return;
|
|
1211
|
+
if (child instanceof HTMLImageElement) {
|
|
1212
|
+
const alt = child.getAttribute("alt");
|
|
1213
|
+
if (alt)
|
|
1214
|
+
text += ` ${alt} `;
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const inline = style.display === "inline" || style.display === "contents";
|
|
1218
|
+
if (!inline)
|
|
1219
|
+
text += " ";
|
|
1220
|
+
for (const grandChild of Array.from(child.childNodes))
|
|
1221
|
+
walk(grandChild);
|
|
1222
|
+
if (!inline)
|
|
1223
|
+
text += " ";
|
|
1224
|
+
};
|
|
1225
|
+
for (const child of Array.from(element.childNodes))
|
|
1226
|
+
walk(child);
|
|
1227
|
+
return text.replace(/\s+/g, " ").trim();
|
|
1228
|
+
};
|
|
823
1229
|
const results = [];
|
|
824
1230
|
const navRegions = document.querySelectorAll('nav a[href], aside a[href], [role="navigation"] a[href], [role="menu"] [role="menuitem"], [role="menubar"] [role="menuitem"]');
|
|
825
1231
|
navRegions.forEach((el) => {
|
|
826
1232
|
const anchor = el;
|
|
827
|
-
|
|
828
|
-
if (!name || name.length > 80)
|
|
1233
|
+
if (el.getClientRects().length === 0)
|
|
829
1234
|
return;
|
|
830
|
-
const
|
|
1235
|
+
const name = el.getAttribute("aria-label")?.trim() || renderedText(el);
|
|
1236
|
+
if (!name)
|
|
1237
|
+
return;
|
|
1238
|
+
const cssSel = el.id ? `#${CSS.escape(el.id)}` : `${el.tagName.toLowerCase()}[href="${(anchor.getAttribute("href") || "").replace(/["\\]/g, "\\$&")}"]`;
|
|
831
1239
|
results.push({
|
|
832
|
-
name
|
|
1240
|
+
name,
|
|
833
1241
|
role: el.getAttribute("role") || "link",
|
|
834
1242
|
href: anchor.href || null,
|
|
835
1243
|
cssSelector: cssSel
|
|
@@ -841,7 +1249,9 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
841
1249
|
if (!item.href)
|
|
842
1250
|
continue;
|
|
843
1251
|
const action = {
|
|
844
|
-
|
|
1252
|
+
// Scoped to the state, so failing here cannot blacklist the same link
|
|
1253
|
+
// in a state where it is reachable.
|
|
1254
|
+
id: `${currentState.id}|nav|${item.cssSelector}`,
|
|
845
1255
|
type: "navigate",
|
|
846
1256
|
description: `Navigate to \u201C${item.name}\u201D via sidebar`,
|
|
847
1257
|
target: item.name,
|
|
@@ -860,7 +1270,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
860
1270
|
candidates.push({
|
|
861
1271
|
priority: 2,
|
|
862
1272
|
action,
|
|
863
|
-
locator: { role: item.role, name: item.name },
|
|
1273
|
+
locator: { role: item.role, name: item.name, cssSelector: item.cssSelector },
|
|
864
1274
|
kind: "sidebar-nav",
|
|
865
1275
|
restoreStrategy: "goto"
|
|
866
1276
|
});
|
|
@@ -885,7 +1295,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
885
1295
|
safe: false,
|
|
886
1296
|
reason: "session-ending action"
|
|
887
1297
|
},
|
|
888
|
-
locator: { role: link.role, name: link.accessibleName },
|
|
1298
|
+
locator: { role: link.role, name: link.accessibleName, cssSelector: link.cssSelector },
|
|
889
1299
|
kind: "navigation-link",
|
|
890
1300
|
restoreStrategy: "goto"
|
|
891
1301
|
});
|
|
@@ -904,13 +1314,13 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
904
1314
|
safe: !blocked,
|
|
905
1315
|
reason: blocked ? "Action matched the Project click filter" : void 0
|
|
906
1316
|
},
|
|
907
|
-
locator: { role: link.role, name: link.accessibleName },
|
|
1317
|
+
locator: { role: link.role, name: link.accessibleName, cssSelector: link.cssSelector },
|
|
908
1318
|
kind: "navigation-link",
|
|
909
1319
|
restoreStrategy: "goto"
|
|
910
1320
|
});
|
|
911
1321
|
}
|
|
912
1322
|
try {
|
|
913
|
-
const navCandidates = await discoverNavigationRegions(page);
|
|
1323
|
+
const navCandidates = await discoverNavigationRegions(page, currentState);
|
|
914
1324
|
candidates.push(...navCandidates);
|
|
915
1325
|
} catch {
|
|
916
1326
|
}
|
|
@@ -928,7 +1338,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
928
1338
|
safe: !blocked,
|
|
929
1339
|
reason: blocked ? "Action matched the Project click filter" : void 0
|
|
930
1340
|
},
|
|
931
|
-
locator: { role: interaction.role, name: interaction.name },
|
|
1341
|
+
locator: { role: interaction.role, name: interaction.name, cssSelector: interaction.cssSelector },
|
|
932
1342
|
kind: "tab",
|
|
933
1343
|
restoreStrategy: "select-tab"
|
|
934
1344
|
});
|
|
@@ -983,7 +1393,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
983
1393
|
safe: !blocked,
|
|
984
1394
|
reason: blocked ? "Action matched the Project click filter" : void 0
|
|
985
1395
|
},
|
|
986
|
-
locator: { role: interaction.role, name: interaction.name },
|
|
1396
|
+
locator: { role: interaction.role, name: interaction.name, cssSelector: interaction.cssSelector },
|
|
987
1397
|
kind: "modal-opener",
|
|
988
1398
|
restoreStrategy: "close-dialog"
|
|
989
1399
|
});
|
|
@@ -1002,7 +1412,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1002
1412
|
safe: !blocked,
|
|
1003
1413
|
reason: blocked ? "Action matched the Project click filter" : void 0
|
|
1004
1414
|
},
|
|
1005
|
-
locator: { role: interaction.role, name: interaction.name },
|
|
1415
|
+
locator: { role: interaction.role, name: interaction.name, cssSelector: interaction.cssSelector },
|
|
1006
1416
|
kind: "dropdown",
|
|
1007
1417
|
restoreStrategy: "goto"
|
|
1008
1418
|
});
|
|
@@ -1021,7 +1431,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1021
1431
|
safe: !blocked,
|
|
1022
1432
|
reason: blocked ? "Action matched the Project click filter" : void 0
|
|
1023
1433
|
},
|
|
1024
|
-
locator: { role: interaction.role, name: interaction.name },
|
|
1434
|
+
locator: { role: interaction.role, name: interaction.name, cssSelector: interaction.cssSelector },
|
|
1025
1435
|
kind: "accordion",
|
|
1026
1436
|
restoreStrategy: "goto"
|
|
1027
1437
|
});
|
|
@@ -1096,15 +1506,37 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1096
1506
|
candidates.sort((a, b) => a.priority - b.priority);
|
|
1097
1507
|
return candidates;
|
|
1098
1508
|
}
|
|
1099
|
-
async function
|
|
1509
|
+
async function replayEntryFlow(page, entryFlow) {
|
|
1510
|
+
const inPageSteps = entryFlow.filter((step) => step.action.selector && step.action.type !== "navigate");
|
|
1511
|
+
if (inPageSteps.length === 0)
|
|
1512
|
+
return;
|
|
1513
|
+
for (const step of inPageSteps) {
|
|
1514
|
+
const selector = step.action.selector;
|
|
1515
|
+
if (!selector)
|
|
1516
|
+
continue;
|
|
1517
|
+
try {
|
|
1518
|
+
const target = page.locator(selector).first();
|
|
1519
|
+
if (await target.count() === 0)
|
|
1520
|
+
continue;
|
|
1521
|
+
if (!await target.isVisible())
|
|
1522
|
+
continue;
|
|
1523
|
+
await target.click({ timeout: legacyOptions.actionTimeoutMs });
|
|
1524
|
+
await page.waitForTimeout(legacyOptions.stateDiscoveryTimeoutMs);
|
|
1525
|
+
} catch {
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
async function restoreState(page, targetUrl, strategy, entryFlow) {
|
|
1100
1530
|
switch (strategy) {
|
|
1101
1531
|
case "goto":
|
|
1102
1532
|
await page.goto(targetUrl, { waitUntil: "domcontentloaded", timeout: legacyOptions.pageTimeoutMs }).catch(() => void 0);
|
|
1103
1533
|
await page.waitForTimeout(legacyOptions.waitAfterNavigationMs);
|
|
1534
|
+
await replayEntryFlow(page, entryFlow);
|
|
1104
1535
|
break;
|
|
1105
1536
|
case "reload":
|
|
1106
1537
|
await page.reload({ waitUntil: "domcontentloaded", timeout: legacyOptions.pageTimeoutMs }).catch(() => void 0);
|
|
1107
1538
|
await page.waitForTimeout(legacyOptions.waitAfterNavigationMs);
|
|
1539
|
+
await replayEntryFlow(page, entryFlow);
|
|
1108
1540
|
break;
|
|
1109
1541
|
case "close-dialog":
|
|
1110
1542
|
try {
|
|
@@ -1117,7 +1549,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1117
1549
|
await page.waitForTimeout(legacyOptions.stateDiscoveryTimeoutMs);
|
|
1118
1550
|
break;
|
|
1119
1551
|
case "entry-replay":
|
|
1120
|
-
for (const step of
|
|
1552
|
+
for (const step of entryFlow) {
|
|
1121
1553
|
try {
|
|
1122
1554
|
if (step.action.selector) {
|
|
1123
1555
|
await page.locator(step.action.selector).click({ timeout: legacyOptions.actionTimeoutMs }).catch(() => void 0);
|
|
@@ -1141,20 +1573,34 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1141
1573
|
}
|
|
1142
1574
|
}
|
|
1143
1575
|
async function executeWithRetry(page, candidate, currentUrl, entryFlow, maxRetries) {
|
|
1576
|
+
const locatorsFor = () => {
|
|
1577
|
+
const options = [];
|
|
1578
|
+
const { role, name, testId, cssSelector } = candidate.locator;
|
|
1579
|
+
if (testId)
|
|
1580
|
+
options.push(() => page.getByTestId(testId));
|
|
1581
|
+
if (role && name) {
|
|
1582
|
+
options.push(() => page.getByRole(role, { name, exact: true }).first());
|
|
1583
|
+
options.push(() => page.getByRole(role, { name }).first());
|
|
1584
|
+
}
|
|
1585
|
+
if (cssSelector)
|
|
1586
|
+
options.push(() => page.locator(cssSelector).first());
|
|
1587
|
+
return options;
|
|
1588
|
+
};
|
|
1144
1589
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1145
1590
|
try {
|
|
1146
|
-
|
|
1147
|
-
if (
|
|
1148
|
-
locator3 = page.locator(candidate.locator.cssSelector).first();
|
|
1149
|
-
} else if (candidate.locator.role && candidate.locator.name) {
|
|
1150
|
-
locator3 = page.getByRole(candidate.locator.role, {
|
|
1151
|
-
name: candidate.locator.name
|
|
1152
|
-
});
|
|
1153
|
-
} else if (candidate.locator.testId) {
|
|
1154
|
-
locator3 = page.getByTestId(candidate.locator.testId);
|
|
1155
|
-
} else {
|
|
1591
|
+
const options = locatorsFor();
|
|
1592
|
+
if (options.length === 0)
|
|
1156
1593
|
return { success: false };
|
|
1594
|
+
let locator3;
|
|
1595
|
+
for (const build2 of options) {
|
|
1596
|
+
const next = build2();
|
|
1597
|
+
if (await next.count() > 0) {
|
|
1598
|
+
locator3 = next;
|
|
1599
|
+
break;
|
|
1600
|
+
}
|
|
1157
1601
|
}
|
|
1602
|
+
if (!locator3)
|
|
1603
|
+
throw new Error("No locator candidate matched");
|
|
1158
1604
|
await locator3.click({ timeout: legacyOptions.actionTimeoutMs });
|
|
1159
1605
|
await page.waitForTimeout(legacyOptions.stateDiscoveryTimeoutMs);
|
|
1160
1606
|
const newUrl = page.url();
|
|
@@ -1173,23 +1619,48 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1173
1619
|
}
|
|
1174
1620
|
return { success: false };
|
|
1175
1621
|
}
|
|
1176
|
-
async function exploreModal(page, parentState, _sourceUrl, entryFlow) {
|
|
1622
|
+
async function exploreModal(page, parentState, _sourceUrl, entryFlow, depth = 1) {
|
|
1623
|
+
if (depth > MAX_MODAL_DEPTH) {
|
|
1624
|
+
debug(`Modal depth limit reached (${MAX_MODAL_DEPTH})`, { stateId: parentState.id });
|
|
1625
|
+
return { candidates: [] };
|
|
1626
|
+
}
|
|
1177
1627
|
try {
|
|
1178
|
-
const
|
|
1179
|
-
|
|
1628
|
+
const containerSelector = await page.evaluate(() => {
|
|
1629
|
+
const open = Array.from(document.querySelectorAll('dialog[open], [role="dialog"], [role="alertdialog"], [aria-modal="true"]')).filter((element) => {
|
|
1630
|
+
const style = window.getComputedStyle(element);
|
|
1631
|
+
return style.display !== "none" && style.visibility !== "hidden";
|
|
1632
|
+
});
|
|
1633
|
+
const container = open.at(-1);
|
|
1634
|
+
if (!container)
|
|
1635
|
+
return void 0;
|
|
1636
|
+
if (container.id)
|
|
1637
|
+
return `#${CSS.escape(container.id)}`;
|
|
1638
|
+
container.setAttribute("data-lazyscout-modal", "true");
|
|
1639
|
+
return '[data-lazyscout-modal="true"]';
|
|
1180
1640
|
});
|
|
1181
|
-
if (!
|
|
1641
|
+
if (!containerSelector)
|
|
1182
1642
|
return { candidates: [] };
|
|
1183
1643
|
const raw = await page.evaluate(collectPageData);
|
|
1184
|
-
const pageModel = mapToPageModel(raw, { url: page.url(), finalUrl: page.url(), depth
|
|
1185
|
-
const
|
|
1186
|
-
if (!
|
|
1644
|
+
const pageModel = mapToPageModel(raw, { url: page.url(), finalUrl: page.url(), depth, statusCode: 200 }, legacyOptions.blockedKeywords);
|
|
1645
|
+
const collected = pageModel.state;
|
|
1646
|
+
if (!collected)
|
|
1187
1647
|
return { candidates: [] };
|
|
1648
|
+
const modalState = {
|
|
1649
|
+
...collected,
|
|
1650
|
+
parentStateId: parentState.id,
|
|
1651
|
+
containerSelector,
|
|
1652
|
+
depth,
|
|
1653
|
+
controls: collected.controls.filter((control) => control.context?.container === "dialog" || control.context?.containerSelector === containerSelector)
|
|
1654
|
+
};
|
|
1188
1655
|
if (visitedStates.has(modalState.id))
|
|
1189
1656
|
return { candidates: [] };
|
|
1190
1657
|
visitedStates.add(modalState.id);
|
|
1191
1658
|
addState(actionGraph, modalState);
|
|
1192
|
-
|
|
1659
|
+
modalStatesDiscovered += 1;
|
|
1660
|
+
debug(`State discovered: ${modalState.name} (modal depth ${depth}, ${modalState.controls.length} controls)`, {
|
|
1661
|
+
stateId: modalState.id,
|
|
1662
|
+
url: page.url()
|
|
1663
|
+
});
|
|
1193
1664
|
const modalCandidates = await discoverSafeCandidates(page, modalState);
|
|
1194
1665
|
const safeCandidates = modalCandidates.filter((c) => c.action.safe).slice(0, legacyOptions.maxActionsPerState);
|
|
1195
1666
|
for (const mc of safeCandidates) {
|
|
@@ -1216,13 +1687,16 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1216
1687
|
}
|
|
1217
1688
|
actionGraph.visitedActionKeys.push(mc.action.id);
|
|
1218
1689
|
const newRaw = await page.evaluate(collectPageData);
|
|
1219
|
-
const newModel = mapToPageModel(newRaw, { url: page.url(), finalUrl: page.url(), depth
|
|
1690
|
+
const newModel = mapToPageModel(newRaw, { url: page.url(), finalUrl: page.url(), depth, statusCode: 200 }, legacyOptions.blockedKeywords);
|
|
1220
1691
|
const newState = newModel.state;
|
|
1221
1692
|
if (newState && !visitedStates.has(newState.id)) {
|
|
1222
1693
|
visitedStates.add(newState.id);
|
|
1223
|
-
addState(actionGraph, newState);
|
|
1694
|
+
addState(actionGraph, { ...newState, parentStateId: modalState.id, depth });
|
|
1224
1695
|
addEdge(actionGraph, modalState.id, newState.id, mc.action, "visited");
|
|
1225
1696
|
debug(`New state in modal: ${newState.name}`, { stateId: newState.id });
|
|
1697
|
+
if (newState.visibleDialogs.length > modalState.visibleDialogs.length) {
|
|
1698
|
+
await exploreModal(page, modalState, page.url(), entryFlow, depth + 1);
|
|
1699
|
+
}
|
|
1226
1700
|
}
|
|
1227
1701
|
}
|
|
1228
1702
|
try {
|
|
@@ -1356,8 +1830,13 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1356
1830
|
break;
|
|
1357
1831
|
}
|
|
1358
1832
|
}
|
|
1359
|
-
const
|
|
1360
|
-
|
|
1833
|
+
const collect = async () => mapToPageModel(await page.evaluate(collectPageData), { url: item.url, finalUrl: page.url(), depth: item.depth, statusCode: 200 }, legacyOptions.blockedKeywords);
|
|
1834
|
+
let currentModel = await collect();
|
|
1835
|
+
const wantedState = item.stateId ? actionGraph.states.find((state) => state.id === item.stateId) : void 0;
|
|
1836
|
+
if (wantedState && currentModel.state && currentModel.state.fingerprint !== wantedState.fingerprint) {
|
|
1837
|
+
await replayEntryFlow(page, item.entryFlow);
|
|
1838
|
+
currentModel = await collect();
|
|
1839
|
+
}
|
|
1361
1840
|
const currentState = currentModel.state;
|
|
1362
1841
|
if (!currentState)
|
|
1363
1842
|
continue;
|
|
@@ -1393,6 +1872,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1393
1872
|
break;
|
|
1394
1873
|
actionGraph.visitedActionKeys.push(candidate.action.id);
|
|
1395
1874
|
const beforeUrl = page.url();
|
|
1875
|
+
const actionStartedAt = Date.now();
|
|
1396
1876
|
if (candidate.kind === "navigation-link" || candidate.kind === "sidebar-nav" || candidate.kind === "breadcrumb") {
|
|
1397
1877
|
const href = candidate.action.target;
|
|
1398
1878
|
if (href && !isWithinScope(href)) {
|
|
@@ -1410,6 +1890,7 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1410
1890
|
totalActionsFailed++;
|
|
1411
1891
|
addEdge(actionGraph, currentState.id, void 0, candidate.action, "failed");
|
|
1412
1892
|
actionGraph.failedActionKeys.push(candidate.action.id);
|
|
1893
|
+
recordTransition(currentState, candidate.action, { url: beforeUrl, fingerprint: currentState.fingerprint }, { url: page.url() }, "failed", Date.now() - actionStartedAt);
|
|
1413
1894
|
debug(`Failed: ${candidate.action.target}`, { actionId: candidate.action.id });
|
|
1414
1895
|
await restoreState(page, beforeUrl, candidate.restoreStrategy, item.entryFlow);
|
|
1415
1896
|
continue;
|
|
@@ -1433,9 +1914,11 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1433
1914
|
const newRaw = await page.evaluate(collectPageData);
|
|
1434
1915
|
const newModel = mapToPageModel(newRaw, { url: beforeUrl, finalUrl: afterUrl, depth: item.depth + 1, statusCode: 200 }, legacyOptions.blockedKeywords);
|
|
1435
1916
|
const newState = newModel.state;
|
|
1917
|
+
const changed = Boolean(newState && (newState.fingerprint !== currentState.fingerprint || afterUrl !== beforeUrl));
|
|
1918
|
+
recordTransition(currentState, candidate.action, { url: beforeUrl, fingerprint: currentState.fingerprint }, { url: afterUrl, state: newState }, changed ? "changed" : "unchanged", Date.now() - actionStartedAt);
|
|
1436
1919
|
if (newState && !visitedStates.has(newState.id)) {
|
|
1437
1920
|
visitedStates.add(newState.id);
|
|
1438
|
-
addState(actionGraph, newState);
|
|
1921
|
+
addState(actionGraph, { ...newState, parentStateId: currentState.id, depth: item.depth + 1 });
|
|
1439
1922
|
addEdge(actionGraph, currentState.id, newState.id, candidate.action, "visited");
|
|
1440
1923
|
debug(`New state: ${newState.name}`, { stateId: newState.id, url: redactUrl(afterUrl) });
|
|
1441
1924
|
if (!visitedUrls.has(normalizedAfter)) {
|
|
@@ -1492,13 +1975,42 @@ async function exploreWithScope(startUrl, explorationConfig = {}, exploreOptions
|
|
|
1492
1975
|
summary,
|
|
1493
1976
|
discoveryLogs: logs
|
|
1494
1977
|
};
|
|
1978
|
+
for (const state of actionGraph.states) {
|
|
1979
|
+
for (const control of state.controls) {
|
|
1980
|
+
const elementId = coverage.discover(control, state.id);
|
|
1981
|
+
if (control.disabled)
|
|
1982
|
+
coverage.record(elementId, "disabled");
|
|
1983
|
+
else if (control.risk === "session-ending")
|
|
1984
|
+
coverage.record(elementId, "blocked-session-ending");
|
|
1985
|
+
else if (control.risk === "destructive")
|
|
1986
|
+
coverage.record(elementId, "blocked-destructive");
|
|
1987
|
+
else if (control.uiPattern === "unknown")
|
|
1988
|
+
coverage.record(elementId, "unknown-pattern");
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
for (const edge of actionGraph.edges) {
|
|
1992
|
+
const state = actionGraph.states.find((candidate) => candidate.id === edge.fromStateId);
|
|
1993
|
+
const control = state?.controls.find((candidate) => candidate.cssSelector === edge.action.selector);
|
|
1994
|
+
if (!control?.elementId)
|
|
1995
|
+
continue;
|
|
1996
|
+
if (edge.status === "visited")
|
|
1997
|
+
coverage.record(control.elementId, "tested");
|
|
1998
|
+
else if (edge.status === "failed")
|
|
1999
|
+
coverage.record(control.elementId, "failed");
|
|
2000
|
+
else if (edge.status === "blocked")
|
|
2001
|
+
coverage.record(control.elementId, "blocked-filter", edge.action.reason);
|
|
2002
|
+
}
|
|
2003
|
+
for (let index = 0; index < modalStatesDiscovered; index++)
|
|
2004
|
+
coverage.countModalState();
|
|
1495
2005
|
return {
|
|
1496
2006
|
startUrl: entryUrl,
|
|
1497
2007
|
origin,
|
|
1498
2008
|
pages,
|
|
1499
2009
|
issues,
|
|
1500
2010
|
stats,
|
|
1501
|
-
actionGraph
|
|
2011
|
+
actionGraph,
|
|
2012
|
+
transitions,
|
|
2013
|
+
coverage: coverage.report()
|
|
1502
2014
|
};
|
|
1503
2015
|
}
|
|
1504
2016
|
function addState(graph, state) {
|
|
@@ -1508,10 +2020,10 @@ function addState(graph, state) {
|
|
|
1508
2020
|
graph.visitedStateIds.push(state.id);
|
|
1509
2021
|
}
|
|
1510
2022
|
function addEdge(graph, fromStateId, toStateId, action, status) {
|
|
1511
|
-
const
|
|
1512
|
-
if (graph.edges.some((edge) => edge.id ===
|
|
2023
|
+
const id2 = `${fromStateId}|${action.id}|${toStateId ?? status}`;
|
|
2024
|
+
if (graph.edges.some((edge) => edge.id === id2))
|
|
1513
2025
|
return;
|
|
1514
|
-
graph.edges.push({ id, fromStateId, toStateId, action, status });
|
|
2026
|
+
graph.edges.push({ id: id2, fromStateId, toStateId, action, status });
|
|
1515
2027
|
}
|
|
1516
2028
|
function getEndReasonDetail(reason, config2) {
|
|
1517
2029
|
switch (reason) {
|
|
@@ -1591,9 +2103,9 @@ function recorderInitScript() {
|
|
|
1591
2103
|
return "textbox";
|
|
1592
2104
|
};
|
|
1593
2105
|
const labelOf2 = (element) => {
|
|
1594
|
-
const
|
|
1595
|
-
if (
|
|
1596
|
-
const explicit = document.querySelector(`label[for="${CSS.escape(
|
|
2106
|
+
const id2 = element.getAttribute("id");
|
|
2107
|
+
if (id2) {
|
|
2108
|
+
const explicit = document.querySelector(`label[for="${CSS.escape(id2)}"]`);
|
|
1597
2109
|
const value = clean(explicit?.textContent);
|
|
1598
2110
|
if (value)
|
|
1599
2111
|
return value;
|
|
@@ -1601,6 +2113,37 @@ function recorderInitScript() {
|
|
|
1601
2113
|
const wrapping = element.closest("label");
|
|
1602
2114
|
return clean(wrapping?.textContent) || void 0;
|
|
1603
2115
|
};
|
|
2116
|
+
const renderedText = (el) => {
|
|
2117
|
+
let text = "";
|
|
2118
|
+
const walk = (node) => {
|
|
2119
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
2120
|
+
text += node.textContent ?? "";
|
|
2121
|
+
return;
|
|
2122
|
+
}
|
|
2123
|
+
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
2124
|
+
return;
|
|
2125
|
+
const child = node;
|
|
2126
|
+
const style = window.getComputedStyle(child);
|
|
2127
|
+
if (style.display === "none" || style.visibility === "hidden")
|
|
2128
|
+
return;
|
|
2129
|
+
if (child instanceof HTMLImageElement) {
|
|
2130
|
+
const alt = child.getAttribute("alt");
|
|
2131
|
+
if (alt)
|
|
2132
|
+
text += ` ${alt} `;
|
|
2133
|
+
return;
|
|
2134
|
+
}
|
|
2135
|
+
const inline = style.display === "inline" || style.display === "contents";
|
|
2136
|
+
if (!inline)
|
|
2137
|
+
text += " ";
|
|
2138
|
+
for (const grandChild of Array.from(child.childNodes))
|
|
2139
|
+
walk(grandChild);
|
|
2140
|
+
if (!inline)
|
|
2141
|
+
text += " ";
|
|
2142
|
+
};
|
|
2143
|
+
for (const child of Array.from(el.childNodes))
|
|
2144
|
+
walk(child);
|
|
2145
|
+
return text;
|
|
2146
|
+
};
|
|
1604
2147
|
const accessibleName = (element) => {
|
|
1605
2148
|
const aria = clean(element.getAttribute("aria-label"));
|
|
1606
2149
|
if (aria)
|
|
@@ -1630,18 +2173,28 @@ function recorderInitScript() {
|
|
|
1630
2173
|
}
|
|
1631
2174
|
return void 0;
|
|
1632
2175
|
}
|
|
1633
|
-
return clean(element
|
|
2176
|
+
return clean(renderedText(element)) || void 0;
|
|
1634
2177
|
};
|
|
2178
|
+
const TEST_ID_ATTRIBUTES = ["data-testid", "data-test-id", "data-test", "data-qa", "data-cy"];
|
|
2179
|
+
const testIdOf = (element) => {
|
|
2180
|
+
for (const attribute2 of TEST_ID_ATTRIBUTES) {
|
|
2181
|
+
const value = element.getAttribute(attribute2);
|
|
2182
|
+
if (value && value.trim())
|
|
2183
|
+
return { attribute: attribute2, value: value.trim() };
|
|
2184
|
+
}
|
|
2185
|
+
return void 0;
|
|
2186
|
+
};
|
|
2187
|
+
const attributeSelector2 = (name, value, tagName = "") => `${tagName}[${name}="${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"]`;
|
|
1635
2188
|
const cssPath = (element) => {
|
|
1636
|
-
const testId =
|
|
2189
|
+
const testId = testIdOf(element);
|
|
1637
2190
|
if (testId)
|
|
1638
|
-
return
|
|
1639
|
-
const
|
|
1640
|
-
if (
|
|
1641
|
-
return `#${CSS.escape(
|
|
2191
|
+
return attributeSelector2(testId.attribute, testId.value);
|
|
2192
|
+
const id2 = element.getAttribute("id");
|
|
2193
|
+
if (id2 && !/\d{4,}/.test(id2))
|
|
2194
|
+
return `#${CSS.escape(id2)}`;
|
|
1642
2195
|
const name = element.getAttribute("name");
|
|
1643
2196
|
if (name)
|
|
1644
|
-
return
|
|
2197
|
+
return attributeSelector2("name", name, element.tagName.toLowerCase());
|
|
1645
2198
|
const parts = [];
|
|
1646
2199
|
let node = element;
|
|
1647
2200
|
let depth = 0;
|
|
@@ -1664,6 +2217,8 @@ function recorderInitScript() {
|
|
|
1664
2217
|
const role = roleOf(element);
|
|
1665
2218
|
const name = accessibleName(element);
|
|
1666
2219
|
const matches = role && name ? Array.from(document.querySelectorAll(CLICKABLE)).filter((candidate) => roleOf(candidate) === role && accessibleName(candidate)?.localeCompare(name, void 0, { sensitivity: "accent" }) === 0) : [];
|
|
2220
|
+
const testId = testIdOf(element);
|
|
2221
|
+
const elementId = element.getAttribute("id") || void 0;
|
|
1667
2222
|
const target = {
|
|
1668
2223
|
role,
|
|
1669
2224
|
name,
|
|
@@ -1671,6 +2226,13 @@ function recorderInitScript() {
|
|
|
1671
2226
|
text: role ? void 0 : clean(element.textContent) || void 0,
|
|
1672
2227
|
label: labelOf2(element),
|
|
1673
2228
|
placeholder: clean(element.getAttribute("placeholder")) || void 0,
|
|
2229
|
+
// Recorded verbatim so the generator can rank them without re-deriving
|
|
2230
|
+
// anything from the DOM it can no longer see.
|
|
2231
|
+
testId: testId?.value,
|
|
2232
|
+
testIdAttribute: testId?.attribute,
|
|
2233
|
+
elementId: elementId && !/\d{4,}/.test(elementId) ? elementId : void 0,
|
|
2234
|
+
attributeName: element.getAttribute("name") || void 0,
|
|
2235
|
+
tagName: element.tagName.toLowerCase(),
|
|
1674
2236
|
cssSelector: cssPath(element)
|
|
1675
2237
|
};
|
|
1676
2238
|
return matches.length > 1 ? { ...target, matchCount: matches.length } : target;
|
|
@@ -1964,10 +2526,10 @@ function assignModules(pages) {
|
|
|
1964
2526
|
const result = /* @__PURE__ */ new Map();
|
|
1965
2527
|
const used = /* @__PURE__ */ new Map();
|
|
1966
2528
|
for (const page of pages) {
|
|
1967
|
-
const
|
|
1968
|
-
const count = used.get(
|
|
1969
|
-
used.set(
|
|
1970
|
-
result.set(page.url, count === 0 ?
|
|
2529
|
+
const base2 = moduleNameFromUrl(page.finalUrl);
|
|
2530
|
+
const count = used.get(base2) ?? 0;
|
|
2531
|
+
used.set(base2, count + 1);
|
|
2532
|
+
result.set(page.url, count === 0 ? base2 : `${base2}-${count + 1}`);
|
|
1971
2533
|
}
|
|
1972
2534
|
return result;
|
|
1973
2535
|
}
|
|
@@ -1982,15 +2544,24 @@ function toTargetRef(element) {
|
|
|
1982
2544
|
contextSelector: element.contextSelector,
|
|
1983
2545
|
contextTestId: element.contextTestId
|
|
1984
2546
|
} : void 0;
|
|
2547
|
+
const identity = defined({
|
|
2548
|
+
testId: element.testId,
|
|
2549
|
+
testIdAttribute: element.testIdAttribute,
|
|
2550
|
+
elementId: element.id,
|
|
2551
|
+
attributeName: element.name,
|
|
2552
|
+
tagName: element.tagName,
|
|
2553
|
+
cssSelector: element.cssSelector
|
|
2554
|
+
});
|
|
1985
2555
|
if (element.accessibleName) {
|
|
1986
|
-
return { role: element.role, name: element.accessibleName,
|
|
2556
|
+
return { role: element.role, name: element.accessibleName, ...identity, ...disambiguation };
|
|
1987
2557
|
}
|
|
1988
2558
|
if (element.placeholder) {
|
|
1989
|
-
return { role: element.role, placeholder: element.placeholder,
|
|
2559
|
+
return { role: element.role, placeholder: element.placeholder, ...identity, ...disambiguation };
|
|
1990
2560
|
}
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
2561
|
+
return { role: element.role, ...identity, ...disambiguation };
|
|
2562
|
+
}
|
|
2563
|
+
function defined(value) {
|
|
2564
|
+
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
|
|
1994
2565
|
}
|
|
1995
2566
|
function labelOf(element) {
|
|
1996
2567
|
return element.accessibleName || element.placeholder || element.name || element.id || element.tagName;
|
|
@@ -2095,40 +2666,6 @@ function pageStructureRule(ctx) {
|
|
|
2095
2666
|
})
|
|
2096
2667
|
];
|
|
2097
2668
|
}
|
|
2098
|
-
function interactionRule(ctx) {
|
|
2099
|
-
const interactions = ctx.page.state?.interactions ?? [];
|
|
2100
|
-
return interactions.slice(0, 12).map((interaction) => {
|
|
2101
|
-
const target = interactionTarget(interaction);
|
|
2102
|
-
return build(ctx, {
|
|
2103
|
-
title: (interaction.name || interaction.kind) + " interaction works",
|
|
2104
|
-
preconditions: precondition(ctx.page),
|
|
2105
|
-
steps: [
|
|
2106
|
-
navigateStep(ctx.page),
|
|
2107
|
-
{ type: "click", target, description: interactionAction(interaction) },
|
|
2108
|
-
{ type: "assertVisible", target }
|
|
2109
|
-
],
|
|
2110
|
-
expectedResult: interaction.kind + ' "' + (interaction.name || "control") + '" opens and is usable.',
|
|
2111
|
-
type: "positive",
|
|
2112
|
-
priority: "medium",
|
|
2113
|
-
automationStatus: "needs-review",
|
|
2114
|
-
notes: "Generated from the observed " + interaction.kind + " interaction."
|
|
2115
|
-
});
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
function interactionTarget(interaction) {
|
|
2119
|
-
return { role: interaction.role, name: interaction.name || void 0, cssSelector: interaction.cssSelector };
|
|
2120
|
-
}
|
|
2121
|
-
function interactionAction(interaction) {
|
|
2122
|
-
const labels = {
|
|
2123
|
-
dialog: "Open modal or dialog",
|
|
2124
|
-
tab: "Select tab",
|
|
2125
|
-
accordion: "Expand accordion",
|
|
2126
|
-
dropdown: "Open dropdown",
|
|
2127
|
-
drawer: "Open drawer",
|
|
2128
|
-
popover: "Open popover"
|
|
2129
|
-
};
|
|
2130
|
-
return labels[interaction.kind];
|
|
2131
|
-
}
|
|
2132
2669
|
function requiredFieldRule(ctx, form) {
|
|
2133
2670
|
const submit = form.submitButtons.find((button) => !button.disabled);
|
|
2134
2671
|
const fields = form.fields.filter(isUsable);
|
|
@@ -2528,6 +3065,273 @@ function destructiveActionRule(ctx) {
|
|
|
2528
3065
|
return cases;
|
|
2529
3066
|
}
|
|
2530
3067
|
|
|
3068
|
+
// ../../packages/generators/dist/testcases/patternRules.js
|
|
3069
|
+
var REVIEW_EXPECTED = "Behavior requires tester review";
|
|
3070
|
+
function base(ctx, draft) {
|
|
3071
|
+
return { module: ctx.module, sourceUrl: ctx.page.finalUrl, ...draft };
|
|
3072
|
+
}
|
|
3073
|
+
function precondition2(page) {
|
|
3074
|
+
try {
|
|
3075
|
+
return [`The application is available at ${new URL(page.finalUrl).origin}`];
|
|
3076
|
+
} catch {
|
|
3077
|
+
return ["The application is available"];
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
function navigate(page) {
|
|
3081
|
+
return { type: "navigate", url: page.finalUrl };
|
|
3082
|
+
}
|
|
3083
|
+
function evidenceOf(element) {
|
|
3084
|
+
const found = [element.patternEvidence ?? matchPattern(element).evidence];
|
|
3085
|
+
if (element.relation?.controls)
|
|
3086
|
+
found.push(`aria-controls="${element.relation.controls}"`);
|
|
3087
|
+
if (element.context?.containerSelector)
|
|
3088
|
+
found.push(`container=${element.context.containerSelector}`);
|
|
3089
|
+
return found;
|
|
3090
|
+
}
|
|
3091
|
+
function reviewCase(ctx, element, pattern, reason, action = []) {
|
|
3092
|
+
return base(ctx, {
|
|
3093
|
+
title: `Review ${labelOf(element)} behaviour`,
|
|
3094
|
+
preconditions: precondition2(ctx.page),
|
|
3095
|
+
steps: [navigate(ctx.page), ...action],
|
|
3096
|
+
expectedResult: REVIEW_EXPECTED,
|
|
3097
|
+
type: "manual",
|
|
3098
|
+
priority: "medium",
|
|
3099
|
+
automationStatus: "needs-review",
|
|
3100
|
+
tags: ["pattern:" + pattern, "needs-review"],
|
|
3101
|
+
pattern,
|
|
3102
|
+
evidence: evidenceOf(element),
|
|
3103
|
+
reviewReason: reason,
|
|
3104
|
+
notes: `Detected as ${pattern}. ${reason}`
|
|
3105
|
+
});
|
|
3106
|
+
}
|
|
3107
|
+
function tabRule(ctx, element) {
|
|
3108
|
+
const target = toTargetRef(element);
|
|
3109
|
+
const panel = element.relation?.controls;
|
|
3110
|
+
const steps = [
|
|
3111
|
+
navigate(ctx.page),
|
|
3112
|
+
{ type: "click", target, description: `Select tab "${labelOf(element)}"` }
|
|
3113
|
+
];
|
|
3114
|
+
steps.push({ type: "assertVisible", target });
|
|
3115
|
+
if (panel) {
|
|
3116
|
+
steps.push({
|
|
3117
|
+
type: "assertVisible",
|
|
3118
|
+
target: { cssSelector: `#${panel}` },
|
|
3119
|
+
description: `Verify the panel controlled by this tab is visible`
|
|
3120
|
+
});
|
|
3121
|
+
}
|
|
3122
|
+
return [
|
|
3123
|
+
base(ctx, {
|
|
3124
|
+
title: `Tab "${labelOf(element)}" selects its panel`,
|
|
3125
|
+
preconditions: precondition2(ctx.page),
|
|
3126
|
+
steps,
|
|
3127
|
+
expectedResult: panel ? `Tab "${labelOf(element)}" becomes selected and the panel it controls is visible.` : `Tab "${labelOf(element)}" becomes selected.`,
|
|
3128
|
+
type: "interaction",
|
|
3129
|
+
priority: "medium",
|
|
3130
|
+
automationStatus: panel ? "ready" : "needs-review",
|
|
3131
|
+
tags: ["pattern:tab"],
|
|
3132
|
+
pattern: "tab",
|
|
3133
|
+
evidence: evidenceOf(element),
|
|
3134
|
+
...panel ? {} : { reviewReason: "No aria-controls, so the panel to assert is unknown." },
|
|
3135
|
+
notes: 'Generated from role="tab". Assertion uses the tab contract, not the label text.'
|
|
3136
|
+
})
|
|
3137
|
+
];
|
|
3138
|
+
}
|
|
3139
|
+
function accordionRule(ctx, element) {
|
|
3140
|
+
const target = toTargetRef(element);
|
|
3141
|
+
const region = element.relation?.controls;
|
|
3142
|
+
return [
|
|
3143
|
+
base(ctx, {
|
|
3144
|
+
title: `${labelOf(element)} expands and collapses`,
|
|
3145
|
+
preconditions: precondition2(ctx.page),
|
|
3146
|
+
steps: [
|
|
3147
|
+
navigate(ctx.page),
|
|
3148
|
+
{ type: "click", target, description: `Expand "${labelOf(element)}"` },
|
|
3149
|
+
...region ? [
|
|
3150
|
+
{
|
|
3151
|
+
type: "assertVisible",
|
|
3152
|
+
target: { cssSelector: `#${region}` },
|
|
3153
|
+
description: "Verify the controlled region is visible"
|
|
3154
|
+
}
|
|
3155
|
+
] : [],
|
|
3156
|
+
{ type: "click", target, description: `Collapse "${labelOf(element)}"` }
|
|
3157
|
+
],
|
|
3158
|
+
expectedResult: region ? `The region controlled by "${labelOf(element)}" becomes visible when expanded and hidden when collapsed.` : `"${labelOf(element)}" toggles between expanded and collapsed.`,
|
|
3159
|
+
type: "interaction",
|
|
3160
|
+
priority: "medium",
|
|
3161
|
+
automationStatus: region ? "ready" : "needs-review",
|
|
3162
|
+
tags: ["pattern:accordion"],
|
|
3163
|
+
pattern: "accordion",
|
|
3164
|
+
evidence: evidenceOf(element),
|
|
3165
|
+
...region ? {} : { reviewReason: "No aria-controls, so the region to assert is unknown." },
|
|
3166
|
+
notes: "Generated from the aria-expanded / <summary> contract."
|
|
3167
|
+
})
|
|
3168
|
+
];
|
|
3169
|
+
}
|
|
3170
|
+
function toggleRule(ctx, element, pattern) {
|
|
3171
|
+
const target = toTargetRef(element);
|
|
3172
|
+
const isRadio = pattern === "radio";
|
|
3173
|
+
return [
|
|
3174
|
+
base(ctx, {
|
|
3175
|
+
title: isRadio ? `${labelOf(element)} can be selected` : `${labelOf(element)} can be checked and unchecked`,
|
|
3176
|
+
preconditions: precondition2(ctx.page),
|
|
3177
|
+
steps: [
|
|
3178
|
+
navigate(ctx.page),
|
|
3179
|
+
{ type: "check", target, checked: true, description: `Select "${labelOf(element)}"` },
|
|
3180
|
+
...isRadio ? [] : [{ type: "check", target, checked: false }]
|
|
3181
|
+
],
|
|
3182
|
+
expectedResult: isRadio ? `"${labelOf(element)}" becomes the selected option.` : `"${labelOf(element)}" reports checked after selecting and unchecked after clearing.`,
|
|
3183
|
+
type: "interaction",
|
|
3184
|
+
priority: "medium",
|
|
3185
|
+
automationStatus: "ready",
|
|
3186
|
+
tags: ["pattern:" + pattern],
|
|
3187
|
+
pattern,
|
|
3188
|
+
evidence: evidenceOf(element),
|
|
3189
|
+
notes: "Assertion uses the native checked state, not the surrounding text."
|
|
3190
|
+
})
|
|
3191
|
+
];
|
|
3192
|
+
}
|
|
3193
|
+
function selectRule(ctx, element) {
|
|
3194
|
+
const options = (element.options ?? []).filter(Boolean).slice(0, 2);
|
|
3195
|
+
if (options.length === 0) {
|
|
3196
|
+
return [reviewCase(ctx, element, "select", "No options were present when the page was collected.")];
|
|
3197
|
+
}
|
|
3198
|
+
const target = toTargetRef(element);
|
|
3199
|
+
return options.map((option) => base(ctx, {
|
|
3200
|
+
title: `${labelOf(element)} accepts option "${option}"`,
|
|
3201
|
+
preconditions: precondition2(ctx.page),
|
|
3202
|
+
steps: [navigate(ctx.page), { type: "select", target, option }],
|
|
3203
|
+
expectedResult: `"${labelOf(element)}" holds the selected option "${option}".`,
|
|
3204
|
+
type: "interaction",
|
|
3205
|
+
priority: "medium",
|
|
3206
|
+
automationStatus: "ready",
|
|
3207
|
+
tags: ["pattern:select"],
|
|
3208
|
+
pattern: "select",
|
|
3209
|
+
evidence: [...evidenceOf(element), `option="${option}"`],
|
|
3210
|
+
notes: "Options were read from the page; none were invented."
|
|
3211
|
+
}));
|
|
3212
|
+
}
|
|
3213
|
+
function openerRule(ctx, element, pattern) {
|
|
3214
|
+
const container = element.relation?.controls ?? element.relation?.target;
|
|
3215
|
+
const target = toTargetRef(element);
|
|
3216
|
+
if (!container) {
|
|
3217
|
+
return [
|
|
3218
|
+
reviewCase(ctx, element, pattern, "The container it opens is not declared through aria-controls or data-target.", [{ type: "click", target, description: `Open "${labelOf(element)}"` }])
|
|
3219
|
+
];
|
|
3220
|
+
}
|
|
3221
|
+
const containerSelector = container.startsWith("#") || container.startsWith(".") ? container : `#${container}`;
|
|
3222
|
+
return [
|
|
3223
|
+
base(ctx, {
|
|
3224
|
+
title: `${labelOf(element)} opens its ${pattern === "dialog-opener" ? "dialog" : "menu"}`,
|
|
3225
|
+
preconditions: precondition2(ctx.page),
|
|
3226
|
+
steps: [
|
|
3227
|
+
navigate(ctx.page),
|
|
3228
|
+
{ type: "click", target, description: `Open "${labelOf(element)}"` },
|
|
3229
|
+
{ type: "assertVisible", target: { cssSelector: containerSelector } }
|
|
3230
|
+
],
|
|
3231
|
+
expectedResult: `The container ${containerSelector} becomes visible.`,
|
|
3232
|
+
type: "interaction",
|
|
3233
|
+
priority: "medium",
|
|
3234
|
+
automationStatus: "ready",
|
|
3235
|
+
tags: ["pattern:" + pattern],
|
|
3236
|
+
pattern,
|
|
3237
|
+
evidence: evidenceOf(element),
|
|
3238
|
+
notes: "The opener is bound to its container through a declared relationship."
|
|
3239
|
+
})
|
|
3240
|
+
];
|
|
3241
|
+
}
|
|
3242
|
+
function reviewOnlyRule(ctx, element, pattern) {
|
|
3243
|
+
const reasons = {
|
|
3244
|
+
combobox: "Custom combobox keyboard and filtering behaviour cannot be derived from markup.",
|
|
3245
|
+
slider: "The value range and step semantics need a tester to confirm.",
|
|
3246
|
+
"file-upload": "Uploading a file needs a fixture chosen by a tester.",
|
|
3247
|
+
table: "Sort, filter and row semantics need a tester to confirm.",
|
|
3248
|
+
menu: "Menu contents are only known once the menu has been opened.",
|
|
3249
|
+
button: "No observable state change was recorded for this control.",
|
|
3250
|
+
unknown: "The element declares no catalogued role, type or ARIA relationship."
|
|
3251
|
+
};
|
|
3252
|
+
return [
|
|
3253
|
+
reviewCase(ctx, element, pattern, reasons[pattern] ?? "This pattern has no provable contract in the DOM.", [
|
|
3254
|
+
{ type: "click", target: toTargetRef(element), description: `Interact with "${labelOf(element)}"` }
|
|
3255
|
+
])
|
|
3256
|
+
];
|
|
3257
|
+
}
|
|
3258
|
+
function blockedActionRule(ctx, element, pattern) {
|
|
3259
|
+
const risk = element.risk === "session-ending" ? "session-ending" : "destructive";
|
|
3260
|
+
return [
|
|
3261
|
+
base(ctx, {
|
|
3262
|
+
title: `Manually verify ${labelOf(element)}`,
|
|
3263
|
+
preconditions: [...precondition2(ctx.page), "Use a disposable test account and data"],
|
|
3264
|
+
steps: [
|
|
3265
|
+
navigate(ctx.page),
|
|
3266
|
+
{
|
|
3267
|
+
type: "manual",
|
|
3268
|
+
description: `Manually trigger "${labelOf(element)}" in a safe test environment and record the result`
|
|
3269
|
+
}
|
|
3270
|
+
],
|
|
3271
|
+
expectedResult: REVIEW_EXPECTED,
|
|
3272
|
+
type: "manual",
|
|
3273
|
+
priority: "high",
|
|
3274
|
+
automationStatus: "manual",
|
|
3275
|
+
tags: ["pattern:" + pattern, risk],
|
|
3276
|
+
pattern,
|
|
3277
|
+
evidence: evidenceOf(element),
|
|
3278
|
+
reviewReason: `Classified as ${risk}, so LazyScout did not execute it.`,
|
|
3279
|
+
notes: `LazyScout detected a ${risk} action and skipped it deliberately.`
|
|
3280
|
+
})
|
|
3281
|
+
];
|
|
3282
|
+
}
|
|
3283
|
+
function elementPatternCases(ctx, element) {
|
|
3284
|
+
const pattern = element.uiPattern ?? matchPattern(element).pattern;
|
|
3285
|
+
if (element.disabled)
|
|
3286
|
+
return [];
|
|
3287
|
+
if (element.risk === "destructive" || element.risk === "session-ending") {
|
|
3288
|
+
return blockedActionRule(ctx, element, pattern);
|
|
3289
|
+
}
|
|
3290
|
+
switch (pattern) {
|
|
3291
|
+
case "tab":
|
|
3292
|
+
return tabRule(ctx, element);
|
|
3293
|
+
case "accordion":
|
|
3294
|
+
return accordionRule(ctx, element);
|
|
3295
|
+
case "checkbox":
|
|
3296
|
+
case "radio":
|
|
3297
|
+
case "switch":
|
|
3298
|
+
return toggleRule(ctx, element, pattern);
|
|
3299
|
+
case "select":
|
|
3300
|
+
return selectRule(ctx, element);
|
|
3301
|
+
case "dialog-opener":
|
|
3302
|
+
return openerRule(ctx, element, pattern);
|
|
3303
|
+
case "menu":
|
|
3304
|
+
return element.relation?.controls ? openerRule(ctx, element, pattern) : reviewOnlyRule(ctx, element, pattern);
|
|
3305
|
+
case "combobox":
|
|
3306
|
+
case "slider":
|
|
3307
|
+
case "file-upload":
|
|
3308
|
+
case "table":
|
|
3309
|
+
case "button":
|
|
3310
|
+
case "unknown":
|
|
3311
|
+
return reviewOnlyRule(ctx, element, pattern);
|
|
3312
|
+
default:
|
|
3313
|
+
return [];
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
function interactionPatternCases(ctx, interaction) {
|
|
3317
|
+
const pattern = interaction.kind === "tab" ? "tab" : interaction.kind === "accordion" ? "accordion" : interaction.kind === "dropdown" ? "menu" : "dialog-opener";
|
|
3318
|
+
const element = {
|
|
3319
|
+
kind: "button",
|
|
3320
|
+
role: interaction.role,
|
|
3321
|
+
accessibleName: interaction.name,
|
|
3322
|
+
tagName: "button",
|
|
3323
|
+
cssSelector: interaction.cssSelector,
|
|
3324
|
+
required: false,
|
|
3325
|
+
disabled: false,
|
|
3326
|
+
destructive: false,
|
|
3327
|
+
uiPattern: pattern,
|
|
3328
|
+
patternEvidence: interaction.evidence,
|
|
3329
|
+
expanded: interaction.expanded,
|
|
3330
|
+
relation: interaction.controlsSelector ? { controls: interaction.controlsSelector.replace(/^#/, "") } : void 0
|
|
3331
|
+
};
|
|
3332
|
+
return elementPatternCases(ctx, element);
|
|
3333
|
+
}
|
|
3334
|
+
|
|
2531
3335
|
// ../../packages/generators/dist/testcases/generateTestCases.js
|
|
2532
3336
|
var DEFAULT_GENERATE_OPTIONS = {
|
|
2533
3337
|
maxTestCasesPerPage: 120,
|
|
@@ -2546,16 +3350,16 @@ function generateTestCases(pages, options = {}) {
|
|
|
2546
3350
|
for (const page of pages) {
|
|
2547
3351
|
const module = moduleByUrl.get(page.url) ?? "PAGE";
|
|
2548
3352
|
const context = { page, module, visitedTitles };
|
|
2549
|
-
const fromPage = [
|
|
3353
|
+
const fromPage = dedupe([
|
|
2550
3354
|
...pageStructureRule(context),
|
|
2551
3355
|
...page.forms.flatMap((form) => requiredFieldRule(context, form)),
|
|
2552
3356
|
...page.forms.flatMap((form) => validationMatrixRule(context, form)),
|
|
2553
3357
|
...page.forms.flatMap((form) => loginFailureRule(context, form)),
|
|
2554
3358
|
...page.forms.flatMap((form) => formSubmitRule(context, form)),
|
|
2555
|
-
...
|
|
3359
|
+
...patternCases(context),
|
|
2556
3360
|
...navigationRule(context),
|
|
2557
3361
|
...destructiveActionRule(context)
|
|
2558
|
-
].slice(0, config2.maxTestCasesPerPage);
|
|
3362
|
+
], counters).slice(0, config2.maxTestCasesPerPage);
|
|
2559
3363
|
for (const generated of fromPage) {
|
|
2560
3364
|
const sequence = (counters.get(module) ?? 0) + 1;
|
|
2561
3365
|
counters.set(module, sequence);
|
|
@@ -2564,6 +3368,30 @@ function generateTestCases(pages, options = {}) {
|
|
|
2564
3368
|
}
|
|
2565
3369
|
return config2.language === "en" ? testCases : localizeThai(testCases);
|
|
2566
3370
|
}
|
|
3371
|
+
function patternCases(context) {
|
|
3372
|
+
const ctx = { page: context.page, module: context.module };
|
|
3373
|
+
const controls = context.page.state?.controls ?? [];
|
|
3374
|
+
const cases = controls.flatMap((control) => elementPatternCases(ctx, control));
|
|
3375
|
+
const covered = new Set(controls.map((control) => control.cssSelector));
|
|
3376
|
+
const fromInteractions = (context.page.state?.interactions ?? []).filter((interaction) => !covered.has(interaction.cssSelector)).flatMap((interaction) => interactionPatternCases(ctx, interaction));
|
|
3377
|
+
return [...cases, ...fromInteractions];
|
|
3378
|
+
}
|
|
3379
|
+
function dedupe(cases, counters) {
|
|
3380
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3381
|
+
const unique = [];
|
|
3382
|
+
let dropped = 0;
|
|
3383
|
+
for (const testCase of cases) {
|
|
3384
|
+
const key = `${testCase.pattern ?? testCase.type}|${testCase.title}|${JSON.stringify(testCase.steps)}`;
|
|
3385
|
+
if (seen.has(key)) {
|
|
3386
|
+
dropped += 1;
|
|
3387
|
+
continue;
|
|
3388
|
+
}
|
|
3389
|
+
seen.add(key);
|
|
3390
|
+
unique.push(testCase);
|
|
3391
|
+
}
|
|
3392
|
+
counters.set("__deduplicated", (counters.get("__deduplicated") ?? 0) + dropped);
|
|
3393
|
+
return unique;
|
|
3394
|
+
}
|
|
2567
3395
|
function localizeThai(testCases) {
|
|
2568
3396
|
return testCases.map((testCase) => ({
|
|
2569
3397
|
...testCase,
|
|
@@ -2762,6 +3590,63 @@ function exportTestCasesToCsv(testCases, testData = []) {
|
|
|
2762
3590
|
return UTF8_BOM + lines.join("\r\n") + "\r\n";
|
|
2763
3591
|
}
|
|
2764
3592
|
|
|
3593
|
+
// ../../packages/generators/dist/locators/candidates.js
|
|
3594
|
+
var GENERATED_ATTRIBUTE = /\bdata-v-[0-9a-f]{6,}\b/i;
|
|
3595
|
+
var GENERATED_ID = /\d{4,}/;
|
|
3596
|
+
var DEFAULT_TEST_ID_ATTRIBUTE = "data-testid";
|
|
3597
|
+
function buildLocatorCandidates(target) {
|
|
3598
|
+
const candidates = [];
|
|
3599
|
+
const push = (kind, expression) => {
|
|
3600
|
+
if (!expression || GENERATED_ATTRIBUTE.test(expression))
|
|
3601
|
+
return;
|
|
3602
|
+
if (candidates.some(([, existing]) => existing === expression))
|
|
3603
|
+
return;
|
|
3604
|
+
candidates.push([kind, expression]);
|
|
3605
|
+
};
|
|
3606
|
+
push(...testIdCandidate(target));
|
|
3607
|
+
push("id", target.elementId && !GENERATED_ID.test(target.elementId) ? cssLocator(id(target.elementId)) : void 0);
|
|
3608
|
+
push("semantic locator", semanticCandidate(target));
|
|
3609
|
+
push("name", target.attributeName ? cssLocator(attribute("name", target.attributeName, target.tagName)) : void 0);
|
|
3610
|
+
push("recorded CSS", target.cssSelector ? cssLocator(normalizeCssSelector(target.cssSelector)) : void 0);
|
|
3611
|
+
if (candidates.length === 0)
|
|
3612
|
+
push("recorded CSS", cssLocator(normalizeCssSelector(target.cssSelector ?? "")));
|
|
3613
|
+
return candidates;
|
|
3614
|
+
}
|
|
3615
|
+
function testIdCandidate(target) {
|
|
3616
|
+
if (!target.testId)
|
|
3617
|
+
return ["test id", void 0];
|
|
3618
|
+
const attributeName = target.testIdAttribute ?? DEFAULT_TEST_ID_ATTRIBUTE;
|
|
3619
|
+
return attributeName === DEFAULT_TEST_ID_ATTRIBUTE ? ["test id", `page.getByTestId(${quote(target.testId)})`] : [attributeName, cssLocator(attribute(attributeName, target.testId))];
|
|
3620
|
+
}
|
|
3621
|
+
function semanticCandidate(target) {
|
|
3622
|
+
const base2 = target.role && target.name ? `page.getByRole(${quote(target.role)}, { name: ${quote(target.name)}, exact: true })` : target.label ? `page.getByLabel(${quote(target.label)}, { exact: true })` : target.placeholder ? `page.getByPlaceholder(${quote(target.placeholder)})` : target.text ? `page.getByText(${quote(target.text)})` : void 0;
|
|
3623
|
+
if (!base2)
|
|
3624
|
+
return void 0;
|
|
3625
|
+
const context = target.contextTestId ? `page.getByTestId(${quote(target.contextTestId)})` : target.contextSelector ? `page.locator(${quote(target.contextSelector)})` : void 0;
|
|
3626
|
+
const scoped = context ? target.contextText ? `${context}.filter({ hasText: ${quote(target.contextText)} }).${base2.slice(5)}` : `${context}.${base2.slice(5)}` : base2;
|
|
3627
|
+
return target.nth === void 0 ? scoped : `${scoped}.nth(${target.nth})`;
|
|
3628
|
+
}
|
|
3629
|
+
function describeTarget2(target) {
|
|
3630
|
+
return target.name ?? target.label ?? target.placeholder ?? target.text ?? target.testId ?? target.elementId ?? target.attributeName ?? target.cssSelector ?? "target";
|
|
3631
|
+
}
|
|
3632
|
+
function attribute(name, value, tagName) {
|
|
3633
|
+
const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
3634
|
+
return `${tagName ? tagName.toLowerCase() : ""}[${name}="${escaped}"]`;
|
|
3635
|
+
}
|
|
3636
|
+
function id(value) {
|
|
3637
|
+
return `#${value.replace(/[^\w-]/g, (character) => `\\${character}`)}`;
|
|
3638
|
+
}
|
|
3639
|
+
function cssLocator(selector) {
|
|
3640
|
+
return `page.locator(${quoteCssSelector(selector)})`;
|
|
3641
|
+
}
|
|
3642
|
+
function normalizeCssSelector(value) {
|
|
3643
|
+
return value.replace(/\\(["'])/g, "$1");
|
|
3644
|
+
}
|
|
3645
|
+
function quoteCssSelector(value) {
|
|
3646
|
+
return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
3647
|
+
}
|
|
3648
|
+
var quote = (value) => JSON.stringify(value);
|
|
3649
|
+
|
|
2765
3650
|
// ../../packages/generators/dist/playwright/generatePlaywrightTest.js
|
|
2766
3651
|
function generatePlaywrightTest(testCase) {
|
|
2767
3652
|
const lines = [
|
|
@@ -2769,75 +3654,87 @@ function generatePlaywrightTest(testCase) {
|
|
|
2769
3654
|
"",
|
|
2770
3655
|
...locatorResolverSource(),
|
|
2771
3656
|
"",
|
|
2772
|
-
`test(${
|
|
3657
|
+
`test(${quote2(testCase.title)}, async ({ page }) => {`
|
|
2773
3658
|
];
|
|
2774
3659
|
for (const step of testCase.steps)
|
|
2775
3660
|
lines.push(` ${playwrightStep(step)}`);
|
|
2776
3661
|
lines.push("})", "");
|
|
2777
3662
|
return lines.join("\n");
|
|
2778
3663
|
}
|
|
3664
|
+
var RESOLVE_TIMEOUT_MS = 5e3;
|
|
3665
|
+
var RESOLVE_POLL_MS = 100;
|
|
2779
3666
|
function locatorResolverSource() {
|
|
2780
3667
|
return [
|
|
2781
|
-
`async function resolveTarget(candidates, description) {`,
|
|
2782
|
-
` const
|
|
2783
|
-
`
|
|
2784
|
-
`
|
|
2785
|
-
`
|
|
2786
|
-
`
|
|
2787
|
-
`
|
|
2788
|
-
`
|
|
2789
|
-
`
|
|
2790
|
-
`
|
|
2791
|
-
`
|
|
3668
|
+
`async function resolveTarget(page, candidates, description, timeout = ${RESOLVE_TIMEOUT_MS}) {`,
|
|
3669
|
+
` const startedAt = Date.now()`,
|
|
3670
|
+
` let attempts = []`,
|
|
3671
|
+
` do {`,
|
|
3672
|
+
` attempts = []`,
|
|
3673
|
+
` for (const [kind, candidate] of candidates) {`,
|
|
3674
|
+
` try {`,
|
|
3675
|
+
` const count = await candidate.count()`,
|
|
3676
|
+
` if (count !== 1) {`,
|
|
3677
|
+
` attempts.push('- ' + kind + ': ' + count + ' matches')`,
|
|
3678
|
+
` continue`,
|
|
3679
|
+
` }`,
|
|
3680
|
+
` if (!(await candidate.isVisible())) {`,
|
|
3681
|
+
` attempts.push('- ' + kind + ': matched but not visible')`,
|
|
3682
|
+
` continue`,
|
|
3683
|
+
` }`,
|
|
3684
|
+
` console.log('[Locator] ' + description + ' -> ' + kind + ' (' + (Date.now() - startedAt) + 'ms)')`,
|
|
3685
|
+
` return candidate`,
|
|
3686
|
+
` } catch (error) {`,
|
|
3687
|
+
` attempts.push('- ' + kind + ': ' + (error instanceof Error ? error.message : String(error)))`,
|
|
3688
|
+
` }`,
|
|
2792
3689
|
` }`,
|
|
2793
|
-
`
|
|
2794
|
-
`
|
|
2795
|
-
|
|
2796
|
-
`
|
|
3690
|
+
` await page.waitForTimeout(${RESOLVE_POLL_MS})`,
|
|
3691
|
+
` } while (Date.now() - startedAt < timeout)`,
|
|
3692
|
+
``,
|
|
3693
|
+
` const diagnostics = await page`,
|
|
3694
|
+
` .evaluate(() => ({ readyState: document.readyState, title: document.title }))`,
|
|
3695
|
+
` .catch(() => ({ readyState: 'unknown', title: 'unknown' }))`,
|
|
3696
|
+
` throw new Error(`,
|
|
3697
|
+
` 'Could not resolve "' + description + '" after ' + (Date.now() - startedAt) + 'ms.\\n' +`,
|
|
3698
|
+
` 'URL: ' + page.url() + '\\n' +`,
|
|
3699
|
+
` 'Page title: ' + diagnostics.title + '\\n' +`,
|
|
3700
|
+
` 'document.readyState: ' + diagnostics.readyState + '\\n' +`,
|
|
3701
|
+
` 'Candidates:\\n' + attempts.join('\\n')`,
|
|
3702
|
+
` )`,
|
|
2797
3703
|
`}`
|
|
2798
3704
|
];
|
|
2799
3705
|
}
|
|
2800
3706
|
function locator(target) {
|
|
2801
|
-
const
|
|
2802
|
-
const
|
|
2803
|
-
const
|
|
2804
|
-
|
|
2805
|
-
const css = target.cssSelector ? `page.locator(${quoteCssSelector(normalizeCssSelector(target.cssSelector))})` : void 0;
|
|
2806
|
-
const candidates = [];
|
|
2807
|
-
if (target.strategy === "css" && css)
|
|
2808
|
-
candidates.push(["recorded CSS", css]);
|
|
2809
|
-
candidates.push(["semantic locator", primary]);
|
|
2810
|
-
if (css && !candidates.some(([, value]) => value === css))
|
|
2811
|
-
candidates.push(["recorded CSS", css]);
|
|
2812
|
-
const description = target.name ?? target.label ?? target.placeholder ?? target.text ?? target.cssSelector ?? "target";
|
|
2813
|
-
return `resolveTarget([${candidates.map(([kind, value]) => `[${quote(kind)}, ${value}]`).join(", ")}], ${quote(description)})`;
|
|
3707
|
+
const candidates = buildLocatorCandidates(target);
|
|
3708
|
+
const ordered = target.strategy === "css" ? [...candidates].sort(([left], [right]) => left === "recorded CSS" ? -1 : right === "recorded CSS" ? 1 : 0) : candidates;
|
|
3709
|
+
const list = ordered.map(([kind, value]) => `[${quote2(kind)}, ${value}]`).join(", ");
|
|
3710
|
+
return `resolveTarget(page, [${list}], ${quote2(describeTarget2(target))})`;
|
|
2814
3711
|
}
|
|
2815
3712
|
function playwrightStep(step) {
|
|
2816
3713
|
switch (step.type) {
|
|
2817
3714
|
case "navigate":
|
|
2818
|
-
return `await page.goto(${
|
|
3715
|
+
return `await page.goto(${quote2(plainUrl(step.url))})`;
|
|
2819
3716
|
case "click":
|
|
2820
3717
|
return `await (await ${locator(step.target)}).click()`;
|
|
2821
3718
|
case "fill":
|
|
2822
|
-
return `await (await ${locator(step.target)}).fill(${
|
|
3719
|
+
return `await (await ${locator(step.target)}).fill(${quote2(step.value)})`;
|
|
2823
3720
|
case "select":
|
|
2824
|
-
return `await (await ${locator(step.target)}).selectOption(${
|
|
3721
|
+
return `await (await ${locator(step.target)}).selectOption(${quote2(step.option)})`;
|
|
2825
3722
|
case "check":
|
|
2826
3723
|
return `await (await ${locator(step.target)}).${step.checked ? "check" : "uncheck"}()`;
|
|
2827
3724
|
case "wait":
|
|
2828
3725
|
if (step.mode === "timeout")
|
|
2829
3726
|
return `await page.waitForTimeout(${Math.min(5e3, Math.max(0, Number(step.value) || 0))})`;
|
|
2830
3727
|
if (step.mode === "url")
|
|
2831
|
-
return `await page.waitForURL(new RegExp(${
|
|
3728
|
+
return `await page.waitForURL(new RegExp(${quote2(step.value)}))`;
|
|
2832
3729
|
if (step.mode === "text")
|
|
2833
|
-
return `await expect(page).toContainText(${
|
|
3730
|
+
return `await expect(page).toContainText(${quote2(step.value)})`;
|
|
2834
3731
|
return `await expect(await ${locator(step.target)}).toBeVisible()`;
|
|
2835
3732
|
case "assertVisible":
|
|
2836
3733
|
return `await expect(await ${locator(step.target)}).toBeVisible()`;
|
|
2837
3734
|
case "assertText":
|
|
2838
|
-
return step.target ? `await expect(await ${locator(step.target)}).toContainText(${
|
|
3735
|
+
return step.target ? `await expect(await ${locator(step.target)}).toContainText(${quote2(step.text)})` : `await expect(page.locator('body')).toContainText(${quote2(step.text)})`;
|
|
2839
3736
|
case "assertUrl":
|
|
2840
|
-
return `await expect(page).toHaveURL(new RegExp(${
|
|
3737
|
+
return `await expect(page).toHaveURL(new RegExp(${quote2(step.urlContains)}))`;
|
|
2841
3738
|
case "assertInvalid":
|
|
2842
3739
|
return `expect(await (await ${locator(step.target)}).evaluate((element) => element.matches(':invalid'))).toBe(true)`;
|
|
2843
3740
|
case "assertValidation":
|
|
@@ -2846,12 +3743,10 @@ function playwrightStep(step) {
|
|
|
2846
3743
|
return `// TODO: ${step.description}`;
|
|
2847
3744
|
}
|
|
2848
3745
|
}
|
|
2849
|
-
var
|
|
2850
|
-
function
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
function quoteCssSelector(value) {
|
|
2854
|
-
return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
3746
|
+
var quote2 = (value) => JSON.stringify(value);
|
|
3747
|
+
function plainUrl(value) {
|
|
3748
|
+
const markdownLink = /^\s*\[([^\]]+)\]\(\s*([^)\s]+)\s*\)\s*$/.exec(value);
|
|
3749
|
+
return markdownLink ? markdownLink[2] : value.trim();
|
|
2855
3750
|
}
|
|
2856
3751
|
|
|
2857
3752
|
// ../../packages/generators/dist/guidedflow/flowToTestCase.js
|
|
@@ -2951,8 +3846,10 @@ function locator2(target) {
|
|
|
2951
3846
|
return `page.getByLabel(${JSON.stringify(target.label ?? target.value ?? "")}, { exact: true })`;
|
|
2952
3847
|
if (target.strategy === "placeholder" || target.placeholder)
|
|
2953
3848
|
return `page.getByPlaceholder(${JSON.stringify(target.placeholder ?? target.value ?? "")})`;
|
|
2954
|
-
if (target.strategy === "testid" || target.testId)
|
|
2955
|
-
|
|
3849
|
+
if (target.strategy === "testid" || target.testId) {
|
|
3850
|
+
const testId = target.testId ?? target.value ?? "";
|
|
3851
|
+
return target.testIdAttribute && target.testIdAttribute !== "data-testid" ? `page.locator(${quoteCssSelector2(attributeSelector(target.testIdAttribute, testId))})` : `page.getByTestId(${JSON.stringify(testId)})`;
|
|
3852
|
+
}
|
|
2956
3853
|
if (target.strategy === "text" || target.text)
|
|
2957
3854
|
return `page.getByText(${JSON.stringify(target.text ?? target.value ?? "")})`;
|
|
2958
3855
|
return `page.locator(${quoteCssSelector2(normalizeCssSelector2(target.cssSelector ?? target.value ?? ""))})`;
|
|
@@ -2960,6 +3857,9 @@ function locator2(target) {
|
|
|
2960
3857
|
function preferStableCss(target) {
|
|
2961
3858
|
return Boolean(target.cssSelector && (target.strategy === "css" || target.matchCount !== void 0 && target.matchCount > 1 && !target.contextSelector && !target.contextText));
|
|
2962
3859
|
}
|
|
3860
|
+
function attributeSelector(name, value) {
|
|
3861
|
+
return `[${name}="${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"]`;
|
|
3862
|
+
}
|
|
2963
3863
|
function normalizeCssSelector2(value) {
|
|
2964
3864
|
return value.replace(/\\(["'])/g, "$1");
|
|
2965
3865
|
}
|
|
@@ -3395,7 +4295,10 @@ function normalizeResult(value) {
|
|
|
3395
4295
|
blockedActionKeys: Array.isArray(actionGraph?.blockedActionKeys) ? actionGraph.blockedActionKeys : []
|
|
3396
4296
|
},
|
|
3397
4297
|
runEvents: Array.isArray(value?.runEvents) ? value.runEvents : [],
|
|
3398
|
-
apiChecks: Array.isArray(value?.apiChecks) ? value.apiChecks : []
|
|
4298
|
+
apiChecks: Array.isArray(value?.apiChecks) ? value.apiChecks : [],
|
|
4299
|
+
// Optional, so a Project saved before pattern coverage existed still loads.
|
|
4300
|
+
...value?.coverage ? { coverage: value.coverage } : {},
|
|
4301
|
+
...Array.isArray(value?.transitions) ? { transitions: value.transitions } : {}
|
|
3399
4302
|
};
|
|
3400
4303
|
}
|
|
3401
4304
|
function enqueueMutation(key, action) {
|
|
@@ -3525,7 +4428,9 @@ function registerAnalyzeRoute(app, workspaceRoot) {
|
|
|
3525
4428
|
stats: result.stats,
|
|
3526
4429
|
actionGraph: result.actionGraph,
|
|
3527
4430
|
runEvents,
|
|
3528
|
-
apiChecks: body.includeApiChecks ? buildApiChecks(result.pages) : []
|
|
4431
|
+
apiChecks: body.includeApiChecks ? buildApiChecks(result.pages) : [],
|
|
4432
|
+
...result.coverage ? { coverage: { ...result.coverage, casesGenerated: testCases.length } } : {},
|
|
4433
|
+
...result.transitions ? { transitions: result.transitions } : {}
|
|
3529
4434
|
};
|
|
3530
4435
|
completed = true;
|
|
3531
4436
|
return reply.send(response);
|
|
@@ -3547,11 +4452,11 @@ function generateStateFlowTestCases(graph) {
|
|
|
3547
4452
|
if (!target || !source)
|
|
3548
4453
|
return [];
|
|
3549
4454
|
const observation = expectedObservation(target);
|
|
3550
|
-
const
|
|
4455
|
+
const id2 = `TC-FLOW-${String(sequence).padStart(3, "0")}`;
|
|
3551
4456
|
sequence += 1;
|
|
3552
4457
|
return [
|
|
3553
4458
|
{
|
|
3554
|
-
id,
|
|
4459
|
+
id: id2,
|
|
3555
4460
|
module: "FLOW",
|
|
3556
4461
|
tags: ["state-flow"],
|
|
3557
4462
|
title: `${edge.action.description} reaches ${target.name}`,
|
|
@@ -4033,7 +4938,7 @@ function registerLoadTestRoute(app) {
|
|
|
4033
4938
|
const started = Date.now();
|
|
4034
4939
|
async function worker(virtualUser) {
|
|
4035
4940
|
for (let count = 0; count < requestsPerUser; count++) {
|
|
4036
|
-
const
|
|
4941
|
+
const id2 = ++requestSequence;
|
|
4037
4942
|
const requestStarted = Date.now();
|
|
4038
4943
|
try {
|
|
4039
4944
|
const response2 = await fetch(url, { signal: AbortSignal.timeout(15e3), redirect: "follow" });
|
|
@@ -4043,7 +4948,7 @@ function registerLoadTestRoute(app) {
|
|
|
4043
4948
|
if (!response2.ok)
|
|
4044
4949
|
errors.push(`HTTP ${response2.status} ${response2.statusText}`.trim());
|
|
4045
4950
|
requests.push({
|
|
4046
|
-
id,
|
|
4951
|
+
id: id2,
|
|
4047
4952
|
virtualUser,
|
|
4048
4953
|
iteration: count + 1,
|
|
4049
4954
|
method: "GET",
|
|
@@ -4061,7 +4966,7 @@ function registerLoadTestRoute(app) {
|
|
|
4061
4966
|
timings.push(durationMs);
|
|
4062
4967
|
errors.push(message);
|
|
4063
4968
|
requests.push({
|
|
4064
|
-
id,
|
|
4969
|
+
id: id2,
|
|
4065
4970
|
virtualUser,
|
|
4066
4971
|
iteration: count + 1,
|
|
4067
4972
|
method: "GET",
|
|
@@ -4753,7 +5658,7 @@ async function openInBrowser(url) {
|
|
|
4753
5658
|
}
|
|
4754
5659
|
|
|
4755
5660
|
// src/version.ts
|
|
4756
|
-
var VERSION = true ? "0.4.
|
|
5661
|
+
var VERSION = true ? "0.4.4" : "0.0.0-dev";
|
|
4757
5662
|
|
|
4758
5663
|
// src/commands/serve.ts
|
|
4759
5664
|
var DEFAULT_PORT = 4321;
|