最近简单学习了playwrightr的一些好用的功能,能及时保存测试数据真的太棒了
1,运行下面的代码
import base64
from playwright.sync_api import sync_playwright
def test_download():
with sync_playwright() as p:
browser = p.chromium.launch()
context = browser.new_context()
# 启用跟踪
context.tracing.start(screenshots=True, snapshots=True)
page = context.new_page()
page.goto("https://www.baidu.com")
screenshot_bytes = page.screenshot()
print(base64.b64encode(screenshot_bytes))
# 关闭跟踪
context.tracing.stop(path="trace.zip")
context.close()
browser.close()
2,以上的简单测试流程就及时保存在trace.zip中啦,然后运行相关的命令就可以查看整个测试过程啦