def test_202_test_foreground_service_without_oncreate_method_is_working( self): """ https://github.com/NativeScript/android-runtime/issues/1373 """ 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', 'AndroidManifest.xml'), True) File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1347', 'without_oncreate_method', 'app.js'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js'), True) File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1347', 'main-view-model.js'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-view-model.js'), True) log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = [ 'Successfully synced application', 'on device', self.emulator.id ] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=240, period=5) assert test_result, "App not build correctly ! Logs: " + File.read( log.log_file) Device.click(self.emulator, text="TAP", case_sensitive=True) time.sleep(5) test_result = Wait.until( lambda: "Create Foreground Service!" in File.read(log.log_file), timeout=30, period=5) assert test_result, "OnCreate foreground service log not found! Logs: " + File.read( log.log_file) service_name = "com.nativescript.location.BackgroundService" service_info = Adb.get_active_services(self.emulator.id, service_name) 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_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, service_info)
def test_200_calling_custom_generated_classes_declared_in_manifest(self): File.copy( os.path.join( TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'calling_custom_generated_classes_declared_in_manifest', 'AndroidManifest.xml'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'src', 'main', 'AndroidManifest.xml'), True) File.copy( os.path.join( TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'calling_custom_generated_classes_declared_in_manifest', 'my-custom-class.js'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'my-custom-class.js'), True) File.copy( os.path.join( TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'calling_custom_generated_classes_declared_in_manifest', 'custom-activity.js'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'custom-activity.js'), True) webpack_config = os.path.join(TEST_RUN_HOME, APP_NAME, 'webpack.config.js') old_string = '"tns-core-modules/ui/frame/activity",' my_custom_class = 'resolve(__dirname, "app/my-custom-class.js")' custom_activity = ',resolve(__dirname, "app/custom-activity.js"),' new_string = old_string + my_custom_class + custom_activity File.replace(path=webpack_config, old_string=old_string, new_string=new_string, backup_files=True) Adb.clear_logcat(device_id=self.emulator.id) Tns.run_android(APP_NAME, device=self.emulator.id, just_launch=True, wait=True) assert_result = Wait.until( lambda: 'we got called from onCreate of custom-activity.js' in Adb. get_logcat(device_id=self.emulator.id)) output = Adb.get_logcat(device_id=self.emulator.id) # make sure app hasn't crashed assert "Displayed org.nativescript.TNSApp/com.tns.ErrorReportActivity" not in output, \ "App crashed with error activity" # check if we got called from custom activity that overrides the default one assert assert_result, "Expected output not found! Logs: " + Adb.get_logcat( device_id=self.emulator.id) assert_result = Wait.until( lambda: "we got called from onCreate of my-custom-class.js" in Adb. get_logcat(device_id=self.emulator.id)) # make sure we called custom activity declared in manifest assert assert_result, "Expected output not found! Logs: " + Adb.get_logcat( device_id=self.emulator.id)
def setUpClass(cls): TnsTest.setUpClass() cls.emulator = DeviceManager.Emulator.ensure_available( Emulators.DEFAULT) Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME)) Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_JS.local_package, update=True) Tns.platform_add_android(APP_NAME, framework_path=Android.FRAMEWORK_PATH) Adb.run_adb_as_root(cls.emulator.id)
def setUpClass(cls): TnsTest.setUpClass() Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME)) Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_NG.local_package) json = App.get_package_json(app_name=APP_NAME) cls.app_id = json['nativescript']['id'] devices = Adb.get_ids(include_emulators=False) device_id = None for device in devices: device_id = device if device_id is not None: cls.device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, version=Adb.get_version(device_id)) Adb.uninstall(cls.app_id, device_id, assert_success=False)
def setUpClass(cls): TnsTest.setUpClass() cls.emulator = DeviceManager.Emulator.ensure_available(Emulators.DEFAULT) Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME)) Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_NG.local_package, update=True) json = App.get_package_json(app_name=APP_NAME) cls.app_id = json['nativescript']['id'] devices = Adb.get_ids(include_emulators=False) device_id = None for device in devices: device_id = device if device_id is not None: cls.device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, version=Adb.get_version(device_id)) Adb.uninstall(cls.app_id, device_id, assert_success=False) Tns.platform_add_android(APP_NAME, framework_path=Android.FRAMEWORK_PATH)
def test_204_test_background_worker_support(self): """ https://github.com/NativeScript/android-runtime/issues/1488 """ Adb.clear_logcat(self.emulator.id) File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1488', 'app.js'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js'), True) File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1488', 'main-view-model.js'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-view-model.js'), True) File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1488', 'app.gradle'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle'), True) log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = [ 'Successfully synced application', 'on device', self.emulator.id ] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=240, period=5) assert test_result, "App not build correctly ! Logs: " + File.read( log.log_file) Device.click(self.emulator, text="TAP", case_sensitive=True) time.sleep(5) device_log = Adb.get_logcat(self.emulator.id) error_message = "Background worker not working as expected. Logs: " + device_log assert "WM-WorkerWrapper: Worker result SUCCESS for Work" in device_log, error_message
def test_390_code_cache_option(self): """ CodeCache option is broken since Android Runtime 4.1.0 https://github.com/NativeScript/android-runtime/issues/1235 """ source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1235', 'package.json') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'package.json') File.copy(source=source_js, target=target_js, backup_files=True) # `tns run android` and wait until app is deployed log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = ['Successfully synced application'] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'Application not build successfully!' code_cache_files = ['bundle.js.cache', 'vendor.js.cache'] json = App.get_package_json(app_name=APP_NAME) app_id = json['nativescript']['id'] # Check that for each .js file, there's a corresponding .js.cache file created on the device for code_cache_file in code_cache_files: error_message = '{0} file is not found on {1}'.format( code_cache_file, self.emulator.id) assert Adb.file_exists( device_id=self.emulator.id, package_id=app_id, file_name='app/{0}'.format(code_cache_file)), error_message # Verify app looks correct inside emulator Device.wait_for_text(self.emulator, text=TAP_THE_BUTTON)
def test_446_test_print_stack_trace_in_release_and_debug(self): """ https://github.com/NativeScript/android-runtime/issues/1359 """ source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1359', '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) Adb.clear_logcat(self.emulator.id) log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = [ 'Successfully synced application', 'Successfully installed on device with identifier' ] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'Build was not successful! Logs:' + File.read( log.log_file) Device.click(self.emulator, text="TAP", case_sensitive=True) error_message_tns_logs = [ """System.err: An uncaught Exception occurred on "main" thread. System.err: Calling js method onClick failed System.err: Error: test!""", """System.err: StackTrace:""" ] test_result = Wait.until( lambda: all(log_message in File.read(log.log_file) for log_message in error_message_tns_logs), timeout=45, period=5) assert test_result, 'Error message in tns logs not found! Logs:' + File.read( log.log_file) system_error_message = [ 'System.err: An uncaught Exception occurred on "main" thread.', 'System.err: StackTrace:' ] log_cat = Adb.get_logcat(self.emulator.id) test_result = Wait.until( lambda: all(message in log_cat for message in system_error_message), timeout=15, period=5) assert test_result, 'Error message in tns log cat not found! Logs:' + log_cat Adb.clear_logcat(self.emulator.id) log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False, release=True) strings = [ 'Project successfully built', 'Successfully installed on device with identifier' ] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'Build was not successful! Logs:' + File.read( log.log_file) Device.click(self.emulator, text="TAP", case_sensitive=True) test_result = Wait.until( lambda: all(message not in File.read(log.log_file) for message in system_error_message), timeout=45, period=5) assert test_result, 'Error message in tns logs not found! Logs:' + File.read( log.log_file) log_cat = Adb.get_logcat(self.emulator.id) if self.emulator.version < 10.0: test_result = Wait.until( lambda: all(message not in log_cat for message in system_error_message), timeout=15, period=5) else: test_result = Wait.until( lambda: all(message in log_cat for message in system_error_message), timeout=15, period=5) assert test_result, 'Error message in log cat should be shown! Logs:' + log_cat
def test_440_tns_run_android_new_date_work_as_expected_when_changing_timezone( self): """ Test new date is working as expected. Test in different timezones """ output = Adb.run_adb_command( "shell settings put global auto_time_zone 0", self.emulator.id, wait=True) assert output.output == '', "Failed to change auto timezone!" output = Adb.run_adb_command("shell settings put system time_12_24 24", self.emulator.id, wait=True) assert output.output == '', "Failed to change system format to 24!" output = Adb.run_adb_command("shell settings put global time_zone UTC", self.emulator.id, wait=True) assert output.output == '', "Failed to change timezone!" if self.emulator.version < 10.0: output = Adb.run_adb_command( "shell setprop persist.sys.timezone Atlantic/Reykjavik", self.emulator.id, wait=True) assert output.output == '', "Failed to change timezone!" else: # Open Date and time settings to change the timezone output = Adb.run_adb_command( "shell am start -a android.settings.DATE_SETTINGS", self.emulator.id, wait=True) assert_text = 'Starting: Intent { act=android.settings.DATE_SETTINGS }' assert assert_text in output.output, "Failed to start Date and Time settings activity!" Device.click(self.emulator, text="Time zone", case_sensitive=True) Device.click(self.emulator, text="Region") Adb.run_adb_command("shell input keyevent \"KEYCODE_I\"", self.emulator.id, wait=True) Adb.run_adb_command("shell input keyevent \"KEYCODE_C\"", self.emulator.id, wait=True) Device.click(self.emulator, text="Iceland") # Change main-page.js so it contains only logging information source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-961', 'main-page.js') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-page.js') File.copy(source=source_js, target=target_js, backup_files=True) # Change main-view-model.js so it contains the new date logging functionality source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-961', '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) # Change app package.json so it contains the options for remove V8 date cache source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-961', 'package.json') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'package.json') 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 = ['Successfully synced application', '### TEST END ###'] assert_result = Wait.until( lambda: all(string in File.read(log.log_file) for string in strings), timeout=240, period=5) assert assert_result, "Application not build correct! Logs: " + File.read( log.log_file) # Get UTC date and time time_utc = datetime.datetime.utcnow() # Generate regex for asserting date and time date_to_find_gmt = time_utc.strftime( r'%a %b %d %Y %H:.{2}:.{2}') + r" GMT\+0000 \(GMT\)" test_result = Wait.until( lambda: Device.is_text_visible(self.emulator, "TAP", True), timeout=200, 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+0000 (GMT)" in File.read(log.log_file), timeout=30, period=5) assert assert_result, "Missing log for time! Logs: " + File.read( log.log_file) # Assert date time is correct assert_result = Wait.until( lambda: re.search(date_to_find_gmt, File.read(log.log_file)), timeout=20, period=5) assert assert_result, 'Date {0} was not found! \n Log: \n {1}'.format( date_to_find_gmt, File.read(log.log_file)) # Get Los Angeles date and time los_angeles_time = time_utc.replace(tzinfo=pytz.utc).astimezone( pytz.timezone("America/Los_Angeles")) # Open Date and time settings to change the timezone output = Adb.run_adb_command( "shell am start -a android.settings.DATE_SETTINGS", self.emulator.id, wait=True) assert_text = 'Starting: Intent { act=android.settings.DATE_SETTINGS }' assert assert_text in output.output, "Failed to start Date and Time settings activity!" # Change TimeZone if self.emulator.version < 10.0: test_result = Wait.until(lambda: Device.is_text_visible( self.emulator, "Select time zone", True), timeout=30, 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, "Pacific Daylight Time", True), timeout=30, period=5) assert test_result, "Pacific Daylight Time Button is missing on the device" Device.click(self.emulator, text="Pacific Daylight Time") else: output = Adb.run_adb_command( "shell am start -a android.settings.DATE_SETTINGS", self.emulator.id, wait=True) assert_text = 'Starting: Intent { act=android.settings.DATE_SETTINGS }' assert assert_text in output.output, "Failed to start Date and Time settings activity!" Device.click(self.emulator, text="Region") Adb.run_adb_command("shell input keyevent \"KEYCODE_U\"", self.emulator.id, wait=True) Adb.run_adb_command("shell input keyevent \"KEYCODE_S\"", self.emulator.id, wait=True) Device.click(self.emulator, text="United States") Device.click(self.emulator, text="Los Angeles") # Open the test app again output = Adb.run_adb_command( "shell am start -n org.nativescript.TestApp/com.tns.NativeScriptActivity", self.emulator.id, wait=True) assert_text = 'Starting: Intent { cmp=org.nativescript.TestApp/com.tns.NativeScriptActivity }' assert assert_text in output.output, "Failed to start Nativescript test app activity!" test_result = Wait.until( lambda: Device.is_text_visible(self.emulator, "TAP", True), timeout=30, 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-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\-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) assert assert_result, 'Date {0} was not found! \n Log: \n {1}'.format( date_to_find_los_angeles, File.read(log.log_file))
def test_100_build_app_with_abi_split_and_snapshot(self): """ Test build with abi split and snapshot. Also check if the apk for emulator is working https://github.com/NativeScript/android-runtime/issues/1234 """ Adb.clear_logcat(device_id=self.emulator.id) old_string = "webpackConfig: config," new_string = "" if platform == "linux" or platform == "linux2": new_string = "webpackConfig: config,\ targetArchs: [ \"arm\", \"arm64\", \"ia32\" ],\ useLibs: true,\ androidNdkPath: \"/tns-official/NDK/android-ndk-r18b-linux/\"" elif platform == "darwin": new_string = "webpackConfig: config,\ targetArchs: [ \"arm\", \"arm64\", \"ia32\" ],\ useLibs: true,\ androidNdkPath: \"/tns-official/NDK/android-ndk-r18b-mac/\"" target_file = os.path.join(TEST_RUN_HOME, APP_NAME, 'webpack.config.js') File.replace(target_file, old_string, new_string) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1234', 'app.gradle') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'App_Resources', 'Android', 'app.gradle') File.copy(source=source_js, target=target_js) log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=False, bundle=True, release=True, snapshot=True) test_result = Wait.until( lambda: "Project successfully built" in log.output, timeout=100, period=5) assert test_result, 'Build with abi split is not successful! Logs:' + log.output assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-arm64-v8a-release.apk")) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-armeabi-v7a-release.apk")) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-universal-release.apk")) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-x86-release.apk")) AbiSplitHelper.assert_apk( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-x86-release.apk"), self.emulator, self.app_id) AbiSplitHelper.assert_apk( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-universal-release.apk"), self.emulator, self.app_id)
def test_317_check_native_crash_will_not_crash_when_discardUncaughtJsExceptions_used( self): """ Test native crash will not crash the app when discardUncaughtJsExceptions used https://github.com/NativeScript/android-runtime/issues/1119 https://github.com/NativeScript/android-runtime/issues/1354 """ source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1119', 'main-page.js') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-page.js') File.copy(source=source_js, target=target_js, backup_files=True) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1119', 'app.js') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js') File.copy(source=source_js, target=target_js, backup_files=True) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1119', '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) # Change app package.json so it contains the options for discardUncaughtJsExceptions source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1119', 'package.json') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'package.json') File.copy(source=source_js, target=target_js, backup_files=True) Tns.plugin_remove("mylib", verify=False, path=APP_NAME) log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = ['Successfully synced application'] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'Application is not build successfully! Logs: ' + File.read( log.log_file) Device.wait_for_text(self.emulator, "TAP") Adb.is_text_visible(self.emulator.id, "TAP", True) Device.click(self.emulator, "TAP", True) stack_trace_first_part = """### Stack Trace Start JS: Frame: function:'viewModel.onTap', file:'file:///app/main-view-model.js:18:0 JS: Frame: function:'push.../node_modules/tns-core-modules/data/observable/observable.js.Observable.notify', file:'file:///node_modules/tns-core-modules/data/observable/observable.js:107:0 JS: Frame: function:'push.../node_modules/tns-core-modules/data/observable/observable.js.Observable._emit', file:'file:///node_modules/tns-core-modules/data/observable/observable.js:127:0 JS: Frame: function:'ClickListenerImpl.onClick', file:'file:///node_modules/tns-core-modules/ui/button/button.js:29:0 JS: at com.tns.Runtime.callJSMethodNative(Native Method) JS: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1242) JS: at com.tns.Runtime.callJSMethodImpl(Runtime.java:1122) JS: at com.tns.Runtime.callJSMethod(Runtime.java:1109) JS: at com.tns.Runtime.callJSMethod(Runtime.java:1089) JS: at com.tns.Runtime.callJSMethod(Runtime.java:1081) """ # noqa: E501 stack_trace_second_part = """JS: at android.view.View.performClick(View.java:5198) JS: at android.view.View$PerformClick.run(View.java:21147) JS: at android.os.Handler.handleCallback(Handler.java:739) JS: at android.os.Handler.dispatchMessage(Handler.java:95) JS: at android.os.Looper.loop(Looper.java:148) JS: at android.app.ActivityThread.main(ActivityThread.java:5417) JS: at java.lang.reflect.Method.invoke(Native Method) JS: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) JS: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) JS: Caused by: java.lang.Exception: Failed resolving method createTempFile on class java.io.File JS: at com.tns.Runtime.resolveMethodOverload(Runtime.java:1201) JS: ... 16 more JS: ### Stack Trace End""" # noqa: E501 strings = [ "Error: java.lang.Exception: Failed resolving method createTempFile on class java.io.File", "Caused by: java.lang.Exception: Failed resolving method createTempFile on class java.io.File", stack_trace_first_part, stack_trace_second_part ] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=20, period=5) message = 'Native crash should not crash the app when discardUncaughtJsExceptions used fails! Logs: ' assert test_result, message + File.read(log.log_file) Device.wait_for_text(self.emulator, text=TAP_THE_BUTTON)
def assert_apk(apk, device, app_id): Adb.install(apk, device.id) Adb.start_application(device.id, app_id) Device.wait_for_text(device, text='Ter Stegen', timeout=90) Adb.stop_application(device_id=device.id, app_id=app_id) Adb.uninstall(app_id, device.id)
def test_100_build_app_with_abi_split_and_snapshot(self): """ Test build with abi split and snapshot. Also check if the apk for emulator is working https://github.com/NativeScript/android-runtime/issues/1234 """ Adb.clear_logcat(device_id=self.emulator.id) old_string = "webpackConfig: config," new_string = "" if platform == "linux" or platform == "linux2": new_string = "webpackConfig: config,\ targetArchs: [ \"arm\", \"arm64\", \"ia32\", \"ia64\" ],\ useLibs: true,\ androidNdkPath: \"/tns-official/NDK/android-ndk-r19c-linux/\"," elif platform == "darwin": new_string = "webpackConfig: config,\ targetArchs: [ \"arm\", \"arm64\", \"ia32\", \"ia64\" ],\ useLibs: true,\ androidNdkPath: \"/tns-official/NDK/android-ndk-r19c-mac/\"," target_file = os.path.join(TEST_RUN_HOME, APP_NAME, 'webpack.config.js') File.replace(target_file, old_string, new_string) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1234', 'app.gradle') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'App_Resources', 'Android', 'app.gradle') File.copy(source=source_js, target=target_js) log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=False, bundle=True, release=True, snapshot=True) test_result = Wait.until(lambda: "Project successfully built" in log.output, timeout=100, period=5) assert test_result, 'Build with abi split is not successful! Logs:' + log.output app_x86_64_release_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-x86_64-release.apk") assert File.is_file_in_zip(app_x86_64_release_path, os.path.join("x86_64", "libNativeScript.so")) assert File.exists(app_x86_64_release_path) app_arm64_v8a_release_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-arm64-v8a-release.apk") assert File.exists(app_arm64_v8a_release_path) assert File.is_file_in_zip(app_arm64_v8a_release_path, os.path.join("arm64-v8a", "libNativeScript.so")) app_armeabi_v7a_release_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-armeabi-v7a-release.apk") assert File.exists(app_armeabi_v7a_release_path) assert File.is_file_in_zip(app_armeabi_v7a_release_path, os.path.join("armeabi-v7a", "libNativeScript.so")) app_x86_release_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-x86-release.apk") assert File.exists(app_x86_release_path) assert File.is_file_in_zip(app_x86_release_path, os.path.join("x86", "libNativeScript.so")) app_universal_release_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-universal-release.apk") assert File.exists(app_universal_release_path) assert File.is_file_in_zip(app_universal_release_path, os.path.join("arm64-v8a", "libNativeScript.so")) assert File.is_file_in_zip(app_universal_release_path, os.path.join("armeabi-v7a", "libNativeScript.so")) assert File.is_file_in_zip(app_universal_release_path, os.path.join("x86", "libNativeScript.so")) assert File.is_file_in_zip(app_universal_release_path, os.path.join("x86_64", "libNativeScript.so")) AbiSplitHelper.assert_apk( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-x86-release.apk"), self.emulator, self.app_id) AbiSplitHelper.assert_apk( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-universal-release.apk"), self.emulator, self.app_id) with self.assertRaises(AssertionError) as error: AbiSplitHelper.assert_apk( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-x86_64-release.apk"), self.emulator, self.app_id) error_message = "x86_64 should not be installed on x86 emulator!Logs:" + str(error.exception) assert "INSTALL_FAILED_NO_MATCHING_ABIS" in str(error.exception), error_message with self.assertRaises(AssertionError) as error: AbiSplitHelper.assert_apk( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-arm64-v8a-release.apk"), self.emulator, self.app_id) error_message = "arm64-v8a should not be installed on x86 emulator!Logs:" + str(error.exception) assert "INSTALL_FAILED_NO_MATCHING_ABIS" in str(error.exception), error_message with self.assertRaises(AssertionError) as error: AbiSplitHelper.assert_apk( os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-armeabi-v7a-release.apk"), self.emulator, self.app_id) error_message = "armeabi-v7a should not be installed on x86 emulator!Logs:" + str(error.exception) assert "INSTALL_FAILED_NO_MATCHING_ABIS" in str(error.exception), error_message