File size: 2,323 Bytes
d61897b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import asyncio, sys, time
from playwright.async_api import async_playwright
URL = "http://localhost:5173/preview/production/ed5ba841-ed53-4eec-a8c5-93237d26b7ab/"
async def main():
    async with async_playwright() as p:
        b = await p.chromium.launch(args=["--use-gl=angle","--use-angle=swiftshader","--enable-unsafe-swiftshader","--autoplay-policy=no-user-gesture-required"])
        pg = await b.new_page(viewport={"width": 1280, "height": 860}, accept_downloads=True)
        logs=[]
        pg.on("console", lambda m: logs.append(m.type+": "+m.text) if m.type in ("error","warning") else None)
        pg.on("pageerror", lambda e: logs.append("PAGEERROR: "+str(e)))
        await pg.goto(URL); await pg.wait_for_timeout(6000)
        print("play visible", await pg.locator("text=点击播放").count())
        await pg.locator("text=点击播放").click(); await pg.wait_for_timeout(4000)
        print("time", await pg.locator("span.tabular-nums").first.inner_text())
        await pg.screenshot(path="/tmp/e2e_play.png")
        await pg.locator("button:has-text('平台文案')").click(); await pg.wait_for_timeout(500)
        print("copy cards", await pg.locator("text=复制全部").count())
        await pg.locator("button:has-text('封面')").click(); await pg.wait_for_timeout(15000)
        print("covers", await pg.locator("text=PNG").count())
        await pg.screenshot(path="/tmp/e2e_cover.png", full_page=True)
        if len(sys.argv) > 1:
            await pg.locator("button:has-text('导出视频')").click()
            await pg.locator("button:has-text('24')").first.click()
            t0=time.time()
            async with pg.expect_download(timeout=1500000) as dl:
                await pg.locator("button:has-text('导出 MP4')").click()
                while True:
                    await pg.wait_for_timeout(20000)
                    try: print("prog", (await pg.locator("text=/第 \\d+/").inner_text(timeout=1000)), int(time.time()-t0), flush=True)
                    except Exception: break
            d = await dl.value
            await d.save_as("/tmp/out.mp4"); print("saved", int(time.time()-t0))
            fails = await pg.locator("text=导出失败").count(); print("fail", fails)
        for l in logs[:20]: print(l[:400])
        await b.close()
asyncio.run(main())