【问题标题】:how to send screenshots from robotframework to reportportal如何将屏幕截图从机器人框架发送到报告门户
【发布时间】:2019-12-07 11:34:28
【问题描述】:

我有一个机器人测试用例来升级我的盒子... 如果有任何错误,机器人框架会截取屏幕截图并将 screenshot.png 保存在报告目录中。

现在我如何将其发送到 reportportal.in

我在运行机器人时传递报告门户信息,如下所示..

robot --outputDir /opt/robotframework/reports --listener robotframework_reportportal.listener -v RP_UUID:07-aeb0-315c81358edd -v RP_ENDPOINT:http://<reportportalipaddress>:8080  -v RP_LAUNCH:TEST_UPGRADE  -v RP_PROJECT:TEST_UPGRADE /opt/robotframework/tests

我的机器人测试用例

***Test Cases***
FROM_GUI
    Close All Browsers
    Open Browser    ${URL}    gc
    Input Text    name:username    admin
    Input Password    name:password    &{${CPE}}[cpe_password]
    Click Button    name:Continue
    Log to Console    Inside GUI ${uploadPath}//${uploadFile}
    input text    name=uploadFile    ${uploadPath}//${uploadFile}
    Page Should Contain    firmware update is in progress
    sleep    10 seconds
    click link    link=Logout
    Close All Browsers
    Sleep     180 seconds
    with open("../", "rb") as image_file:
        file_data = image_file.read()

    rp_logger.info("Some Text Here",
                            attachment={"name": "selenium-screenshot-1.png",
                                                 "data": file_data,
                                                 "mime": "image/png"})
    [Teardown]

在报告门户中

我只看到下面,看不到截图

</td></tr><tr><td colspan="3"><a href="selenium-screenshot-1.png"><img src="selenium-screenshot-1.png" width="800px"></a>

【问题讨论】:

    标签: robotframework reportportal


    【解决方案1】:

    我已经尝试了两种方法来做到这一点(可能还有更多):

    1. 将图像嵌入到报告中,它也将嵌入到报告门户报告中。

    使用 SeleniumLibrary 提供的 Run-on-failure 功能: SeleniumLibrary 有一个方便的功能,如果它自己的任何关键字失败,它可以自动执行关键字。默认情况下,它使用捕获页面截图 关键词。更多信息请访问official documentation

    默认情况下,捕获页面屏幕截图的文件名值为

    文件名 = selenium-screenshot-{index}.png

    您可以在加载 Selenium 库时为 run_on_failure 参数提供自定义关键字。

    在自定义关键字中调用捕获页面屏幕截图,文件名=EMBED,如下所示。

    *** Settings ***
    Library           SeleniumLibrary    run_on_failure=Capture Screenshot and embed it into the report
    
    *** Keywords ***
    Capture Screenshot and embed it into the report
        Capture Page Screenshot    filename=EMBED
    

    注意:当您将图像嵌入到报告中时,图像文件不会作为单独的文件出现在您的 Result 文件夹中。

    1. 捕获屏幕截图并将其作为附件发送: 使用以下函数 robotframework-reportportal documentation 创建自定义 python 库,例如:utilityLib.py:
    from robotframework_reportportal import logger
    
    @keyword
    def send_attachment_to_report_portal(path):
      with open(path, "rb") as image_file:
        file_data = image_file.read()
      logger.info("Some Text Here",
        attachment={"name": "test_name_screenshot.png",
                    "data": file_data,
                    "mime": "image/png"})
    

    与第一种解决方案中的步骤类似:通过 Run-on-failure 功能调用自定义关键字

    *** Settings ***
    Library           SeleniumLibrary    run_on_failure=Capture Screenshot and attach it to reportportal
    Library           utilityLib.py
    
    *** Keywords ***
    Capture Screenshot and attach it to reportportal
        ${path} =    Capture Page Screenshot
        Send attachment to report portal    ${path}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 2020-06-11
      • 2019-08-16
      • 1970-01-01
      • 2021-04-11
      相关资源
      最近更新 更多