首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从robotframework向reportportal发送截图

如何从robotframework向reportportal发送截图
EN

Stack Overflow用户
提问于 2019-07-30 14:25:26
回答 1查看 511关注 0票数 2

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

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

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

代码语言:javascript
复制
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

我的机器人测试用例

代码语言:javascript
复制
***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]

在报告门户中

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

代码语言:javascript
复制
</td></tr><tr><td colspan="3"><a href="selenium-screenshot-1.png"><img src="selenium-screenshot-1.png" width="800px"></a>
EN

回答 1

Stack Overflow用户

发布于 2021-07-01 19:34:20

我已经尝试了两种方法(可能还有更多):

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

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

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

索引文件名=selenium-

-{.png}索引

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

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

代码语言:javascript
复制
*** 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

注意:将图像嵌入到报表中时,图像文件不会作为单独的文件出现在结果文件夹中。

截取截图并将其作为附件发送的

  1. :使用以下函数robotframework-reportportal documentation创建自定义python库,例如:python

代码语言:javascript
复制
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"})

类似于第一个解决方案中的步骤:通过失败时运行功能调用自定义关键字

代码语言:javascript
复制
*** 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}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57265502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档