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_300_verbose_log_android(self): File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'verbose_log', 'app.js'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js'), True) output = File.read( os.path.join(TEST_RUN_HOME, APP_NAME, "app", "app.js")) assert "__enableVerboseLogging()" in output, "Verbose logging not enabled in app.js" # `tns run android` and wait until app is deployed log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = [ 'Project successfully built', 'Successfully installed on device with identifier', 'TNS.Native', 'TNS.Java', self.emulator.id ] Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=240, period=5) log = File.read(log.log_file) assert "TNS.Native" in log, "__enableVerboseLogging() do not enable TNS.Native logs!" assert "TNS.Java" in log, "__enableVerboseLogging() do not enable TNS.Java logs!"
def test_387_test_pointers_and_conversions_to_string(self): """ Test pointers and conversions to strings https://github.com/NativeScript/ios-runtime/pull/1069 https://github.com/NativeScript/ios-runtime/issues/921 """ File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-921', 'special-value', 'main-view-model.js'), os.path.join(APP_PATH, 'app', 'main-view-model.js'), True) log = Tns.run_ios(app_name=APP_NAME, emulator=True) strings = [ "<Pointer: 0xfffffffffffffffe>", "<Pointer: 0xffffffffffffffff>", "<Pointer: 0x800000000>" ] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, '-1 pointer is not correct(interop.Pointer)!' File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-921', 'wrapped-value', 'main-view-model.js'), os.path.join(APP_PATH, 'app', 'main-view-model.js'), True) strings = [ "wrapped: <Pointer: 0xfffffffffffffffe>", "wrapped: <Pointer: 0xffffffffffffffff>", "wrapped: <Pointer: 0x800000000>" ] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'wrapped pointers are not working correctly(interop.Pointer(new Number(value)))!' File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-921', 'toHexString-and-toDecimalString', 'main-view-model.js'), os.path.join(APP_PATH, 'app', 'main-view-model.js'), True) strings = [ "Hex: 0xfffffffffffffffe", "Decimal: -2", "Hex: 0xffffffffffffffff", "Decimal: -1", "Hex: 0x800000000", "Decimal: 34359738368" ] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'toHexString and toDecimalString are not working correctly!'
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_10_wait(self): assert Wait.until(lambda: WaitTests.seconds_are_odd(), timeout=10, period=0.01) assert Wait.until(lambda: WaitTests.get_int() == 3, timeout=10, period=0.01) assert not Wait.until(lambda: False, timeout=1, period=0.01)
def test_447_test_worker_post_message(self): """ https://github.com/NativeScript/android-runtime/issues/1408 """ source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1408', '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-1408', 'worker.js') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'worker.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) correct_object = """JS: ==== object dump start ==== JS: id: "1" JS: data: { JS: "Hi": "Hi", JS: "table1": [ JS: { JS: "blah": "a" JS: }, JS: { JS: "blah": "a" JS: } JS: ], JS: "table2": [ JS: { JS: "blah": "a" JS: } JS: ] JS: } JS: data2: "{"Hi":"Hi","table1":[{"blah":"a"},{"blah":"a"}],"table2":[{"blah":"a"}]}" JS: ==== object dump end ====""" 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) test_result = Wait.until( lambda: correct_object in File.read(log.log_file), timeout=30, period=5) assert test_result, 'Worker PostMessage Data is not correct! Logs:' + File.read( log.log_file)
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 test_322_extends_method_is_working_in_non_native_inheritance(self): """ Test __extends is working non native inheritance https://github.com/NativeScript/android-runtime/issues/1181 """ Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME)) Tns.create(APP_NAME, template=Template.VUE_BLANK.local_package, verify=False) Tns.platform_add_android(APP_NAME, framework_path=Android.FRAMEWORK_PATH) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1181', 'js', '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) log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False, bundle=True) strings = [ 'Successfully synced application', "'NativeScript-Vue has \"Vue.config.silent\" set to true, to see output logs set it to false.'" ] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) message = 'Test __extends is working non native inheritance ts code fails! Logs:' assert test_result, message + File.read(log.log_file) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1181', 'ts', '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) test_result = Wait.until( lambda: "'NativeScript-Vue has \"Vue.config.silent\" set to true, to see output logs set it to false.'" in File.read(log.log_file), timeout=300, period=5) assert test_result, 'Test extends is working non native inheritance fails for js code!'
def test_443_build_app_and_assert_that_tns_core_modules_could_be_updated( self): """ Test update of tns-core-modules works correctly if you have build the app first https://github.com/NativeScript/android-runtime/issues/1257 """ Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME)) Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_JS.local_package) Tns.platform_add_android(APP_NAME, framework_path=Android.FRAMEWORK_PATH) 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) Npm.install(package=Packages.MODULES, folder=os.path.join(TEST_RUN_HOME, APP_NAME)) Tns.plugin_add(plugin_name="[email protected]", path=os.path.join(TEST_RUN_HOME, APP_NAME)) 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=120, period=5) assert test_result, "App not build correctly after updating tns-core modules! Logs: " + File.read( log.log_file) test_result = Wait.until( lambda: Device.is_text_visible(self.emulator, "TAP", True), timeout=90, period=5) assert test_result, "TAP Button is missing on the device! Update of tns-core-modules not successful!"
def test_500_test_ES6_support(self): """ https://github.com/NativeScript/android-runtime/issues/1375 """ Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME)) Tns.create( app_name=APP_NAME, template="https://github.com/NativeScript/es6-syntax-app.git", update=True) Tns.platform_add_android(APP_NAME, framework_path=Android.FRAMEWORK_PATH) 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=120, period=5) assert test_result, "App not build correctly after updating tns-core modules! Logs: " + File.read( log.log_file) button_text = "Use ES6 language features" test_result = Wait.until( lambda: Device.is_text_visible(self.emulator, button_text), timeout=30, period=5) message = "Use ES6 language features Button is missing on the device! The app has crashed!" assert test_result, message Device.click(self.emulator, text=button_text, case_sensitive=False) test_result = Wait.until( lambda: "class com.js.NativeList" in File.read(log.log_file), timeout=25, period=5) assert test_result, "com.js.NativeList not found! Logs: " + File.read( log.log_file) test_result = Wait.until( lambda: Device.is_text_visible(self.emulator, button_text), timeout=30, period=5) assert test_result, message
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_384_check_for_native_and_js_callstacks(self): """ https://github.com/NativeScript/ios-runtime/pull/1144 """ # Replace main-page.js so there is an error File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-pr-1144', 'main-page.js'), os.path.join(APP_PATH, 'app', 'main-page.js'), True) result = Tns.run_ios(app_name=APP_NAME, emulator=True, wait=False, verify=False) strings = [ 'Native Stack:', 'sig_handler(int)', 'JS Stack:', '1 @[native code]', '2 onNavigatingTo@file:///app/main-page.js:34:0' ] TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=150, check_interval=10) # Verify app is NOT running on device test_result = Wait.until(lambda: Simctl.is_process_running( self.sim, 'org.nativescript.' + APP_NAME) is False, timeout=120, period=5) assert test_result, "It seems that " + APP_NAME + " is still running when it should not!"
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 test_303_check_if_class_implements_java_interface_java(self): """ Test if java class implements java interface https://github.com/NativeScript/android-runtime/issues/739 """ # Change main-page.js so it contains only logging information source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-739', 'java', '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) log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = ['Successfully synced application', "### TEST PASSED ###"] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'JAVA : Check(instanceof) for java class implements java interface does not work' \ '(myRunnable instanceof java.lang.Runnable)'
def test_313_check_minsdk_could_be_set_in_app_gradle(self): """ Test minSdk works in app.gradle https://github.com/NativeScript/android-runtime/issues/1104 """ target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle') source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104', 'app.gradle') 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-1104', '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) Tns.plugin_remove("mylib", verify=False, path=APP_NAME) plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104', "plugin", 'src') output = Tns.plugin_add(plugin_path, path=APP_NAME, verify=False) assert "Successfully installed plugin mylib" in output.output, "mylib plugin not installed correctly!" 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 SHOULD NOT CRASH ###'] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'Minsdk set in app.gradle is not working! Logs: ' + File.read(log.log_file) Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
def test_391_native_properties_provided_by_internal_classes_are_available( self): """ Test native properties provided by internal classes are available https://github.com/NativeScript/ios-runtime/issues/1149 """ File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-1149', 'main-view-model.js'), os.path.join(APP_PATH, 'app', 'main-view-model.js'), True) log = Tns.run_ios(app_name=APP_NAME, emulator=True) # Verify app is running on device Device.wait_for_text(self.sim, text='Tap the button') strings = [ 'response1: <NSHTTPURLResponse:', 'response2: <NSHTTPURLResponse:', 'Status Code: 200' ] result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert result, 'It seems that native properties provided by internal classes are not available'
def test_390_check_correct_name_of_internal_class_is_returned(self): """ Test that NSStringFromClass function returns correct name of iOS internal class https://github.com/NativeScript/ios-runtime/issues/1120 """ # Delete src folder from the previous test till Folder copy strt to backup folders too Folder.clean( os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src')) File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-1120', 'main-page.js'), os.path.join(APP_PATH, 'app', 'main-page.js'), True) log = Tns.run_ios(app_name=APP_NAME, emulator=True) # Verify app is running on device Device.wait_for_text(self.sim, text='Tap the button') string = ['Internal class: UITableViewCellContentView'] result = Wait.until(lambda: all(st in File.read(log.log_file) for st in string), timeout=60, period=5) assert result, 'NSStringFromClass function returns INCORRECT name of iOS internal class!'
def test_302_test_SBG_works_when_you_have_nativescript_property_in_package_json(self): """ https://github.com/NativeScript/android-runtime/issues/1409 """ source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1409', '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) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1409', 'new', 'package.json') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'new', 'package.json') new_folder = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'new') Folder.create(new_folder) File.copy(source=source_js, target=target_js, backup_files=True) webpack_config = os.path.join(TEST_RUN_HOME, APP_NAME, 'webpack.config.js') old_string = 'new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),' new_string = 'new CopyWebpackPlugin(dataToCopy), new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),' File.replace(path=webpack_config, old_string=old_string, new_string=new_string, backup_files=True) old_string = 'const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));' new_string = """ const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); const fileName = "package.json" const dataInfo = { from: `../app/new/${fileName}`, to: `${dist}/new/${fileName}`, } env.externals = [fileName]; const dataToCopy = [dataInfo];""" File.replace(path=webpack_config, old_string=old_string, new_string=new_string, backup_files=False) log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=False).output test_result = Wait.until(lambda: "Project successfully built." in log, timeout=300, period=5) assert test_result, 'App not build correct! Logs:' + log
def test_392_use_objective_c_plus_plus_file(self): """ https://github.com/NativeScript/ios-runtime/issues/1203 """ Folder.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-1203', 'src'), os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'), True) File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-1203', 'main-page.js'), os.path.join(APP_PATH, 'app', 'main-page.js'), True) log = Tns.run_ios(app_name=APP_NAME, emulator=True) strings = ['NativeScript logInfo method called'] result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert result, 'It seems that there\'s a problem with using objective C++ files that are added in App_Resources' # Verify app is running on device Device.wait_for_text(self.sim, text='Tap the button')
def wait_for_main_color(self, color, timeout=60): result = Wait.until(lambda: (self.get_main_color() == color).all(), timeout=timeout) if result: Log.info('Main color is: ' + str(color)) assert result, "Expected main color: " + str(color) + os.linesep + \ "Actual main color: " + str(self.get_main_color())
def test_314_check_minsdk_set_in_app_gradle_18(self): """ Test minSdk in app.gradle set to 18 https://github.com/NativeScript/android-runtime/issues/1104 """ target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle') source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104', 'api18_gradle', 'app.gradle') 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-1104', '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) Tns.plugin_remove("mylib", verify=False, path=APP_NAME) plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104', "plugin", 'src') output = Tns.plugin_add(plugin_path, path=APP_NAME, verify=False) assert "Successfully installed plugin mylib" in output.output, "mylib plugin not installed correctly!" log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = ['Manifest merger failed : uses-sdk:minSdkVersion 18', 'cannot be smaller than version 23 declared in library ', 'as the library might be using APIs not available in 18'] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) error_message = 'Test minSdk in AndroidManifest set to 23 and app.gradle set to 17 fails! Logs: ' assert test_result, error_message + File.read(log.log_file) Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
def test_311_native_package_in_arr_plugin(self): """ Test native packages in arr plugin https://github.com/NativeScript/android-runtime/issues/993 """ source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-993', "plugins", 'with_dependency', '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 app app.gradle so it contains the dependencies to com.github.myinnos:AwesomeImagePicker:1.0.2 target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle') source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-993', "plugins", 'app.gradle') File.copy(source=source_js, target=target_js, backup_files=True) plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-993', "plugins", 'with_dependency', 'src') Tns.plugin_remove("mylib", verify=False, path=APP_NAME) output = Tns.plugin_add(plugin_path, path=APP_NAME, verify=False) assert "Successfully installed plugin mylib" in output.output, "mylib plugin not installed correctly!" 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 ARR PLUGIN PASSED###'] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'Native packages could not be used in arr plugin' Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
def test_312_check_minsdk_error_when_building_plugin_with_api23(self): """ Test plugin with minSdk(23) fails when build with default minSdk(17) https://github.com/NativeScript/android-runtime/issues/1104 """ source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104', '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) target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle') if File.exists(target_js): File.delete(target_js, True) plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104', "plugin", 'src') Tns.plugin_remove("mylib", verify=False, path=APP_NAME) output = Tns.plugin_add(plugin_path, path=APP_NAME, verify=False) assert "Successfully installed plugin mylib" in output.output, "mylib plugin not installed correctly!" log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = [ 'uses-sdk:minSdkVersion 17 cannot be smaller than version 23 declared in library [:com.tns-release:]', 'as the library might be using APIs not available in 17', 'Suggestion: use a compatible library with a minSdk of at most 17', 'or increase this project\'s minSdk version to at least 23', 'or use tools:overrideLibrary="com.example.comtns" to force usage (may lead to runtime failures)'] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'Should not be able to build with plugin which minsdk version is 23!' Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
def __debug_elements(self, platform, device): # Start debug and open elements tab Tns.debug(app_name=self.app_name, platform=platform, emulator=True) self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.ELEMENTS) self.dev_tools.wait_element_by_text(text=ACTION_BAR_TITLE) # Add child and verify it is visible in CDT device.click(text=HOME_ADD_CHILD_BUTTON) self.dev_tools.doubleclick_line(text='StackLayout') self.dev_tools.doubleclick_line(text='ScrollView') time.sleep(4) self.dev_tools.doubleclick_line(text='FlexboxLayout') if platform == Platform.ANDROID: assert self.dev_tools.wait_element_by_text( text='StackLayout id=') is not None else: assert self.dev_tools.wait_element_by_text( text='StackLayout iosOverflowSafeArea="true" id=') is not None # Remove child and verify it is NOT visible in CDT device.click(text=HOME_REMOVE_CHILD_BUTTON) text = 'StackLayout id=' if platform == Platform.IOS: text = 'StackLayout iosOverflowSafeArea="true" id=' found = Wait.until( lambda: self.dev_tools.find_element_by_text(text=text) is None, timeout=10) assert found is True, 'Item not removed from elements tab after removed from app.'
def test_389_add_swift_files_to_xcode_project(self): """ Test that users are be able to add swift files and use it https://github.com/NativeScript/ios-runtime/issues/1131 """ Folder.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-1131', 'src'), os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'), True) File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-1131', 'main-page.js'), os.path.join(APP_PATH, 'app', 'main-page.js'), True) log = Tns.run_ios(app_name=APP_NAME, emulator=True) # Verify app is running on device Device.wait_for_text(self.sim, text='Tap the button') strings = ['Swift class property: 123', 'Swift class method: GREAT!'] result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert result, 'It seems that there\'s a problem with using swift files that are added in App_Resources'
def test_205_test_foreground__intent_service_without_oncreate_method_is_working_api28( self): """ https://github.com/NativeScript/android-runtime/issues/1426 """ DeviceManager.Emulator.stop() self.emulator = DeviceManager.Emulator.ensure_available( Emulators.EMU_API_28) File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1426', '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-1426', '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-1426', '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: "Intent Handled!" in File.read(log.log_file), timeout=30, period=5) assert test_result, "Intent service is not working! Missing Log! Logs: " + File.read( log.log_file)
def wait_for_log(self, text, timeout=30): """ Wait until text is available in device logs. :param text: Text to be searched in logs. :param timeout: Timeout in seconds. :return: True if text found in device logs. """ return Wait.until(lambda: text in self.get_log(), timeout=timeout, period=1)
def wait_element_by_text(self, text, timeout=30): self.chrome.driver.implicitly_wait(1) result = Wait.until( lambda: self.find_element_by_text(text) is not None, timeout=timeout, period=1) self.chrome.driver.implicitly_wait(self.chrome.implicitly_wait) assert result, 'Failed to find element by "{0}" text.'.format( text.encode('utf-8')) Log.info('Element with text "{0}" found in CDT.'.format( text.encode('utf-8'))) return self.find_element_by_text(text)
def test_453_native_package_with_kotlin_are_working(self): """ Test native packages with kotlin are working https://github.com/NativeScript/android-runtime/issues/1571 """ # Change main-page.js so it contains only logging information source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1571', '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 app app.gradle so it contains the dependencies to androidx.core:core-ktx:1.0.2 source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1571', 'app.gradle') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle') 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 ] Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=240, period=5) test_result = Wait.until( lambda: "###TEST PASSED###" in File.read(log.log_file), timeout=100, period=5) assert test_result, 'Native packages with kotlin are not working! Logs:' + File.read( log.log_file)
def test_401_test_filtering_without_usage_flag(self): """ Test api filtering functionality with usage flag set to true """ Tns.plugin_remove("mylib", verify=False, path=APP_NAME) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'filtering', 'ios', 'without_usage', '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) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'filtering', 'ios', 'without_usage', 'native-api-usage.json') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'iOS') File.copy(source=source_js, target=target_js, backup_files=True) source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'filtering', 'plugin', 'ios', 'native-api-usage.json') target_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'filtering', 'src', 'platforms', 'ios', 'native-api-usage.json') File.copy(source=source_js, target=target_js, backup_files=True) plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'filtering', 'src') output = Tns.plugin_add(plugin_path, path=APP_NAME, verify=False) assert "Successfully installed plugin mylib" in output.output, "mylib plugin not installed correctly!" log = Tns.run_ios(APP_NAME, emulator=True, wait=False, verify=False) strings = [ 'Project successfully built', 'Successfully installed on device with identifier', 'Successfully synced application', 'CFNumberCreate created!', 'CFArrayCreate created!', 'CFCalendarCopyCurrent created!', 'Can\'t find variable: CFUUIDCreate', 'Can\'t find variable: CFTimeZoneCreateWithName' ] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'Filtering feature is not working correctly! Log:' + File.read( log.log_file) Tns.plugin_remove("mylib", verify=False, path=APP_NAME)