def test_420_include_gradle_flavor(self): # https://github.com/NativeScript/android-runtime/pull/937 # https://github.com/NativeScript/nativescript-cli/pull/3467 source = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-pr-937', 'app.gradle') target = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle') File.copy(source=source, target=target, backup_files=True) Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=False) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, "platforms", "android", "app", "build", "outputs", "apk", "arm64Demo", "debug", "app-arm64-demo-debug.apk")) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, "platforms", "android", "app", "build", "outputs", "apk", "arm64Full", "debug", "app-arm64-full-debug.apk")) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, "platforms", "android", "app", "build", "outputs", "apk", "armDemo", "debug", "app-arm-demo-debug.apk")) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, "platforms", "android", "app", "build", "outputs", "apk", "armFull", "debug", "app-arm-full-debug.apk")) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, "platforms", "android", "app", "build", "outputs", "apk", "x86Demo", "debug", "app-x86-demo-debug.apk")) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, "platforms", "android", "app", "build", "outputs", "apk", "x86Full", "debug", "app-x86-full-debug.apk"))
def test_201_build_app_for_both_platforms(self): Tns.plugin_add(plugin_name='tns-plugin', path=self.app_name) # Verify files of the plugin assert File.exists( os.path.join(TnsPaths.get_app_node_modules_path(self.app_name), 'tns-plugin', 'index.js')) assert File.exists( os.path.join(TnsPaths.get_app_node_modules_path(self.app_name), 'tns-plugin', 'package.json')) assert File.exists( os.path.join(TnsPaths.get_app_node_modules_path(self.app_name), 'tns-plugin', 'test.android.js')) assert File.exists( os.path.join(TnsPaths.get_app_node_modules_path(self.app_name), 'tns-plugin', 'test.ios.js')) assert File.exists( os.path.join(TnsPaths.get_app_node_modules_path(self.app_name), 'tns-plugin', 'test2.android.xml')) assert File.exists( os.path.join(TnsPaths.get_app_node_modules_path(self.app_name), 'tns-plugin', 'test2.ios.xml')) Tns.build_ios(app_name=self.app_name) Tns.build_android(app_name=self.app_name) apk_path = os.path.join(TnsPaths.get_apk_path(self.app_name)) output = Adb.get_package_permission(apk_path) assert 'android.permission.READ_EXTERNAL_STORAGE' in output assert 'android.permission.WRITE_EXTERNAL_STORAGE' in output assert 'android.permission.INTERNET' in output
def test_450_support_external_buildscript_config_in_app_res_android_folder( self): """ Support external buildscript configurations - buildscript.gradle file placed in `App_Resources/Android` folder https://github.com/NativeScript/android-runtime/issues/1279 """ source_app_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1279', 'app.gradle') target_app_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle') File.copy(source=source_app_gradle, target=target_app_gradle, backup_files=True) source_build_script_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1279', 'buildscript.gradle') target_build_script_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android') File.copy(source=source_build_script_gradle, target=target_build_script_gradle, backup_files=True) Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=True)
def test_350_sgb_fails_generating_custom_activity(self): """ Static Binding Generator fails if class has static properties that are used within the class https://github.com/NativeScript/android-runtime/issues/1160 """ source = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1160', 'testActivity.android.js') target = os.path.join(TEST_RUN_HOME, APP_NAME, 'app') File.copy(source=source, target=target, backup_files=True) webpack_config = os.path.join(TEST_RUN_HOME, APP_NAME, 'webpack.config.js') old_string = '"tns-core-modules/ui/frame/activity",' custom_activity = 'resolve(__dirname, "app/testActivity.android.js"),' new_string = old_string + custom_activity File.replace(path=webpack_config, old_string=old_string, new_string=new_string, backup_files=True) Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME)) activity_class_path = os.path.join(TEST_RUN_HOME, APP_NAME, "platforms", "android", "app", "src", "main", "java", "com", "test") if File.exists(os.path.join(activity_class_path, "Activity.java")): assert True else: assert False, "Fail: Custom activity class is NOT generated in {0} !".format( activity_class_path)
def test_200_build_android_app_bundle(self): """Build app with android app bundle option. Verify the output(app.aab) and use bundletool to deploy on device""" path_to_aab = os.path.join(self.app_name, "platforms", "android", "app", "build", "outputs", "bundle", "debug", "app.aab") Tns.build_android(self.app_path, aab=True, verify=False) # There is an issue at the moment that the path is not shown in log. # TODO: uncomment this when the issue is fixed # assert "The build result is located at:" in result.output # assert path_to_aab in result.output assert File.exists(path_to_aab) # Verify app can be deployed on emulator via bundletool # Use bundletool to create the .apks file self.bundletool_build(self.bundletool_path, path_to_aab, self.path_to_apks) assert File.exists(self.path_to_apks) # Deploy on device self.bundletool_deploy(self.bundletool_path, self.path_to_apks, device_id=self.emu.id) # Start the app on device Adb.start_application(self.emu.id, "org.nativescript.TestApp") # Verify app looks correct inside emulator self.emu.wait_for_text(text='TAP')
def test_301_check_if_sbg_is_working_correctly_with_nativescript_purchase_plugin(self): """ https://github.com/NativeScript/android-runtime/issues/1329 """ Tns.plugin_add("nativescript-purchase", path=APP_NAME, verify=False) Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=True)
def test_451_support_external_buildscript_config_in_plugin(self): """ Support external buildscript configurations - buildscript.gradle file placed in plugin folder https://github.com/NativeScript/android-runtime/issues/1279 """ Tns.plugin_remove("sample-plugin", verify=False, path=APP_NAME) source_app_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1279', 'in-plugin', 'app.gradle') target_app_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle') File.copy(source=source_app_gradle, target=target_app_gradle, backup_files=True) source_build_script_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1279', 'buildscript.gradle') target_build_script_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android') File.copy(source=source_build_script_gradle, target=target_build_script_gradle, backup_files=True) plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1279', 'in-plugin', 'sample-plugin-2', 'src') Tns.plugin_add(plugin_path, path=APP_NAME, verify=False) Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=True) Tns.plugin_remove("sample-plugin-2", verify=False, path=APP_NAME)
def test_300_build_demo(self): # TODO: Run npm scripts from plugin seed (build plugin, link plugin and then build the app). Tns.plugin_create(self.plugin_name, type_script=True) demo_path = os.path.join(self.plugin_name, 'demo') Tns.build_android(demo_path) if Settings.HOST_OS is OSType.OSX: Tns.build_ios(demo_path)
def test_200_plugin_platforms_should_not_exist_in_tns_modules_android( self): """ Test for issue https://github.com/NativeScript/nativescript-cli/issues/3932 """ issue_path = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'issues', 'nativescript-cli-3932') Tns.platform_remove(app_name=self.app_name, platform=Platform.ANDROID) Tns.plugin_add(plugin_name='nativescript-ui-listview', path=self.app_name) Folder.clean(os.path.join(self.app_name, 'node_modules')) File.delete(os.path.join(self.app_name, 'package.json')) copy = os.path.join(issue_path, 'nativescript-ui-listview') paste = os.path.join(self.app_path, 'nativescript-ui-listview') Folder.copy(copy, paste) copy = os.path.join(issue_path, 'package.json') paste = os.path.join(self.app_name) File.copy(copy, paste) Tns.platform_add_android( app_name=self.app_name, framework_path=Settings.Android.FRAMEWORK_PATH) folder_path = os.path.join(self.app_path, 'nativescript-ui-listview') Npm.install(option='--ignore-scripts', folder=folder_path) Tns.build_android(app_name=self.app_name, bundle=False) app_path = os.path.join( TnsPaths.get_platforms_android_npm_modules(self.app_name)) assert not File.exists( os.path.join(app_path, 'nativescript-ui-listview', 'node_modules', 'nativescript-ui-core', 'platforms'))
def test_001_build_android(self, repo, org, text): Tns.build_android(app_name=repo, release=True, bundle=True, aot=True, uglify=True, snapshot=True)
def test_001_build_android(self): Tns.build_android(self.app_name) assert not File.exists( os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.plist')) assert not File.exists( os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.android.js')) assert not File.exists( os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.ios.js')) src = os.path.join(self.app_name, 'app', 'app.js') dest_1 = os.path.join(self.app_name, 'app', 'new.android.js') dest_2 = os.path.join(self.app_name, 'app', 'new.ios.js') File.copy(src, dest_1) File.copy(src, dest_2) result = Tns.build_android(self.app_name) assert "Gradle build..." in result.output, "Gradle build not called." assert result.output.count( "Gradle build...") == 1, "Only one gradle build is triggered." assert not File.exists( os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.plist')) assert not File.exists( os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.android.js')) assert not File.exists( os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.ios.js')) # Verify apk does not contain aar files apk_path = TnsPaths.get_apk_path(app_name=self.app_name, release=False) File.unzip(apk_path, self.temp_folder) # Clean META-INF folder. It contains com.android.support.... files which are expected to be there due to # https://github.com/NativeScript/nativescript-cli/pull/3923 Folder.clean(os.path.join(self.temp_folder, 'META-INF')) assert not File.pattern_exists(self.temp_folder, '*.aar') assert not File.pattern_exists(self.temp_folder, '*.plist') assert not File.pattern_exists(self.temp_folder, '*.android.*') assert not File.pattern_exists(self.temp_folder, '*.ios.*') # Verify app is built with android sdk 29 by default TnsAssert.string_in_android_manifest(apk_path, 'compileSdkVersion="29"') Folder.clean(self.temp_folder) # Verify incremental native build result = Tns.exec_command(command='build --clean', path=self.app_name, platform=Platform.ANDROID) assert "Gradle clean..." in result.output, "Gradle clean is not called." assert "Gradle build..." in result.output, "Gradle build is not called." assert result.output.count( "Gradle build...") == 1, "More than 1 gradle build is triggered."
def test_302_plugin_and_npm_modules_in_same_project_android(self): Tns.plugin_add(plugin_name='nativescript-social-share', path=self.app_name) output = Npm.install(package='nativescript-appversion', option='--save', folder=self.app_path) assert 'ERR!' not in output assert 'nativescript-appversion@' in output Tns.build_android(app_name=self.app_name, verify=False)
def test_002_build_android_release(self): Tns.build_android(self.app_name, release=True) # Configs are respected assert File.exists(TnsPaths.get_apk_path(self.app_name, release=True)) # Create zip command = "tar -czf " + self.app_name + "/app/app.tar.gz " + self.app_name + "/app/app.js" run(cmd=command, cwd=Settings.TEST_RUN_HOME, wait=True) assert File.exists(os.path.join(self.app_path, 'app', 'app.tar.gz'))
def test_200_build_android_release(self): if Settings.HOST_OS != OSType.WINDOWS: Tns.build_android(app_name=self.ng_app, release=True, bundle=True, aot=True, uglify=True, snapshot=True) else: Tns.build_android(app_name=self.ng_app, release=True, snapshot=True)
def setUpClass(cls): TnsTest.setUpClass() Docker.start() # Create JS app and copy to temp data folder Tns.create(app_name=cls.js_app, template=Template.HELLO_WORLD_JS.local_package, update=True) Tns.platform_add_android( app_name=cls.js_app, framework_path=Settings.Android.FRAMEWORK_PATH) if Settings.HOST_OS is OSType.OSX: Tns.platform_add_ios(app_name=cls.js_app, framework_path=Settings.IOS.FRAMEWORK_PATH) # Create NG app and copy to temp data folder Tns.create(app_name=cls.ng_app, template=Template.HELLO_WORLD_NG.local_package, update=True) Tns.platform_add_android( app_name=cls.ng_app, framework_path=Settings.Android.FRAMEWORK_PATH) if Settings.HOST_OS is OSType.OSX: Tns.platform_add_ios(app_name=cls.ng_app, framework_path=Settings.IOS.FRAMEWORK_PATH) # Build apps Tns.build_android(cls.js_app, release=True, bundle=True, aot=True, uglify=True, snapshot=True) Tns.build_android(cls.ng_app, release=True, bundle=True, aot=True, uglify=True, snapshot=True) if Settings.HOST_OS == OSType.OSX: Tns.build_ios(cls.js_app, release=True, bundle=True, aot=True, uglify=True, for_device=True) Tns.build_ios(cls.ng_app, release=True, bundle=True, aot=True, uglify=True, for_device=True)
def __create_and_build_app(self): Tns.create(app_name=self.app_name, template=Template.HELLO_WORLD_JS.local_package, update=False) Tns.platform_add_android( app_name=self.app_name, framework_path=Settings.Android.FRAMEWORK_PATH) if Settings.HOST_OS == OSType.OSX: Tns.platform_add_ios(app_name=self.app_name, framework_path=Settings.IOS.FRAMEWORK_PATH) Tns.build_android(self.app_name) if Settings.HOST_OS == OSType.OSX: Tns.build_ios(self.app_name)
def test_301_build_project_with_space_release(self): # Ensure ANDROID_KEYSTORE_PATH contain spaces (verification for CLI issue 2650) Folder.create("with space") file_name = os.path.basename(Settings.Android.ANDROID_KEYSTORE_PATH) cert_with_space_path = os.path.join("with space", file_name) File.copy(Settings.Android.ANDROID_KEYSTORE_PATH, cert_with_space_path) Tns.build_android(app_name='"' + self.app_name_with_space + '"', release=True) output = File.read(os.path.join(self.app_name_with_space, "package.json")) assert self.app_identifier in output.lower() output = File.read(os.path.join(TnsPaths.get_platforms_android_src_main_path(self.app_name_with_space), 'AndroidManifest.xml')) assert self.app_identifier in output.lower()
def test_302_build_project_with_space_debug_with_plugin(self): # skip remove platform because androidx is not released official app_space_path = TnsPaths.get_app_path(app_name=self.app_name_with_space) # Tns.platform_remove(app_name='"' + self.app_name_with_space + '"', platform=Platform.ANDROID) Npm.install(package='nativescript-mapbox', option='--save', folder=app_space_path) result = Tns.build_android(app_name='"' + self.app_name_with_space + '"') assert "Project successfully built" in result.output
def test_002_build_android_release_uglify_snapshot_sourcemap(self): # https://github.com/NativeScript/nativescript-dev-webpack/issues/920 result = Tns.build_android(self.app_name, release=True, uglify=True, snapshot=True, source_map=True) assert "ERROR in NativeScriptSnapshot. Snapshot generation failed!" not in result.output assert "Target architecture: arm64-v8a" not in result.output # Verify snapshot files in the built .apk apk_path = TnsPaths.get_apk_path(app_name=self.app_name, release=True) if Settings.HOST_OS != OSType.WINDOWS: TnsAssert.snapshot_build(apk_path, self.temp_folder) # Verify app is built with android sdk 29 by default TnsAssert.string_in_android_manifest(apk_path, 'compileSdkVersion="29"') # Configs are respected assert File.exists(TnsPaths.get_apk_path(self.app_name, release=True)) # Create zip command = "tar -czf " + self.app_name + "/app/app.tar.gz " + self.app_name + "/app/app.js" run(cmd=command, cwd=Settings.TEST_RUN_HOME, wait=True) assert File.exists(os.path.join(self.app_path, 'app', 'app.tar.gz'))
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_205_build_android_app_bundle_env_snapshot(self): """Build app with android app bundle option with --bundle and optimisations for snapshot. Verify the output(app.aab) and use bundletool to deploy on device.""" # This test will not run on windows because env.snapshot option is not available on that OS path_to_aab = os.path.join(self.app_name, "platforms", "android", "app", "build", "outputs", "bundle", "release", "app.aab") # Configure app with snapshot optimisations source = os.path.join('assets', 'abdoid-app-bundle', 'app.gradle') target = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'app.gradle') File.copy(source, target) webpack_config = os.path.join(self.app_name, 'webpack.config.js') File.replace(webpack_config, 'webpackConfig: config,', """webpackConfig: config, \ntargetArchs: [\"arm\", \"arm64\", \"ia32\"], \nuseLibs: true,\nandroidNdkPath: \"$ANDROID_NDK_HOME\"""") # env.snapshot is applicable only in release build Tns.build_android(self.app_path, aab=True, release=True, snapshot=True, uglify=True, verify=False) # There is an issue at the moment that the path is not shown in log. # TODO: uncomment this when the issue is fixed # assert "The build result is located at:" in result.output # assert path_to_aab in result.output assert File.exists(path_to_aab) # Verify app can be deployed on emulator via bundletool # Use bundletool to create the .apks file self.bundletool_build(self.bundletool_path, path_to_aab, self.path_to_apks) assert File.exists(self.path_to_apks) # Verify that the correct .so file is included in the package File.unzip(self.path_to_apks, os.path.join(self.app_name, 'apks')) File.unzip(os.path.join(self.app_name, 'apks', 'splits', 'base-x86.apk'), os.path.join(self.app_name, 'base_apk')) assert File.exists(os.path.join(self.app_name, 'base_apk', 'lib', 'x86', 'libNativeScript.so')) # Deploy on device self.bundletool_deploy(self.bundletool_path, self.path_to_apks, device_id=self.emu.id) # Start the app on device Adb.start_application(self.emu.id, "org.nativescript.TestApp") # Verify app looks correct inside emulator self.emu.wait_for_text(text='TAP')
def test_318_generated_classes_not_be_deleted_on_rebuild(self): """ https://github.com/NativeScript/nativescript-cli/issues/3560 """ target = os.path.join(TEST_RUN_HOME, APP_NAME, 'app') source = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-904', 'MyActivity.js') File.copy(source, target, True) webpack_config = os.path.join(TEST_RUN_HOME, APP_NAME, 'webpack.config.js') old_string = '"tns-core-modules/ui/frame/activity",' custom_activity = 'resolve(__dirname, "app/MyActivity.js"),' new_string = old_string + custom_activity File.replace(path=webpack_config, old_string=old_string, new_string=new_string, backup_files=True) Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME)) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, "app", "MyActivity.js")) assert File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, "platforms", "android", "app", "src", "main", "java", "com", "tns", "MyActivity.java")) File.delete( os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'MyActivity.js')) webpack_config = os.path.join(TEST_RUN_HOME, APP_NAME, 'webpack.config.js') old_string = 'resolve(__dirname, "app/MyActivity.js"),' new_string = '' File.replace(path=webpack_config, old_string=old_string, new_string=new_string, backup_files=False) Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME)) assert not File.exists( os.path.join(TEST_RUN_HOME, APP_NAME, "platforms", "android", "app", "src", "main", "java", "com", "tns", "MyActivity.java"))
def test_442_assert_arm64_is_enabled_by_default(self): """ Test arm64-v8 is enabled by default """ Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=True) apk_folder = os.path.join(TEST_RUN_HOME, APP_NAME, "platforms", "android", "app", "build", "outputs", "apk", "debug") apk_file = os.path.join(apk_folder, "app-debug.apk") apk_folder_to_unzip = os.path.join(apk_folder, "apk") Folder.create(apk_folder_to_unzip) command = "unzip " + apk_file + " -d " + apk_folder_to_unzip run(command, wait=False) time.sleep(20) unzip_apk_folder = os.path.join(apk_folder, "apk") arm64_folder = os.path.join(unzip_apk_folder, "lib", "arm64-v8a") assert Folder.exists( arm64_folder), "arm64-v8a architecture is missing!" error_message = "libNativeScript.so in arm64-v8a folder is missing!" assert File.exists(os.path.join(arm64_folder, "libNativeScript.so")), error_message
def test_201_error_is_shown_when_metadata_folder_in_apk_is_missing(self): """ https://github.com/NativeScript/android-runtime/issues/1471 https://github.com/NativeScript/android-runtime/issues/1382 """ Adb.uninstall("org.nativescript.TestApp", self.emulator.id, True) Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=True) apk_folder_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_DEBUG_PATH) apk_path = os.path.join(apk_folder_path, "app-debug.apk") unzip_folder = os.path.join(apk_folder_path, "app-debug") File.unzip(apk_path, unzip_folder) Folder.clean(os.path.join(unzip_folder, "assets", "metadata")) File.delete(apk_path) File.zip(unzip_folder, apk_path) self.sign_apk(apk_path) Adb.install(apk_path, self.emulator.id, 60) Adb.start_application(self.emulator.id, "org.nativescript.TestApp") text_on_screen = "com.tns.NativescriptException: metadata folder couldn\'t be opened!" self.emulator.wait_for_text(text_on_screen) error_message = "Missing metadata in apk is not causing the correct error! Logs: " assert self.emulator.is_text_visible(text_on_screen), error_message + self.emulator.get_text()
def test_319_build_project_with_foursquare_android_oauth(self): # Add foursquare native library as dependency source = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-755', 'app.gradle') target = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle') File.copy(source=source, target=target, backup_files=True) # Build the project output = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=False) assert ':asbg:generateBindings', 'Static Binding Generator not executed' assert 'cannot access its superclass' not in output.output
def test_444_test_useV8Symbols_flag_in_package_json(self): """ https://github.com/NativeScript/android-runtime/issues/1368 """ log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME)) # check the default value for v8 symbols strings = [ 'adding nativescript runtime package dependency: nativescript-optimized-with-inspector' ] test_result = Wait.until(lambda: all(string in log.output for string in strings), timeout=240, period=5) assert test_result, "Missing nativescript runtime package dependency! Logs: " + log.output File.copy( os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1368', 'package.json'), os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'package.json'), True) # check useV8Symbols flag is working log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME)) strings = [ 'adding nativescript runtime package dependency: nativescript-regular' ] test_result = Wait.until(lambda: all(string in log.output for string in strings), timeout=240, period=5) assert test_result, "Missing nativescript runtime package dependency! Logs: " + log.output # check app is working Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) test_result = Wait.until( lambda: Device.is_text_visible(self.emulator, "TAP", True), timeout=50, period=5) assert test_result, "TAP Button is missing on the device! V8 with debug symbols is making the app crash!"
def test_401_plugin_add_invalid_plugin(self): Tns.platform_remove(app_name=self.app_name, platform=Platform.IOS) Tns.platform_remove(app_name=self.app_name, platform=Platform.ANDROID) result = Tns.plugin_add(plugin_name='wd', path=self.app_name, verify=False) assert 'wd is not a valid NativeScript plugin' in result.output assert 'Verify that the plugin package.json file ' + \ 'contains a nativescript key and try again' in result.output Tns.platform_add_android( self.app_name, framework_path=Settings.Android.FRAMEWORK_PATH) Tns.platform_add_ios(self.app_name, framework_path=Settings.IOS.FRAMEWORK_PATH) # Verify iOS only plugin result = Tns.plugin_add(plugin_name='[email protected]', path=self.app_name) assert 'tns-plugin is not supported for android' in result.output assert 'Successfully installed plugin tns-plugin' in result.output # Verify Android only plugin result = Tns.plugin_add(plugin_name='acra-telerik-analytics', path=self.app_name) assert 'acra-telerik-analytics is not supported for ios' in result.output assert 'Successfully installed plugin acra-telerik-analytics' in result.output Tns.build_ios(app_name=self.app_name, bundle=False) ios_path = os.path.join( TnsPaths.get_platforms_ios_folder(self.app_name)) assert not File.pattern_exists(ios_path, pattern='*.aar') assert not File.pattern_exists(ios_path, pattern='*acra*') Tns.build_android(app_name=self.app_name, bundle=False) android_path = os.path.join( TnsPaths.get_platforms_android_folder(self.app_name)) assert File.pattern_exists(android_path, pattern='*.aar') assert File.pattern_exists(android_path, pattern='*acra*')
def test_250_check_plugin_dependencies_are_found(self): """ Test that all plugin's dependencies are found https://github.com/NativeScript/android-runtime/issues/1379 """ Tns.plugin_add(plugin_name="nativescript-image", path=os.path.join(TEST_RUN_HOME, APP_NAME)) log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME)) strings = ['WARNING: Skipping interface', 'as it cannot be resolved'] test_result = Wait.until(lambda: all(string not in log.output for string in strings), timeout=10, period=5) assert test_result, 'It seems that not all plugin\'s dependencies are found!'
def test_300_fail_build_when_sbg_bindings_file_is_missing(self): # add webpack.config.js where devtool: "eval" File.copy(os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1286', 'webpack.config.js'), os.path.join(TEST_RUN_HOME, APP_NAME, 'webpack.config.js'), True) result = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=False, bundle=True) sbg_bindings_path = os.path.join(TEST_RUN_HOME, APP_NAME, 'platforms', 'android', 'build-tools', 'sbg-bindings.txt') js_parser_path = os.path.join(TEST_RUN_HOME, APP_NAME, 'platforms', 'android', 'build-tools', 'jsparser', 'js_parser.js') exception_text = "Exception in thread \"main\" java.io.IOException: Couldn\'t find \'{0}\' bindings input " \ "file. Most probably there\'s an error in the JS Parser execution. You can run JS Parser " \ "with verbose logging by executing \"node \'{1}\' enableErrorLogging\"" \ .format(sbg_bindings_path, js_parser_path) assert "BUILD FAILED" in result.output, "Expected output not found" assert exception_text in result.output, "Expected output not found"
def test_455_gradle_hooks(self): """ Test gradle hooks works correctly https://docs.nativescript.org/core-concepts/android-runtime/advanced-topics/gradle-hooks """ source_app_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-gradle-hooks', 'app.gradle') target_app_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle') File.copy(source=source_app_gradle, target=target_app_gradle, backup_files=True) source_build_script_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-gradle-hooks', 'buildscript.gradle') target_build_script_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android') File.copy(source=source_build_script_gradle, target=target_build_script_gradle, backup_files=True) source_build_script_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-gradle-hooks', 'before-plugins.gradle') target_build_script_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android') File.copy(source=source_build_script_gradle, target=target_build_script_gradle, backup_files=True) source_build_script_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-gradle-hooks', 'gradle.properties') target_build_script_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android') File.copy(source=source_build_script_gradle, target=target_build_script_gradle, backup_files=True) plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'sample-plugin', 'src') Tns.plugin_add(plugin_path, path=APP_NAME, verify=False) result = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=True).output log_regex = r"""MESSAGE: buildscript\.gradle in app is applied! .+ MESSAGE: buildscript\.gradle in plugin is applied! .+ .+ MESSAGE: before-plugins\.gradle is applied! Test variable is set to true in plugin before-plugins\.gradle MESSAGE: Plugin include gradle is applied! Test variable is set to true in plugin include\.gradle .+ MESSAGE: app\.gradle is applied! Test variable is set to true in plugin app\.gradle""" # noqa: E501 Assert.assert_with_regex(result, log_regex) Tns.plugin_remove("sample-plugin", verify=False, path=APP_NAME)