1+ from robot .api import ExecutionResult , ResultVisitor
2+ from pytablewriter import MarkdownTableWriter
3+ import sys
4+
5+
6+ class SuitesWithTestsVisitor (ResultVisitor ):
7+ def __init__ (self ):
8+ self .suites_with_tests = []
9+
10+ def start_suite (self , suite ):
11+ if suite .tests :
12+ self .suites_with_tests .append (suite )
13+
14+
15+ def main ():
16+ output_file = sys .argv [1 ]
17+ markdown_file = sys .argv [2 ]
18+
19+ f = open (markdown_file , "w" )
20+
21+ result = ExecutionResult (output_file )
22+
23+ # Write PieChart as Markdown
24+ stats = result .statistics
25+ f .write ("```mermaid\n " )
26+ f .write (
27+ "%%{init: {'theme': 'base', 'themeVariables': { 'pie1': '#00FF00', 'pie2': '#FF0000', 'pie3': '#FFFF00'}}}%%\n "
28+ )
29+ f .write ("pie title Test Status\n " )
30+ f .write (f' "Passed" : { stats .total .passed } \n ' )
31+ f .write (f' "Failed" : { stats .total .failed } \n ' )
32+ f .write (f' "Skipped" : { stats .total .skipped } \n ' )
33+ f .write ("```\n " )
34+
35+ # Get all suites with Tests
36+ suite_visitor = SuitesWithTestsVisitor ()
37+ result .visit (suite_visitor )
38+ suites_with_tests = suite_visitor .suites_with_tests
39+
40+ suite_results = []
41+ for suite in suites_with_tests :
42+ suite_results .append (
43+ [
44+ suite .name ,
45+ suite .statistics .passed ,
46+ suite .statistics .failed ,
47+ suite .statistics .skipped ,
48+ suite .statistics .total ,
49+ suite .elapsed_time .total_seconds (),
50+ ]
51+ )
52+
53+ # Write Table with Results for each Suite as Markdown
54+ table_columns = [
55+ "Test Suite" ,
56+ "Passed ✅" ,
57+ "Failed ❌" ,
58+ "Skipped 🛑" ,
59+ "Total" ,
60+ "Elapsed Time ⏱️" ,
61+ ]
62+ writer = MarkdownTableWriter (
63+ table_name = "Test Suite Status" ,
64+ headers = table_columns ,
65+ value_matrix = suite_results ,
66+ )
67+ writer .stream = f
68+ writer .write_table ()
69+ f .write ("\n " )
70+ status_emoji = {
71+ "PASS" : "✅PASS" ,
72+ "FAIL" : "❌FAIL" ,
73+ "SKIP" : "🛑SKIP" ,
74+ "NOT RUN" : "NOT RUN" ,
75+ "NOT SET" : "❓NOT SET" ,
76+ }
77+ for suite in suites_with_tests :
78+ tests_in_suite = []
79+ for test in suite .tests :
80+ tests_in_suite .append (
81+ [
82+ test .name ,
83+ status_emoji .get (test .status , "unknown" ),
84+ test .elapsed_time .total_seconds (),
85+ ]
86+ )
87+
88+ # Write Table with Results for each Test Case for a Suite as Markdown
89+ table_columns = ["Test Case" , "Status" , "Elapsed Time ⏱️" ]
90+ writer = MarkdownTableWriter (
91+ table_name = suite .name , headers = table_columns , value_matrix = tests_in_suite
92+ )
93+ writer .stream = f
94+ writer .write_table ()
95+ f .write ("\n " )
96+
97+
98+ if __name__ == "__main__" :
99+ main ()
0 commit comments