Reputation: 13
I am trying to get the failed test case names from a output.xml using robot api in python, I am able to get the count for failed/passed tests using the below code but could not find any methods to get test case names. Thanks in advance.
from robot.api import ExecutionResult
result = ExecutionResult('output.xml')
result.configure(stat_config={'suite_stat_level': 2,
'tag_stat_combine': 'tagANDanother'})
stats = result.statistics
print stats.total.critical.failed
print stats.total.critical.passed
print stats.tags.combined[0].total
Upvotes: 0
Views: 1181
Reputation: 11
Using gatherfailed module from robot python module, you can have gather_failed_tests and gather_failed_suites functions to directly fetch failed tests and suites. Which is kind of one line answer.
from robot.conf.gatherfailed import gather_failed_tests, gather_failed_suites
print(gather_failed_suites("output.xml")
print(gather_failed_tests("output.xml")
Upvotes: 0
Reputation: 1569
Probably you need ResultVisitor
. Something like that should help:
from robot.api import ExecutionResult, ResultVisitor
class Visitor(ResultVisitor):
def __init__(self):
self.failed = []
def end_test(self, test):
if test.status == "FAIL":
self.failed.append(test)
visitor = Visitor()
result = ExecutionResult('output.xml')
result.visit(visitor)
print(visitor.failed)
Documentation could be found at https://robot-framework.readthedocs.io/en/v3.1.2/autodoc/robot.result.html#module-robot.result.visitor
Upvotes: 1