Reputation: 3690
I'm new to Robot framework and trying to better understand the concepts and usage in Suite Setup and Suite Teardown when the test's folder structure is not "flat". After a long search on the web, the Robot framework user guide - executing tests section and also this question which is similar but not exactly my situation, I still did not find any solution, so here we go.
My project now contains the following files:
_init__.robot
that contains the Suite Setup
& Suite Teardown
"definitions", as follows:
*** Settings ***
Library /path/to/some/python/file.py
Suite Setup myCustomSuiteSetup
Suite Teardown myCustomSuiteTeardown
*** Keywords ***
myCustomSuiteSetup
${ret_code} = run keyword MySuiteSetupKeyword
should be eqaul as integers ${ret_code} 0
myCustomSuiteTeardown
${ret_code} = run keyword MySuiteTeardownKeyword
should be eqaul as integers ${ret_code} 0
Where myCustomSuiteTeardown
and MySuiteTeardownKeyword
are keywords "linked" to some Python functions in the file /path/to/some/python/file.py
.
The 4 suite files in my project are currently arranged like so:
|--tests
|----suite_1.robot
|----suite_2.robot
|----suite_3.robot
|----suite_4.robot
|----__init__.robot
Now, the purpose (and usage) of the Suite Setup
& Suite Teardown
is that the Suite Setup
will run at the beginning of the run of the ENTIRE tests
folder, i.e.- before the first test case of the first suite, which in this case is suite_1.robot
and the Suite Teardown
will run after the last test case of the last suite, which in this case it is suite_4.robot
.
For this to happen, I simply invoke all the suites as follows (from within one folder "above" the tests
folder):
robot tests
So far so good.
Now my question is as follows: Actually I wish to "re-arrange" the folder's structure of the test files, like so:
|--tests
|----testGroup1
|--------suite_1.robot
|--------suite_2.robot
|----testGroup2
|--------suite_3.robot
|--------suite_4.robot
|--__init__.robot <----- Where the __init__.robot file should be placed now ?
Meaning, to "gather" test suites to sub-folders, nevertheless, I still wish to keep the usage of the Suite Setup
& Suite Teardown
as before,i.e.- upon invocation of every possible subset of the test suites under the "root" folder tests
, Suite Setup
& Suite Teardown
MUST be the first and last (respectively) "steps" to be executed, meaning, for example, let say I wish to run suite_3.robot
& suite_4.robot
, then now, Suite Setup
should be called before the first test case in suite_3.robot
and Suite Teardown
should be called after the last test case in the suite_4.robot
. Also, of course, I wish to keep only a single copy of the __init__.robot
file - i.e. - not keep two similar copies of the __init__.robot
in each subfolder, testGroup1
& testGroup2
. When I did this, it worked, but this is not the (proper) way I wish to do that.
So my questions are:
Where do I need to place the __init__.robot
file?
In case I wish to run,for instance, only the two test suites within testGroup2
(i.e.- suite_3.robot
& suite_4.robot
), what command do I need to use?
Of course, in case it is not the "correct" way (approach) to achieve my objectives (single and unified Suite Setup
& Suite Teardown
for every test suites subset) - please advice how should it be done.
Note: I'm using Robot framework 3.1.2 (Python 3.5.2 on Linux)
Upvotes: 3
Views: 3768
Reputation: 1763
Your placement of the initialization file in the tests
folder that contains both testGroup1
and testGroup2
is correct. This way, if you run at least one test that's somewhere in tests
or within a sub folder of it, the Suite Setup will run before all such tests and Suite Teardown afterwards.
To force the Suite Setup and Suite Teardown to run, you must keep the parent folder (tests
) as the folder you run. It is good practice to always run the folder that contains all of your tests. That way, you don't miss any suite setups or teardowns by mistake.
To then run only select tests, use the options --include
or --exclude
for tags, or --suite
or --test
.
In your example, you would run the following:
robot --suite suite_3 --suite suite_4 tests
, to run only suite_3 and suite_4
Or, you can use fully qualified suite names:
robot --suite tests.testGroup2.suite_3 --suite tests.testGroup2.suite_4 tests
Upvotes: 2