nex_animation/reports/ui_evidence/nex-p21/tabtrace.py

60 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# -*- coding: utf-8 -*-
"""分镜页 Tab 走位定点探针 v2:按元素身份(打句柄)去重,看真实走位终点。"""
import os, json
from playwright.sync_api import sync_playwright
BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173")
W = int(os.environ.get("W", "1440"))
MARK = """() => {
let n = 0;
const sel = 'a[href],button,input,select,textarea,[tabindex],[contenteditable="true"]';
for (const el of document.querySelectorAll(sel)) {
if (el.getAttribute('tabindex') === '-1' || el.disabled) continue;
const r = el.getBoundingClientRect(), cs = getComputedStyle(el);
if (!(r.width>1 && r.height>1 && cs.visibility!=='hidden' && cs.display!=='none' && el.offsetParent!==null)) continue;
el.dataset.nexProbe = 'p' + (++n);
}
return n;
}"""
PROBE = """() => {
const a = document.activeElement;
if (!a || a === document.body || a === document.documentElement) return null;
const cards = [...document.querySelectorAll('[data-shot-card]')];
const ci = cards.findIndex(c => c.contains(a));
return {h: a.dataset.nexProbe || '(untagged)',
tag: a.tagName.toLowerCase(),
name: (a.getAttribute('aria-label') || (a.innerText||'').trim() || '').replace(/\\s+/g,' ').slice(0,16),
inCard: ci, inDrawer: a.closest('.ant-drawer')?1:0};
}"""
res = {}
with sync_playwright() as pw:
br = pw.chromium.launch()
ctx = br.new_context(viewport={"width": W, "height": 900})
pg = ctx.new_page()
pg.goto(BASE + "/login", wait_until="domcontentloaded")
pg.wait_for_selector("#login-user", timeout=15000)
pg.fill("#login-user", "admin"); pg.fill("#login-pass", "admin1234")
pg.click("button[type=submit]"); pg.wait_for_timeout(700)
pg.evaluate("(t)=>localStorage.setItem('nex-the', t)", "light")
pg.goto(BASE + "/projects/10/storyboard", wait_until="domcontentloaded")
pg.wait_for_selector("[data-shot-card]", timeout=20000)
pg.wait_for_timeout(1500)
res["census"] = pg.evaluate(MARK)
pg.evaluate("""() => {const a=document.activeElement; if(a&&a.blur)a.blur();
document.body.setAttribute('tabindex','-1'); document.body.focus(); window.scrollTo(0,0);}""")
pg.wait_for_timeout(400)
seen, term, stops = set(), "?", []
for i in range(140):
pg.keyboard.press("Tab"); pg.wait_for_timeout(110)
d = pg.evaluate(PROBE)
if not d:
term = "焦点掉出文档@%d" % (i + 1); break
if d["h"] in seen:
term = "绕回同一元素(%s)@%d" % (d["h"], i + 1); break
seen.add(d["h"]); stops.append(d)
res["stations"] = len(stops); res["term"] = term
res["inCard_stops"] = len([s for s in stops if s["inCard"] >= 0])
res["untagged_stops"] = len([s for s in stops if s["h"] == "(untagged)"])
res["stop_30_46"] = stops[29:46]
print(json.dumps(res, ensure_ascii=False, indent=1))
br.close()