[英]Robot Framework: Take screenshot if any keyword fails
In the robot framework, I need to take a screenshot of the page when any keyword is failed.在机器人框架中,我需要在任何关键字失败时对页面进行截图。 Currently, I am using code like:目前,我正在使用如下代码:
*** Settings ***
Library SeleniumLibrary run_on_failure=Capture Page Screenshot
Suite Setup Open Browser
Suite Teardown Close Browsers
*** Variables ***
${url}
${browser} chrome
*** Test Cases ***
TC01
Keyword 1
Keyword 2
Keyword 3
TC02
Keyword 4
Keyword 5
However, along with failed cases, it takes screenshots even if the keyword succeeds.但是,与失败的情况一起,即使关键字成功,它也会截图。 As a result, there is an influx of screenshots and it is hard to find which one is for the failed case.结果,屏幕截图大量涌入,很难找到哪个是针对失败案例的。
Is there any way to take a screenshot only if the keyword fails?有没有办法只在关键字失败的情况下截屏?
There is a feature in Selenium2Library. Selenium2Library 中有一个特性。 Try reading more about it here's the documentation link->https://robotframework.org/Selenium2Library/Selenium2Library.html Download that using pip command!尝试阅读更多关于它的文档链接-> https://robotframework.org/Selenium2Library/Selenium2Library.html 使用 pip 命令下载!
Library Selenium2Library timeout=10 implicit_wait=1.5 run_on_failure=Capture Page Screenshot库 Selenium2Library 超时=10 implicit_wait=1.5 run_on_failure=捕获页面截图
Let me know if it helps!让我知道它是否有帮助!
Try such code:试试这样的代码:
${success} = Run Keyword And Return Status YourKeyword
Run Keyword If not ${success} Capture Page Screenshot
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.