Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 288
Daniel Led Avatar asked May 21 '15 08:05

Daniel Led


People also ask

How do you find the test case name in robot framework?

You can use ${TEST_NAME} if you want the name of test case inside a suite, ${SUITE_NAME} to get the name of the file which contains the test cases ( Generally referred as Test Suite).

How do you skip test cases in Robot Framework?

If you used Pass Execution to skip your tests, you can pass an optional SKIP tag at the end so that the case will be tagged as SKIP in the log/report. Eg: Pass Execution Skipping this test SKIP. Here SKIP is the tag that will be added to this test case and it will show up in your log/report as a tag.

How do you run all test cases in Robot Framework?

To execute robot tests in your prompt, type: robot path/to/tests. 'path/to/tests' should be a name of a suite file or a suite directory.

How do you create a list variable in Robot Framework?

Clicking on New Scalar will open the following screen to create the variable and the value we need to replace with when the variable in used inside test cases. We get ${} for the Name field. The name of the variable is ${url}. The value is − http://localhost/robotframework/login.html.


1 Answers

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:

  • Visitor model
  • TestSuiteBuilder class reference
like image 136
Błażej Michalik Avatar answered Sep 20 '22 12:09

Błażej Michalik