@capagents/forgeqe 2.9.8 → 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.
- package/HOW_TO_USE.md +90 -33
- package/dist/docs-site/docs/index.html +53 -4
- package/dist/docs-site/docs/search.js +1 -1
- package/dist/forgeqe.js +2042 -1892
- package/dist/web/assets/Agent-B_mG1pww.js +8 -0
- package/dist/web/assets/ApiTests-C2QIp_tG.js +10 -0
- package/dist/web/assets/Browse-zQoOQXpA.js +2 -0
- package/dist/web/assets/{Chat-DSlBwNAI.js → Chat-BtLEKYY8.js} +3 -3
- package/dist/web/assets/CommandPalette-BgQORiKD.js +1 -0
- package/dist/web/assets/{Compare-BI8IMq49.js → Compare-DQNg3ldO.js} +1 -1
- package/dist/web/assets/Cost-T0NH8ymc.js +1 -0
- package/dist/web/assets/{Data-CjnqjcAx.js → Data-CqKsrslC.js} +4 -4
- package/dist/web/assets/Desktop-CgDXi3lX.js +1 -0
- package/dist/web/assets/DesktopReview-C-gW_gli.js +1 -0
- package/dist/web/assets/Evidence-1pipN6K6.js +1 -0
- package/dist/web/assets/{Explore-Cc-1cTwG.js → Explore-lG_kobPj.js} +2 -2
- package/dist/web/assets/Features-BIrW3AiQ.js +1 -0
- package/dist/web/assets/{Flags-CICcBCkH.js → Flags-sG1vr7NU.js} +2 -2
- package/dist/web/assets/Flaky-ChKBXlcW.js +1 -0
- package/dist/web/assets/Impact-D5a5fyc2.js +3 -0
- package/dist/web/assets/Jobs-B52pIZUx.js +5 -0
- package/dist/web/assets/KindPage-BFoKPj7l.js +6 -0
- package/dist/web/assets/Migration-DbuzD_s4.js +2 -0
- package/dist/web/assets/Product-DiH61j0X.js +7 -0
- package/dist/web/assets/Production-8h5LixDt.js +1 -0
- package/dist/web/assets/Quality-CI5n8b_k.js +1 -0
- package/dist/web/assets/Readiness-D4n4HSlW.js +1 -0
- package/dist/web/assets/Record-O8LOzHLo.js +2 -0
- package/dist/web/assets/Regression-DbShD6ji.js +5 -0
- package/dist/web/assets/RelationGraph-D_ZVeOBh.js +1 -0
- package/dist/web/assets/Reports-IdoUvtaW.js +2 -0
- package/dist/web/assets/{Response-CaWPiZyx.js → Response-BRVM9mW_.js} +2 -2
- package/dist/web/assets/{RunDiff-BQKwTCbM.js → RunDiff-uQoK3Q6q.js} +1 -1
- package/dist/web/assets/Runs-BhDgzDo4.js +2 -0
- package/dist/web/assets/Steps-BDSeIznj.js +2 -0
- package/dist/web/assets/TestCases-DQ2oWXt2.js +1 -0
- package/dist/web/assets/TestData-D-ZdmHVa.js +2 -0
- package/dist/web/assets/TestDebt-_jer4Dmy.js +1 -0
- package/dist/web/assets/Tosca-DOT6-53c.js +3 -0
- package/dist/web/assets/{WhatsNew-CznfTEFM.js → WhatsNew-DU5k6dz6.js} +1 -1
- package/dist/web/assets/dataParts-BzuL6pAo.js +3 -0
- package/dist/web/assets/{families-B0QIuAe3.js → families-zlLgApNV.js} +1 -1
- package/dist/web/assets/filters-CflRmNDz.js +1 -0
- package/dist/web/assets/flowLayout-cXVJhLpH.js +1 -0
- package/dist/web/assets/{fold-HnodvJWj.js → fold-DZYvcIP0.js} +1 -1
- package/dist/web/assets/frame-Bjxy1jvq.js +4 -0
- package/dist/web/assets/index-DH21lIE7.js +66 -0
- package/dist/web/assets/index-DwUumNPZ.css +2 -0
- package/dist/web/assets/{logos-CNarWSPL.js → logos-Co26FM0G.js} +1 -1
- package/dist/web/assets/markdown-nTIj9lyp.js +10 -0
- package/dist/web/assets/{palette-B2YywN1k.js → palette-CitkMCod.js} +1 -1
- package/dist/web/assets/{parts-z_AE9U-M.js → parts-C53RxMcR.js} +1 -1
- package/dist/web/assets/{productParts-C4vc_bLJ.js → productParts-DK3ULNpv.js} +1 -1
- package/dist/web/assets/qualityParts-DADI5Fqn.js +1 -0
- package/dist/web/assets/{recordTest-GvGQjhR4.js → recordTest-CqxnF953.js} +1 -1
- package/dist/web/assets/{rows-7zDrF-Yp.js → rows-BqT7fknl.js} +1 -1
- package/dist/web/assets/{segmented-DANusepM.js → segmented-CAf_qz5Z.js} +1 -1
- package/dist/web/assets/{thread-BUBgX0xW.js → thread-iRsceqhM.js} +2 -2
- package/dist/web/assets/{usePageChat-DnOXyd_B.js → usePageChat-BCrPoTyS.js} +1 -1
- package/dist/web/index.html +5 -4
- package/docs/BUSINESS_ASSURANCE.md +105 -0
- package/docs/user-guide.html +53 -4
- package/package.json +1 -1
- package/prompts/README.md +3 -0
- package/prompts/brain.md +11 -0
- package/prompts/business-interview.md +43 -0
- package/prompts/business-persona.md +3 -1
- package/prompts/business-strategist.md +44 -0
- package/prompts/persona-own.md +47 -0
- package/py/forgeqe_engine/browser.py +29 -0
- package/py/forgeqe_engine/capture.py +2 -2
- package/py/forgeqe_engine/cli.py +5 -0
- package/py/forgeqe_engine/dynamic.py +8 -0
- package/py/forgeqe_engine/memory.py +33 -2
- package/py/forgeqe_engine/recordsession.py +301 -28
- package/py/forgeqe_engine/webrecord.py +80 -0
- package/py/forgeqe_engine/webrecord_page.py +136 -17
- package/dist/web/assets/Agent-D0jovbz1.js +0 -6
- package/dist/web/assets/ApiTests-CMMMApBR.js +0 -10
- package/dist/web/assets/Browse-Bimy9-t0.js +0 -2
- package/dist/web/assets/CommandPalette-D7NWAtOU.js +0 -1
- package/dist/web/assets/Cost-BV0JavsG.js +0 -1
- package/dist/web/assets/Desktop-Bu72INy4.js +0 -1
- package/dist/web/assets/DesktopReview-jDnb5Gfn.js +0 -1
- package/dist/web/assets/Evidence-CIlcAy5n.js +0 -1
- package/dist/web/assets/Features-CewFSOSI.js +0 -1
- package/dist/web/assets/Flaky-BrWbRajc.js +0 -1
- package/dist/web/assets/ForceGraph-BLYMwmyj.js +0 -1
- package/dist/web/assets/Impact-D7seby-G.js +0 -3
- package/dist/web/assets/Jobs-D7yPretO.js +0 -5
- package/dist/web/assets/KindPage-Cjt1s7Vd.js +0 -6
- package/dist/web/assets/Migration-CbCqOsJI.js +0 -2
- package/dist/web/assets/Product-CxXVrpoD.js +0 -7
- package/dist/web/assets/Production-D5jIe328.js +0 -1
- package/dist/web/assets/Quality-D3G8IKLZ.js +0 -1
- package/dist/web/assets/Readiness-B4Fy4Vln.js +0 -1
- package/dist/web/assets/Record-DLfODYjy.js +0 -2
- package/dist/web/assets/Regression-Daoc9Qvx.js +0 -5
- package/dist/web/assets/Reports-DEzDDoGF.js +0 -2
- package/dist/web/assets/Runs-BIUnN08h.js +0 -2
- package/dist/web/assets/Steps-DjR_K32c.js +0 -2
- package/dist/web/assets/TestCases-BZWiTLjC.js +0 -1
- package/dist/web/assets/TestData-D6YiouU4.js +0 -2
- package/dist/web/assets/TestDebt-COFagfQU.js +0 -1
- package/dist/web/assets/Tosca-B3sZ9uqe.js +0 -3
- package/dist/web/assets/dataParts-DpVitZdm.js +0 -3
- package/dist/web/assets/filters-mFECJpMB.js +0 -1
- package/dist/web/assets/frame-DiKY0GWx.js +0 -4
- package/dist/web/assets/index-HjX2EOmp.js +0 -75
- package/dist/web/assets/index-VgSzQGK8.css +0 -2
- package/dist/web/assets/qualityParts-jsPhayON.js +0 -1
|
@@ -38,6 +38,9 @@ NAV_CAUSED_SECONDS = 1.5
|
|
|
38
38
|
DOUBLE_CLICK_SECONDS = 0.5
|
|
39
39
|
MAX_TEXT = 200
|
|
40
40
|
EXPECT_KINDS = ("text", "visible", "hidden", "value", "checked", "url", "title", "intent")
|
|
41
|
+
# Browser dialogs a step can answer (Page.javascriptDialogOpening's types); a dialog's message is kept one line, clipped.
|
|
42
|
+
DIALOG_KINDS = ("alert", "confirm", "prompt", "beforeunload")
|
|
43
|
+
MAX_DIALOG_MESSAGE = 300
|
|
41
44
|
# Keys recorded inside a text field; any other key there is typing.
|
|
42
45
|
FIELD_KEYS = ("Enter", "Escape")
|
|
43
46
|
AUTOCOMPLETE_KEYS = ("ArrowDown", "ArrowUp")
|
|
@@ -283,6 +286,14 @@ def describe(step: Dict[str, Any]) -> str:
|
|
|
283
286
|
return f"wait for {label}"
|
|
284
287
|
if op == "captcha":
|
|
285
288
|
return f"solve the {step.get('provider') or 'CAPTCHA'} (a person; a test turns it off)"
|
|
289
|
+
if op == "dialog":
|
|
290
|
+
return dialog_words(step)
|
|
291
|
+
if op == "drag":
|
|
292
|
+
to = step.get("to") if isinstance(step.get("to"), dict) else None
|
|
293
|
+
if to:
|
|
294
|
+
return f"drag {label} onto {to.get('label') or 'element'}"
|
|
295
|
+
off = step.get("offset") if isinstance(step.get("offset"), dict) else {}
|
|
296
|
+
return f"drag {label} by {off.get('x', 0)},{off.get('y', 0)}"
|
|
286
297
|
if op == "upload":
|
|
287
298
|
names = list(step.get("files") or []) + [os.path.basename(f) for f in step.get("run_files") or []]
|
|
288
299
|
return f"{'drop' if step.get('drop') else 'upload'} {', '.join(names)} {'onto' if step.get('drop') else 'into'} {label}"
|
|
@@ -306,6 +317,26 @@ def describe(step: Dict[str, Any]) -> str:
|
|
|
306
317
|
return op
|
|
307
318
|
|
|
308
319
|
|
|
320
|
+
def dialog_message(raw: Any) -> str:
|
|
321
|
+
"""A dialog's message as a step keeps it: page text, one line, clipped (never markup or a command)."""
|
|
322
|
+
text = " ".join(str(raw or "").split())
|
|
323
|
+
return text if len(text) <= MAX_DIALOG_MESSAGE else text[: MAX_DIALOG_MESSAGE - 1] + "…"
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def dialog_words(step: Dict[str, Any]) -> str:
|
|
327
|
+
"""A dialog step in words: what the page asked and how it was answered."""
|
|
328
|
+
kind, ok = step.get("kind"), bool(step.get("accept"))
|
|
329
|
+
said = f" {step['message']!r}" if step.get("message") else ""
|
|
330
|
+
if kind == "beforeunload":
|
|
331
|
+
return "leave the page when it asks" if ok else "stay on the page when it asks"
|
|
332
|
+
if kind == "alert":
|
|
333
|
+
return f"close the alert{said}"
|
|
334
|
+
if kind == "prompt" and ok:
|
|
335
|
+
given = f"${step['text_env']}" if step.get("text_env") else repr(step.get("text") or "")
|
|
336
|
+
return f"answer the prompt{said} with {given}"
|
|
337
|
+
return f"answer the {kind}{said} with {'OK' if ok else 'Cancel'}"
|
|
338
|
+
|
|
339
|
+
|
|
309
340
|
@dataclass
|
|
310
341
|
class WebRecorder:
|
|
311
342
|
start_url: str
|
|
@@ -389,6 +420,49 @@ class WebRecorder:
|
|
|
389
420
|
self._add({"op": "captcha", "provider": provider, "page": page_id(self.url) or self.url})
|
|
390
421
|
return describe(self.steps[-1])
|
|
391
422
|
|
|
423
|
+
def on_dialog(self, kind: str, message: Any, accept: bool, text: Any = None) -> Optional[str]:
|
|
424
|
+
"""
|
|
425
|
+
A browser dialog the page showed (an alert, a confirm, a prompt, or "leave this page?") and how the person answered
|
|
426
|
+
it: OK or Cancel, and a prompt's typed text. The step comes after the one that made the page ask; a replay answers
|
|
427
|
+
the dialog the same way when that step runs. Its message is page text: kept as data, one line.
|
|
428
|
+
"""
|
|
429
|
+
if self.paused or kind not in DIALOG_KINDS:
|
|
430
|
+
return None
|
|
431
|
+
self._last_action = self.clock()
|
|
432
|
+
self._last_click = None
|
|
433
|
+
step: Dict[str, Any] = {"op": "dialog", "kind": kind, "message": dialog_message(message), "accept": bool(accept), "page": page_id(self.url) or self.url}
|
|
434
|
+
if kind == "prompt" and accept:
|
|
435
|
+
value = _clip(" ".join(str(text or "").split()))
|
|
436
|
+
env = next((k for k, v in self.login_values.items() if v and value == v), None)
|
|
437
|
+
if env:
|
|
438
|
+
step.update(text="", text_env=env)
|
|
439
|
+
else:
|
|
440
|
+
var = next((k for k, v in self.variables.items() if v and value == v), None)
|
|
441
|
+
step["text"] = "{{%s}}" % var if var else value
|
|
442
|
+
self._add(step)
|
|
443
|
+
return describe(step)
|
|
444
|
+
|
|
445
|
+
def on_drag(self, t: Target, to: Optional[Target], offset: Optional[Dict[str, int]]) -> Optional[str]:
|
|
446
|
+
"""
|
|
447
|
+
An element the tester dragged: `t` the one taken (its position the point it was taken by), `to` the one it was let
|
|
448
|
+
go on (with the point), none when that is the same element (a slider's thumb, a pin that moves with the pointer),
|
|
449
|
+
and `offset` how far the pointer moved. A replay drags it with the mouse onto `to`, or by `offset`.
|
|
450
|
+
"""
|
|
451
|
+
if self.paused:
|
|
452
|
+
return None
|
|
453
|
+
self._last_action = self.clock()
|
|
454
|
+
self._last_click = None
|
|
455
|
+
step = element_step("drag", t)
|
|
456
|
+
if to is not None and not _same_element(t, to):
|
|
457
|
+
dst = element_step("drag", to)
|
|
458
|
+
step["to"] = {k: dst[k] for k in ("label", "best_locator", "position", "shadow", "locators", "locator", "frame", "frames") if dst.get(k)}
|
|
459
|
+
if offset:
|
|
460
|
+
step["offset"] = dict(offset)
|
|
461
|
+
if "to" not in step and "offset" not in step:
|
|
462
|
+
return None
|
|
463
|
+
self._add(step)
|
|
464
|
+
return describe(step)
|
|
465
|
+
|
|
392
466
|
def on_dblclick(self, t: Target) -> Optional[str]:
|
|
393
467
|
"""The browser's own double-click event: the two clicks before it on the element become one double-click."""
|
|
394
468
|
if self.paused:
|
|
@@ -738,6 +812,12 @@ def _name_hint(facts: Dict[str, Any]) -> str:
|
|
|
738
812
|
return str(facts.get("name") or "") if facts.get("tag") in ("input", "select", "textarea") else ""
|
|
739
813
|
|
|
740
814
|
|
|
815
|
+
def _same_element(a: Target, b: Target) -> bool:
|
|
816
|
+
"""Whether two targets are the same element: the same page, frames and best locator (wherever in it)."""
|
|
817
|
+
best = lambda t: (t.locators[0].get("type"), t.locators[0].get("value")) if t.locators else (None, None) # noqa: E731
|
|
818
|
+
return (a.url, a.frames, best(a)) == (b.url, b.frames, best(b))
|
|
819
|
+
|
|
820
|
+
|
|
741
821
|
def _same(step: Dict[str, Any], t: Target) -> bool:
|
|
742
822
|
"""Whether a recorded step acted on target `t`: the same page and the same best locator."""
|
|
743
823
|
locs = step.get("locators") or []
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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.
|
|
@@ -300,10 +306,14 @@ RECORDER_JS = r"""(() => {
|
|
|
300
306
|
'.chat{display:flex;gap:6px;padding:8px 12px;border-top:1px solid var(--line)}' +
|
|
301
307
|
'textarea{flex:1;font:inherit;font-size:13px;resize:none;height:44px;border:1px solid var(--line);border-radius:7px;padding:5px 8px;background:var(--surface);color:var(--text)}' +
|
|
302
308
|
'.hint{margin:0;padding:0 12px 8px;color:var(--muted);font-size:12px}' +
|
|
303
|
-
// Badge (a recording started from the web app): no panel, only a small
|
|
304
|
-
//
|
|
305
|
-
// test data are chosen after it stops, in the review.
|
|
306
|
-
'.
|
|
309
|
+
// Badge (a recording started from the web app): no panel, only a small bar that says it records and how many steps,
|
|
310
|
+
// with a Stop button. Only the button takes a click, so the bar never covers what the tester clicks. Pause and Undo
|
|
311
|
+
// are on the Record page and on the keys; checks and test data are chosen after it stops, in the review.
|
|
312
|
+
'.bar{position:fixed;right:16px;bottom:16px;display:inline-flex;align-items:center;gap:8px;height:32px;padding:0 4px 0 12px;border-radius:16px;border:1px solid var(--line);background:var(--surface);color:var(--text);font:12px var(--font);box-shadow:0 6px 18px rgba(15,27,61,.2);pointer-events:none;opacity:.94}' +
|
|
313
|
+
'.bar[hidden]{display:none}' +
|
|
314
|
+
'.bar i{width:9px;height:9px;border-radius:50%;background:var(--fail);flex:none}' +
|
|
315
|
+
'.bar.paused i{background:var(--warn)}' +
|
|
316
|
+
'.bar button{pointer-events:auto;height:24px;padding:0 10px;border-radius:12px;font-size:12px}' +
|
|
307
317
|
'kbd{font:11px var(--mono);border:1px solid var(--line);border-radius:4px;padding:0 4px;background:var(--surface-2)}' +
|
|
308
318
|
'.pill{position:fixed;right:16px;bottom:16px;display:inline-flex;align-items:center;gap:8px;height:32px;padding:0 12px;border-radius:16px;border:1px solid var(--line);background:var(--surface);color:var(--text);font:13px var(--font);box-shadow:0 6px 18px rgba(15,27,61,.2);pointer-events:auto}' +
|
|
309
319
|
// The pick highlight and the key bar: brand.py's overlay colours and font.
|
|
@@ -326,10 +336,10 @@ RECORDER_JS = r"""(() => {
|
|
|
326
336
|
'<div class="chat"><textarea data-ui="text" aria-label="Describe a check, or start with note: for a note" placeholder="Describe a check: the total shows "$40.00""></textarea><button class="primary" data-ui="send">Send</button></div>' +
|
|
327
337
|
'<p class="hint"></p></section>' +
|
|
328
338
|
'<button class="pill" data-ui="expand" hidden aria-label="Open the Recorder"><i></i><span></span></button>' +
|
|
339
|
+
'<div class="bar" hidden role="status"><i></i><span></span><button data-cmd="stop" class="stop" title="Stop recording" aria-label="Stop recording">Stop</button></div>' +
|
|
329
340
|
'<div class="box"></div><div class="tip"></div>';
|
|
330
341
|
const $ = (s) => root.querySelector(s);
|
|
331
|
-
const panel = $('.panel'), pill = $('.pill'), box = $('.box'), tip = $('.tip'), text = $('textarea');
|
|
332
|
-
if (CFG.badge) { pill.classList.add('badge'); pill.removeAttribute('data-ui'); pill.setAttribute('aria-label', 'ForgeQE is recording'); pill.tabIndex = -1; }
|
|
342
|
+
const panel = $('.panel'), pill = $('.pill'), bar = $('.bar'), box = $('.box'), tip = $('.tip'), text = $('textarea');
|
|
333
343
|
const raise = () => { try { if (host.matches(':popover-open')) host.hidePopover(); host.showPopover(); } catch (e) {} };
|
|
334
344
|
// Inside <html>, never in place of it: the script runs before the page's own document element exists.
|
|
335
345
|
const mount = () => { if (!host.isConnected && document.documentElement) { document.documentElement.appendChild(host); raise(); } };
|
|
@@ -343,7 +353,7 @@ RECORDER_JS = r"""(() => {
|
|
|
343
353
|
let paused = false;
|
|
344
354
|
let ui = { collapsed: false, x: null, y: null };
|
|
345
355
|
const place = () => {
|
|
346
|
-
panel.hidden = inFrame || CFG.badge || ui.collapsed; pill.hidden = inFrame ||
|
|
356
|
+
panel.hidden = inFrame || CFG.badge || ui.collapsed; pill.hidden = inFrame || CFG.badge || !ui.collapsed; bar.hidden = inFrame || !CFG.badge;
|
|
347
357
|
for (const p of [panel, pill]) {
|
|
348
358
|
if (ui.x === null || ui.x === undefined) { p.style.left = p.style.top = p.style.right = p.style.bottom = ''; continue; }
|
|
349
359
|
const w = p.offsetWidth || 340, h = p.offsetHeight || 32;
|
|
@@ -356,11 +366,13 @@ RECORDER_JS = r"""(() => {
|
|
|
356
366
|
const render = (s) => {
|
|
357
367
|
mount();
|
|
358
368
|
paused = s.state === 'paused';
|
|
359
|
-
panel.classList.toggle('paused', paused); pill.classList.toggle('paused', paused);
|
|
369
|
+
panel.classList.toggle('paused', paused); pill.classList.toggle('paused', paused); bar.classList.toggle('paused', paused);
|
|
360
370
|
$('.st').textContent = paused ? 'Paused' : s.state === 'stopped' ? 'Stopped' : 'Recording';
|
|
361
371
|
$('.count').textContent = s.summary || '';
|
|
362
372
|
$('.pause').textContent = paused ? 'Resume' : 'Pause';
|
|
363
373
|
pill.querySelector('span').textContent = (paused ? 'Paused' : 'Recording') + (s.summary ? ' · ' + s.summary : '');
|
|
374
|
+
bar.querySelector('span').textContent = (paused ? 'Paused' : s.state === 'stopped' ? 'Stopped' : 'Recording') + (s.summary ? ' · ' + s.summary : '');
|
|
375
|
+
bar.querySelector('button').disabled = s.state === 'stopped';
|
|
364
376
|
const hint = $('.hint');
|
|
365
377
|
hint.textContent = '';
|
|
366
378
|
hint.append('In the page: ', el('kbd', '', s.leader || ''), ' then ' + CFG.commands.map(([k, , label]) => k.toUpperCase() + ' ' + label).join(', '));
|
|
@@ -415,7 +427,8 @@ RECORDER_JS = r"""(() => {
|
|
|
415
427
|
if (s.ui) ui = { ...ui, ...s.ui };
|
|
416
428
|
place();
|
|
417
429
|
};
|
|
418
|
-
|
|
430
|
+
// With only the badge there is no panel to read a warning in (Stop with a case step unchecked): it shows as a tip.
|
|
431
|
+
const log = (t, level) => { const p = $('.log'); p.textContent = t; p.classList.toggle('warn', level === 'warn'); if (CFG.badge && level === 'warn' && !inFrame) say([[0, String(t)]], 6000); };
|
|
419
432
|
const sendChat = () => { const t = text.value.trim(); if (t) send({ kind: 'command', cmd: 'chat', text: t }); text.value = ''; };
|
|
420
433
|
|
|
421
434
|
let drag = null;
|
|
@@ -488,8 +501,11 @@ RECORDER_JS = r"""(() => {
|
|
|
488
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"]';
|
|
489
502
|
const revealed = [];
|
|
490
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);
|
|
491
507
|
const onReveal = (list) => {
|
|
492
|
-
if (!hovered || Date.now() - hovered.at > 1500) return;
|
|
508
|
+
if (!hovered || Date.now() - hovered.at > 1500 || Date.now() - pressedAt < 1500) return;
|
|
493
509
|
for (const m of list) {
|
|
494
510
|
const n = m.type === 'childList' ? [...m.addedNodes].find((x) => x.nodeType === 1) : m.target;
|
|
495
511
|
if (n && n.nodeType === 1 && !deepContains(n, hovered.el) && n !== host) revealed.push({ by: hovered.el, root: n, at: Date.now() });
|
|
@@ -516,10 +532,12 @@ RECORDER_JS = r"""(() => {
|
|
|
516
532
|
const t = deepClosest(deep(ev), TRIGGER);
|
|
517
533
|
if (t && (!hovered || t !== hovered.el)) hovered = { el: t, at: Date.now() };
|
|
518
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'; };
|
|
519
537
|
const hoverFor = (c) => {
|
|
520
538
|
for (let i = revealed.length - 1; i >= 0; i--) {
|
|
521
539
|
const r = revealed[i];
|
|
522
|
-
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;
|
|
523
541
|
}
|
|
524
542
|
for (let e = up(c), i = 0; e && e !== document.body && i < 8; e = up(e), i++) {
|
|
525
543
|
if (!e.matches(MENU)) continue;
|
|
@@ -583,6 +601,8 @@ RECORDER_JS = r"""(() => {
|
|
|
583
601
|
let lastLabel = null;
|
|
584
602
|
window.addEventListener('click', (ev) => {
|
|
585
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; }
|
|
586
606
|
if (picking) {
|
|
587
607
|
ev.preventDefault(); ev.stopImmediatePropagation();
|
|
588
608
|
const e = pickable(pickTarget(ev));
|
|
@@ -609,7 +629,104 @@ RECORDER_JS = r"""(() => {
|
|
|
609
629
|
const c = control(deep(ev));
|
|
610
630
|
if (c && !isField(c)) send({ kind: 'dblclick', ...describeEl(c), ...where(c, ev) });
|
|
611
631
|
}, true);
|
|
612
|
-
|
|
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);
|
|
613
730
|
// Files dropped on the page from this computer (a drop zone): an upload. The files are kept here, by number, for
|
|
614
731
|
// ForgeQE to read their paths through the DevTools protocol (the page itself only sees their names).
|
|
615
732
|
const drops = [];
|
|
@@ -690,6 +807,8 @@ RECORDER_JS = r"""(() => {
|
|
|
690
807
|
if (role) return deepAll(ROLE_SEL).filter((x) => visible(x) && (x.getAttribute('role') || implicitRole(x)) === role && rx.test(accName(x))).length;
|
|
691
808
|
return deepAll('*').filter((x) => visible(x) && !host.contains(x) && rx.test(norm(x.textContent)) && ![...x.children].some((c) => rx.test(norm(c.textContent)))).length;
|
|
692
809
|
},
|
|
810
|
+
// What a part of the panel or bar says, and whether it shows (tests read it as a person would, in this world only).
|
|
811
|
+
text: (sel) => { const e = root.querySelector(sel); return e ? { text: norm(e.textContent), shown: !e.closest('[hidden]') && e.getClientRects().length > 0 } : null; },
|
|
693
812
|
// Where a control of the panel is on screen (tests click it as a person would).
|
|
694
813
|
box: (sel) => { const e = root.querySelector(sel); if (!e) return null; const r = e.getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; },
|
|
695
814
|
};
|
|
@@ -700,5 +819,5 @@ RECORDER_JS = r"""(() => {
|
|
|
700
819
|
|
|
701
820
|
def recorder_js(binding: str, kept: Any, *, leader: Dict[str, Any], badge: bool = False) -> str:
|
|
702
821
|
"""The page script; ``badge``: no panel, only a badge that says it records (a recording started from the web app)."""
|
|
703
|
-
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}
|
|
704
823
|
return RECORDER_JS.replace("__CONFIG__", json.dumps(config))
|