How to Read Data from report.html file in Robotic Framework

594 Views Asked by At

I have a use case to read data from report.html (Example Test case name & Elapsed time) and store into MySQL, then implement Grafana dashboard wrt test case name & Elapsed time)

How can I achieve it ? How can I read data from report.html ?

1

There are 1 best solutions below

0
Flibidisch On

Read output.xml, You can use Python methods with this lib "xml.etree.ElementTree". I already parse the output.xml from robotFramework for personal usage, this is an exemple for the beginning of parsing:

# -*- coding: utf:8 -*-
import os, sys
import xml.etree.ElementTree as ET

class OutputAnalyser() :

    def __init__(self) :
        self.xml_report_file = '/Logs/output.xml'  
        self.root_full_report = self.load_output_xml_results_file()
        self.all_test_by_suite = self.get_all_tests_by_suite()

    def load_output_xml_results_file(self):
        try:
            root_full_report = ET.parse(self.xml_report_file).getroot()
        except FileNotFoundError as e:
            raise FileNotFoundError({'errorCode' : 'FileNotFoundError', 'errorMessage' : 'File : ' + str(self.xml_report_file) + ' inexisting. Error : ' + str(e)})
        return root_full_report

    def get_all_tests_by_suite(self):
        all_suite = [item for elem in self.root_full_report.findall('.//suite') for item in elem]
        all_test_by_suite = []
        for suite in all_suite:
            sublist_test = {}
            sublist_test["suiteName"] = suite.get('name')
            sublist_test["tests"] = suite.findall('./test')
            all_test_by_suite.append(sublist_test)
        return all_test_by_suite