"""Scripted (model-free) solutions for suite C, used to validate every task before it enters the suite. python apps/suite_c_scripts.py [name-filter] REPEATS=3 -> each script must pass its check every run python apps/suite_c_scripts.py --probe URL [step ...] interactive probe: print the observed actions after the steps A script is a list of steps executed against jev's Browser (observe -> pick the action by label -> act): ("click", "label substring") ("fill", "label substring", "text") ("select", "label substring", "option label substring") ("enter",) ("scroll", n) ("sleep", seconds) Labels match case-insensitively; a "re:" prefix means a regular expression; "#k" suffix picks the k-th match (0-based); an "@role " prefix (e.g. "@button re:^Search$") restricts the match to that role. Each task's check is run on the start page too (must FAIL there) and on the final page (must PASS). """ import json, os, re, sys, time sys.path.insert(0, "/home/ckl/projects/S/jev-ultrafast") os.environ.setdefault("BU_CDP_URL", "http://127.0.0.1:9222") from jev_ultrafast.browser import Browser, StalePage # noqa: E402 def observe(br, tries=12, settle=0.0): time.sleep(settle) for i in range(tries): try: return br.observe(screenshot=False) except StalePage: if i == tries - 1: raise time.sleep(0.5) def find(page, kind, label): """First action of `kind` whose label matches; "@role " prefix restricts the role, "re:" = regex, "#k" = k-th match.""" idx = 0; role = None if label.startswith("@"): role, _, label = label[1:].partition(" ") m = re.search(r"#(\d+)$", label) if m: idx, label = int(m.group(1)), label[: m.start()] if label.startswith("re:"): pat = re.compile(label[3:], re.I) hits = [a for a in page["actions"] if a["kind"] == kind and pat.search(a["label"])] else: hits = [a for a in page["actions"] if a["kind"] == kind and label.lower() in a["label"].lower()] if role: hits = [a for a in hits if a.get("role") == role] if len(hits) <= idx: raise LookupError(f"no {kind} action matching {label!r} (have {[a['label'][:40] for a in page['actions'] if a['kind']==kind][:40]})") return hits[idx] def find_select(page, label, option): """Select action whose