【问题标题】:Is there any selenium/python script for the Screen Recording?屏幕录制是否有任何 selenium/python 脚本?
【发布时间】:2022-08-05 21:01:18
【问题描述】:

我想通过在 python 中使用 selenium 来记录屏幕,我搜索了这些,但我只得到 java 的结果和屏幕截图。请让我知道是否有任何脚本可以记录屏幕。

    标签: selenium selenium-webdriver selenium-chromedriver automation-testing


    【解决方案1】:

    你需要记录谁的截图?试试这个library

    并尝试以下代码:

    from clicknium import clicknium as cc, locator, ui
    cc.get_screenshot("D:\\test.jpg")
    

    【讨论】:

    • Clicknium:Clicknium 扩展可帮助您轻松捕获和管理 UI 定位器。只需单击目标 UI 元素即可生成定位器,使用 clicknium python 模块,您可以立即启动 Web 和桌面的自动化。该扩展还提供编码中的定位器智能感知、云中的集中定位器管理和分发项目。
    • 这只是为了截图,我要求在自动化测试执行期间记录屏幕
    【解决方案2】:

    试试这个,非常流行的框架,例如。 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"

    使用这个魅力框架,您将获得带有屏幕截图的测试报告:

    【讨论】:

      猜你喜欢
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2022-08-04
      相关资源
      最近更新 更多