@capagents/forgeqe 3.4.6 → 3.4.7
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/forgeqe.js +2106 -1967
- package/dist/web/assets/{Agent-D_W8YJWv.js → Agent-5Q96YSvr.js} +1 -1
- package/dist/web/assets/{AgentWork-CPYvG2HI.js → AgentWork-BWjyDUEc.js} +1 -1
- package/dist/web/assets/{ApiTests-CElarw4P.js → ApiTests-D493px70.js} +1 -1
- package/dist/web/assets/{Chat-CJsKzudh.js → Chat-CzEPSJKG.js} +1 -1
- package/dist/web/assets/{Compare-DlSaG3td.js → Compare-BYFsbaGF.js} +1 -1
- package/dist/web/assets/{Compare-DBNzy6Hm.js → Compare-sqYji9Pk.js} +1 -1
- package/dist/web/assets/{Cost-DsERWen5.js → Cost-CWWczZfn.js} +1 -1
- package/dist/web/assets/{Data-BSemg5Ky.js → Data-BNcT6ygh.js} +1 -1
- package/dist/web/assets/{Desktop-BcXzby1F.js → Desktop-CG9lFU5l.js} +1 -1
- package/dist/web/assets/{DesktopReview-CDv_Swu0.js → DesktopReview-Cd-oH_U5.js} +1 -1
- package/dist/web/assets/{Evidence-BYQvjtqD.js → Evidence-DPF6gCpK.js} +1 -1
- package/dist/web/assets/{Explore-GAaQCWbY.js → Explore-CIrFwA2S.js} +1 -1
- package/dist/web/assets/{Features-BoFooP6n.js → Features-DzK_-8h1.js} +1 -1
- package/dist/web/assets/{FileTree-a0-UuNhM.js → FileTree-CNGOe2xf.js} +1 -1
- package/dist/web/assets/{Flags-B9BwmpT9.js → Flags-C69Twz3o.js} +1 -1
- package/dist/web/assets/{Flaky-NIz-XNcl.js → Flaky-CNPjhYIZ.js} +1 -1
- package/dist/web/assets/{Impact-D-2WTh3g.js → Impact-Dc1w1OJz.js} +1 -1
- package/dist/web/assets/{Jobs-BtLMd2Pe.js → Jobs-hS20eWew.js} +1 -1
- package/dist/web/assets/{KindPage-YFqKZMNZ.js → KindPage-Dwn1bRlI.js} +1 -1
- package/dist/web/assets/{LiveDevice-BDmDTtX_.js → LiveDevice-CAqR5xdi.js} +1 -1
- package/dist/web/assets/{Migration-Bs1Qc0Yg.js → Migration-B8Cde1ef.js} +1 -1
- package/dist/web/assets/{Mobile-zXRXR_3S.js → Mobile-D3Pch-1L.js} +1 -1
- package/dist/web/assets/{Observability-qNxOzrmI.js → Observability-QUxLZNhO.js} +1 -1
- package/dist/web/assets/{OwnItems-CO-zBy4W.js → OwnItems-Cw923K1y.js} +1 -1
- package/dist/web/assets/{PageAgent-C0u0uyou.js → PageAgent-xDYi2Zgw.js} +1 -1
- package/dist/web/assets/{Product-5nybx8oL.js → Product-CVn9yHyn.js} +1 -1
- package/dist/web/assets/{Production-C2FVz9Df.js → Production-BNg-ims6.js} +1 -1
- package/dist/web/assets/{Quality-CwlN84zJ.js → Quality-BzcQTBgO.js} +1 -1
- package/dist/web/assets/{Readiness-gzFYSc8y.js → Readiness-Bx5JZpXY.js} +1 -1
- package/dist/web/assets/Record-CM_ZJv5n.js +1 -0
- package/dist/web/assets/{Regression-DuP8VGvl.js → Regression-DSGl56Mr.js} +1 -1
- package/dist/web/assets/{Reports-Bk5A2rMW.js → Reports-CBanmypE.js} +1 -1
- package/dist/web/assets/{Requirements-BnOO72Q7.js → Requirements-D-FLXDK0.js} +1 -1
- package/dist/web/assets/{Responsive-9eqRKydd.js → Responsive-DLU7BLkW.js} +1 -1
- package/dist/web/assets/{RunDiff-DAiOiWdE.js → RunDiff-D2IKjRcf.js} +1 -1
- package/dist/web/assets/{Settings-jkOoqeEY.js → Settings-Bi99A4lM.js} +3 -3
- package/dist/web/assets/{SiteScan-BVI8Z-cC.js → SiteScan-CKc7eUOn.js} +1 -1
- package/dist/web/assets/{Steps-CZxAX4yk.js → Steps-DvTL0-9L.js} +1 -1
- package/dist/web/assets/{TestData-CyqXcyZv.js → TestData-Bo0i6j6h.js} +1 -1
- package/dist/web/assets/{TestManagement-UKBq1Jcj.js → TestManagement-a1zMxdc6.js} +1 -1
- package/dist/web/assets/{WhatsNew-BnWCLSSu.js → WhatsNew-OtotufjV.js} +1 -1
- package/dist/web/assets/{agentSettingsSheet-Bca1rnig.js → agentSettingsSheet-DJDT3xqY.js} +1 -1
- package/dist/web/assets/{dataParts-DD4VTinq.js → dataParts-DCcZLVns.js} +1 -1
- package/dist/web/assets/{index-DZMkBMxL.js → index-B58JrUzp.js} +3 -3
- package/dist/web/assets/{productParts-Cjy7N4bQ.js → productParts-BTy_xRc1.js} +1 -1
- package/dist/web/assets/{qualityParts-Bnl_yBH6.js → qualityParts-CaibRb_n.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/py/forgeqe_engine/capture.py +80 -2
- package/py/forgeqe_engine/d365.py +117 -11
- package/py/forgeqe_engine/memory.py +91 -25
- package/py/forgeqe_engine/recordsession.py +9 -1
- package/py/forgeqe_engine/webrecord_page.py +87 -4
- package/dist/web/assets/Record-DeucQwHe.js +0 -1
|
@@ -98,7 +98,7 @@ def generated_path(xpath: str) -> bool:
|
|
|
98
98
|
def page_config() -> Dict[str, Any]:
|
|
99
99
|
"""What the page scripts need to tell a D365 page and read its attributes (webrecord_page.py, capture.py)."""
|
|
100
100
|
return {"host": HOST_JS, "shell": SHELL_ID, "attrs": list(ATTRS), "gen": GENERATED_JS, "up": MAX_UP, "min_prefix": MIN_PREFIX, "trim": _TRIM,
|
|
101
|
-
"path_attrs": list(PATH_ATTRS), "path_up": MAX_PATH_UP, "path_max": MAX_PATH}
|
|
101
|
+
"path_attrs": list(PATH_ATTRS), "path_up": MAX_PATH_UP, "path_max": MAX_PATH, "path_roles": list(PATH_ROLES)}
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
def _attrs(raw: Any) -> Dict[str, str]:
|
|
@@ -236,17 +236,31 @@ def note() -> str:
|
|
|
236
236
|
# written test uses the skill's page objects. Every part is matched by a fixed pattern and kept only in its shape.
|
|
237
237
|
|
|
238
238
|
# What the page script reads around an element (itself first, then up to MAX_PATH_UP ancestors), and how many it keeps.
|
|
239
|
-
PATH_ATTRS = ("data-id", "data-lp-id", "id", "col-id")
|
|
239
|
+
PATH_ATTRS = ("data-id", "data-lp-id", "id", "col-id", "role")
|
|
240
240
|
MAX_PATH_UP = 14
|
|
241
|
-
MAX_PATH =
|
|
241
|
+
MAX_PATH = 20
|
|
242
|
+
# The roles the trail keeps (a grid's header, row and checkbox, a menu's item, a dialog), so other roles never fill it.
|
|
243
|
+
PATH_ROLES = ("columnheader", "row", "gridcell", "checkbox", "menuitem", "option", "dialog", "alertdialog")
|
|
242
244
|
|
|
243
245
|
# The controls the recorder names, as the catalogue's sections and the skill's recipes do.
|
|
244
246
|
CONTROLS = frozenset({
|
|
245
247
|
"text", "date", "time", "lookup", "lookup_search", "lookup_result", "lookup_value", "lookup_clear", "choice", "status",
|
|
246
248
|
"boolean", "multi_select", "field", "command", "overflow", "tab", "sitemap", "grid_cell", "open_record", "quick_find",
|
|
247
249
|
"bpf_stage", "bpf_next", "quick_create_save", "dialog_button",
|
|
250
|
+
# Grid (elements.md "Grid"): the view selector and a view in its list, a column header (sort, filter), a row's
|
|
251
|
+
# checkbox and Select All, paging.
|
|
252
|
+
"grid_view_selector", "grid_view", "grid_column", "grid_row_select", "grid_select_all", "grid_first_page",
|
|
253
|
+
"grid_next_page", "grid_previous_page",
|
|
254
|
+
# Lookup (elements.md "Lookup"): "+ New" and Advanced lookup with its dialog's search, results and Done.
|
|
255
|
+
"lookup_new", "lookup_advanced", "advanced_lookup_search", "advanced_lookup_result", "advanced_lookup_done",
|
|
256
|
+
# Business process flow: Set Active, pin and close the stage's flyout.
|
|
257
|
+
"bpf_set_active", "bpf_pin", "bpf_close",
|
|
258
|
+
# Quick Create: Cancel, the launcher (+) and a table in its menu.
|
|
259
|
+
"quick_create_cancel", "quick_create_launcher", "quick_create_item",
|
|
248
260
|
})
|
|
249
261
|
SCOPES = frozenset({"header", "bpf", "quick_create"})
|
|
262
|
+
# The data dialogs a dialog button is in (elements.md "Dialogs"): Activate/Deactivate, duplicate records found.
|
|
263
|
+
DIALOGS = frozenset({"set_state", "duplicates"})
|
|
250
264
|
# A logical name (field, table, column, subgrid, tab, command): letters, digits, underscore, a command's dots.
|
|
251
265
|
LOGICAL = re.compile(r"^[A-Za-z][A-Za-z0-9_]{0,99}$")
|
|
252
266
|
COMMAND_ID = re.compile(r"^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*){0,5}$")
|
|
@@ -269,7 +283,7 @@ def clean_path(raw: Any) -> List[List[str]]:
|
|
|
269
283
|
return []
|
|
270
284
|
out: List[List[str]] = []
|
|
271
285
|
for item in raw[:MAX_PATH]:
|
|
272
|
-
if isinstance(item, (list, tuple)) and len(item) == 2 and item[0] in PATH_ATTRS and plain(item[1]):
|
|
286
|
+
if isinstance(item, (list, tuple)) and len(item) == 2 and item[0] in PATH_ATTRS and plain(item[1]) and (item[0] != "role" or item[1] in PATH_ROLES):
|
|
273
287
|
out.append([str(item[0]), str(item[1])])
|
|
274
288
|
return out
|
|
275
289
|
|
|
@@ -290,6 +304,8 @@ def _field_kind(field: str, rest: str, tag: str) -> str:
|
|
|
290
304
|
return "lookup_clear"
|
|
291
305
|
if "selected_tag" in sub:
|
|
292
306
|
return "lookup_value"
|
|
307
|
+
if "addNewBtnContainer" in sub:
|
|
308
|
+
return "lookup_new"
|
|
293
309
|
if sub == "search" or sub.endswith("_search") or tag == "button" and "search" in sub:
|
|
294
310
|
return "lookup_search"
|
|
295
311
|
return "lookup"
|
|
@@ -308,6 +324,25 @@ def _field_kind(field: str, rest: str, tag: str) -> str:
|
|
|
308
324
|
return "text"
|
|
309
325
|
|
|
310
326
|
|
|
327
|
+
# A control whose kind is all there is to it: by a fixed part of its data-id or id (elements.md), nearest first.
|
|
328
|
+
_BY_DATA_ID = (
|
|
329
|
+
("setActiveButton", "bpf_set_active"),
|
|
330
|
+
("quickCreateLauncher", "quick_create_launcher"),
|
|
331
|
+
("loadFirstPage", "grid_first_page"),
|
|
332
|
+
("moveToNextPage", "grid_next_page"),
|
|
333
|
+
("moveToPreviousPage", "grid_previous_page"),
|
|
334
|
+
)
|
|
335
|
+
_BY_ID = (
|
|
336
|
+
("stageDockModeButton", "bpf_pin"),
|
|
337
|
+
("stageContentClose", "bpf_close"),
|
|
338
|
+
)
|
|
339
|
+
ADVANCED_LOOKUP = "MscrmControls.FieldControls.AdvancedLookupControl"
|
|
340
|
+
QUICK_CREATE_MENU = "MenuSectionItemsquickCreate"
|
|
341
|
+
# Words the catalogue finds these by (elements.md: `//button[.//label[text()='Advanced lookup']]`, the Done button).
|
|
342
|
+
ADVANCED_LOOKUP_WORDS = "advanced lookup"
|
|
343
|
+
DONE_WORDS = "done"
|
|
344
|
+
|
|
345
|
+
|
|
311
346
|
def control(f: Dict[str, Any]) -> Dict[str, str]:
|
|
312
347
|
"""
|
|
313
348
|
What D365 control an element is, from its D365 names and those around it (`d365_path`, nearest first), as the
|
|
@@ -319,7 +354,7 @@ def control(f: Dict[str, Any]) -> Dict[str, str]:
|
|
|
319
354
|
tag = str(f.get("tag") or "")
|
|
320
355
|
role = str(f.get("role") or "")
|
|
321
356
|
attrs = f.get("attributes") or {}
|
|
322
|
-
own = [[k, str(attrs[k])] for k in PATH_ATTRS if plain(attrs.get(k))]
|
|
357
|
+
own = [[k, str(attrs[k])] for k in PATH_ATTRS if plain(attrs.get(k)) and (k != "role" or attrs[k] in PATH_ROLES)]
|
|
323
358
|
trail = own + [p for p in clean_path(f.get("d365_path")) if p not in own]
|
|
324
359
|
text = _one_line(f.get("name") or f.get("text"))
|
|
325
360
|
out: Dict[str, str] = {}
|
|
@@ -331,6 +366,12 @@ def control(f: Dict[str, Any]) -> Dict[str, str]:
|
|
|
331
366
|
out["scope"] = "bpf"
|
|
332
367
|
|
|
333
368
|
values = [v for _, v in trail]
|
|
369
|
+
# The roles of the element and around it, nearest first (`PATH_ROLES` only).
|
|
370
|
+
roles = ([role] if role in PATH_ROLES else []) + [v for k, v in trail if k == "role" and v in PATH_ROLES]
|
|
371
|
+
if any(v == "SetStateDialog" for v in values):
|
|
372
|
+
out["dialog"] = "set_state"
|
|
373
|
+
elif any("ManageDuplicates" in v for v in values):
|
|
374
|
+
out["dialog"] = "duplicates"
|
|
334
375
|
if any("quickCreateRoot" in v for v in values):
|
|
335
376
|
out["scope"] = "quick_create"
|
|
336
377
|
for _, v in trail:
|
|
@@ -341,18 +382,52 @@ def control(f: Dict[str, Any]) -> Dict[str, str]:
|
|
|
341
382
|
|
|
342
383
|
def done(kind: str, **parts: str) -> Dict[str, str]:
|
|
343
384
|
res = {"control": kind, **{k: v for k, v in parts.items() if v}, **{k: v for k, v in out.items() if k not in parts}}
|
|
344
|
-
if text and kind in
|
|
385
|
+
if text and kind in TEXT_KINDS:
|
|
345
386
|
res.setdefault("text", text)
|
|
387
|
+
if kind != "dialog_button":
|
|
388
|
+
res.pop("dialog", None)
|
|
346
389
|
return _shaped(res)
|
|
347
390
|
|
|
391
|
+
# Advanced lookup's dialog: its search box, a result row, Done (elements.md AdvancedLookup_*).
|
|
392
|
+
if any(ADVANCED_LOOKUP in v for k, v in trail if k == "data-lp-id"):
|
|
393
|
+
if tag == "input" and str(attrs.get("type") or "text") == "text":
|
|
394
|
+
return done("advanced_lookup_search")
|
|
395
|
+
if "row" in roles or "gridcell" in roles:
|
|
396
|
+
return done("advanced_lookup_result")
|
|
397
|
+
if (tag == "button" or role == "button") and text.lower() == DONE_WORDS:
|
|
398
|
+
return done("advanced_lookup_done")
|
|
399
|
+
return {}
|
|
400
|
+
# A table in Quick Create's menu (Nav_QuickCreateMenuItems): by its name.
|
|
401
|
+
if any(QUICK_CREATE_MENU in v for k, v in trail if k == "id") and "menuitem" in roles:
|
|
402
|
+
return done("quick_create_item")
|
|
403
|
+
|
|
348
404
|
# The element's own D365 name first, then the nearest around it.
|
|
349
|
-
for k, v in trail:
|
|
405
|
+
for i, (k, v) in enumerate(trail):
|
|
350
406
|
if k not in ("data-id", "id"):
|
|
351
407
|
continue
|
|
352
408
|
m = _FIELD.match(v)
|
|
353
409
|
if m:
|
|
354
410
|
scope_of(m.group(1) or "")
|
|
355
|
-
|
|
411
|
+
kind = _field_kind(m.group(2), m.group(3) or "", tag)
|
|
412
|
+
if kind == "lookup" and text.lower() == ADVANCED_LOOKUP_WORDS:
|
|
413
|
+
kind = "lookup_advanced"
|
|
414
|
+
return done(kind, field=m.group(2))
|
|
415
|
+
if k == "data-id":
|
|
416
|
+
hit = next((c for part, c in _BY_DATA_ID if part in v), "")
|
|
417
|
+
if hit:
|
|
418
|
+
return done(hit)
|
|
419
|
+
if k == "id":
|
|
420
|
+
hit = next((c for part, c in _BY_ID if part in v), "")
|
|
421
|
+
if hit:
|
|
422
|
+
return done(hit)
|
|
423
|
+
if v.startswith("quickCreateCancel"):
|
|
424
|
+
return done("quick_create_cancel")
|
|
425
|
+
if "ViewSelector" in v:
|
|
426
|
+
# A view in the selector's list is inside it (a menu item), the selector itself is not.
|
|
427
|
+
nearer = [x for kk, x in trail[:i] if kk == "role"] + ([role] if role else [])
|
|
428
|
+
return done("grid_view" if any(r in ("menuitem", "option") for r in nearer) else "grid_view_selector")
|
|
429
|
+
if k == "data-id" and (v.startswith("ignore_save") or v.startswith("close_dialog")) and out.get("dialog") == "duplicates":
|
|
430
|
+
return done("dialog_button")
|
|
356
431
|
m = _COMMAND.search(v)
|
|
357
432
|
if m and k == "data-id":
|
|
358
433
|
return done("command", bar=m.group(1), table=m.group(2), command=m.group(3))
|
|
@@ -379,13 +454,37 @@ def control(f: Dict[str, Any]) -> Dict[str, str]:
|
|
|
379
454
|
scope_of(m.group(1) or "")
|
|
380
455
|
classes = [c for c in f.get("classes") or [] if isinstance(c, str)]
|
|
381
456
|
return done("multi_select" if any(c.startswith("msos-") for c in classes) else "field", field=m.group(2))
|
|
382
|
-
#
|
|
457
|
+
# Select All (Grid_SelectAll: `button[title*="Select All"]`), a row's checkbox, a column's header.
|
|
458
|
+
title = str(attrs.get("title") or attrs.get("aria-label") or "")
|
|
459
|
+
in_grid = any("PCFGridControl" in v or "data-set-body-container" in v or _SUBGRID_GRID.match(v) for v in values)
|
|
460
|
+
if title.startswith("Select All") and (tag == "button" or role == "button" or "checkbox" in roles[:1]):
|
|
461
|
+
return done("grid_select_all")
|
|
383
462
|
column = next((v for k, v in trail if k == "col-id" and _COLUMN.match(v)), "")
|
|
463
|
+
if roles[:1] == ["checkbox"] and ("row" in roles or in_grid):
|
|
464
|
+
return done("grid_row_select")
|
|
465
|
+
if "columnheader" in roles and "gridcell" not in roles[: roles.index("columnheader")]:
|
|
466
|
+
return done("grid_column", column=column) if column else {}
|
|
467
|
+
# A grid cell, by its column (`col-id`): a link in it opens the record.
|
|
384
468
|
if column or role in ("gridcell", "row") and any("PCFGridControl" in v or "data-set-body-container" in v for v in values):
|
|
385
469
|
return done("open_record" if tag == "a" or role == "link" else "grid_cell", column=column)
|
|
386
470
|
return {}
|
|
387
471
|
|
|
388
472
|
|
|
473
|
+
# Controls a step names by the words on them as well (a record, a view, a table, a column's label).
|
|
474
|
+
TEXT_KINDS = frozenset({
|
|
475
|
+
"lookup_result", "lookup_value", "grid_cell", "open_record", "tab", "bpf_stage", "command", "choice", "status",
|
|
476
|
+
"dialog_button", "grid_view", "grid_column", "advanced_lookup_result", "quick_create_item",
|
|
477
|
+
})
|
|
478
|
+
# Controls a recipe finds only by their words: without them they are not named.
|
|
479
|
+
NEEDS_TEXT = frozenset({"grid_view", "advanced_lookup_result", "quick_create_item"})
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
FIELD_KINDS = frozenset({
|
|
483
|
+
"text", "date", "time", "lookup", "lookup_search", "lookup_result", "lookup_value", "lookup_clear", "choice", "status",
|
|
484
|
+
"boolean", "multi_select", "field", "lookup_new", "lookup_advanced",
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
|
|
389
488
|
def _shaped(c: Dict[str, str]) -> Dict[str, str]:
|
|
390
489
|
"""A control's parts, each kept only in its shape: a control of `CONTROLS`, logical names, a command id, one line."""
|
|
391
490
|
if c.get("control") not in CONTROLS:
|
|
@@ -402,11 +501,17 @@ def _shaped(c: Dict[str, str]) -> Dict[str, str]:
|
|
|
402
501
|
out["column"] = c["column"]
|
|
403
502
|
if c.get("scope") in SCOPES:
|
|
404
503
|
out["scope"] = c["scope"]
|
|
504
|
+
if out["control"] == "dialog_button" and c.get("dialog") in DIALOGS:
|
|
505
|
+
out["dialog"] = c["dialog"]
|
|
405
506
|
t = _one_line(c.get("text"))
|
|
406
507
|
if t:
|
|
407
508
|
out["text"] = t
|
|
509
|
+
if out["control"] in NEEDS_TEXT and "text" not in out:
|
|
510
|
+
return {}
|
|
511
|
+
if out["control"] == "grid_column" and "column" not in out:
|
|
512
|
+
return {}
|
|
408
513
|
# A field's control without its field, a command without its id: not named after all.
|
|
409
|
-
if out["control"] in
|
|
514
|
+
if out["control"] in FIELD_KINDS and "field" not in out:
|
|
410
515
|
return {}
|
|
411
516
|
if out["control"] == "command" and "command" not in out:
|
|
412
517
|
return {}
|
|
@@ -438,7 +543,8 @@ def control_words(c: Dict[str, Any]) -> str:
|
|
|
438
543
|
c = _shaped(dict(c)) if isinstance(c, dict) else {}
|
|
439
544
|
if not c:
|
|
440
545
|
return ""
|
|
441
|
-
kind = c["control"].replace("_", " ")
|
|
546
|
+
kind = re.sub(r"^bpf\b", "BPF", c["control"].replace("_", " "))
|
|
442
547
|
name = c.get("field") or c.get("command") or c.get("tab") or c.get("entity") or c.get("column") or ""
|
|
443
548
|
where = {"header": " in the header", "bpf": " in the process stage", "quick_create": " in Quick Create"}.get(c.get("scope", ""), "")
|
|
549
|
+
where += {"set_state": " in the Set state dialog", "duplicates": " in Duplicate records found"}.get(c.get("dialog", ""), "")
|
|
444
550
|
return f"{kind[:1].upper()}{kind[1:]} {name}".strip() + where
|
|
@@ -66,6 +66,11 @@ BASE = {
|
|
|
66
66
|
"css": 0.50,
|
|
67
67
|
# Anchored on the container that holds it, by a text only that container has (within_locator).
|
|
68
68
|
"within": 0.66,
|
|
69
|
+
# By a part of the page's role and name (the dialog "New Contact") and the element's role and name inside it: as a
|
|
70
|
+
# person names it, and unique where its own name is not.
|
|
71
|
+
"within_named": 0.86,
|
|
72
|
+
# A row by the one cell that names it (filter({ has })), then the element's role and name in it.
|
|
73
|
+
"within_key": 0.80,
|
|
69
74
|
"role_pattern": 0.80,
|
|
70
75
|
# A text by a pattern: the words that hold, with the state a page adds to them (state_pattern).
|
|
71
76
|
"text_pattern": 0.55,
|
|
@@ -102,6 +107,7 @@ SHAKY_TEXT = (
|
|
|
102
107
|
r"|\b(?:ago|just now|today|yesterday|tomorrow)\b"
|
|
103
108
|
r"|^\d{1,2}[/.-]\d{1,2}[/.-]\d{2,4}$"
|
|
104
109
|
)
|
|
110
|
+
SHAKY_RE = re.compile(SHAKY_TEXT, re.I)
|
|
105
111
|
|
|
106
112
|
_GENERATED = (
|
|
107
113
|
re.compile(r"\d{4,}"),
|
|
@@ -494,55 +500,115 @@ def _container_css(v: Any) -> bool:
|
|
|
494
500
|
)
|
|
495
501
|
|
|
496
502
|
|
|
503
|
+
# A part of the page Playwright finds by its role and accessible name (the page script's scopeFor): the dialog named
|
|
504
|
+
# "New Contact", the region "Billing". Kept in step with SCOPE_ROLES in webrecord_page.py and replay.ts.
|
|
505
|
+
NAMED_SCOPE_ROLES = frozenset({
|
|
506
|
+
"dialog", "alertdialog", "region", "form", "group", "tabpanel", "navigation", "complementary", "search", "toolbar",
|
|
507
|
+
"menu", "menubar", "list", "listbox", "grid", "table", "treegrid", "tree", "tablist", "article",
|
|
508
|
+
})
|
|
509
|
+
# The cell a row is found by (filter({ has })): KEY_ROLES in webrecord_page.py and replay.ts.
|
|
510
|
+
KEY_ROLES = frozenset({"cell", "gridcell", "rowheader"})
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def _plain_name(v: Any, limit: int = 80) -> Optional[str]:
|
|
514
|
+
"""A name read from the page, as a locator may hold it: one line, already whitespace-folded, capped; else None."""
|
|
515
|
+
if not isinstance(v, str) or not v or len(v) > limit or v != " ".join(v.split()) or _clean(v, limit) != v:
|
|
516
|
+
return None
|
|
517
|
+
return v
|
|
518
|
+
|
|
519
|
+
|
|
497
520
|
def within_locator(raw: Any) -> Optional[Dict[str, Any]]:
|
|
498
521
|
"""
|
|
499
|
-
A locator anchored on the container that holds the element (the page script's anchorFor, counted there
|
|
500
|
-
exactly it)
|
|
501
|
-
|
|
522
|
+
A locator anchored on the container that holds the element (the page script's anchorFor or scopeFor, counted there
|
|
523
|
+
as finding exactly it), in one of three shapes:
|
|
524
|
+
|
|
525
|
+
- a container by its role or a tag and class, filtered by a text only it has (``t``);
|
|
526
|
+
- a part of the page by its role and accessible name (``c: {role, name}``), the dialog named "New Contact";
|
|
527
|
+
- a row filtered by the one cell that names it (``c: {role: row}``, ``k: {role, name}``), the row of "INV-1042".
|
|
528
|
+
|
|
529
|
+
Then the element inside it by its role and name, its text, or a tag and class. Read as data: only these shapes,
|
|
530
|
+
each value one line and capped.
|
|
502
531
|
"""
|
|
503
532
|
if not isinstance(raw, dict):
|
|
504
533
|
return None
|
|
505
|
-
c, t, i = raw.get("c"), raw.get("t"), raw.get("i")
|
|
506
|
-
if not isinstance(c, dict) or not isinstance(i, dict) or not
|
|
507
|
-
return None
|
|
508
|
-
text = _clean(t, 80)
|
|
509
|
-
if not text or len(t) > 80 or t != " ".join(t.split()):
|
|
534
|
+
c, t, k, i = raw.get("c"), raw.get("t"), raw.get("k"), raw.get("i")
|
|
535
|
+
if not isinstance(c, dict) or not isinstance(i, dict) or not set(raw) <= {"c", "t", "k", "i"}:
|
|
510
536
|
return None
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
537
|
+
within: Dict[str, Any] = {}
|
|
538
|
+
shaky = False
|
|
539
|
+
if t is not None:
|
|
540
|
+
# A container filtered by a text only it has.
|
|
541
|
+
if not isinstance(t, str) or k is not None or "name" in c:
|
|
542
|
+
return None
|
|
543
|
+
text = _clean(t, 80)
|
|
544
|
+
if not text or len(t) > 80 or t != " ".join(t.split()):
|
|
545
|
+
return None
|
|
546
|
+
if c.get("role") in WITHIN_ROLES and set(c) == {"role"}:
|
|
547
|
+
box, box_words = f"page.getByRole({_q(c['role'])})", c["role"]
|
|
548
|
+
within["c"] = {"role": c["role"]}
|
|
549
|
+
elif _container_css(c.get("css")) and set(c) == {"css"}:
|
|
550
|
+
box, box_words = f"page.locator({_q(c['css'])})", c["css"]
|
|
551
|
+
within["c"] = {"css": c["css"]}
|
|
552
|
+
else:
|
|
553
|
+
return None
|
|
554
|
+
box = f"{box}.filter({{ hasText: {_q(text)} }})"
|
|
555
|
+
box_words = f"{box_words} with {text!r}"
|
|
556
|
+
within["t"] = text
|
|
557
|
+
shaky = bool(re.search(r"\d", text))
|
|
558
|
+
base = BASE["within"]
|
|
559
|
+
elif k is not None:
|
|
560
|
+
# A row by the one cell that names it.
|
|
561
|
+
if c != {"role": "row"} or not isinstance(k, dict) or set(k) != {"role", "name"} or k.get("role") not in KEY_ROLES:
|
|
562
|
+
return None
|
|
563
|
+
key = _plain_name(k.get("name"))
|
|
564
|
+
if not key:
|
|
565
|
+
return None
|
|
566
|
+
has = f"page.getByRole({_q(k['role'])}, {{ name: {_q(key)}, exact: true }})"
|
|
567
|
+
box = f"page.getByRole({_q('row')}).filter({{ has: {has} }})"
|
|
568
|
+
box_words = f"row with {k['role']} {key!r}"
|
|
569
|
+
within.update(c={"role": "row"}, k={"role": k["role"], "name": key})
|
|
570
|
+
shaky = bool(SHAKY_RE.search(key))
|
|
571
|
+
base = BASE["within_key"]
|
|
517
572
|
else:
|
|
518
|
-
|
|
573
|
+
# A part of the page by its role and name.
|
|
574
|
+
if set(c) != {"role", "name"} or c.get("role") not in NAMED_SCOPE_ROLES:
|
|
575
|
+
return None
|
|
576
|
+
name = _plain_name(c.get("name"))
|
|
577
|
+
if not name:
|
|
578
|
+
return None
|
|
579
|
+
box = f"page.getByRole({_q(c['role'])}, {{ name: {_q(name)}, exact: true }})"
|
|
580
|
+
box_words = f"{c['role']} {name!r}"
|
|
581
|
+
within["c"] = {"role": c["role"], "name": name}
|
|
582
|
+
shaky = bool(re.search(r"\d", name))
|
|
583
|
+
base = BASE["within_named"]
|
|
519
584
|
kind, value = i.get("type"), i.get("value")
|
|
520
|
-
if not isinstance(value, str) or not value or len(value) > 200 or value != " ".join(value.split()):
|
|
585
|
+
if not isinstance(value, str) or not value or len(value) > 200 or value != " ".join(value.split()) or set(i) != {"type", "value"}:
|
|
521
586
|
return None
|
|
522
587
|
if kind == "role":
|
|
523
588
|
role, _, name = value.partition("|")
|
|
524
589
|
if role not in ROLES:
|
|
525
590
|
return None
|
|
526
591
|
inner = f"getByRole({_q(role)}, {{ name: {_q(name)}, exact: true }})" if name else f"getByRole({_q(role)})"
|
|
527
|
-
elif kind == "text" and len(value) <= 80:
|
|
592
|
+
elif kind == "text" and len(value) <= 80 and "t" in within:
|
|
528
593
|
inner = f"getByText({_q(value)}, {{ exact: true }})"
|
|
529
|
-
elif kind == "css" and _container_css(value):
|
|
594
|
+
elif kind == "css" and _container_css(value) and "t" in within:
|
|
530
595
|
inner = f"locator({_q(value)})"
|
|
531
596
|
else:
|
|
532
597
|
return None
|
|
533
|
-
within
|
|
598
|
+
within["i"] = {"type": kind, "value": value}
|
|
534
599
|
loc = {
|
|
535
600
|
"type": "within",
|
|
536
|
-
"value": f"{box_words}
|
|
601
|
+
"value": f"{box_words} > {value}",
|
|
537
602
|
"within": within,
|
|
538
|
-
"playwright": f"{box}.
|
|
539
|
-
"base":
|
|
603
|
+
"playwright": f"{box}.{inner}",
|
|
604
|
+
"base": base,
|
|
540
605
|
"matches": 1,
|
|
541
606
|
"verified": True,
|
|
542
607
|
}
|
|
543
|
-
# Digits in
|
|
544
|
-
|
|
545
|
-
|
|
608
|
+
# Digits in what it is anchored on are often data that changes (a price, a date): less trusted. A row's key cell
|
|
609
|
+
# is judged by the narrower rule (SHAKY_TEXT): an invoice number is the steadiest key a row has.
|
|
610
|
+
if shaky:
|
|
611
|
+
loc["base"] = round(base * 0.6, 3)
|
|
546
612
|
loc["confidence"] = confidence(loc)
|
|
547
613
|
return loc
|
|
548
614
|
|
|
@@ -30,7 +30,7 @@ from pathlib import Path
|
|
|
30
30
|
from types import SimpleNamespace
|
|
31
31
|
from typing import Any, Awaitable, Callable, Dict, List, Optional, Set, Tuple
|
|
32
32
|
|
|
33
|
-
from .capture import capture_element, element_facts_cdp, locate_check
|
|
33
|
+
from .capture import capture_element, element_facts_cdp, locate_check, verify_within
|
|
34
34
|
from .clientcert import client_cert_host
|
|
35
35
|
from .network import NetworkCapture
|
|
36
36
|
from .d365 import ATTRS as D365_ATTRS, clean_facts as d365_clean_facts, note as d365_note
|
|
@@ -1207,6 +1207,14 @@ class RecordSession:
|
|
|
1207
1207
|
target = Target(url, live.facts, counted_at_event(live.locators, data["matches"]), live.frames, closed_shadow=closed)
|
|
1208
1208
|
# None of its own locators unique: the one anchored on its container (the page script counted it), where there is one.
|
|
1209
1209
|
anchored = within_locator(data.get("anchor"))
|
|
1210
|
+
# A named part of the page or a keyed row, while the element still shows: counted again in the browser's own
|
|
1211
|
+
# accessibility tree, whose reading of names decides over the page script's (capture.verify_within).
|
|
1212
|
+
if anchored and backend and "t" not in anchored["within"] and await self._shows(sid, int(backend)):
|
|
1213
|
+
anchored = await verify_within(_Page(self.client, sid), int(backend), anchored)
|
|
1214
|
+
if anchored is None:
|
|
1215
|
+
# Not this element alone as the browser reads it: the container by its text, counted beside it.
|
|
1216
|
+
fallback_anchor = within_locator(data.get("anchor_text"))
|
|
1217
|
+
anchored = fallback_anchor if fallback_anchor and "t" in fallback_anchor["within"] else None
|
|
1210
1218
|
if anchored and generic_name(target.facts) and not any((l.get("type") in ("test_id", "id") or l.get("site") == "d365") and l.get("verified") for l in target.locators):
|
|
1211
1219
|
# A name many controls share ("Close" of a toast): another like it may show on a replay; its container first.
|
|
1212
1220
|
locs = [anchored] + [l for l in target.locators if l.get("type") != "within"]
|
|
@@ -261,7 +261,7 @@ RECORDER_JS = r"""(() => {
|
|
|
261
261
|
const d365Path = (e) => {
|
|
262
262
|
const out = [];
|
|
263
263
|
for (let x = e, i = 0; x && x.nodeType === 1 && i <= D365.path_up && x !== document.body && out.length < D365.path_max; x = up(x), i++) {
|
|
264
|
-
for (const k of D365.path_attrs) { const v = x.getAttribute(k); if (v && out.length < D365.path_max) out.push([k, v.slice(0, 200)]); }
|
|
264
|
+
for (const k of D365.path_attrs) { const v = x.getAttribute(k); if (v && (k !== 'role' || D365.path_roles.includes(v)) && out.length < D365.path_max) out.push([k, v.slice(0, 200)]); }
|
|
265
265
|
}
|
|
266
266
|
return out;
|
|
267
267
|
};
|
|
@@ -452,17 +452,100 @@ RECORDER_JS = r"""(() => {
|
|
|
452
452
|
}
|
|
453
453
|
return null;
|
|
454
454
|
};
|
|
455
|
+
// ---- in the named part of the page that holds it, or in the row a key cell names --------------------------------
|
|
456
|
+
// A SaaS page repeats its controls: a "Save" in every dialog, an "Edit" on every row. Playwright reads a page as a
|
|
457
|
+
// person does: the Save of the dialog named "New Contact" (getByRole('dialog', { name }).getByRole('button', …)), the
|
|
458
|
+
// Edit of the row whose cell says "INV-1042" (getByRole('row').filter({ has: getByRole('cell', { name }) })…). Each
|
|
459
|
+
// is counted as Playwright's role queries count (shown, never inside aria-hidden or inert) and kept only when it finds
|
|
460
|
+
// this element alone. Kept in step with NAMED_SCOPE_ROLES and KEY_ROLES in memory.py and replay.ts.
|
|
461
|
+
const SCOPE_ROLES = new Set(['dialog', 'alertdialog', 'region', 'form', 'group', 'tabpanel', 'navigation', 'complementary',
|
|
462
|
+
'search', 'toolbar', 'menu', 'menubar', 'list', 'listbox', 'grid', 'table', 'treegrid', 'tree', 'tablist', 'article']);
|
|
463
|
+
// A tag's own role, where it is one of those (a <section> or a <form> is a region or a form only once named, and the
|
|
464
|
+
// name is required below).
|
|
465
|
+
const SCOPE_TAGS = { DIALOG: 'dialog', SECTION: 'region', FORM: 'form', FIELDSET: 'group', DETAILS: 'group', NAV: 'navigation',
|
|
466
|
+
ASIDE: 'complementary', TABLE: 'table', UL: 'list', OL: 'list', ARTICLE: 'article' };
|
|
467
|
+
const SCOPE_SEL = '[role], dialog, section, form, fieldset, details, nav, aside, table, ul, ol, article';
|
|
468
|
+
const firstRole = (x) => (x.getAttribute('role') || '').trim().split(/\s+/)[0];
|
|
469
|
+
const scopeRole = (x) => { const r = firstRole(x); if (r) return SCOPE_ROLES.has(r) ? r : ''; return SCOPE_TAGS[x.tagName] || ''; };
|
|
470
|
+
// A scope's name as Playwright computes it for these roles: aria-labelledby or aria-label, a fieldset's legend, a
|
|
471
|
+
// table's caption; never the text inside it (a dialog is not named by its heading unless it points at it).
|
|
472
|
+
const scopeName = (x) => {
|
|
473
|
+
let n = labelText(x);
|
|
474
|
+
if (!n && x.tagName === 'FIELDSET') { const l = x.querySelector(':scope > legend'); n = l ? norm(l.textContent) : ''; }
|
|
475
|
+
if (!n && x.tagName === 'TABLE') { const c = x.querySelector(':scope > caption'); n = c ? norm(c.textContent) : ''; }
|
|
476
|
+
return n;
|
|
477
|
+
};
|
|
478
|
+
const scopeNameOk = (n) => !!n && n.length <= 80 && !XP_GEN_TEXT.test(n);
|
|
479
|
+
const KEY_ROLES = new Set(['cell', 'gridcell', 'rowheader']);
|
|
480
|
+
const cellRole = (x) => {
|
|
481
|
+
const r = firstRole(x);
|
|
482
|
+
if (r) return KEY_ROLES.has(r) ? r : '';
|
|
483
|
+
if (x.tagName !== 'TD') return '';
|
|
484
|
+
const t = x.closest('table');
|
|
485
|
+
return t && ['grid', 'treegrid'].includes(firstRole(t)) ? 'gridcell' : 'cell';
|
|
486
|
+
};
|
|
487
|
+
const CELL_SEL = 'td, [role=cell], [role=gridcell], [role=rowheader]';
|
|
488
|
+
const ROW_SEL = 'tr, [role=row]';
|
|
489
|
+
const isRow = (x) => { const r = firstRole(x); return r ? r === 'row' : x.tagName === 'TR'; };
|
|
490
|
+
const cellName = (x) => labelText(x) || textOf(x);
|
|
491
|
+
// The element inside the scope by its role (and name, written whole: a name with a state at its end is left to the
|
|
492
|
+
// other anchors), as innerOf counts it there.
|
|
493
|
+
const scopeInner = (e, f, box) => {
|
|
494
|
+
if (f.name && nameKey(f.name) !== f.name) return null;
|
|
495
|
+
const i = innerOf(e, f, box);
|
|
496
|
+
return i && i.type === 'role' ? i : null;
|
|
497
|
+
};
|
|
498
|
+
const scopeFor = (e, f) => {
|
|
499
|
+
for (let box = up(e), i = 0; box && i < 12 && box !== document.body && box !== document.documentElement; box = up(box), i++) {
|
|
500
|
+
if (box.nodeType !== 1 || !axShown(box)) continue;
|
|
501
|
+
if (isRow(box)) {
|
|
502
|
+
const inner = scopeInner(e, f, box);
|
|
503
|
+
if (inner) {
|
|
504
|
+
const keys = [];
|
|
505
|
+
for (const c of box.querySelectorAll(CELL_SEL)) {
|
|
506
|
+
if (deepContains(c, e) || !axShown(c)) continue;
|
|
507
|
+
const role = cellRole(c), name = cellName(c);
|
|
508
|
+
if (role && scopeNameOk(name) && !keys.some((k) => k.name === name)) keys.push({ role, name });
|
|
509
|
+
}
|
|
510
|
+
// A name first (an invoice number, a customer), a state or an amount (SHAKY_TEXT) only after.
|
|
511
|
+
const ordered = [...keys.filter((k) => !SHAKY_TEXT.test(k.name)), ...keys.filter((k) => SHAKY_TEXT.test(k.name))].slice(0, 12);
|
|
512
|
+
const rows = ordered.length ? deepAll(ROW_SEL).filter((x) => isRow(x) && axShown(x)) : [];
|
|
513
|
+
for (const k of ordered) {
|
|
514
|
+
const same = deepAll(CELL_SEL).filter((x) => axShown(x) && cellRole(x) === k.role && cellName(x) === k.name);
|
|
515
|
+
if (same.length !== 1) continue;
|
|
516
|
+
// Every row that holds it, as filter({ has }) finds them: a row nested in another is two.
|
|
517
|
+
const holding = rows.filter((r) => deepContains(r, same[0]));
|
|
518
|
+
if (holding.length === 1 && holding[0] === box) return { c: { role: 'row' }, k, i: inner };
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
const role = scopeRole(box);
|
|
523
|
+
const name = role ? scopeName(box) : '';
|
|
524
|
+
if (scopeNameOk(name)) {
|
|
525
|
+
const peers = deepAll(SCOPE_SEL).filter((x) => scopeRole(x) === role && axShown(x) && scopeName(x) === name);
|
|
526
|
+
if (peers.length === 1 && peers[0] === box) { const inner = scopeInner(e, f, box); if (inner) return { c: { role, name }, i: inner }; }
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return null;
|
|
530
|
+
};
|
|
455
531
|
const GENERIC_NAMES = new Set(['close', '×', 'x', '✕', 'ok', 'cancel', 'delete', 'remove', 'edit', 'dismiss', 'more', 'yes', 'no', 'save', 'next', 'back', 'view', 'open']);
|
|
456
532
|
// Unique by a locator of its own: no anchor needed.
|
|
457
533
|
const uniqueAlone = (m) => [m.role, m.text, m.label, m.name, m.href, m.attr && m.attr.id, m.attr && m.attr['data-testid']].some((n) => n === 1);
|
|
458
534
|
const describeEl = (e) => {
|
|
459
535
|
const f = facts(e);
|
|
460
536
|
const m = matches(e, f);
|
|
461
|
-
let anchor = null;
|
|
537
|
+
let anchor = null, textAnchor = null;
|
|
462
538
|
// A name many controls share ("Close", "×", "Delete"): unique now, another like it may show on a replay (a second
|
|
463
539
|
// toast), so the container that holds it is kept too.
|
|
464
|
-
if (!uniqueAlone(m) || GENERIC_NAMES.has(String(f.name || f.text || '').trim().toLowerCase())) {
|
|
465
|
-
|
|
540
|
+
if (!uniqueAlone(m) || GENERIC_NAMES.has(String(f.name || f.text || '').trim().toLowerCase())) {
|
|
541
|
+
let scope = null;
|
|
542
|
+
try { scope = scopeFor(e, f); } catch (err) { scope = null; }
|
|
543
|
+
try { anchor = anchorFor(e, f); } catch (err) { anchor = null; }
|
|
544
|
+
// The named part or keyed row first; the container by its text stays beside it, for when the browser's own
|
|
545
|
+
// accessibility tree does not agree with this script's count (recordsession.py, capture.verify_within).
|
|
546
|
+
if (scope) { textAnchor = anchor; anchor = scope; }
|
|
547
|
+
}
|
|
548
|
+
return { id: ref(e), el: f, matches: m, url: location.href, ...(anchor ? { anchor } : {}), ...(textAnchor ? { anchor_text: textAnchor } : {}) };
|
|
466
549
|
};
|
|
467
550
|
|
|
468
551
|
// ---- the Recorder panel, docked in the page, with the pick highlight and the key bar --------------------------------
|