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_tests = self.get_passed_tests() failed_tests = self.get_failed_tests() if len(tests) > 0: title_html = "## %.0f%% of end-end tests have passed\n" % (len(passed_tests) / len(tests) * 100) summary_html = "```\n" summary_html += "Total executed tests: %d\n" % len(tests) summary_html += "Failed tests: %d\n" % len(failed_tests) summary_html += "Passed tests: %d\n" % len(passed_tests) summary_html += "```\n" failed_tests_html = str() passed_tests_html = str() if failed_tests: failed_tests_html = self.build_tests_table_html(failed_tests, run_id, failed_tests=True) summary_html += "```\n" summary_html += 'IDs of failed tests: %s \n' % self.list_of_failed_testrail_ids(failed_tests) summary_html += "```\n" if passed_tests: passed_tests_html = self.build_tests_table_html(passed_tests, run_id, failed_tests=False) return title_html + summary_html + failed_tests_html + passed_tests_html else: return None def build_tests_table_html(self, tests, run_id, failed_tests=False): tests_type = "Failed tests" if failed_tests else "Passed tests" html = "

%s (%d)

" % (tests_type, len(tests)) html += "
" html += "Click to expand" html += "
" if failed_tests: from tests import pytest_config_global pr_id = pytest_config_global['pr_number'] apk_name = pytest_config_global['apk'] tr_case_ids = self.list_of_failed_testrail_ids(self.get_failed_tests()) html += "
  • Rerun tests
  • " % self.get_jenkins_link_to_rerun_e2e(pr_id=pr_id, apk_name=apk_name, tr_case_ids=tr_case_ids) html += "
    " html += "" html += "" html += "" html += "" html += "" html += "" html += "" html += "" for i, test in enumerate(tests): html += self.build_test_row_html(i, test, run_id) html += "" html += "
    " html += "
    " return html def build_test_row_html(self, index, test, run_id): test_rail_link = TestrailReport().get_test_result_link(run_id, test.testrail_case_id) if test_rail_link: html = "%s. %s, id: %s " % (index + 1, test_rail_link, test.name, test.testrail_case_id) else: html = "%d. %s (TestRail link is not found)" % (index + 1, test.name) html += "" test_steps_html = list() last_testrun = test.testruns[-1] for step in last_testrun.steps: test_steps_html.append("
    %s
    " % step) if last_testrun.error: if test_steps_html: html += "

    " html += "

    " # last 2 steps as summary html += "%s" % ''.join(test_steps_html[-2:]) html += "
    " html += "

    " html += "%s" % last_testrun.error[:255] html += "

    " if last_testrun.jobs: html += self.build_device_sessions_html(last_testrun.jobs, last_testrun) html += "" return html def build_device_sessions_html(self, jobs, test_run): html = "Device sessions" html += "

    " return html