且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在乘骑机器人框架中处理try catch异常?

更新时间:2022-01-25 06:37:00

在Robot Framework中,没有出现 Try/Catch/Finally 的概念.从本质上讲,您的Test Case body是此三连击的 Try 部分,另外两个结合到相应的测试用例

In Robot Framework the concept of Try/Catch/Finally is not present. In essence your Test Case body is the Try part of this trifecta and the other two are combined into the [Teardown] keywords of the respective Test Suite, Test Case or Keyword sections.

在此Teardown关键字中,可以通过Run Keyword If ...

Within this Teardown keyword it is possible to recognize if a Test Case has Passed or Failed through the automatic variables of Robot Framework itself or the Run Keyword If ... family of keywords. This would allow you to create a separate section for the Catch, and finally. In the below section of code an example is given of a pass and fail test case, each using the same Teardown.

此构造应允许您检查测试用例中的步骤是否失败,验证应用程序是否已崩溃(通过弹出窗口的Sikuli图像测试),然后关闭并重新启动应用程序.

This construct should allow you to check if a step in a test case failed, verify if the application has crashed (through the Sikuli image test of the popup) and then close and restart the application.

*** Test Cases ***

Open Application and fail
    Log to Console    About to Fail
    Fail
    Log to Console    Will never trigger.
    [Teardown]    Generic Test Case Teardown

Open Application and Pass
    Log to Console    About to Pass
    No Operation
    Log to Console    Will trigger.
    [Teardown]    Generic Test Case Teardown

*** Keywords ***
Generic Test Case Teardown
    # Catch of Try Catch Finally
    Run Keyword If Test Failed    Test Case Catch

    # Finally of Try Catch Finally
    #  RKITS is only executed when test passed.
    Run Keyword If Test Passed    Test Case Finally
    #  Always executed regardless of test execution status.
    Log To Console     I am always executed.

Test Case Catch
    Log To Console    Test Case Catch

Test Case Finally
    Log To Console    Test Case Finally