Reputation: 41
Is there any possible way to access list of all test execution in current test suite during it's execution. In my case I have one scripts with 20 test cases. Each of them has some tags. When starting Robot I can ask it to execute only test with specific tags. I'd like to know which test were chosen by Robot form my script. I know that such info is provided to listener. Can I access it for example in suite setup during execution?
Thanks Pawel R.
Upvotes: 4
Views: 1657
Reputation: 7271
Today, you can create a small library that will act as a listener as well that can do a runtime check which tests have been selected. I am using Robot Framework 3.1.2 here.
It basically needs two things
start_suite
method from the listener API. This method will be invoked at the start of every suite or until it returns an explicit False
. When invoked a parameter called attributes
will be passed to it. This parameter is a dictionary, that has the following key/value pair, "tests: Names of the tests this suite has as a list. Does not include tests of the possible child suites."
.Suite Setup
.lib.py
from robot.api import logger
class lib(object):
ROBOT_LIBRARY_SCOPE = 'TEST SUITE' # define library scope
ROBOT_LISTENER_API_VERSION = 2 # select listener API
ROBOT_LIBRARY_VERSION = 0.1
def __init__(self):
self.ROBOT_LIBRARY_LISTENER = self # tell the framework that it will be a listener library
self.attributes = None
def _start_suite(self, name, attributes):
self.attributes = attributes
def log_suite_test_names(self):
for test in self.attributes['tests']:
logger.info(test)
globals()[__name__] = lib
test.robot
*** Settings ***
Library lib
Suite Setup log suite test names
*** Test Cases ***
Test 1
[Tags] A
No Operation
Test 11
[Tags] A B
No Operation
Test 111
[Tags] A B C
No Operation
Test 1111
[Tags] A B C D
No Operation
Results when launched like: robot --pythonpath . --include C test.robot
Upvotes: 1
Reputation: 906
If usage of RF itself was not obligatory and the OS was *nix-related I would go for
grep -E -B 1 "( )(tag|tag2)( |$)" test.robot
where:
-E
initiates regex syntax of grep,
-B 1
prints out one preceding string relative to matched (which gives us Test Case names).
You could also add |grep -v Tags
to only keep the strings that contain Case names.
If you have some other stuff between a [Tags]
section and a Case name just increase -B %index%
a little and put more stuff after |grep -v
.
Upvotes: 0
Reputation: 33
You could always try doing a dry run using
--dryrun
This should be nice and quick to see what is run when you look at the report.html
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#dry-run
Upvotes: 0