From 942c703bd8bad1fb7e870b96bc919c3be6dfde2a Mon Sep 17 00:00:00 2001 From: Anton Danchenko Date: Thu, 26 Apr 2018 15:34:15 +0300 Subject: [PATCH] testrail report for extended automated tests Signed-off-by: yevh-berdnyk --- test/appium/support/base_test_report.py | 63 ++++++++++++++++ ...github_test_report.py => github_report.py} | 59 +-------------- test/appium/support/testrail_report.py | 72 +++++++++++++++++++ test/appium/tests/__init__.py | 3 +- test/appium/tests/conftest.py | 62 +++++++++------- test/appium/tests/marks.py | 7 ++ test/appium/tests/test_messaging.py | 15 ++-- test/appium/tests/test_profile.py | 15 ++-- test/appium/tests/test_transaction.py | 38 ++++++---- test/appium/views/base_view.py | 2 +- 10 files changed, 228 insertions(+), 108 deletions(-) create mode 100644 test/appium/support/base_test_report.py rename test/appium/support/{github_test_report.py => github_report.py} (60%) create mode 100644 test/appium/support/testrail_report.py create mode 100644 test/appium/tests/marks.py diff --git a/test/appium/support/base_test_report.py b/test/appium/support/base_test_report.py new file mode 100644 index 0000000000..2d289c9089 --- /dev/null +++ b/test/appium/support/base_test_report.py @@ -0,0 +1,63 @@ +import json +import hmac +import os +from hashlib import md5 +from tests import SingleTestData + + +class BaseTestReport: + + TEST_REPORT_DIR = "%s/../report" % os.path.dirname(os.path.abspath(__file__)) + + def __init__(self, sauce_username, sauce_access_key): + self.sauce_username = sauce_username + self.sauce_access_key = sauce_access_key + self.init_report() + + def init_report(self): + if not os.path.exists(self.TEST_REPORT_DIR): + os.makedirs(self.TEST_REPORT_DIR) + # delete all old files in report dir + file_list = [f for f in os.listdir(self.TEST_REPORT_DIR)] + for f in file_list: + os.remove(os.path.join(self.TEST_REPORT_DIR, f)) + + def get_test_report_file_path(self, test_name): + file_name = "%s.json" % test_name + return os.path.join(self.TEST_REPORT_DIR, file_name) + + def save_test(self, test): + file_path = self.get_test_report_file_path(test.name) + json.dump(test.__dict__, open(file_path, 'w')) + + def get_all_tests(self): + tests = list() + file_list = [f for f in os.listdir(self.TEST_REPORT_DIR)] + for file_name in file_list: + file_path = os.path.join(self.TEST_REPORT_DIR, file_name) + test_dict = json.load(open(file_path)) + tests.append(SingleTestData(name=test_dict['name'], steps=test_dict['steps'], + jobs=test_dict['jobs'], error=test_dict['error'], + testrail_case_id=test_dict['testrail_case_id'])) + return tests + + def get_failed_tests(self): + tests = self.get_all_tests() + failed = list() + for test in tests: + if test.error is not None: + failed.append(test) + return failed + + def get_passed_tests(self): + tests = self.get_all_tests() + passed = list() + for test in tests: + if test.error is None: + passed.append(test) + return passed + + def get_sauce_job_url(self, job_id): + token = hmac.new(bytes(self.sauce_username + ":" + self.sauce_access_key, 'latin-1'), + bytes(job_id, 'latin-1'), md5).hexdigest() + return "https://saucelabs.com/jobs/%s?auth=%s" % (job_id, token) \ No newline at end of file diff --git a/test/appium/support/github_test_report.py b/test/appium/support/github_report.py similarity index 60% rename from test/appium/support/github_test_report.py rename to test/appium/support/github_report.py index 3426cb056d..05ce8b2264 100644 --- a/test/appium/support/github_test_report.py +++ b/test/appium/support/github_report.py @@ -1,31 +1,13 @@ -import json -from hashlib import md5 -import hmac import os - -from tests import SingleTestData +from support.base_test_report import BaseTestReport -class GithubHtmlReport: +class GithubHtmlReport(BaseTestReport): TEST_REPORT_DIR = "%s/../report" % os.path.dirname(os.path.abspath(__file__)) def __init__(self, sauce_username, sauce_access_key): - self.sauce_username = sauce_username - self.sauce_access_key = sauce_access_key - self.init_report() - - def init_report(self): - if not os.path.exists(self.TEST_REPORT_DIR): - os.makedirs(self.TEST_REPORT_DIR) - # delete all old files in report dir - file_list = [f for f in os.listdir(self.TEST_REPORT_DIR)] - for f in file_list: - os.remove(os.path.join(self.TEST_REPORT_DIR, f)) - - def get_test_report_file_path(self, test_name): - file_name = "%s.json" % test_name - return os.path.join(self.TEST_REPORT_DIR, file_name) + super(GithubHtmlReport, self).__init__(sauce_username, sauce_access_key) def build_html_report(self): tests = self.get_all_tests() @@ -49,36 +31,6 @@ class GithubHtmlReport: else: return None - def save_test(self, test): - file_path = self.get_test_report_file_path(test.name) - json.dump(test.__dict__, open(file_path, 'w')) - - def get_all_tests(self): - tests = list() - file_list = [f for f in os.listdir(self.TEST_REPORT_DIR)] - for file_name in file_list: - file_path = os.path.join(self.TEST_REPORT_DIR, file_name) - test_dict = json.load(open(file_path)) - tests.append(SingleTestData(name=test_dict['name'], steps=test_dict['steps'], - jobs=test_dict['jobs'], error=test_dict['error'])) - return tests - - def get_failed_tests(self): - tests = self.get_all_tests() - failed = list() - for test in tests: - if test.error is not None: - failed.append(test) - return failed - - def get_passed_tests(self): - tests = self.get_all_tests() - passed = list() - for test in tests: - if test.error is None: - passed.append(test) - return passed - def build_tests_table_html(self, tests, failed_tests=False): tests_type = "Failed tests" if failed_tests else "Passed tests" html = "

%s (%d)

" % (tests_type, len(tests)) @@ -121,11 +73,6 @@ class GithubHtmlReport: html += "" return html - def get_sauce_job_url(self, job_id): - token = hmac.new(bytes(self.sauce_username + ":" + self.sauce_access_key, 'latin-1'), - bytes(job_id, 'latin-1'), md5).hexdigest() - return "https://saucelabs.com/jobs/%s?auth=%s" % (job_id, token) - def build_device_sessions_html(self, jobs): html = "Device sessions:" html += "