【问题标题】:Robot Framework: Take screenshot if any keyword failsRobot Framework:如果任何关键字失败,请截图
【发布时间】:2020-10-20 16:53:33
【问题描述】:

在机器人框架中,我需要在任何关键字失败时对页面进行截图。目前,我正在使用如下代码:

*** 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

但是,与失败的情况一起,即使关键字成功,它也会截图。结果,屏幕截图大量涌入,很难找到失败案例的截图。

有没有办法只在关键字失败的情况下截图?

【问题讨论】:

  • 大部分关键字通过时不会生成截图。能否提供一个关键字通过时截屏的实际示例?

标签: selenium-webdriver automation robotframework ui-automation


【解决方案1】:

Selenium2Library 中有一个功能。 尝试阅读更多关于它的文档链接-> https://robotframework.org/Selenium2Library/Selenium2Library.html 使用 pip 命令下载!

库 Selenium2Library timeout=10 implicit_wait=1.5 run_on_failure=捕获页面截图

如果有帮助请告诉我!

【讨论】:

  • 您基本上只是重写了 OP 在他们的问题中包含的内容。请在你的答案中更具体一点。
【解决方案2】:

试试这样的代码:

${success} =  Run Keyword And Return Status  YourKeyword
Run Keyword If  not ${success}  Capture Page Screenshot

【讨论】:

    猜你喜欢
    • 2023-01-27
    • 2018-01-17
    • 2018-10-10
    • 1970-01-01
    • 2011-11-26
    • 2015-07-19
    • 2015-08-17
    • 1970-01-01
    • 2016-09-17
    相关资源
    最近更新 更多