def _extract_cts_results_summary(self, cts_result_file_path): """ Extract summary report data from CTS XML report: <Summary failed="0" notExecuted="0" timeout="0" pass="******" /> :return: """ verdict = Global.SUCCESS msg = "" try: tree = et.parse(cts_result_file_path) self._logger.debug("CTS - Parsing of the CTS report XML file completed") except et.XMLSyntaxError: error_msg = "CTS report file: " + str(cts_result_file_path) + \ "- parsing-reading issue (exception= " + str(Utils.format_exception_info()) + ")" raise AcsToolException(AcsToolException.XML_PARSING_ERROR, error_msg) summary = tree.find('Summary') if summary is not None: failed_t = int(summary.get("failed")) not_executed_t = int(summary.get("notExecuted")) timeout_t = int(summary.get("timeout")) passed_t = int(summary.get("pass")) msg = "CTS results Summary: failed=%s notExecuted=%s timeout=%s pass=%s"\ %(failed_t, not_executed_t, timeout_t, passed_t) if (failed_t + not_executed_t + timeout_t) > 0: verdict = Global.FAILURE else: verdict = Global.FAILURE msg = "Summary section was not found in CTS result XML file: %s" %cts_result_file_path return verdict, msg
def _extract_cts_results_for_bulk_tcr_upload(self, cts_result_file_path): """ This function will extract CTS results from default XML into acceptable TCR for bulk results upload :return: payload - results structure to be uploaded into TCR as bulk update """ verdict = Global.SUCCESS msg = "" payload = [] rt = {} try: tree = et.parse(cts_result_file_path) self._logger.debug("CTS - Parsing of the CTS report XML file completed") except et.XMLSyntaxError: error_msg = "CTS report file: " + str(cts_result_file_path) + \ "- parsing-reading issue (exception= " + str(Utils.format_exception_info()) + ")" raise AcsToolException(AcsToolException.XML_PARSING_ERROR, error_msg) package_list = tree.getroot().xpath("//TestPackage") for package in package_list: self._logger.debug("CTS - Packages results processing") package_name = package.get('appPackageName') if package_name is not None: rt['useCase'] = package_name test_case = "" element = package.find("TestSuite") while element is not None: test_case += '.' + element.get('name') element = element.find("TestSuite") tcs = package.xpath(".//TestCase") for tc_node in tcs: tc_name = tc_node.get('name') if tc_name is not None: tests = tc_node.xpath(".//Test") for test_node in tests: test_name = test_node.get('name') if test_name is not None: test_name = '.' + tc_name + '.' + test_name result = test_node.get('result') if result == "pass": result = Verdict.PASS elif result == "fail": result = Verdict.FAIL elif result == "timeout": result = Verdict.INTERRUPTED elif result == "notExecuted": result = "NA" rt['verdict'] = result rt['testCase'] = package_name + test_case + test_name payload.append(copy.deepcopy(rt)) nr_elem = len(payload) if nr_elem == 0: msg = "Calculated CTS bulk upload payload is empty. Was this an empty CTS test plan execution?" verdict = Global.FAILURE else: msg = "calculated CTS bulk upload payload contains %s elements"% nr_elem LiveReporting.instance().create_bulk_tc(payload) return verdict, msg
def _extract_cts_results_from_cts_report(self, path_to_cts_report, previous_cts_results=None, publishInExternalReport=False): """ Extract in a list the cts tests results from cts xml file return structure will be like this: { package1: { test1: { "NOT_EXECUTED": ["test7", "test8"], "PASS": ["test4", "test6"], "FAIL": ["test1", "test2"], test2: ... ... } package2: ... } :type path_to_cts_report: str :param path_to_cts_report: path to CTS report where result will be extracted :type previous_cts_results: str :param previous_cts_results: path to a PREVIOUS CTS report in order to compare results :type publishInExternalReport: str :param publishInExternalReport: do we add result in external report :rtype: dict :return: full cts result by package """ cts_results = None self._logger.debug( "CTS - _extract_cts_results_from_cts_report starts...") if not isinstance(previous_cts_results, dict): previous_cts_results = {} cts_report_path = "" if HttpDownloaderUtil.is_http_uri(path_to_cts_report): # Test is available thru URL => download it localy result, full_path = self._download_file(path_to_cts_report) else: result, full_path = self._get_file_path(path_to_cts_report) if result != Global.SUCCESS: self._logger.error("Cannot find %s" % path_to_cts_report) else: self._logger.debug( "CTS - _extract_cts_results_from_cts_report - CTS report Download OK" ) cts_report_path = full_path try: cts_parsed_result = et.parse(cts_report_path) self._logger.debug( "CTS - _extract_cts_results_from_cts_report - Parsing of the CTS report completed" ) except et.XMLSyntaxError: error_msg = "CTS report file " + str( cts_report_path ) + "- parsing-reading issue (exception= " + str( Utils.format_exception_info()) + ")" raise AcsToolException(AcsToolException.XML_PARSING_ERROR, error_msg) xpath_request_pck = "//TestPackage" package_list = cts_parsed_result.getroot().xpath(xpath_request_pck) cts_results = previous_cts_results results_tc = {} for package in package_list: self._logger.debug( "CTS - _extract_cts_results_from_cts_report - Packages results processing" ) package_name = package.get('appPackageName') if package_name is not None: xpath_request_tc = ".//TestCase" tcs = package.xpath(xpath_request_tc) cts_results[package_name] = {} for tc_node in tcs: tc_name = tc_node.get('name') if tc_name is not None: default_value = { "PASS": [], "FAIL": [], "NOT_EXECUTED": [] } results_tc = cts_results[package_name].get( tc_name, default_value) xpath_request_test = ".//Test" tests = tc_node.xpath(xpath_request_test) for test_node in tests: test_name = test_node.get('name') if test_name is not None: test_result = test_node.get("result") if test_result is not None: test_result = test_result.lower() if test_result == "fail": if publishInExternalReport: self.__tc_report.add_result( test_name, self.__tc_report.verdict.FAIL, "cts test is FAIL", self.get_name(), self.tc_order) results_tc["FAIL"].append(test_name) elif test_result == "pass": if publishInExternalReport: self.__tc_report.add_result( test_name, self.__tc_report.verdict.PASS, "cts test is PASS", self.get_name(), self.tc_order) results_tc["PASS"].append(test_name) else: if publishInExternalReport: self.__tc_report.add_result( test_name, self.__tc_report. verdict.BLOCKED, "cts test has not been executed", self.get_name(), self.tc_order) results_tc["NOT_EXECUTED"].append( test_name) cts_results[package_name][tc_name] = results_tc return cts_results