From a8395e51a4c2990e2aa48ecf7cb4415c96b5ec69 Mon Sep 17 00:00:00 2001 From: Yevheniia Berdnyk Date: Wed, 17 Apr 2024 03:46:59 +0300 Subject: [PATCH] e2e: GH report: rerun tests link update --- test/appium/support/base_test_report.py | 8 +++++--- test/appium/support/github_report.py | 12 +++++++++--- test/appium/support/test_data.py | 7 ++++--- test/appium/support/testrail_report.py | 10 +++++++--- test/appium/tests/conftest.py | 8 ++++++-- test/appium/tests/critical/test_wallet.py | 1 + test/appium/tests/marks.py | 1 + 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/test/appium/support/base_test_report.py b/test/appium/support/base_test_report.py index dcf4f126da6..c64d5aff883 100644 --- a/test/appium/support/base_test_report.py +++ b/test/appium/support/base_test_report.py @@ -51,7 +51,8 @@ def save_test(self, test, geth: dict = None): 'name': test.name, 'geth_paths': geth_paths, 'testruns': list(), - 'group_name': test.group_name + 'group_name': test.group_name, + 'secured': test.secured } for testrun in test.testruns: test_dict['testruns'].append(testrun.__dict__) @@ -75,7 +76,8 @@ def get_all_tests(self): geth_paths=test_data['geth_paths'], testruns=testruns, testrail_case_id=test_data['testrail_case_id'], - grop_name=test_data['group_name'])) + grop_name=test_data['group_name'], + secured=test_data['secured'])) return tests def get_tests_by_status(self): @@ -106,7 +108,7 @@ def get_sauce_job_url(self, job_id, first_command=0): @staticmethod def get_jenkins_link_to_rerun_e2e(branch_name="develop", pr_id="", tr_case_ids=""): return 'https://ci.status.im/job/status-mobile/job/e2e/job/status-app-prs-rerun/parambuild/' \ - '?BRANCH_NAME=%s&PR_ID=%s&TR_CASE_IDS=%s' % (branch_name, pr_id, tr_case_ids) + '?BRANCH_NAME=%s&PR_ID=%s&APK_URL=%s.apk&TR_CASE_IDS=%s' % (branch_name, pr_id, pr_id, tr_case_ids) def get_sauce_final_screenshot_url(self, job_id): return 'https://media.giphy.com/media/9M5jK4GXmD5o1irGrF/giphy.gif' diff --git a/test/appium/support/github_report.py b/test/appium/support/github_report.py index 6a8beb89cdc..50e5cb69cfa 100644 --- a/test/appium/support/github_report.py +++ b/test/appium/support/github_report.py @@ -76,13 +76,19 @@ def build_tests_table_html(self, tests, run_id, failed_tests=False, xfailed_test from tests import pytest_config_global pr_id = pytest_config_global['pr_number'] + from github import Github + from conftest import github_token + branch_name = Github(github_token).get_user('status-im').get_repo('status-mobile').get_pull(int(pr_id)).head.ref + if not_executed_tests: html += "
  • Rerun not executed tests
  • " % self.get_jenkins_link_to_rerun_e2e( + branch_name=branch_name, pr_id=pr_id, tr_case_ids=','.join([str(i) for i in tests])) if failed_tests: html += "
  • Rerun failed tests
  • " % self.get_jenkins_link_to_rerun_e2e( + branch_name=branch_name, pr_id=pr_id, tr_case_ids=','.join([str(test.testrail_case_id) for test in tests])) @@ -141,7 +147,7 @@ def build_test_row_html(self, index, test, run_id): else: html += "\n\n```\n%s\n```\n\n" % error.replace("[[", "[[").replace("]]", "]]") html += "

    " - if last_testrun.jobs: + if last_testrun.jobs and not test.secured: html += self.build_device_sessions_html(last_testrun) html += "" return html @@ -158,8 +164,8 @@ def build_device_sessions_html(self, test_run): self.get_sauce_job_url(job_id, test_run.first_commands[job_id]) else: html += "
  • Steps, video, logs
  • " % self.get_sauce_job_url(job_id) - if test_run.error: - html += "
  • Failure screenshot
  • " % self.get_sauce_final_screenshot_url(job_id) + # if test_run.error: + # html += "
  • Failure screenshot
  • " % self.get_sauce_final_screenshot_url(job_id) html += "

    " html += "

    " return html diff --git a/test/appium/support/test_data.py b/test/appium/support/test_data.py index 064af811af1..a902fa1c8a3 100644 --- a/test/appium/support/test_data.py +++ b/test/appium/support/test_data.py @@ -2,12 +2,13 @@ class SingleTestData(object): - def __init__(self, name, testruns, testrail_case_id, geth_paths, grop_name): + def __init__(self, name, testruns, testrail_case_id, geth_paths, grop_name, secured): self.testrail_case_id = testrail_case_id self.name = name self.testruns = testruns self.geth_paths = geth_paths self.group_name = grop_name + self.secured = secured class TestRunData(object): def __init__(self, steps, jobs, error, first_commands: Dict[str, int], xfail): @@ -27,11 +28,11 @@ def __init__(self): self.current_test = None self.tests = list() - def set_current_test(self, test_name, testrail_case_id): + def set_current_test(self, test_name, testrail_case_id, secured): existing_test = next((test for test in self.tests if test.name == test_name), None) if existing_test: self.current_test = existing_test else: - test = SingleTestData(test_name, list(), testrail_case_id, list(), None) + test = SingleTestData(test_name, list(), testrail_case_id, list(), None, secured) self.tests.append(test) self.current_test = test diff --git a/test/appium/support/testrail_report.py b/test/appium/support/testrail_report.py index a80cc75428f..2f349e2a975 100644 --- a/test/appium/support/testrail_report.py +++ b/test/appium/support/testrail_report.py @@ -187,10 +187,14 @@ def add_results(self): test_steps += step + "\n" for i, device in enumerate(last_testrun.jobs): if last_testrun.first_commands: - devices += "# [Device %d](%s) \n" % ( - i + 1, self.get_sauce_job_url(job_id=device, first_command=last_testrun.first_commands[device])) + first_command = last_testrun.first_commands[device] else: - devices += "# [Device %d](%s) \n" % (i + 1, self.get_sauce_job_url(job_id=device)) + first_command = 0 + try: + devices += "# [Device %d](%s) \n" % (i + 1, self.get_sauce_job_url(job_id=device, + first_command=first_command)) + except KeyError: + devices += "# Device %s: SauceLabs session was not found \n" % (i + 1) comment = str() if test.group_name: comment += "# Class: %s \n" % test.group_name diff --git a/test/appium/tests/conftest.py b/test/appium/tests/conftest.py index 304a9eac60d..fd6d0c18305 100644 --- a/test/appium/tests/conftest.py +++ b/test/appium/tests/conftest.py @@ -338,6 +338,8 @@ def catch_error(): error = error.replace(re.findall(failure_pattern, report.longreprtext)[0], '') return error + secured_test = "secured" in item.keywords._markers or "secured" in item.parent.keywords._markers + if report.when == 'setup': is_group = "xdist_group" in item.keywords._markers or "xdist_group" in item.parent.keywords._markers error_intro, error = 'Test setup failed:', '' @@ -345,7 +347,8 @@ def catch_error(): if (hasattr(report, 'wasxfail') and not case_ids_set) or (hasattr(report, 'wasxfail') and ( str([mark.args[0] for mark in item.iter_markers(name='testrail_id')][0]) in str(case_ids_set))): if '[NOTRUN]' in report.wasxfail: - test_suite_data.set_current_test(item.name, testrail_case_id=get_testrail_case_id(item)) + test_suite_data.set_current_test(test_name=item.name, testrail_case_id=get_testrail_case_id(item), + secured=secured_test) test_suite_data.current_test.create_new_testrun() if is_group: test_suite_data.current_test.group_name = item.instance.__class__.__name__ @@ -429,7 +432,8 @@ def pytest_runtest_setup(item): if run_testrail_ids: if str(testrail_id) not in list(run_testrail_ids.split(",")): pytest.skip("test requires testrail case id %s" % testrail_id) - test_suite_data.set_current_test(item.name, testrail_case_id=get_testrail_case_id(item)) + secured = bool([mark for mark in item.iter_markers(name='secured')]) + test_suite_data.set_current_test(test_name=item.name, testrail_case_id=get_testrail_case_id(item), secured=secured) test_suite_data.current_test.create_new_testrun() diff --git a/test/appium/tests/critical/test_wallet.py b/test/appium/tests/critical/test_wallet.py index 207457ec327..6c1e6260c3a 100644 --- a/test/appium/tests/critical/test_wallet.py +++ b/test/appium/tests/critical/test_wallet.py @@ -13,6 +13,7 @@ @pytest.mark.xdist_group(name="new_four_2") @marks.new_ui_critical +@marks.secured class TestWalletMultipleDevice(MultipleSharedDeviceTestCase): def prepare_devices(self): diff --git a/test/appium/tests/marks.py b/test/appium/tests/marks.py index 4377be8c259..da55e4039f7 100644 --- a/test/appium/tests/marks.py +++ b/test/appium/tests/marks.py @@ -12,3 +12,4 @@ upgrade = pytest.mark.upgrade skip = pytest.mark.skip xfail = pytest.mark.xfail +secured = pytest.mark.secured