From 69664322b8ea01a87e7762c24dcace3c6f917991 Mon Sep 17 00:00:00 2001 From: Yevheniia Berdnyk Date: Tue, 17 Sep 2024 22:31:34 +0300 Subject: [PATCH] e2e: requests.log for failed tests --- test/appium/support/base_test_report.py | 36 ++++++++++++---------- test/appium/support/test_data.py | 4 +-- test/appium/support/testrail_report.py | 5 ++- test/appium/tests/base_test_case.py | 41 ++++++++++++++----------- 4 files changed, 46 insertions(+), 40 deletions(-) diff --git a/test/appium/support/base_test_report.py b/test/appium/support/base_test_report.py index 033ad41bff..2411027554 100644 --- a/test/appium/support/base_test_report.py +++ b/test/appium/support/base_test_report.py @@ -28,29 +28,31 @@ class BaseTestReport: file_name = "%s.json" % test_name return os.path.join(self.TEST_REPORT_DIR, file_name) - def save_geth(self, geth: dict): - geth_paths = {} - for log in geth.keys(): - geth_path = os.path.join(self.TEST_REPORT_DIR, log) - result = open(geth_path, 'wb') - result.write(geth[log]) + def save_logs(self, logs: dict): + logs_paths = {} + for log in logs.keys(): + log_path = os.path.join(self.TEST_REPORT_DIR, log) + result = open(log_path, 'wb') + result.write(logs[log]) result.close() - geth_paths[log] = geth_path - return geth_paths + logs_paths[log] = log_path + return logs_paths - def save_test(self, test, geth: dict = None): - if geth: - geth_paths = self.save_geth(geth) - else: - if hasattr(test, 'geth_paths'): - geth_paths = test.geth_paths + def save_test(self, test, geth: dict = None, requests_log: dict = None): + for log in geth, requests_log: + if log: + logs_paths = self.save_logs(log) else: - geth_paths = '' + if hasattr(test, 'logs_paths'): + logs_paths = test.logs_paths + else: + logs_paths = '' + file_path = self.get_test_report_file_path(test.name) test_dict = { 'testrail_case_id': test.testrail_case_id, 'name': test.name, - 'geth_paths': geth_paths, + 'logs_paths': logs_paths, 'testruns': list(), 'group_name': test.group_name, 'secured': test.secured @@ -74,7 +76,7 @@ class BaseTestReport: first_commands=testrun_data['first_commands'], xfail=testrun_data['xfail'])) tests.append(SingleTestData(name=test_data['name'], - geth_paths=test_data['geth_paths'], + logs_paths=test_data['logs_paths'], testruns=testruns, testrail_case_id=test_data['testrail_case_id'], grop_name=test_data['group_name'], diff --git a/test/appium/support/test_data.py b/test/appium/support/test_data.py index a902fa1c8a..660b975ae8 100644 --- a/test/appium/support/test_data.py +++ b/test/appium/support/test_data.py @@ -2,11 +2,11 @@ from typing import Dict class SingleTestData(object): - def __init__(self, name, testruns, testrail_case_id, geth_paths, grop_name, secured): + def __init__(self, name, testruns, testrail_case_id, logs_paths, grop_name, secured): self.testrail_case_id = testrail_case_id self.name = name self.testruns = testruns - self.geth_paths = geth_paths + self.logs_paths = logs_paths self.group_name = grop_name self.secured = secured diff --git a/test/appium/support/testrail_report.py b/test/appium/support/testrail_report.py index 535ad19159..8422a9c02c 100644 --- a/test/appium/support/testrail_report.py +++ b/test/appium/support/testrail_report.py @@ -8,7 +8,6 @@ from os import environ from sys import argv import emoji -import pytest import requests from support.base_test_report import BaseTestReport @@ -214,9 +213,9 @@ class TestrailReport(BaseTestReport): if re.findall(pattern, res['comment']): res_id = res['id'] try: - for geth in test.geth_paths.keys(): + for log in test.logs_paths.keys(): self.add_attachment(method='add_attachment_to_result/%s' % str(res_id), - path=test.geth_paths[geth]) + path=test.logs_paths[log]) except (AttributeError, FileNotFoundError): pass break diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index 6af9c477ee..46402ffb18 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -111,12 +111,13 @@ def get_app_path(): return app_path -def get_geth_path(): - return get_app_path() + 'geth.log' - - def pull_geth(driver): - result = driver.pull_file(get_geth_path()) + result = driver.pull_file(get_app_path() + 'geth.log') + return base64.b64decode(result) + + +def pull_requests_log(driver): + result = driver.pull_file(get_app_path() + 'requests.log') return base64.b64decode(result) @@ -377,21 +378,23 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase): test_suite_data.current_test.group_name = self.__class__.__name__ def teardown_method(self, method): - geth_names, geth_contents = [], [] + log_names, log_contents = [], [] for driver in self.drivers: try: self.print_sauce_lab_info(self.drivers[driver]) self.add_alert_text_to_report(self.drivers[driver]) - geth_names.append( + log_names.append( '%s_geth%s.log' % (test_suite_data.current_test.name, str(self.drivers[driver].number))) - geth_contents.append(pull_geth(self.drivers[driver])) - + log_contents.append(pull_geth(self.drivers[driver])) + log_names.append( + '%s_requests%s.log' % (test_suite_data.current_test.name, str(self.drivers[driver].number))) + log_contents.append(pull_requests_log(self.drivers[driver])) except (WebDriverException, AttributeError, RemoteDisconnected, ProtocolError): pass finally: try: - geth = {geth_names[i]: geth_contents[i] for i in range(len(geth_names))} - test_suite_data.current_test.geth_paths = github_report.save_geth(geth) + logs = {log_names[i]: log_contents[i] for i in range(len(log_names))} + test_suite_data.current_test.logs_paths = github_report.save_logs(logs) except IndexError: pass @@ -413,11 +416,14 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase): group_setup_failed = True else: group_setup_failed = False - geth_contents = list() + log_contents, log_names = list(), list() try: - for _, driver in cls.drivers.items(): + for i, driver in cls.drivers.items(): if group_setup_failed: - geth_contents.append(pull_geth(driver=driver)) + log_contents.append(pull_geth(driver=driver)) + log_names.append('%s_geth%s.log' % (cls.__name__, i)) + log_contents.append(pull_requests_log(driver=driver)) + log_names.append('%s_requests%s.log' % (cls.__name__, i)) session_id = driver.session_id try: sauce.jobs.update_job(username=sauce_username, job_id=session_id, name=cls.__name__) @@ -449,13 +455,12 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase): except AttributeError: pass - geth_names = ['%s_geth%s.log' % (cls.__name__, i) for i in range(len(geth_contents))] - geth = dict(zip(geth_names, geth_contents)) - geth_paths = github_report.save_geth(geth) + logs = dict(zip(log_names, log_contents)) + logs_paths = github_report.save_logs(logs) for test in test_suite_data.tests: if group_setup_failed: - test.geth_paths = geth_paths + test.logs_paths = logs_paths github_report.save_test(test)