129 lines
5.3 KiB
Python
129 lines
5.3 KiB
Python
#!/usr/bin/env python3
|
|
"""复现:项目列表卡片改名是否真正落库/刷新后是否保留。
|
|
用法: python3 scripts/dbg_rename.py
|
|
"""
|
|
import sys, asyncio, json
|
|
|
|
BASE = "https://127.0.0.1:3005"
|
|
|
|
|
|
async def main():
|
|
from playwright.async_api import async_playwright
|
|
async with async_playwright() as p:
|
|
browser = await p.chromium.launch(args=["--ignore-certificate-errors"])
|
|
ctx = await browser.new_context(ignore_https_errors=True,
|
|
viewport={"width": 1600, "height": 900})
|
|
page = await ctx.new_page()
|
|
errs = []
|
|
page.on("pageerror", lambda e: errs.append(str(e)))
|
|
|
|
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded", timeout=120000)
|
|
await page.wait_for_timeout(5000)
|
|
|
|
# 预置本地存储文件夹句柄(与 e2e_quickvideo_cover.py 的 GUARD 一致)
|
|
GUARD = """async () => {
|
|
try {
|
|
const root = await navigator.storage.getDirectory();
|
|
const db = await new Promise((res, rej) => {
|
|
const rq = indexedDB.open('H5VideoLocalDB');
|
|
rq.onupgradeneeded = () => rq.result.createObjectStore('folderHandles');
|
|
rq.onsuccess = () => res(rq.result);
|
|
rq.onerror = () => rej(rq.error);
|
|
});
|
|
const done = await new Promise((res, rej) => {
|
|
const tx = db.transaction('folderHandles', 'readwrite');
|
|
const st = tx.objectStore('folderHandles');
|
|
const rec = { id: 'root', handle: root };
|
|
if (st.keyPath) st.put(rec); else st.put(rec, 'root');
|
|
tx.oncomplete = () => res(true);
|
|
tx.onerror = () => rej(tx.error);
|
|
});
|
|
db.close();
|
|
return done;
|
|
} catch (e) { return String(e); }
|
|
}"""
|
|
print("GUARD:", await page.evaluate(GUARD))
|
|
await page.reload(wait_until="domcontentloaded")
|
|
await page.wait_for_timeout(6000)
|
|
|
|
print("URL:", page.url)
|
|
print("TITLE:", await page.title())
|
|
|
|
# 若无项目,先创建一个
|
|
if await page.locator("input[class*='__name__']").count() == 0:
|
|
btn = page.get_by_text("创建项目", exact=True).first
|
|
if await btn.count():
|
|
await btn.click()
|
|
await page.wait_for_timeout(6000)
|
|
# 创建后可能跳进编辑器,返回列表
|
|
if "workspace/draft" not in page.url:
|
|
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded", timeout=120000)
|
|
await page.wait_for_timeout(5000)
|
|
print("创建后 name input count:", await page.locator("input[class*='__name__']").count())
|
|
|
|
# 列表卡片名输入框
|
|
inputs = page.locator("input[class*='__name__']")
|
|
n = await inputs.count()
|
|
print("input.title count:", n)
|
|
if n == 0:
|
|
# 打印可见输入框与页面骨架
|
|
allin = page.locator("input")
|
|
print("all input count:", await allin.count())
|
|
for i in range(min(await allin.count(), 8)):
|
|
el = allin.nth(i)
|
|
print(" input", i, await el.get_attribute("class"),
|
|
repr(await el.get_attribute("value")),
|
|
"visible=", await el.is_visible())
|
|
print("BODY:", (await page.inner_text("body"))[:600])
|
|
await browser.close()
|
|
return 1
|
|
|
|
old = await inputs.first.get_attribute("value")
|
|
print("原名:", repr(old))
|
|
|
|
# 聚焦 + 全选 + 输入 + 失焦
|
|
await inputs.first.click()
|
|
await page.keyboard.press("Control+a")
|
|
await page.keyboard.type("RENAME_TEST_001")
|
|
await page.keyboard.press("Tab")
|
|
await page.wait_for_timeout(2000)
|
|
|
|
val_after = await inputs.first.input_value()
|
|
print("失焦后输入框:", repr(val_after))
|
|
|
|
# 读 IndexedDB projects 表
|
|
async def read_meta():
|
|
return await page.evaluate("""async () => {
|
|
try {
|
|
const rq = indexedDB.open('H5VideoLocalDB');
|
|
const db = await new Promise((res, rej) => { rq.onsuccess=()=>res(rq.result); rq.onerror=()=>rej(rq.error); });
|
|
const tx = db.transaction('projects','readonly');
|
|
const all = await new Promise((res, rej) => {
|
|
const r = tx.objectStore('projects').getAll();
|
|
r.onsuccess=()=>res(r.result); r.onerror=()=>rej(r.error);
|
|
});
|
|
return all.map(x => ({id:x.id, name:x.name, updatedAt:x.updatedAt}));
|
|
} catch(e){ return 'ERR:'+e; }
|
|
}""")
|
|
|
|
meta1 = await read_meta()
|
|
print("失焦后 IndexedDB:", json.dumps(meta1, ensure_ascii=False))
|
|
|
|
# 刷新
|
|
await page.reload(wait_until="domcontentloaded")
|
|
await page.wait_for_timeout(5000)
|
|
inputs2 = page.locator("input[class*='__name__']")
|
|
n2 = await inputs2.count()
|
|
print("刷新后 input.title count:", n2)
|
|
if n2:
|
|
print("刷新后输入框值:", repr(await inputs2.first.input_value()))
|
|
meta2 = await read_meta()
|
|
print("刷新后 IndexedDB:", json.dumps(meta2, ensure_ascii=False))
|
|
|
|
print("JS errors:", errs[:5])
|
|
await browser.close()
|
|
return 0
|
|
|
|
|
|
sys.exit(asyncio.run(main()))
|