-2

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 ?

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • Please only tag items that are relevant to the specific question you are asking, not the entire stack you are using (or planning to use).What programming language do you plan to use for reading the html file? What is the structure of the html file? Which part of the html file do you need to read? – Shadow Oct 03 '22 at 12:27
  • @Shadow I can use java python any to read html file, I want to extract "Start Time, End Time, AND test case name mentioned under Statistic by Tag and Elapsed time https://www.google.com/imgres?imgurl=https%3A%2F%2Frobotframework.org%2Frobotframework%2Flatest%2Fimages%2Freport_passed.png&imgrefurl=https%3A%2F%2Frobotframework.org%2Frobotframework%2Flatest%2FRobotFrameworkUserGuide.html&tbnid=SotejKGqB7uzFM&vet=1&docid=btEZSzglndbTaM&w=1046&h=764&source=sh%2Fx%2Fim – Mohd Sarfraz Oct 03 '22 at 13:15
  • 1
    It might be easier to read output.xml file. Data is more structured and report.html is parsed from that anyway. Another way is to save test results as xunit (--xunit flag) and parse that. – Pekka Oct 03 '22 at 13:47
  • @Pekka Thanks for your reply, How can i read the data from output.xml file? I want to extract "Start Time" , "End Time" , "Start Time" , "Test Case Name" , "Elapsed Time" and insert into MYSQL DB – Mohd Sarfraz Oct 03 '22 at 14:05
  • Both java and python have several existing libraries to read xml. Choose a programming language, choose an existing xml reading library and get the data you need. – Shadow Oct 03 '22 at 14:32
  • If you are using Python and going with xunit method, you should look into [junitparser](https://pypi.org/project/junitparser/) – Pekka Oct 04 '22 at 06:16

1 Answers1

0

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
Flibidisch
  • 36
  • 2