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

时间:2017-06-01 14:19:54

标签: user-interface automated-tests robotframework ui-automation sikuli

我正在使用RIDE机器人框架,我希望在应用程序崩溃时处理异常我关闭它然后打开它的新实例。

*** Settings ***
Library           SikuliLibrary

*** Variables ***
${openProject}    sikuli_captured\\Emna\\openProject.png
${DataBaseSTProject}    sikuli_captured\\Emna\\DataBaseSTProject.png
${testSession}    sikuli_captured\\Emna\\testSession.png
${menu}           sikuli_captured\\menu.png
${fileName}       sikuli_captured\\Emna\\fileName.png
${save}           sikuli_captured\\Emna\\save.png

*** Test Cases ***
createNewProject
    Click    ${menu}
    Click    ${testSession}
    Input Text    ${fileName}    FirstProjecT3
    Click    ${save}

openTestProject
    Click    ${openProject}
    Double Click    ${DataBaseSTProject}

任何建议都将不胜感激。

感谢您的帮助:)

enter image description here

2 个答案:

答案 0 :(得分:3)

在Robot Framework中, Try / Catch / Finally 的概念不存在。从本质上讲,您的Test Case body是此三连胜的尝试部分,其他两个被合并到相应Test Suite[Teardown]个关键字中,Test CaseKeyword部分。

在此Teardown关键字中,可以通过机器人框架本身的automatic variablesRun Keyword If ... family of keywords来识别测试用例是通过还是失败。这将允许您为Catch创建一个单独的部分,最后。在下面的代码部分中,给出了一个通过和失败测试用例的示例,每个都使用相同的拆解。

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

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

答案 1 :(得分:1)

要添加到 Kootstra 的答案中,您可能想要测试一个函数是否失败,而测试实际上没有失败。

*** Keywords ***
Do Something And Fail
    Log To Console  FAIL
    Fail

Do Something And Succeed
    Log To Console  SUCCESS

Test Something
    ${success}=  Run Keyword And Return Status  Do Something And Fail
    Log To Console  ${success}  #False
    ${success}=  Run Keyword And Return Status  Do Something And Succeed
    Log To Console  ${success}  #True

请参阅 Run Keyword And Return Status 文档。 将此与 Run Keyword If 结合以创建取决于关键字是否成功的行为。