Robot framework: run setup for an entire test suite

我们两清 提交于 2019-12-06 06:18:53

Robot supports suite setups. For example:

*** Settings ***
Suite Setup    Setup Fails

*** Test Cases ***
Case1
    Should Be True    1<2

Case2
    Should Be True    2<1

*** Keywords ***
Setup Fails
    fail    Danger Will Robinson!

The above yields the following results:

==============================================================================
Example                                                                       
==============================================================================
Case1                                                                 | FAIL |
Parent suite setup failed:
Danger Will Robinson!
------------------------------------------------------------------------------
Case2                                                                 | FAIL |
Parent suite setup failed:
Danger Will Robinson!
------------------------------------------------------------------------------
Example                                                               | FAIL |
Suite setup failed:
Danger Will Robinson!

2 critical tests, 0 passed, 2 failed
2 tests total, 0 passed, 2 failed
==============================================================================

You need to define a file called __init__.robot in the folder.

That file should contain a suite-setup and it would run before any other file in that folder.

You can also nest those files. If you have the following folders:

A-
 -B
 -C

And you put an __init__.robot file in the folder A, It's suite setup would run (once) before any test or any init in the folders B and C.

Note that the same trick goes for teardown as well - only in reverse.

You can use the [Tags] functionality

    *** Settings ***
Suite Setup    Setup Fails

*** Test Cases ***
Case1
    [Tags]  wip
    Should Be True    1<2

Case2
    [Tags]  wip
    Should Be True    2<1

*** Keywords ***
Setup Fails
    fail    Danger Will Robinson!

Then when you run your robot, you can use include (-i) and exclude (-e) arguments to run or not run whichever tags you want. So your script parameter would looks something like this

-i run -e wip --outputdir <log dir> <robot dir>

You can also have multiple tags in the include/exclude like this

-i run -e wipORbug etc...

There is also Forced Tags that you can put in your settings of a test suite that will apply those tags to each individual test case, which is handy if you have multiple test suites and want to just test one.

If you have multiple files running test suites, you can use an init.robot file containing Suite Setup and Suite Teardown keywords.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!