我有一个机器人测试箱来升级我的盒子..。如果有任何错误,robot框架会截取屏幕截图,并将screenshot.png保存在reports目录中。
现在如何将其发送到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>发布于 2021-07-01 19:34:20
我已经尝试了两种方法(可能还有更多):
使用SeleniumLibrary提供的失败时运行功能:SeleniumLibrary有一个方便的特性,如果它自己的任何关键字失败,它可以自动执行关键字。默认情况下,它使用捕获页屏幕截图关键字。有关更多信息,请访问official documentation
默认情况下,捕获页面屏幕截图的文件名值为
索引文件名=selenium-
-{.png}索引
您可以在加载Selenium库时为run_on_failure参数提供一个自定义关键字。
在自定义关键字中,使用filename=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注意:将图像嵌入到报表中时,图像文件不会作为单独的文件出现在结果文件夹中。
截取截图并将其作为附件发送的
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"})类似于第一个解决方案中的步骤:通过失败时运行功能调用自定义关键字
*** 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}https://stackoverflow.com/questions/57265502
复制相似问题