Last active
December 4, 2024 08:16
-
-
Save adiralashiva8/d66348748e9720ad595700ce83a084c3 to your computer and use it in GitHub Desktop.
python script to fetch list of robotframework suites which contains "regression" tag suites using get_modal(), robot api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from robot.api.parsing import get_model, ModelVisitor, Token | |
class RobotParser(ModelVisitor): | |
def __init__(self, filepath): | |
self.filepath = filepath | |
self.has_smoke_tag = False | |
def visit_SettingSection(self, node): | |
# Check for 'Force Tags' in the settings section | |
for child in node.body: | |
if child.type == Token.FORCE_TAGS: | |
suite_tags = child.get_values(Token.ARGUMENT) | |
if any("regression" in tag.lower() for tag in suite_tags): | |
self.has_smoke_tag = True | |
return # Exit early if 'regression' is found | |
def visit_TestCase(self, node): | |
# Check for 'Tags' in the test cases | |
for section in node.body: | |
try: | |
if section.type == Token.TAGS: | |
test_tags = section.get_values(Token.ARGUMENT) | |
if any("regression" in tag.lower() for tag in test_tags): | |
self.has_smoke_tag = True | |
return # Exit early if 'regression' is found | |
except: | |
print(section) | |
pass | |
def suite_contains_smoke(self): | |
return self.has_smoke_tag | |
def get_robot_metadata(filepath): | |
"""Checks if a Robot Framework suite file contains the 'regression' tag.""" | |
model = get_model(filepath) | |
robot_parser = RobotParser(filepath) | |
robot_parser.visit(model) | |
return robot_parser.suite_contains_smoke() | |
def fetch_suites_with_smoke_tag(folder): | |
"""Fetches all Robot Framework suite files containing the 'regression' tag.""" | |
suites = [] | |
for root, _, files in os.walk(folder): | |
for file in files: | |
if file.lower().endswith(".robot"): | |
file_path = os.path.join(root, file) | |
if get_robot_metadata(file_path): | |
suites.append(file_path) | |
return suites | |
if __name__ == '__main__': | |
folder = 'SNOW\CMDB' | |
suites_with_smoke_tag = fetch_suites_with_smoke_tag(folder) | |
for suite in suites_with_smoke_tag: | |
print(suite) | |
# final_suites = set(suites_with_smoke_tag) | |
# print(len(final_suites)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment