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 get_log(self): """ Get device log. """ if self.type is DeviceType.EMU or self.type is DeviceType.ANDROID: return Adb.get_logcat(self.id) elif self.type is DeviceType.SIM: Log.debug('Read log file: {0}'.format(self.device_log_file)) return File.read(self.device_log_file) else: raise NotImplementedError('Click not implemented for iOS devices.')
def assert_kotlin_is_working(emulator): assert File.exists(APK_DEBUG_PATH) assert File.is_file_in_zip(APK_DEBUG_PATH, os.path.join("kotlin")), "Kotlin is not working!" Device.click(emulator, text="TAP", case_sensitive=True) error_message = "Kotlin code is not executed correctly! Logs: " assert "Kotlin is here!" in Adb.get_logcat(emulator.id), error_message + Adb.get_logcat(emulator.id)