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.
60 lines
2.7 KiB
60 lines
2.7 KiB
|
4 hours ago
|
# -*- coding: utf-8 -*-
|
||
|
|
"""定向探针:demo 编辑分组改状态,抓请求 URL/响应/ID 精度"""
|
||
|
|
import pathlib, sys, io, time, re
|
||
|
|
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/group" in r.url:
|
||
|
|
try: body = r.text()[:200]
|
||
|
|
except Exception: body = "<no body>"
|
||
|
|
reqs.append((r.request.method, r.request.post_data, r.url[-90:], 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)
|
||
|
|
time.sleep(1)
|
||
|
|
# 造一个探针分组(走 demo 弹窗)
|
||
|
|
page.click("button:has-text('+ 新建分组')")
|
||
|
|
page.fill("#fgName", "e2d-探针编辑")
|
||
|
|
page.fill("#fgCode", "e2d_probe_edit_%d" % time.time())
|
||
|
|
page.click(".dfoot button.ok")
|
||
|
|
page.wait_for_selector(".toast-item:has-text('分组保存成功')", timeout=15000)
|
||
|
|
time.sleep(0.8)
|
||
|
|
# 搜到它
|
||
|
|
page.fill("#gKeyword", "e2d-探针编辑")
|
||
|
|
page.click("#tab-group .viewbar button:has-text('查询')")
|
||
|
|
time.sleep(0.8)
|
||
|
|
name_id = page.evaluate("() => { const m = document.querySelector('#gBody td.ops button').getAttribute('onclick'); return m; }")
|
||
|
|
print("编辑按钮 onclick:", name_id)
|
||
|
|
m = re.search(r"dlgGroup\((\d+)\)", name_id)
|
||
|
|
gid = m.group(1)
|
||
|
|
print("gid from attr:", gid)
|
||
|
|
# id 在 JS 里的形态(list 数据)
|
||
|
|
js_id = page.evaluate("() => (window.S_G && S_G.rows && S_G.rows[0] ? typeof S_G.rows[0].id + ':' + String(S_G.rows[0].id) : 'none')")
|
||
|
|
print("JS 中 rows[0].id:", js_id)
|
||
|
|
# 打开编辑、改状态、保存
|
||
|
|
page.click(f"#gBody td.ops button:has-text('编辑')")
|
||
|
|
page.wait_for_selector("#fgStatus")
|
||
|
|
page.select_option("#fgStatus", "0")
|
||
|
|
page.click(".dfoot button.ok")
|
||
|
|
time.sleep(2.5)
|
||
|
|
print("toasts:", page.locator(".toast-item").all_text_contents())
|
||
|
|
print("fgOut:", page.inner_html("#fgOut")[:200])
|
||
|
|
time.sleep(0.8)
|
||
|
|
badges = page.locator("#gBody tr:has-text('e2d-探针编辑') .badge").all_text_contents()
|
||
|
|
print("行内 badge:", badges)
|
||
|
|
print("== 网络请求轨迹:")
|
||
|
|
for r in reqs: print(" ", r[0], "|", r[1], "|", r[2], "|", r[3], "|", r[4])
|
||
|
|
browser.close()
|