You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.5 KiB

4 hours ago
# -*- coding: utf-8 -*-
"""探针:复刻 demo_smoke 步骤17→18 的 tab 切换 + 查询路径,dump 中间状态"""
import pathlib, sys, io, time, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
from playwright.sync_api import sync_playwright
ROOT = pathlib.Path(__file__).resolve().parent
DEMO = ROOT / "demo" / "index.html"
API = "http://localhost:8080"
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.set_default_timeout(15000)
reqs = []
def on_resp(r):
if "/api/dict" in r.url:
try: body = r.text()[:160]
except Exception: body = "<no body>"
reqs.append((r.request.method, r.request.post_data, r.url[-70:], r.status, body))
page.on("response", on_resp)
page.goto(DEMO.as_uri() + "?api=" + API)
page.wait_for_load_state("networkidle")
page.click("button:has-text('uid 登录')")
page.wait_for_selector(".toast-item:has-text('登录成功')", timeout=15000)
page.wait_for_selector("#gBody tr td", timeout=15000)
# 直接进 item tab,选 customer_type 组,确认 b 可见
page.click("nav.tabs button[data-tab='item']")
page.wait_for_timeout(600)
import re
pairs = page.eval_on_selector_all("#iGroup option", "os => os.map(o => [o.value, o.textContent])")
ct = next((v for v, t in pairs if t.startswith('客户类型')), '')
page.select_option("#iGroup", ct)
page.wait_for_timeout(600)
n1 = page.locator("#iBody tr:has-text('e2d-演示类型B')").count()
print("[A] customer_type 过滤下 b 行数:", n1)
# 去别的 tab 再回来(模拟步骤17 从 ref tab 切回)
page.click("nav.tabs button[data-tab='ref']")
page.wait_for_timeout(400)
page.click("nav.tabs button[data-tab='item']")
page.wait_for_timeout(400)
print("[B] 回来后 iGroup value:", page.eval_on_selector("#iGroup", "e => e.value"))
# 复刻步骤18:清组过滤 + keyword 查询
page.select_option("#iGroup", "")
page.fill("#iKeyword", "e2d_type_b")
page.click("#tab-item .viewbar button:has-text('查询')")
page.wait_for_timeout(1500)
n2 = page.locator("#iBody tr:has-text('e2d-演示类型B')").count()
body_head = page.eval_on_selector("#iBody", "e => e.innerHTML.slice(0, 240)")
print("[C] 查询后 b 行数:", n2)
print("[C] #iBody 头 240 字:", body_head.replace(chr(10), ' '))
print("== 网络轨迹(最后6条):")
for r in reqs[-6:]:
print(" ", r[0], "|", r[1], "|", r[2], "|", r[3], "|", r[4])
browser.close()