【发布时间】:2022-08-05 21:01:18
【问题描述】:
我想通过在 python 中使用 selenium 来记录屏幕,我搜索了这些,但我只得到 java 的结果和屏幕截图。请让我知道是否有任何脚本可以记录屏幕。
标签: selenium selenium-webdriver selenium-chromedriver automation-testing
我想通过在 python 中使用 selenium 来记录屏幕,我搜索了这些,但我只得到 java 的结果和屏幕截图。请让我知道是否有任何脚本可以记录屏幕。
标签: selenium selenium-webdriver selenium-chromedriver automation-testing
试试这个,非常流行的框架,例如。 java或python等
在 cmd 行中:pip install allure-pytest
去这里:https://docs.qameta.io/allure/
第 2.1 节。安装命令行
下载最新版本,例如。 windows xxx.zip
bin 文件夹的复制路径 例如:D:\Drivers\allure-2.18.1\bin
并将其粘贴到环境变量>找到“路径”并编辑它>
使用 bin 路径添加新路径。
到您的 test.py 文件:
进口诱惑
从 allure_commons.types 导入 AttachmentType
并将其添加到您的测试末尾,例如:断言语句
例子:
method_name = self.driver.find_element(By.XPATH, "xxx").text
if method_name == 'some text':
assert True
else:
allure.attach(self.driver.get_screenshot_as_png(), name="test_name",
attachment_type=AttachmentType.PNG)
assert False
在 IDE 终端或 cmd 中执行以下操作:
pytest -v -s --alluredir="D:\projectPath\raport" 路径/to/your/tests
然后将执行测试
在终端执行此操作以从测试中读取报告:
allure serve "D:\raport\Path"
使用这个魅力框架,您将获得带有屏幕截图的测试报告:
【讨论】: