-
Notifications
You must be signed in to change notification settings - Fork 48
Using the parser to walk a suite
Bryan Oakley edited this page Mar 8, 2016
·
1 revision
The suite object has a walk
method with makes it easy to visit all of the objects in a suite.
The method takes zero or more arguments which are classes you want to visit. For example, to just visit test cases, you would supply Testcase
. If you provide no arguments it will return all instances of the following classes: SuiteFile, ResourceFile, SuiteFolder, Testcase, Keyword.
Here's a quick example that shows how to print out all of the test case names, their starting line numbers, and their documentation.
from __future__ import print_function
from rflint import RobotFactory, Testcase, Keyword
import sys
if len(sys.argv) < 2:
print("please provide the path to a robot suite as an argument")
sys.exit(1)
suite = RobotFactory(sys.argv[1])
for testcase in suite.walk(Testcase):
doc = ""
for setting in testcase.settings:
if setting[1].lower() == "[documentation]":
doc = doc + " ".join(setting[2:]) + " "
print("%4d :: %s :: %s" % (testcase.linenumber, testcase.name.encode('utf-8'), doc))