Files
pricing_review/CostReview/app/tests/_shot_245.py

96 lines
4.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""决策 245 截图取证:真实页面(临时副本服务)拍工作台/后台两个弹框,供主人过目。
跑法:python app/tests/_shot_245.py → 产物 app/tests/_shots_245/*.png(不留服务进程)
"""
import os
import shutil
import subprocess
import sys
import time
from pathlib import Path
HERE = Path(__file__).resolve().parent
sys.path.insert(0, str(HERE))
from api_harness import _free_port # noqa: E402
ROOT = HERE.parent.parent / "_dbg_shot245"
OUT = HERE / "_shots_245"
def main():
if ROOT.exists():
shutil.rmtree(ROOT)
app_dst = ROOT / "CostReview" / "app"
shutil.copytree(HERE.parent, app_dst,
ignore=shutil.ignore_patterns("__pycache__", "_deprecated", "tests", "_shots_245"))
lic = ROOT / "lic"
lic.mkdir()
(lic / "config.json").write_text('{"enforce": false}', encoding="utf-8")
OUT.mkdir(exist_ok=True)
port = _free_port()
env = dict(os.environ, PR_PORT=str(port), LICENSE_DATA_DIR=str(lic))
log = open(ROOT / "server.log", "wb")
proc = subprocess.Popen([sys.executable, "run_server_headless.py"],
cwd=str(app_dst), env=env, stdout=log, stderr=subprocess.STDOUT)
base = "http://127.0.0.1:%d" % port
try:
import httpx
cl = httpx.Client(base_url=base, timeout=60)
deadline = time.time() + 30
while time.time() < deadline:
try:
if cl.get("/api/license/status").status_code == 200:
break
except Exception:
time.sleep(0.3)
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
br = p.chromium.launch(channel="msedge", headless=True)
pg = br.new_page(viewport={"width": 1440, "height": 900})
pg.goto(base + "/workbench.html")
pg.wait_for_load_state("networkidle")
pg.click("button:has-text('打开项目')")
pg.wait_for_selector("#omask.on #ofile")
pg.wait_for_timeout(400)
pg.locator("#odlg").screenshot(path=str(OUT / "1_工作台_打开项目.png"))
# 后台
pg.goto(base + "/admin.html")
pg.wait_for_load_state("networkidle")
pg.click("#btnImp")
pg.wait_for_selector("#imask.on #ifile")
pg.wait_for_timeout(600)
pg.locator("#idlg").screenshot(path=str(OUT / "2_后台_打开项目.png"))
pg.click("#impBtnX")
pg.wait_for_selector("#apanel", state="visible")
pg.wait_for_timeout(400)
print(pg.evaluate("""()=>{
const g=s=>{const e=document.querySelector(s); if(!e) return null; const r=e.getBoundingClientRect();
return {w:Math.round(r.width),l:Math.round(r.left),ow:e.offsetWidth,sw:e.scrollWidth};};
return {dlg:g('#idlg'),body:g('#ibody'),left:g('#ileft'),panel:g('#apanel'),
foot:g('#idlg > div:last-child'),remind:g('#imRemind'),btn:g('#ibtnGo'),
cls:document.querySelector('#idlg').className,
st:document.querySelector('#idlg').style.width};
}"""), flush=True)
pg.locator("#idlg").screenshot(path=str(OUT / "3_后台_导入Excel树区.png"))
# 价格类(市场价)弹框:字段按 kind 条件显示,确认没被统一改坏
pg.click("#idlg button:has-text('取消')")
pg.wait_for_timeout(300)
pg.click(".tab[data-kind='market']")
pg.wait_for_timeout(400)
pg.click("#btnImp")
pg.wait_for_selector("#imask.on #ifile")
pg.wait_for_timeout(400)
pg.locator("#idlg").screenshot(path=str(OUT / "4_后台_市场价导入.png"))
br.close()
print("saved:", [p.name for p in OUT.glob("*.png")], flush=True)
return 0
finally:
proc.kill()
time.sleep(0.5)
shutil.rmtree(ROOT, ignore_errors=True)
if __name__ == "__main__":
sys.exit(main())