diff --git a/.pylintrc b/.pylintrc index dc36894c..bf2c6e72 100644 --- a/.pylintrc +++ b/.pylintrc @@ -530,7 +530,7 @@ max-locals=15 max-parents=7 # Maximum number of public methods for a class (see R0904). -max-public-methods=30 +max-public-methods=35 # Maximum number of return / yield for function / method body. max-returns=6 diff --git a/core/utils/device/adb.py b/core/utils/device/adb.py index 50bb36e0..c13675f8 100644 --- a/core/utils/device/adb.py +++ b/core/utils/device/adb.py @@ -118,7 +118,7 @@ def is_running(device_id): return bool('mSurface=Surface' in result.output) @staticmethod - def wait_until_boot(device_id, timeout=180, check_interval=3): + def wait_until_boot(device_id, timeout=250, check_interval=3): """ Wait android device/emulator is up and running. :param device_id: Device identifier. @@ -413,6 +413,19 @@ def kill_process(device_id, process_name): assert result.output == "", "Process {0} not killed! Logs:{1}".format(process_name, result.output) time.sleep(5) + @staticmethod + def kill_application(device_id, app_id, process_id): + """ + Stop application + :param device_id: Device identifier + :param app_id: Bundle identifier (example: org.nativescript.TestApp) + :param process_id: The id of the process + """ + Adb.run_adb_command(command='shell run-as {0} kill {1}'.format(app_id, process_id), + device_id=device_id, wait=True) + # wait application to be killed + time.sleep(2) + @staticmethod def run_adb_as_root(device_id): """ diff --git a/tests/runtimes/android/android_runtime_tests.py b/tests/runtimes/android/android_runtime_tests.py index 68ed431f..4803b3d3 100644 --- a/tests/runtimes/android/android_runtime_tests.py +++ b/tests/runtimes/android/android_runtime_tests.py @@ -627,10 +627,10 @@ def test_440_tns_run_android_new_date_work_as_expected_when_changing_timezone(se period=5) assert test_result, "Select time zone Button is missing on the device" Device.click(self.emulator, text="Select time zone") - test_result = Wait.until(lambda: Device.is_text_visible(self.emulator, "Los Angeles", True), + test_result = Wait.until(lambda: Device.is_text_visible(self.emulator, "Tijuana", True), timeout=30, period=5) assert test_result, "Los Angeles Button is missing on the device." - Device.click(self.emulator, text="Los Angeles") + Device.click(self.emulator, text="Tijuana") else: output = Adb.run_adb_command("shell am start -a android.settings.DATE_SETTINGS", self.emulator.id, @@ -654,10 +654,10 @@ def test_440_tns_run_android_new_date_work_as_expected_when_changing_timezone(se period=5) assert test_result, "TAP Button is missing on the device" Device.click(self.emulator, text="TAP", case_sensitive=True) - assert_result = Wait.until(lambda: "GMT-0800 (PST)" in File.read(log.log_file), timeout=240, period=5) + assert_result = Wait.until(lambda: "GMT-0700 (PDT)" in File.read(log.log_file), timeout=240, period=5) assert assert_result, "Missing log for time! Logs: " + File.read(log.log_file) # Generate regex for asserting date and time - date_to_find_los_angeles = los_angeles_time.strftime(r'%a %b %d %Y %H:.{2}:.{2}') + r" GMT\-0800 \(PST\)" + date_to_find_los_angeles = los_angeles_time.strftime(r'%a %b %d %Y %H:.{2}:.{2}') + r" GMT\-0700 \(PDT\)" # Assert date time is correct assert_result = Wait.until(lambda: re.search(date_to_find_los_angeles, File.read(log.log_file)), timeout=20, period=5) diff --git a/tests/runtimes/android/android_service_tests.py b/tests/runtimes/android/android_service_tests.py index 4011d445..06050d17 100644 --- a/tests/runtimes/android/android_service_tests.py +++ b/tests/runtimes/android/android_service_tests.py @@ -68,7 +68,9 @@ def test_200_test_foreground_sticky_services_are_working(self): assert service_name in service_info, "{0} service not found! Logs: {1}".format(service_name, service_info) pid = Adb.get_process_pid(self.emulator.id, "org.nativescript.TestApp") - Adb.kill_process(self.emulator.id, "org.nativescript.TestApp") + Adb.kill_application(self.emulator.id, "org.nativescript.TestApp", pid) + service_info = Adb.get_active_services(self.emulator.id) + assert service_name in service_info, "{0} service not found! Logs: {1}".format(service_name, service_info) services = Adb.get_active_services(self.emulator.id, service_name) assert service_name in services, "{0} service not found! Logs: {1}".format(service_name, services) @@ -81,6 +83,7 @@ def test_201_test_foreground_not_sticky_services_are_working(self): """ https://github.com/NativeScript/android-runtime/issues/1347 """ + Adb.stop_application(self.emulator.id, "org.nativescript.TestApp") File.copy(os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1347', 'AndroidManifest.xml'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'src', 'main', @@ -108,8 +111,7 @@ def test_201_test_foreground_not_sticky_services_are_working(self): assert service_name in service_info, "{0} service not found! Logs: {1}".format(service_name, service_info) pid = Adb.get_process_pid(self.emulator.id, "org.nativescript.TestApp") - Adb.kill_process(self.emulator.id, "org.nativescript.TestApp") - + Adb.kill_application(self.emulator.id, "org.nativescript.TestApp", pid) service_info = Adb.get_active_services(self.emulator.id, service_name) assert service_name not in service_info, "{0} service found! Logs: {1}".format(service_name, service_info) assert pid not in service_info, "{0} service with id {1} found! Logs: {2}".format(service_name, pid, @@ -146,7 +148,7 @@ def test_202_test_foreground_service_without_oncreate_method_is_working(self): assert service_name in service_info, "{0} service not found! Logs: {1}".format(service_name, service_info) pid = Adb.get_process_pid(self.emulator.id, "org.nativescript.TestApp") - Adb.kill_process(self.emulator.id, "org.nativescript.TestApp") + Adb.kill_application(self.emulator.id, "org.nativescript.TestApp", pid) service_info = Adb.get_active_services(self.emulator.id, service_name) assert service_name not in service_info, "{0} service found! Logs: {1}".format(service_name, service_info)