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.
41 lines
1.8 KiB
41 lines
1.8 KiB
# -*- coding: utf-8 -*-
|
|
"""demo 页面探针:登录→分组列表→新建分组,抓取每步 DOM 状态与 console"""
|
|
import pathlib, sys, io, time
|
|
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"
|
|
logs = []
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True)
|
|
page = browser.new_page()
|
|
page.set_default_timeout(15000)
|
|
page.on("console", lambda m: logs.append(f"[console.{m.type}] {m.text}"))
|
|
page.on("pageerror", lambda e: logs.append(f"[pageerror] {e}"))
|
|
page.goto(DEMO.as_uri() + "?api=" + API)
|
|
page.wait_for_load_state("networkidle")
|
|
time.sleep(1)
|
|
print("== init 后 gBody HTML(前300):", page.inner_html("#gBody")[:300].replace("\n"," "))
|
|
print("== apiBox:", page.text_content("#apiBox"))
|
|
page.click("button:has-text('uid 登录')")
|
|
page.wait_for_selector(".toast-item:has-text('登录成功')", timeout=15000)
|
|
time.sleep(1.5)
|
|
rows = page.locator("#gBody tr").count()
|
|
print("== 登录后 gBody 行数:", rows)
|
|
print("== gBody 第一行:", page.inner_html("#gBody")[:300].replace("\n"," "))
|
|
# 打开新建分组弹窗
|
|
page.click("button:has-text('+ 新建分组')")
|
|
page.wait_for_selector("#fgName")
|
|
page.fill("#fgName", "e2d-探针分组")
|
|
page.fill("#fgCode", "e2d_probe_grp")
|
|
page.click(".dfoot button.ok")
|
|
time.sleep(3)
|
|
toasts = page.locator(".toast-item").all_text_contents()
|
|
print("== toasts:", toasts)
|
|
print("== dlg open?", page.evaluate("document.getElementById('dlg').open"))
|
|
print("== fgOut:", page.inner_html("#fgOut")[:400])
|
|
print("== logs:")
|
|
for l in logs[-15:]: print(" ", l)
|
|
browser.close()
|
|
|