ewok
ewok

Reputation: 21443

Robot framework: run setup for an entire test suite

Is it possible in ROBOT to run a setup for an entire test suite, rather than running the setup individually for each file? I want to run setup at the beginning of the suite, and if the setup fails, not run any of the test cases at all.

For example, given the following file:

*** Settings ***
Test Setup    Setup Fails

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

Case2
    Should Be True    2<1

*** Keywords ***
Setup Fails
    Should Be True    2<1

I want neither Case1 nor Case2 to execute at all. As it is, both attempt to use Setup Fails as setup individually, and the output.xml file has a status for each test case of FAIL with a message saying "Setup failed...". Instead, I would like the xml file to have a status for the suite of 'FAIL' with a message of "Setup failed..." and the test cases to either not be included or to indicate that they have not been run.

Is this something ROBOT supports?

Instead, I would like to receive an error message

Upvotes: 6

Views: 25094

Answers (3)

PsyFer
PsyFer

Reputation: 33

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.

Upvotes: 1

Uri Shtand
Uri Shtand

Reputation: 1737

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.

Upvotes: 5

Bryan Oakley
Bryan Oakley

Reputation: 385830

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

Upvotes: 12

Related Questions