diff --git a/test/appium/support/base_test_report.py b/test/appium/support/base_test_report.py index 92d2c60ec5..8f898522ff 100644 --- a/test/appium/support/base_test_report.py +++ b/test/appium/support/base_test_report.py @@ -11,9 +11,9 @@ from support.test_data 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 + def __init__(self): + self.sauce_username = os.environ.get('SAUCE_USERNAME') + self.sauce_access_key = os.environ.get('SAUCE_ACCESS_KEY') self.init_report() def init_report(self): diff --git a/test/appium/support/github_report.py b/test/appium/support/github_report.py index 5292084036..ce5733fa12 100644 --- a/test/appium/support/github_report.py +++ b/test/appium/support/github_report.py @@ -1,14 +1,15 @@ 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, sauce_username, sauce_access_key): - super(GithubHtmlReport, self).__init__(sauce_username, sauce_access_key) + def __init__(self): + super(GithubHtmlReport, self).__init__() - def build_html_report(self): + def build_html_report(self, run_id): tests = self.get_all_tests() passed_tests = self.get_passed_tests() failed_tests = self.get_failed_tests() @@ -23,14 +24,14 @@ class GithubHtmlReport(BaseTestReport): failed_tests_html = str() passed_tests_html = str() if failed_tests: - failed_tests_html = self.build_tests_table_html(failed_tests, failed_tests=True) + failed_tests_html = self.build_tests_table_html(failed_tests, run_id, failed_tests=True) if passed_tests: - passed_tests_html = self.build_tests_table_html(passed_tests, failed_tests=False) + 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, failed_tests=False): + 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 += "
" @@ -45,14 +46,18 @@ class GithubHtmlReport(BaseTestReport): html += "" html += "" for i, test in enumerate(tests): - html += self.build_test_row_html(i, test) + html += self.build_test_row_html(i, test, run_id) html += "" html += "" html += "
" return html - def build_test_row_html(self, index, test): - html = "%d. %s" % (index + 1, test.name) + 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" % (index + 1, test_rail_link, test.name) + else: + html = "%d. %s (TestRail link is not found)" % (index + 1, test.name) html += "" test_steps_html = list() last_testrun = test.testruns[-1] diff --git a/test/appium/support/testrail_report.py b/test/appium/support/testrail_report.py index 63f368bd25..69e531d26e 100644 --- a/test/appium/support/testrail_report.py +++ b/test/appium/support/testrail_report.py @@ -8,8 +8,8 @@ from support.base_test_report import BaseTestReport class TestrailReport(BaseTestReport): - def __init__(self, sauce_username, sauce_access_key): - super(TestrailReport, self).__init__(sauce_username, sauce_access_key) + def __init__(self): + super(TestrailReport, self).__init__() self.password = environ.get('TESTRAIL_PASS') self.user = environ.get('TESTRAIL_USER') @@ -27,16 +27,15 @@ class TestrailReport(BaseTestReport): base64.b64encode(bytes('%s:%s' % (self.user, self.password), 'utf-8')), 'ascii').strip() self.headers['Content-Type'] = 'application/json' - self.url = 'https://ethstatus.testrail.net/index.php?/api/v2/' + self.url = 'https://ethstatus.testrail.net/index.php?/' + self.api_url = self.url + 'api/v2/' def get(self, method): - raw_response = requests.get(self.url + method, headers=self.headers).text - return json.loads(raw_response) + return requests.get(self.api_url + method, headers=self.headers).json() def post(self, method, data): data = bytes(json.dumps(data), 'utf-8') - raw_response = requests.post(self.url + method, data=data, headers=self.headers).text - return json.loads(raw_response) + return requests.post(self.api_url + method, data=data, headers=self.headers).json() def get_suites(self): return self.get('get_suites/%s' % self.project_id) @@ -102,3 +101,10 @@ class TestrailReport(BaseTestReport): 'comment': '%s' % ('# Error: \n %s \n' % emoji.demojize(last_testrun.error)) + devices + test_steps if last_testrun.error else devices + test_steps} self.post(method, data=data) + + def get_test_result_link(self, test_run_id, test_case_id): + try: + test_id = self.get('get_results_for_case/%s/%s' % (test_run_id, test_case_id))[0]['test_id'] + return '%stests/view/%s' % (self.url, test_id) + except KeyError: + return None diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index 49dc14d2b1..a59e031b84 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -112,7 +112,7 @@ class AbstractTestCase: errors = [] network_api = NetworkApi() - github_report = GithubHtmlReport(sauce_username, sauce_access_key) + github_report = GithubHtmlReport() def verify_no_errors(self): if self.errors: diff --git a/test/appium/tests/conftest.py b/test/appium/tests/conftest.py index bd7dae0ee7..9bef95baca 100644 --- a/test/appium/tests/conftest.py +++ b/test/appium/tests/conftest.py @@ -18,8 +18,8 @@ sauce_access_key = environ.get('SAUCE_ACCESS_KEY') github_token = environ.get('GIT_HUB_TOKEN') sauce = SauceClient(sauce_username, sauce_access_key) -github_report = GithubHtmlReport(sauce_username, sauce_access_key) -testrail_report = TestrailReport(sauce_username, sauce_access_key) +github_report = GithubHtmlReport() +testrail_report = TestrailReport() def pytest_addoption(parser): @@ -136,13 +136,13 @@ def pytest_configure(config): def pytest_unconfigure(config): if is_master(config): + if config.getoption('testrail_report'): + testrail_report.add_results() if config.getoption('pr_number'): from github import Github repo = Github(github_token).get_user('status-im').get_repo('status-react') pull = repo.get_pull(int(config.getoption('pr_number'))) - pull.create_issue_comment(github_report.build_html_report()) - if config.getoption('testrail_report'): - testrail_report.add_results() + pull.create_issue_comment(github_report.build_html_report(testrail_report.run_id)) @pytest.mark.hookwrapper diff --git a/test/appium/tests/test_general_verifications.py b/test/appium/tests/test_general_verifications.py index 4c46c57619..5a107de2fe 100644 --- a/test/appium/tests/test_general_verifications.py +++ b/test/appium/tests/test_general_verifications.py @@ -6,7 +6,7 @@ from views.sign_in_view import SignInView class TestLinksVerifications(SingleDeviceTestCase): @marks.testrail_id(5453) - @marks.critical + @marks.medium def test_privacy_policy_is_accessible(self): signin_view = SignInView(self.driver) no_link_found_error_msg = 'Could not find privacy policy link at'