简体   繁体   中英

How to get test cases list in Robot Framework without launching the actual tests?

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?

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)

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".

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM