简体   繁体   中英

How to get current test case(s) status pass/failed in Robot Framework

我已经使用$ {TEST STATUS}(自动变量)来获取状态错误。

you can use that variable only in teardown section. like below example. robot is maintaining two levels "test levels" and "suit levels". inside test level there is another two things called "setup" and "teardown". setup means before executing every testcase it will run. and teardown means after executing every testcase it will run. In below example before executing Default_values, Overridden setup, No_teardown,etc. testcases Open_Application will run and after exiting the testcases Close Application will run. you can use that automatic variable in the tear down section only as described in docs and demonstated in the No_teardown testcase. In the No_teardown testcase it is checking whether it is true or not. you can change anything according to your need.

*** Settings ***
Test Setup       Open Application    App A
Test Teardown    Close Application

*** Test Cases ***
Default values
    [Documentation]    Setup and teardown from setting table
    Do Something

Overridden setup
    [Documentation]    Own setup, teardown from setting table
    [Setup]    Open Application    App B
    Do Something

No teardown
    [Documentation]    Default setup, no teardown at all
    Do Something
    [Teardown]    Should Be True      '${TEST STATUS}' == 'True'

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}

This example is modified version of this robot docs link:- http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-setup-and-teardown

Hope this will remove your doubts.

There is a global variable called ${TEST_STATUS} . You can use it in teardown section.

See the corresponding part Automatic Variables in the documentation.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#id514

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM