将playwright的trace.zip保存加上时间,可以很直观的方便对测试的结果进行查找,分析哪一步出现了问题,并且知道这个问题出现在了哪一天哪个时间点!
from playwright.sync_api import Playwright, sync_playwright, expect import pytest import datetime now=datetime.datetime.now() date_time_str=now.strftime("%Y-%m-%d_%H-%M-%S") zip_filename=f"_{date_time_str}.zip" @pytest.mark.run(order=1) def test_two(playwright: Playwright) -> None: browser = playwright.chromium.launch(headless=False) context = browser.new_context() context.tracing.start(screenshots=True, snapshots=True) page = context.new_page() page.goto("http://www.baidu.com") page.locator("#kw").click() page.locator("#kw").fill("test2") page.locator("#kw").press("Enter") context.tracing.stop(path="test_two"+zip_filename) # --------------------- context.close() browser.close()
运行上面的代码就可以看到生成了一个zip压缩包
通过这个压缩包我们就知道这个trace中的test_two脚本是在2024年5月31日的早上9点过3分二十秒跑的,这样就方便我们查找啦!!!