如何在Robot Framework中的每一步之后运行一些东西



我想在Robot Framework中的测试用例的每一步之后都检查一些东西。我包含了一个伪示例来表示我所指的内容:

*** Test Cases ***
Order From Somewhere
[Tags]  whatever tags here
Step1
#Grab Exception
Step2
#Grab Exception
Step3
#Grab Exception
Step4
#Grab Exception
Step5
#Grab Exception
Step6
#Grab Exception
Step7

我认为有一些方法可以在每个步骤之后执行"#Grab Exception",但方法很好。

感谢您提前提供的帮助。

您可以定义自己的关键字来实现这一点,例如:

*** Test Cases ***
Test Special Keywords
Special Keyword    Sleep    5 seconds
Special Keyword    Log    <b>This is another keyword</b>    HTML
*** Keywords ***
Special Keyword
[Arguments]    ${kw}    @{arguments}
Run Keyword    ${kw}    @{arguments}
Grab Exception
Grab Exception
Log    Called <i>Grab Exception</i>    HTML

您可以在您的设置区域中添加类似以下的内容,并使用Test-Teardown选项:

Run Keyword If Test Failed or Passed <name of the kw> 

---您可以使用其中一个pass或fail,也可以使用除非满足条件。例如:

*** Settings ***
Test Setup       Open Application    App A
Test Teardown    Close Application
*** Test Cases ***
Default values
[Documentation]    Setup and teardown from setting section
Do Something
Overridden setup
[Documentation]    Own setup, teardown from setting section
[Setup]    Open Application    App B
Do Something
No teardown
[Documentation]    Default setup, no teardown at all
Do Something
[Teardown]
No teardown 2
[Documentation]    Setup and teardown can be disabled also with special value NONE
Do Something
[Teardown]    NONE
Using variables
[Documentation]    Setup and teardown specified using variables
[Setup]    ${SETUP}
Do Something
[Teardown]    ${TEARDOWN}

更多信息,请访问-https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-的设置和拆卸

相关内容

最新更新