Reputation: 103
I have file test.robot with test cases.
How can i get the list of this test cases without activating the tests, from command line or python?
Upvotes: 10
Views: 9466
Reputation: 11
As we know, we have --dryrun flag to get all the tests in xml/html files but we need to parse them to get all test cases. Just to minimize this effort, we have written small utility to parse the xml/html file and get the results in list format.
['Test case one', 'Test case two' ...]
You can go through the robot_list
documentation here.
Example:
python -m robot_list.robot_list "$ROBOT_CMD" where,
ROBOT_CMD: robot --include tag1 --exclude tag2 --suite suite1 /source/path
Note: robot command should be in either single or double quotes
Upvotes: 1
Reputation: 5055
For v3.2 and up:
In RobotFramework 3.2 the parsing APIs have been rewritten, so the answer from Bryan Oakley won't work on these versions anymore.
The proper code that is compatible with both pre-3.2 and post-3.2 versions is the following:
from robot.running import TestSuiteBuilder
from robot.model import SuiteVisitor
class TestCasesFinder(SuiteVisitor):
def __init__(self):
self.tests = []
def visit_test(self, test):
self.tests.append(test)
builder = TestSuiteBuilder()
testsuite = builder.build('testsuite/')
finder = TestCasesFinder()
testsuite.visit(finder)
print(*finder.tests)
Further reading:
Upvotes: 8
Reputation: 385830
Robot test suites are easy to parse with the robot parser:
from robot.parsing.model import TestData
suite = TestData(parent=None, source=path_to_test_suite)
for testcase in suite.testcase_table:
print(testcase.name)
Upvotes: 16
Reputation: 6935
You can check out testdoc tool. Like explained in the doc, "The created documentation is in HTML format and it includes name, documentation and other metadata of each test suite and test case".
Upvotes: 7