def test_400_no_error_activity_in_release_builds(self): # Break the app to test error activity # add workaround with for-cycle for https://github.com/NativeScript/nativescript-cli/issues/3812 Adb.clear_logcat(self.emulator.id) wait_code = 'var e = new Date().getTime() + 3000; while (new Date().getTime() <= e) {} ' exception_code = 'throw new Error("Kill the app!");' file_path = os.path.join(Settings.TEST_RUN_HOME, APP_NAME, 'app', 'app.js') old_value = 'application.run({ moduleName: "app-root" });' new_value = wait_code + exception_code File.replace(path=file_path, old_string=old_value, new_string=new_value, backup_files=True) Tns.run_android(app_name=APP_NAME, release=True, emulator=True, wait=False) if self.emulator.version < 10.0: self.emulator.wait_for_text('Unfortunately', timeout=180, retry_delay=10) self.emulator.is_text_visible('Exception') else: regex_to_check = r"""System\.err: Error: Kill the app! .+System\.err: File: \(file:\/\/\/]data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\) .+System\.err:.+ .+System\.err: StackTrace:.+ .+System\.err:.+\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\) .+System\.err:.+at \.\/app\.js\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\) .+System\.err:.+at __webpack_require__\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/runtime\.js:\d+:\d+\) .+System\.err:.+at checkDeferredModules\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/runtime\.js:\d+:\d+\) .+System\.err:.+at webpackJsonpCallback\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/runtime\.js:\d+:\d+\) .+System\.err:.+at \(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\) .+System\.err:.+at require\(:\d+:\d+\)""" # noqa: E501, E261, W291 Wait.until(lambda: "Error: Kill the app!" in Adb.get_logcat(self.emulator.id), timeout=240, period=5) Assert.assert_with_regex(Adb.get_logcat(self.emulator.id), regex_to_check)
def test_454_support_Kotlin_with_jar_without_use_kotlin(self): """ Support gradle.properties file for enable Kotlin https://github.com/NativeScript/android-runtime/issues/1459 https://github.com/NativeScript/android-runtime/issues/1463 """ Tns.plugin_remove("sample-plugin-2", verify=False, path=APP_NAME) Adb.clear_logcat(self.emulator.id) source_app_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1463-1459', 'test-jar-1.0-SNAPSHOT.jar') target_app_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'libs') Folder.create(target_app_gradle) File.copy(source=source_app_gradle, target=target_app_gradle, backup_files=True) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1463-1459', 'main-view-model.js') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-view-model.js') File.copy(source=source_js, target=target_js, backup_files=True) log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = ['Project successfully built', 'Successfully installed on device with identifier', self.emulator.id, 'Successfully synced application'] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) messages = "App with Kotlin enabled and kotlin jar not build correctly! Logs: " assert test_result, messages + File.read(log.log_file) self.assert_kotlin_is_working(self.emulator)
def test_453_support_gradle_properties_for_enable_Kotlin_with_kotlin_file(self): """ Support gradle.properties file for enable Kotlin https://github.com/NativeScript/android-runtime/issues/1459 https://github.com/NativeScript/android-runtime/issues/1463 """ Tns.platform_remove(APP_NAME, platform=Platform.ANDROID) Tns.platform_add_android(APP_NAME, framework_path=Android.FRAMEWORK_PATH) Adb.clear_logcat(self.emulator.id) source_app_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1463-1459', 'gradle.properties') target_app_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android') File.copy(source=source_app_gradle, target=target_app_gradle, backup_files=True) source_app_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1463-1459', 'Test.kt') target_app_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'src', 'main', 'java', 'com') Folder.create(target_app_gradle) File.copy(source=source_app_gradle, target=target_app_gradle, backup_files=True) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1463-1459', 'main-view-model.js') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-view-model.js') File.copy(source=source_js, target=target_js, backup_files=True) log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = ['Project successfully built', 'Successfully installed on device with identifier', self.emulator.id, 'Successfully synced application'] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) messages = "App with Kotlin enabled and kotlin jar not build correctly! Logs: " assert test_result, messages + File.read(log.log_file) self.assert_kotlin_is_working(self.emulator)
def clear_log(self): """ Clean device log. """ if self.type is DeviceType.EMU or self.type is DeviceType.ANDROID: Adb.clear_logcat(self.id) elif self.type is DeviceType.SIM: self.device_log_file = Simctl.get_log_file(self.id) else: raise NotImplementedError('Click not implemented for iOS devices.')
def setUp(self): TnsTest.setUp(self) Adb.open_home(self.emu.id) Adb.clear_logcat(self.emu.id) if Settings.HOST_OS is OSType.OSX: Simctl.stop_all(self.sim)
def setUp(self): TnsTest.setUp(self) Adb.open_home(self.emu.id) Adb.clear_logcat(self.emu.id)