기술나눔

使用pytest-playwright截图和录制视频并添加到Allure报告

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

一、依赖环境

python, version3.9.5
pytest-playwright, version==0.5.1
allure-pytest, version
2.13.5
pytest, version6.2.5
allure, version
2.22.0

pytest-playwright支持如下命令行参数:

Playwright:
  --browser={chromium,firefox,webkit}
                        Browser engine which should be used
  --headed              Run tests in headed mode.
  --browser-channel=BROWSER_CHANNEL
                        Browser channel to be used.
  --slowmo=SLOWMO       Run tests with slow mo
  --device=DEVICE       Device to be emulated.
  --output=OUTPUT       Directory for artifacts produced by tests, defaults to test-results.
  --tracing={on,off,retain-on-failure}
                        Whether to record a trace for each test.
  --video={on,off,retain-on-failure}
                        Whether to record video for each test.
  --screenshot={on,off,only-on-failure}
                        Whether to automatically capture a screenshot after each test.
  --full-page-screenshot
                        Whether to take a full page screenshot

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

二、参数说明

pytest-playwright 插件的这3 个参数用于截图,录屏和跟踪:

  • --tracing 是否为每个测试记录轨迹。onoffretain-on-failure(默认值:off)。
  • --video 是否为每次测试录制视频。onoffretain-on-failure(默认值:off)。
  • --