@capagents/forgeqe 2.9.9 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/forgeqe.js +1640 -1581
  2. package/dist/web/assets/{Agent-B0R4tnqF.js → Agent-B_mG1pww.js} +1 -1
  3. package/dist/web/assets/{ApiTests-CqWPHWCs.js → ApiTests-C2QIp_tG.js} +1 -1
  4. package/dist/web/assets/{Browse-DlbTQPA8.js → Browse-zQoOQXpA.js} +2 -2
  5. package/dist/web/assets/{Chat-DtI3dgGs.js → Chat-BtLEKYY8.js} +1 -1
  6. package/dist/web/assets/{CommandPalette-BTI3Q3sc.js → CommandPalette-BgQORiKD.js} +1 -1
  7. package/dist/web/assets/{Compare-BMcHYq3I.js → Compare-DQNg3ldO.js} +1 -1
  8. package/dist/web/assets/{Cost-BcZ6gC9M.js → Cost-T0NH8ymc.js} +1 -1
  9. package/dist/web/assets/{Data-Cbl35RTK.js → Data-CqKsrslC.js} +1 -1
  10. package/dist/web/assets/{Desktop-D4JLSUnE.js → Desktop-CgDXi3lX.js} +1 -1
  11. package/dist/web/assets/{DesktopReview-vyosGOyC.js → DesktopReview-C-gW_gli.js} +1 -1
  12. package/dist/web/assets/{Evidence-MDaV4ttv.js → Evidence-1pipN6K6.js} +1 -1
  13. package/dist/web/assets/{Explore-yjmJHnzH.js → Explore-lG_kobPj.js} +1 -1
  14. package/dist/web/assets/{Features-kXt6Um2p.js → Features-BIrW3AiQ.js} +1 -1
  15. package/dist/web/assets/{Flags-CdLXiacX.js → Flags-sG1vr7NU.js} +1 -1
  16. package/dist/web/assets/{Flaky-BZx54uo3.js → Flaky-ChKBXlcW.js} +1 -1
  17. package/dist/web/assets/{Impact-_t7bwCwP.js → Impact-D5a5fyc2.js} +1 -1
  18. package/dist/web/assets/{Jobs-D4PIAcdO.js → Jobs-B52pIZUx.js} +1 -1
  19. package/dist/web/assets/{KindPage-CGfjoezZ.js → KindPage-BFoKPj7l.js} +1 -1
  20. package/dist/web/assets/{Migration-OGOnRmUX.js → Migration-DbuzD_s4.js} +1 -1
  21. package/dist/web/assets/{Product-DycPE2MI.js → Product-DiH61j0X.js} +1 -1
  22. package/dist/web/assets/{Production-DqnrcSfn.js → Production-8h5LixDt.js} +1 -1
  23. package/dist/web/assets/{Quality-C__pEYpt.js → Quality-CI5n8b_k.js} +1 -1
  24. package/dist/web/assets/{Readiness-j22NEcwR.js → Readiness-D4n4HSlW.js} +1 -1
  25. package/dist/web/assets/{Record-D7h6g_aw.js → Record-O8LOzHLo.js} +1 -1
  26. package/dist/web/assets/{Regression-ByBOHx96.js → Regression-DbShD6ji.js} +1 -1
  27. package/dist/web/assets/{Reports-BGs_YnwI.js → Reports-IdoUvtaW.js} +1 -1
  28. package/dist/web/assets/{Response-DWF22-5i.js → Response-BRVM9mW_.js} +1 -1
  29. package/dist/web/assets/{RunDiff-YxrBVtxF.js → RunDiff-uQoK3Q6q.js} +1 -1
  30. package/dist/web/assets/{Runs-CP3CgO6s.js → Runs-BhDgzDo4.js} +1 -1
  31. package/dist/web/assets/{TestCases-BzuM4M4t.js → TestCases-DQ2oWXt2.js} +1 -1
  32. package/dist/web/assets/{TestData-CRmYpEgE.js → TestData-D-ZdmHVa.js} +1 -1
  33. package/dist/web/assets/{TestDebt-D3I2zyGE.js → TestDebt-_jer4Dmy.js} +1 -1
  34. package/dist/web/assets/{Tosca-jVIQnyZv.js → Tosca-DOT6-53c.js} +1 -1
  35. package/dist/web/assets/{WhatsNew-EKniIJ6W.js → WhatsNew-DU5k6dz6.js} +1 -1
  36. package/dist/web/assets/{dataParts-DRO6c2Kb.js → dataParts-BzuL6pAo.js} +1 -1
  37. package/dist/web/assets/{fold-D9yUIbTt.js → fold-DZYvcIP0.js} +1 -1
  38. package/dist/web/assets/{frame--ur6lpMR.js → frame-Bjxy1jvq.js} +2 -2
  39. package/dist/web/assets/{index-GLMqsotN.js → index-DH21lIE7.js} +4 -4
  40. package/dist/web/assets/{logos-CdIbTq_J.js → logos-Co26FM0G.js} +1 -1
  41. package/dist/web/assets/{palette-D5_w8xup.js → palette-CitkMCod.js} +1 -1
  42. package/dist/web/assets/{qualityParts-BPBFzuHH.js → qualityParts-DADI5Fqn.js} +1 -1
  43. package/dist/web/assets/{rows-BVHC-HKz.js → rows-BqT7fknl.js} +1 -1
  44. package/dist/web/assets/{thread-B4g66SWA.js → thread-iRsceqhM.js} +1 -1
  45. package/dist/web/assets/{usePageChat-BU6VEv0K.js → usePageChat-BCrPoTyS.js} +1 -1
  46. package/dist/web/index.html +2 -2
  47. package/package.json +1 -1
  48. package/py/forgeqe_engine/browser.py +29 -0
  49. package/py/forgeqe_engine/capture.py +2 -2
  50. package/py/forgeqe_engine/dynamic.py +8 -0
  51. package/py/forgeqe_engine/memory.py +33 -2
  52. package/py/forgeqe_engine/recordsession.py +167 -19
  53. package/py/forgeqe_engine/webrecord.py +80 -0
  54. package/py/forgeqe_engine/webrecord_page.py +118 -8
@@ -14,6 +14,8 @@ from __future__ import annotations
14
14
  import json
15
15
  from typing import Any, Dict
16
16
 
17
+ from .memory import STATE_CLASS
18
+
17
19
  # The leader key, then one letter: what each letter does, as the key bar and the panel's hint show it.
18
20
  COMMAND_KEYS = (
19
21
  ("a", "assert", "check an element"),
@@ -137,7 +139,8 @@ RECORDER_JS = r"""(() => {
137
139
  const attrs = {};
138
140
  for (const k of CFG.kept) { const v = e.getAttribute(k); if (v) attrs[k] = v; }
139
141
  const name = accName(e);
140
- const classes = [...e.classList].filter((c) => /^[A-Za-z_-][\w-]*$/.test(c)).slice(0, 4);
142
+ // Never a state class (active, selected, is-open): it moves to another element (memory.py STATE_CLASS).
143
+ const classes = [...e.classList].filter((c) => /^[A-Za-z_-][\w-]*$/.test(c) && !STATE_CLASS.test(c)).slice(0, 4);
141
144
  return { tag: e.tagName.toLowerCase(), attributes: attrs, classes, xpath: xpath(e), role: e.getAttribute('role') || implicitRole(e), name: name.slice(0, 120), text: name ? '' : textOf(e).slice(0, 120) };
142
145
  };
143
146
  // How many elements each kind of locator for `e` matches right now, counted at the event: ForgeQE checks locators
@@ -152,14 +155,15 @@ RECORDER_JS = r"""(() => {
152
155
  for (const [k, v] of Object.entries(f.attributes)) out.attr[k] = count('[' + k + '=' + q(v) + ']', rs);
153
156
  if (f.attributes.name) out.name = count(f.tag + '[name=' + q(f.attributes.name) + ']', rs);
154
157
  if (f.attributes.href) out.href = count('a[href=' + q(f.attributes.href) + ']', rs);
155
- if (f.classes.length) out.css = count(f.tag + f.classes.slice(0, 2).map((c) => '.' + c).join(''), rs);
158
+ // The selector counted too: ForgeQE uses the count only for that same selector.
159
+ if (f.classes.length) { out.css_sel = f.tag + f.classes.slice(0, 2).map((c) => '.' + c).join(''); out.css = count(out.css_sel, rs); }
156
160
  const t = f.text || f.name;
157
161
  if (t) out.text = deepAll('*', rs).filter((x) => visible(x) && norm(x.textContent) === t && ![...x.children].some((c) => norm(c.textContent) === t)).length;
158
162
  if (f.role && f.name) {
159
163
  const same = deepAll(ROLE_SEL, rs).filter((x) => visible(x) && (x.getAttribute('role') || implicitRole(x)) === f.role);
160
164
  out.role = same.filter((x) => accName(x) === f.name).length;
161
165
  // The names of the others with this role, for a locator by part of the name, counted after the page is gone.
162
- if (/\d/.test(f.name)) out.role_names = same.slice(0, 400).map((x) => accName(x).slice(0, 160));
166
+ if (/\d/.test(f.name) || f.name.length > 80) out.role_names = same.slice(0, 400).map((x) => accName(x).slice(0, 160));
163
167
  }
164
168
  if (f.name) out.label = deepAll('input, select, textarea, [aria-label]', rs).filter((x) => labelText(x) === f.name).length;
165
169
  return out;
@@ -185,7 +189,9 @@ RECORDER_JS = r"""(() => {
185
189
  if (x.tagName === 'FIELDSET') return 'group';
186
190
  return '';
187
191
  };
188
- const stableClass = (c) => /^[A-Za-z][\w-]{2,40}$/.test(c) && !/\d{3,}|__|^(?:css|sc|jsx|svelte|emotion)-/i.test(c);
192
+ const stableClass = (c) => /^[A-Za-z][\w-]{2,40}$/.test(c) && !/\d{3,}|__|^(?:css|sc|jsx|svelte|emotion)-/i.test(c) && !STATE_CLASS.test(c);
193
+ // A class a page sets for a state (the item under the pointer, the one chosen, a menu open): it moves between elements.
194
+ const STATE_CLASS = new RegExp(CFG.stateClass, 'i');
189
195
  const containerCss = (x) => { const c = [...x.classList].find(stableClass); return c ? x.tagName.toLowerCase() + '.' + c : ''; };
190
196
  const lowText = (x) => norm(x.textContent).toLowerCase();
191
197
  // The texts that could tell this container from the others: its headings, then its labels, then short texts of its own.
@@ -495,8 +501,11 @@ RECORDER_JS = r"""(() => {
495
501
  const MENU = '[role=menu], [role=menubar] [role=menu], [role=listbox], ul ul, .dropdown-menu, .submenu, .sub-menu, [class*="dropdown"], [class*="submenu"], [class*="flyout"], [class*="mega"]';
496
502
  const revealed = [];
497
503
  let hovered = null;
504
+ // What shows soon after a press (a click's doing: a list of results, the fields a choice opens) is not a hover's.
505
+ let pressedAt = 0;
506
+ window.addEventListener('pointerdown', (ev) => { if (ev.isTrusted && !ours(ev)) pressedAt = Date.now(); }, true);
498
507
  const onReveal = (list) => {
499
- if (!hovered || Date.now() - hovered.at > 1500) return;
508
+ if (!hovered || Date.now() - hovered.at > 1500 || Date.now() - pressedAt < 1500) return;
500
509
  for (const m of list) {
501
510
  const n = m.type === 'childList' ? [...m.addedNodes].find((x) => x.nodeType === 1) : m.target;
502
511
  if (n && n.nodeType === 1 && !deepContains(n, hovered.el) && n !== host) revealed.push({ by: hovered.el, root: n, at: Date.now() });
@@ -523,10 +532,12 @@ RECORDER_JS = r"""(() => {
523
532
  const t = deepClosest(deep(ev), TRIGGER);
524
533
  if (t && (!hovered || t !== hovered.el)) hovered = { el: t, at: Date.now() };
525
534
  }, true);
535
+ // Showing on the page now: a menu's trigger a person still points at, not one gone with its list.
536
+ const shows = (e) => { const r = e.getBoundingClientRect(); if (r.width < 1 || r.height < 1) return false; const cs = getComputedStyle(e); return cs.visibility !== 'hidden' && cs.display !== 'none'; };
526
537
  const hoverFor = (c) => {
527
538
  for (let i = revealed.length - 1; i >= 0; i--) {
528
539
  const r = revealed[i];
529
- if (deepContains(r.root, c) && r.by !== c && !deepContains(r.by, c) && r.by.isConnected && Date.now() - r.at < 60000) return r.by;
540
+ if (deepContains(r.root, c) && r.by !== c && !deepContains(r.by, c) && r.by.isConnected && shows(r.by) && Date.now() - r.at < 60000) return r.by;
530
541
  }
531
542
  for (let e = up(c), i = 0; e && e !== document.body && i < 8; e = up(e), i++) {
532
543
  if (!e.matches(MENU)) continue;
@@ -590,6 +601,8 @@ RECORDER_JS = r"""(() => {
590
601
  let lastLabel = null;
591
602
  window.addEventListener('click', (ev) => {
592
603
  if (!ev.isTrusted || ours(ev)) return;
604
+ // The click a browser fires where a mouse drag ended: part of the drag.
605
+ if (!picking && Date.now() - dragClick < 400) { dragClick = 0; return; }
593
606
  if (picking) {
594
607
  ev.preventDefault(); ev.stopImmediatePropagation();
595
608
  const e = pickable(pickTarget(ev));
@@ -616,7 +629,104 @@ RECORDER_JS = r"""(() => {
616
629
  const c = control(deep(ev));
617
630
  if (c && !isField(c)) send({ kind: 'dblclick', ...describeEl(c), ...where(c, ev) });
618
631
  }, true);
619
- window.addEventListener('dragstart', (ev) => { if (ev.isTrusted && !paused && !picking && !ours(ev)) send({ kind: 'unsupported', action: 'drag', reason: 'drag and drop is not recorded yet; add it in the test' }); }, true);
632
+ // ---- drags: an element moved with the mouse (a list's item, a card, a slider's thumb, a map's pin), or dragged the
633
+ // browser's own way (draggable): one step, from where it was taken to where it was let go. The element let go on, a
634
+ // point in each (from its top left), and how far the pointer moved; the click a browser fires after it is not a step.
635
+ const DRAG_MIN = 8;
636
+ const DRAG_TAKE = new Set(['listitem', 'option', 'row', 'treeitem', 'gridcell', 'slider', 'img', 'button', 'link', 'tab']);
637
+ const DRAG_DROP = new Set(['listitem', 'list', 'listbox', 'row', 'grid', 'table', 'region', 'group', 'tabpanel', 'tree', 'treeitem', 'gridcell', 'cell', 'application', 'img']);
638
+ const roleOf = (e) => (e.getAttribute && e.getAttribute('role')) || implicitRole(e);
639
+ // The element that moves or that takes it: the nearest one a test can name (draggable, a role of a list or a table, a
640
+ // test id, an id, a label), else the one under the pointer.
641
+ const named = (e) => e.hasAttribute('data-testid') || e.hasAttribute('data-test') || e.hasAttribute('data-cy') || !!e.id || e.hasAttribute('aria-label');
642
+ const dragEnd = (node, roles, tags) => {
643
+ let e = node && node.nodeType === 1 ? node : node && node.parentElement;
644
+ for (let i = 0, c = e; c && i <= 6 && c !== document.body && c !== document.documentElement; i++, c = up(c)) {
645
+ if (c.getAttribute('draggable') === 'true' || roles.has(roleOf(c)) || tags.test(c.tagName) || named(c)) return c;
646
+ }
647
+ return e;
648
+ };
649
+ const taken = (n) => dragEnd(n, DRAG_TAKE, /^(LI|TR|IMG|CANVAS|INPUT)$/);
650
+ const takes = (n) => dragEnd(n, DRAG_DROP, /^(LI|UL|OL|TR|TD|TABLE|SECTION|CANVAS|IMG)$/);
651
+ const at = (e, x, y) => { const r = e.getBoundingClientRect(); const w = Math.max(0, Math.round(r.width)), h = Math.max(0, Math.round(r.height)); return { x: Math.min(w, Math.max(0, Math.round(x - r.left))), y: Math.min(h, Math.max(0, Math.round(y - r.top))) }; };
652
+ // What is under the pointer, through open shadow roots, leaving out the element that moves (and what is inside it).
653
+ const atPoint = (x, y, skip) => {
654
+ let scope = document, found = null;
655
+ for (let d = 0; d < 8 && scope; d++) {
656
+ const hit = (scope.elementsFromPoint ? scope.elementsFromPoint(x, y) : []).find((e) => e !== document.documentElement && e !== document.body && !(skip && (e === skip || skip.contains(e))));
657
+ if (!hit || hit === found) break;
658
+ found = hit;
659
+ scope = hit.shadowRoot || null;
660
+ }
661
+ return found;
662
+ };
663
+ const sendDrag = (src, sx, sy, dst, x, y, native) => {
664
+ if (!src || !src.isConnected) return;
665
+ // Let go on the element itself or on what holds it (a slider's track): moved by the offset only.
666
+ const apart = (e) => e && e !== src && !src.contains(e) && !e.contains(src);
667
+ const to = apart(dst) && apart(takes(dst)) ? takes(dst) : null;
668
+ send({ kind: 'drag', native: !!native, source: { ...describeEl(src), position: at(src, sx, sy) }, ...(to && to !== src ? { target: { ...describeEl(to), position: at(to, x, y) } } : {}), offset: { x: Math.round(x - sx), y: Math.round(y - sy) } });
669
+ };
670
+ let press = null, dragged = null, dragClick = 0;
671
+ window.addEventListener('pointerdown', (ev) => {
672
+ press = null;
673
+ if (!ev.isTrusted || ours(ev) || paused || picking || ev.button !== 0 || !ev.isPrimary) return;
674
+ const t = deep(ev);
675
+ // Selecting text in a field, or the page's scroll bar, is not a drag.
676
+ if (!t || isField(t) || t.tagName === 'SELECT' || t.tagName === 'OPTION') return;
677
+ // On the page itself: never a drag, but the click after a sweep is not a step either.
678
+ if (t === document.documentElement || t === document.body) { press = { el: t, x: ev.clientX, y: ev.clientY, moved: false, src: null }; return; }
679
+ const src = taken(t);
680
+ const r = src.getBoundingClientRect();
681
+ press = { el: t, x: ev.clientX, y: ev.clientY, moved: false, src, left: r.left, top: r.top };
682
+ }, true);
683
+ // A mouse drag is a step only on an element that moves: one the drag moved, one the page says can be moved (a grab or
684
+ // move cursor, draggable), or an item of a list or a table, a slider, an image or a canvas. A sweep over a page is not.
685
+ const MOVE_CURSOR = /^(grab|grabbing|move|all-scroll|[nsew]{1,2}-resize|col-resize|row-resize)$/;
686
+ const movable = (p) => {
687
+ const r = p.src.getBoundingClientRect();
688
+ if (Math.abs(r.left - p.left) >= 4 || Math.abs(r.top - p.top) >= 4) return true;
689
+ for (let e = p.el, i = 0; e && e.nodeType === 1 && i <= 6; e = up(e), i++) {
690
+ if (e.getAttribute('draggable') === 'true' || MOVE_CURSOR.test(getComputedStyle(e).cursor)) return true;
691
+ if (e === p.src) break;
692
+ }
693
+ const role = roleOf(p.src);
694
+ return ['listitem', 'option', 'row', 'treeitem', 'slider', 'img'].includes(role) || /^(LI|TR|IMG|CANVAS)$/.test(p.src.tagName) || (p.src.tagName === 'INPUT' && (p.src.getAttribute('type') || '').toLowerCase() === 'range');
695
+ };
696
+ window.addEventListener('pointermove', (ev) => {
697
+ if (press && !press.moved && ev.isTrusted && (ev.buttons & 1) && Math.hypot(ev.clientX - press.x, ev.clientY - press.y) >= DRAG_MIN) press.moved = true;
698
+ }, true);
699
+ window.addEventListener('pointercancel', () => { if (!dragged) press = null; }, true);
700
+ window.addEventListener('pointerup', (ev) => {
701
+ const p = press;
702
+ press = null;
703
+ if (!p || !p.moved || !ev.isTrusted || ours(ev) || paused || picking || dragged) return;
704
+ // A press that moved is not a click a person meant: the click the browser fires after it is no step either way.
705
+ dragClick = Date.now();
706
+ // Text selected by the drag: a person selecting text, not moving an element.
707
+ const sel = window.getSelection && window.getSelection();
708
+ if (sel && !sel.isCollapsed && String(sel).trim()) return;
709
+ if (!p.src || !movable(p)) return;
710
+ if (dirty) flush();
711
+ sendDrag(p.src, p.x, p.y, atPoint(ev.clientX, ev.clientY, p.src), ev.clientX, ev.clientY, false);
712
+ }, true);
713
+ // The browser's own drag (a draggable element): from dragstart to the drop the page took.
714
+ window.addEventListener('dragstart', (ev) => {
715
+ if (!ev.isTrusted || paused || picking || ours(ev)) return;
716
+ const p = press;
717
+ const t = deep(ev);
718
+ dragged = { el: t && t.nodeType === 1 ? (t.getAttribute('draggable') === 'true' ? t : taken(t)) : null, x: p ? p.x : ev.clientX, y: p ? p.y : ev.clientY };
719
+ press = null;
720
+ }, true);
721
+ window.addEventListener('drop', (ev) => {
722
+ const d = dragged;
723
+ if (!d || !ev.isTrusted || paused || picking || ours(ev)) return;
724
+ if (ev.dataTransfer && ev.dataTransfer.files && ev.dataTransfer.files.length) return;
725
+ dragged = null;
726
+ if (dirty) flush();
727
+ sendDrag(d.el, d.x, d.y, deep(ev), ev.clientX, ev.clientY, true);
728
+ }, true);
729
+ window.addEventListener('dragend', () => { dragged = null; }, true);
620
730
  // Files dropped on the page from this computer (a drop zone): an upload. The files are kept here, by number, for
621
731
  // ForgeQE to read their paths through the DevTools protocol (the page itself only sees their names).
622
732
  const drops = [];
@@ -709,5 +819,5 @@ RECORDER_JS = r"""(() => {
709
819
 
710
820
  def recorder_js(binding: str, kept: Any, *, leader: Dict[str, Any], badge: bool = False) -> str:
711
821
  """The page script; ``badge``: no panel, only a badge that says it records (a recording started from the web app)."""
712
- config = {"binding": binding, "kept": list(kept), "leader": leader, "commands": [list(c) for c in COMMAND_KEYS], "badge": bool(badge)}
822
+ config = {"binding": binding, "kept": list(kept), "leader": leader, "commands": [list(c) for c in COMMAND_KEYS], "badge": bool(badge), "stateClass": STATE_CLASS}
713
823
  return RECORDER_JS.replace("__CONFIG__", json.dumps(config))