How to print available tags while using Robot Framework
automation, python, robotframework
Solution
There is nothing provided by robot to give you this information. However, it's pretty easy to write a python script that uses the robot parser to get all of the tag information. Here's a quick hack that I think is correct (though I only tested it very briefly):
from robot.parsing import TestData
import sys
def main(path):
suite = TestData(parent=None, source=path)
tags = get_tags(suite)
print ", ".join(sorted(set(tags)))
def get_tags(suite):
tags = []
if suite.setting_table.force_tags:
tags.extend(suite.setting_table.force_tags.value)
if suite.setting_table.default_tags:
tags.extend(suite.setting_table.default_tags.value)
for testcase in suite.testcase_table.tests:
if testcase.tags:
tags.extend(testcase.tags.value)
for child_suite in suite.children:
tags.extend(get_tags(child_suite))
return tags
if __name__ == "__main__":
main(sys.argv[1])
Note that this will not get any tags created by the Set Tags keyword, nor does it take into account tags removed by Remove Tags.
Save the code to a file, eg get_tags.py, and run it like this:
$ python /tmp/get_tags.py /tmp/tests/
a tag, another force tag, another tag, default tag, force tag, tag-1, tag-2
Problem
If I have a large test suite in Robot Framework and a lot of tags is it possible to to get to know a list of tag names available within the suite ? some thing like pybot --listtags ?? It will be useful for the person who is actually going to run the test. For example in a scenario related to publishing of news articles , the test cases may be tagged as "publish", "published", or "publishing" . The tester is not going to have RIDE at his/her disposal . And hence he/she may not know the exact tag name . Under these circumstances I thought it will be useful to extract the available tags to display - without running any tests . And then he/she can choose to run the test with the desired tag I searched the robot framework user guide and didn't see any command line options that do this.