import os from support.base_test_report import BaseTestReport from support.testrail_report import TestrailReport class GithubHtmlReport(BaseTestReport): TEST_REPORT_DIR = "%s/../report" % os.path.dirname(os.path.abspath(__file__)) def __init__(self): super(GithubHtmlReport, self).__init__() def list_of_failed_testrail_ids(self, tests_data): ids_failed_test = [] for i, test in enumerate(tests_data): if test.testrail_case_id: ids_failed_test.append(test.testrail_case_id) return ','.join(map(str, ids_failed_test)) def build_html_report(self, run_id): tests = self.get_all_tests() passed, failed, xfailed = self.get_tests_by_status() not_executed_tests = TestrailReport().get_not_executed_tests(run_id) if len(tests) > 0: title_html = "## %.0f%% of end-end tests have passed\n" % (len(passed) / len(tests) * 100) summary_html = "```\n" summary_html += "Total executed tests: %d\n" % len(tests) summary_html += "Failed tests: %d\n" % len(failed) summary_html += "Expected to fail tests: %d\n" % len(xfailed) summary_html += "Passed tests: %d\n" % len(passed) if not_executed_tests: summary_html += "Not executed tests: %d\n" % len(not_executed_tests) summary_html += "```\n" not_executed_tests_html = str() failed_tests_html = str() xfailed_tests_html = str() passed_tests_html = str() if not_executed_tests: not_executed_tests_html = self.build_tests_table_html(not_executed_tests, run_id, not_executed_tests=True) summary_html += "```\n" summary_html += 'IDs of not executed tests: %s \n' % ','.join([str(i) for i in not_executed_tests]) summary_html += "```\n" if failed: failed_tests_html = self.build_tests_table_html(failed, run_id, failed_tests=True) summary_html += "```\n" summary_html += 'IDs of failed tests: %s \n' % self.list_of_failed_testrail_ids(failed) summary_html += "```\n" if xfailed: xfailed_tests_html = self.build_tests_table_html(xfailed, run_id, xfailed_tests=True) summary_html += "```\n" summary_html += 'IDs of expected to fail tests: %s \n' % self.list_of_failed_testrail_ids(xfailed) summary_html += "```\n" if passed: passed_tests_html = self.build_tests_table_html(passed, run_id, failed_tests=False) return title_html + summary_html + not_executed_tests_html + failed_tests_html + xfailed_tests_html \ + passed_tests_html else: return None def build_tests_table_html(self, tests, run_id, failed_tests=False, xfailed_tests=False, not_executed_tests=False): if failed_tests: tests_type = "Failed tests" elif not_executed_tests: tests_type = "Not executed tests" elif xfailed_tests: tests_type = "Expected to fail tests" else: tests_type = "Passed tests" html = "
" html += "
" # last 2 steps as summary html += "%s" % ''.join(test_steps_html[-2:]) html += "" html += "" code_error, no_code_error_str, _ = self.separate_xfail_error(error) if no_code_error_str: html += "\n\n```\n%s\n```\n\n" % code_error html += "%s" % no_code_error_str else: html += "\n\n```\n%s\n```\n\n" % error.replace("[[", "[[").replace("]]", "]]") html += "
" html += "Device %d:" % i html += "