webui自动化框架-playwright
Playwright 为现代 web 应用提供了跨浏览器、快速且可靠的端到端的测试能力。 | Playwright 中文文档 | Playwright 中文网 (bootcss.com)
with sync_playwright() as p: #启动浏览器,默认是True无头模式 browser = p.chromium.launch(headless=False) #打开一个标签页 page = browser.new_page() #访问目标网址 page.goto("https://www.baidu.com") print(page.title) #关闭浏览器 broswer.close()
import asyncio from playwright.async_api import async_playwright with async_playwright() as p: browser = await p.chromium.launch(headless = True) page = await browser.new_page() await page.goto("https://www.baidu.com) print(await page.title) await browser.close()
browser = p.chromium.launch(headless=False, args=[--start-maximiszed]) context = browser.new_context(no_viewport=True) page = context.new_page()
browser = p.chromium.launch(headless=False, args=[--start-maximiszed]) page = browser.new_page(no_viewport=True)
browser = p.chromium.launch(channel="msedge")
context = p.chromium.launch_persistent_context(user_data_dir=Path})
browser = p.chromium.launch(headless=False, slow_mo=500) context = browser.new_content(record_video_dir="videos/") context.close()
context = browser.new_context() context.tracing.start(screenshots=True, snapshots=True, sources=True) page = context.new_page() context.tracing.stop(path="trace.zip")
with page.expect_navigation(url="**/GPT-4"): page.get_by_role("button", name="xxx").click()
context = browser.new_context(storage_state="auth.json")