From 253c8c8e7aaa9577dc3b0c128a5d1dfe866ef162 Mon Sep 17 00:00:00 2001 From: Anton Danchenko Date: Mon, 3 Jun 2019 22:44:06 +0300 Subject: [PATCH] Test time to load for login screen Signed-off-by: Serhy --- test/appium/tests/base_test_case.py | 4 +- test/appium/tests/marks.py | 1 + test/appium/tests/test_performance.py | 65 +++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 test/appium/tests/test_performance.py diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index 7dd87aa919..6680671567 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -123,7 +123,7 @@ class AbstractTestCase: def verify_no_errors(self): if self.errors: - pytest.fail('. '.join([self.errors.pop(0) for _ in range(len(self.errors))])) + pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))])) def is_alert_present(self, driver): try: @@ -136,7 +136,7 @@ class AbstractTestCase: def add_alert_text_to_report(self, driver): if self.is_alert_present(driver): - test_suite_data.current_test.testruns[-1].error += ", also Unexpected Alert is shown: '%s'" \ + test_suite_data.current_test.testruns[-1].error += "; also Unexpected Alert is shown: '%s'" \ % self.get_alert_text(driver) diff --git a/test/appium/tests/marks.py b/test/appium/tests/marks.py index 85662bf580..a1cf15817d 100644 --- a/test/appium/tests/marks.py +++ b/test/appium/tests/marks.py @@ -21,6 +21,7 @@ wallet = pytest.mark.wallet sign_in = pytest.mark.sign_in skip = pytest.mark.skip logcat = pytest.mark.logcat +performance = pytest.mark.performance battery_consumption = pytest.mark.battery_consumption diff --git a/test/appium/tests/test_performance.py b/test/appium/tests/test_performance.py new file mode 100644 index 0000000000..d6b248f91a --- /dev/null +++ b/test/appium/tests/test_performance.py @@ -0,0 +1,65 @@ +from tests import marks +from tests.base_test_case import SingleDeviceTestCase +from views.sign_in_view import SignInView +from datetime import datetime +import time + + +class TestPerformance(SingleDeviceTestCase): + + def get_timestamps_by_event(self, *args): + # earlier event will be overwritten by latest in case of multiple events in a logcat! + + timestamps_by_event = dict() + logcat = self.driver.get_log('logcat') + for event in args: + for line in logcat: + if event in line['message']: + timestamps_by_event[event] = line['timestamp'] + return timestamps_by_event + + @marks.testrail_id(6216) + @marks.high + @marks.performance + def test_time_to_load_sign_in_screen(self): + + app_started = ':init/app-started' + login_shown = ':on-will-focus :login' + password_submitted = ':accounts.login.ui/password-input-submitted' + login_success = ':accounts.login.callback/login-success' + + sign_in = SignInView(self.driver) + sign_in.create_user() + profile = sign_in.profile_button.click() + profile.logout() + home = sign_in.sign_in() + home.plus_button.click() + self.driver.info("Close app") + self.driver.close_app() + self.driver.info("Launch app") + self.driver.launch_app() + time.sleep(5) + + timestamps_by_event = self.get_timestamps_by_event(app_started, login_shown, password_submitted, login_success) + for event in app_started, login_shown, password_submitted, login_success: + self.driver.info("event: '%s' | timestamp: '%s' | time: '%s'" % (event, timestamps_by_event[event], + datetime.utcfromtimestamp(timestamps_by_event[event] / 1000))) + + time_to_login= (timestamps_by_event[login_success] - timestamps_by_event[password_submitted]) / 1000 + self.driver.info("Time to login is '%s'" % time_to_login) + + time_to_start_app = (timestamps_by_event[login_shown] - timestamps_by_event[app_started]) / 1000 + self.driver.info("Time to start the app is '%s'" % time_to_start_app) + + baseline_start_app = 0.8 + baseline_login = 1.2 + + if time_to_start_app > baseline_start_app: + self.errors.append( + "time between starting the app and login screen is '%s' seconds, while baseline is '%s'!" + % (time_to_start_app, baseline_start_app)) + if time_to_login > baseline_login: + self.errors.append( + "time between submitting a password and successful login is '%s' seconds, while baseline is '%s'!" + % (time_to_login, baseline_login)) + self.verify_no_errors()