def create_app_ts(app_name, attributes={}, log_trace=False, assert_success=True, update_modules=True): """ Create TypeScript application based on hello-world-ts template in GitHub (branch is respected) :param app_name: Application name. :param attributes: Additional attributes for `tns create` command. :param log_trace: If true runs with `--log trace`. :param assert_success: If true application is verified once it is created. :param update_modules: If true update modules (branch is respected). :return: output of `tns create command` """ if BRANCH is "master": attr = { "--template": SUT_FOLDER + os.path.sep + "tns-template-hello-world-ts.tgz" } else: attr = {"--template": "tns-template-hello-world-ts"} attributes.update(attr) output = Tns.create_app(app_name=app_name, attributes=attributes, log_trace=log_trace, assert_success=assert_success, update_modules=update_modules) if update_modules: Tns.update_typescript(path=app_name) if assert_success: TnsAsserts.created_ts(app_name=app_name, output=output) return output
def test_200_prepare_additional_appresources(self): # prepare project output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL) # Create new files in AppResources File.copy( self.app_name + "/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png", self.app_name + "/app/App_Resources/iOS/newDefault.png") # prepare project output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.INCREMENTAL) # Verify XCode Project include files from App Resources folder output = run( "cat " + self.app_name + "/platforms/ios/TestApp.xcodeproj/project.pbxproj | grep newDefault.png" ) assert "newDefault.png" in output
def platform_add(platform=Platform.NONE, version=None, attributes={}, assert_success=True, log_trace=False, tns_path=None, measureTime=False): platform_string = Tns.__get_platform_string(platform) if version is not None: platform_string = platform_string + "@" + version output = Tns.run_tns_command("platform add " + platform_string, attributes=attributes, log_trace=log_trace, tns_path=tns_path, measureTime=measureTime) # Verify platforms added app_name = Tns.__get_app_name_from_attributes(attributes) if assert_success: TnsAsserts.platform_added(app_name=app_name, platform=platform, output=output) return output
def create_app(app_name, attributes={}, log_trace=False, assert_success=True, update_modules=True, force_clean=True, measureTime=False): if force_clean: if File.exists(app_name): Folder.cleanup(app_name) path = app_name attributes_to_string = "" for k, v in attributes.iteritems(): if "--path" in k: path = v attributes_to_string = "".join("{0} {1}".format(k, v)) attr = {} if not any(s in attributes_to_string for s in ("--ng", "--template", "--tsc", "--vue")): if BRANCH == "master": attr = {"--template": SUT_FOLDER + os.path.sep + "tns-template-hello-world.tgz"} else: attr = {"--template": "tns-template-hello-world"} attr.update(attributes) if app_name is None: output = Tns.run_tns_command("create ", attributes=attr, log_trace=log_trace, measureTime=measureTime) else: output = Tns.run_tns_command("create \"" + app_name + "\"", attributes=attr, log_trace=log_trace, measureTime=measureTime) if assert_success: TnsAsserts.created(app_name=app_name, output=output) if update_modules: Tns.update_modules(path) # Tns.ensure_app_resources(path) return output
def test_391_platform_list(self): """Platform list command should list installed platforms and if app is prepared for those platforms""" Folder.cleanup(self.app_name) Tns.create_app(self.app_name, update_modules=False) # `tns platform list` on brand new project output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.NONE, added=Platform.NONE) # `tns platform list` when iOS is added Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_PACKAGE}) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.NONE, added=Platform.IOS) # `tns platform list` when iOS is prepared Tns.prepare_ios(attributes={"--path": self.app_name}) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.IOS, added=Platform.IOS) # `tns platform list` when android is added (iOS already prepared) Tns.platform_add_android(attributes={"--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE}) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.IOS, added=Platform.BOTH) # `tns platform list` when android is prepared (iOS already prepared) Tns.prepare_android(attributes={"--path": self.app_name}) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.BOTH, added=Platform.BOTH) # Verify build both platforms is not allowed # Test for https://github.com/NativeScript/nativescript-cli/pull/3425 output = Tns.run_tns_command(command="build", attributes={"--path": self.app_name}) assert "The input is not valid sub-command for 'build' command" in output assert "<Platform> is the target mobile platform for which you want to build your project" in output
def test_300_prepare_ios_preserve_case(self): File.copy( self.app_name + "/node_modules/tns-core-modules/application/application-common.js", self.app_name + "/node_modules/tns-core-modules/application/New-application-common.js" ) File.copy( self.app_name + "/node_modules/tns-core-modules/application/application.android.js", self.app_name + "/node_modules/tns-core-modules/application/New-application.android.js" ) File.copy( self.app_name + "/node_modules/tns-core-modules/application/application.ios.js", self.app_name + "/node_modules/tns-core-modules/application/New-application.ios.js" ) output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL) # Verify case is preserved path = TnsAsserts._get_ios_modules_path(self.app_name) assert File.exists(path + 'application/New-application-common.js') assert File.exists(path + 'application/New-application.js') assert not File.exists(path + 'application/New-application.ios.js')
def test_003_debug_ios_simulator_start(self): """ Attach the debug tools to a running app in the iOS Simulator """ # Run the app and ensure it works log = Tns.run_ios(attributes={ '--path': self.app_name, '--emulator': '', '--justlaunch': '' }, assert_success=False, timeout=30) TnsAsserts.prepared(app_name=self.app_name, platform=Platform.IOS, output=log, prepare=Prepare.SKIP) Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home') # Attach debugger log = Tns.debug_ios( attributes={ '--path': self.app_name, '--emulator': '', '--start': '', '--inspector': '' }) DebugiOSInspectorSimulatorTests.__verify_debugger_attach( log, app_started=False)
def test_210_platform_update_android_when_platform_not_added(self): """`platform update` should work even if platform is not added""" output = Tns.platform_update(platform=Platform.ANDROID, attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.platform_added(self.app_name, platform=Platform.ANDROID, output=output)
def test_201_prepare_ios_platform_not_added(self): Tns.platform_remove(platform=Platform.IOS, attributes={"--path": self.app_name}, assert_success=False) output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FIRST_TIME)
def test_330_prepare_android_next(self): Tns.platform_remove(platform=Platform.ANDROID, attributes={"--path": self.app_name}, assert_success=False) Tns.platform_add_android(attributes={"--path": self.app_name}, version="next") Folder.cleanup(os.path.join(self.app_name, "node_modules")) Folder.cleanup(os.path.join(self.app_name, "platforms")) android_version = Npm.get_version("tns-android@next") File.replace(file_path=os.path.join(self.app_name, "package.json"), str1=android_version, str2="next") output = Tns.prepare_android(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.FIRST_TIME)
def test_200_platform_update_android(self): """Update platform""" # Create project with tns-android@4 Tns.platform_add_android(version="4.0.0", attributes={"--path": self.app_name}) TnsAsserts.package_json_contains(self.app_name, ["\"version\": \"4.0.0\""]) # Update platform to 5 Tns.platform_update(platform=Platform.ANDROID, version="5.0.0", attributes={"--path": self.app_name}) TnsAsserts.package_json_contains(self.app_name, ["\"version\": \"5.0.0\""])
def test_120_platform_add_android_inside_project(self): """ Add platform inside project folder (not using --path)""" Folder.navigate_to(self.app_name) output = Tns.platform_add_android(tns_path=os.path.join( "..", TNS_PATH), assert_success=False) Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False) TnsAsserts.platform_added(self.app_name, platform=Platform.ANDROID, output=output)
def test_220_platform_clean_android(self): """Prepare after `platform clean` should add the same version that was before clean""" # Create project with [email protected] Tns.platform_add_android(version="5.0.0", attributes={"--path": self.app_name}) TnsAsserts.package_json_contains(self.app_name, ["\"version\": \"5.0.0\""]) # Clean platform and verify platform is 5.0.0 Tns.platform_clean(platform=Platform.ANDROID, attributes={"--path": self.app_name}) TnsAsserts.package_json_contains(self.app_name, ["\"version\": \"5.0.0\""])
def test_201_build_android_with_additional_prepare(self): """Verify that manually running prepare does not break next build command.""" ReplaceHelper.replace(self.app_name, file_change=ReplaceHelper.CHANGE_JS) output = Tns.prepare_android(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.INCREMENTAL) Tns.build_android(attributes={"--path": self.app_name})
def test_130_platform_remove_and_platform_add_android_custom_version(self): """Verify platform add supports custom versions""" # Add custom version number Tns.platform_add_android(version="5.0.0", attributes={"--path": self.app_name}) TnsAsserts.package_json_contains(self.app_name, ["\"version\": \"5.0.0\""]) # Add remove Tns.platform_remove(platform=Platform.ANDROID, attributes={"--path": self.app_name}) # Add custom version with tag Tns.platform_add_android(version="rc", attributes={"--path": self.app_name})
def test_310_tns_run_ios_emulator_should_run_only_on_emulator(self): """ `tns run ios --emulator` should start emulator even if physical device is connected """ self.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME) output = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--justlaunch': ''}, assert_success=False) TnsAsserts.prepared(app_name=self.app_name, output=output, platform=Platform.IOS, prepare=Prepare.INCREMENTAL) app_id = Tns.get_app_id(self.app_name) assert app_id + " on device " + self.SIMULATOR_ID in output, "App not deployed on iOS Simulator!" for device_id in self.DEVICES: assert app_id + " on device " + device_id not in output, 'App is deployed on {0} device.'.format(device_id)
def test_391_platform_list(self): """Platform list command should list installed platforms and if app is prepared for those platforms""" Folder.cleanup(self.app_name) Tns.create_app(self.app_name, update_modules=False) # `tns platform list` on brand new project output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.NONE, added=Platform.NONE) # `tns platform list` when iOS is added Tns.platform_add_ios(attributes={ "--path": self.app_name, "--frameworkPath": IOS_PACKAGE }) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.NONE, added=Platform.IOS) # `tns platform list` when iOS is prepared Tns.prepare_ios(attributes={"--path": self.app_name}) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.IOS, added=Platform.IOS) # `tns platform list` when android is added (iOS already prepared) Tns.platform_add_android(attributes={ "--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE }) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.IOS, added=Platform.BOTH) # `tns platform list` when android is prepared (iOS already prepared) Tns.prepare_android(attributes={"--path": self.app_name}) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.BOTH, added=Platform.BOTH) # Verify build both platforms is not allowed # Test for https://github.com/NativeScript/nativescript-cli/pull/3425 output = Tns.run_tns_command(command="build", attributes={"--path": self.app_name}) assert "The input is not valid sub-command for 'build' command" in output assert "<Platform> is the target mobile platform for which you want to build your project" in output
def test_220_platform_clean_android(self): """Prepare after `platform clean` should add the same version that was before clean""" # Create project with [email protected] Tns.platform_add_android(version="5.0.0", attributes={"--path": self.app_name}) TnsAsserts.package_json_contains(self.app_name, ["\"version\": \"5.0.0\""]) # Clean platform and verify platform is 5.0.0 Tns.platform_clean(platform=Platform.ANDROID, attributes={"--path": self.app_name}) TnsAsserts.package_json_contains(self.app_name, ["\"version\": \"5.0.0\""])
def test_003_debug_ios_simulator_start(self): """ Attach the debug tools to a running app in the iOS Simulator """ # Run the app and ensure it works log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--justlaunch': ''}, assert_success=False, timeout=30) TnsAsserts.prepared(app_name=self.app_name, platform=Platform.IOS, output=log, prepare=Prepare.SKIP) Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home') # Attach debugger log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': '', '--start': '', '--inspector': ''}) DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log, app_started=False)
def test_200_platform_update_android(self): """Update platform""" # Create project with tns-android@4 Tns.platform_add_android(version="4.0.0", attributes={"--path": self.app_name}) TnsAsserts.package_json_contains(self.app_name, ["\"version\": \"4.0.0\""]) # Update platform to 5 Tns.platform_update(platform=Platform.ANDROID, version="5.0.0", attributes={"--path": self.app_name}) TnsAsserts.package_json_contains(self.app_name, ["\"version\": \"5.0.0\""])
def test_320_platform_add_ios_custom_bundle_id(self): # Create project with different appId Folder.cleanup(self.app_name) output = Tns.create_app(self.app_name, attributes={"--appid": "org.nativescript.MyApp"}, assert_success=False) TnsAsserts.created(self.app_name, output=output, full_check=False) output = File.read(self.app_name + os.sep + "package.json") assert "\"id\": \"org.nativescript.MyApp\"" in output # Add iOS platform Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_PACKAGE}) # Verify plist file in native project (after prepare) Tns.prepare_ios(attributes={"--path": self.app_name}) output = File.read(self.app_name + "/platforms/ios/TestApp/TestApp-Info.plist") assert "org.nativescript.MyApp" in output
def test_300_prepare_ios_preserve_case(self): File.copy(self.app_name + "/node_modules/tns-core-modules/application/application-common.js", self.app_name + "/node_modules/tns-core-modules/application/New-application-common.js") File.copy(self.app_name + "/node_modules/tns-core-modules/application/application.android.js", self.app_name + "/node_modules/tns-core-modules/application/New-application.android.js") File.copy(self.app_name + "/node_modules/tns-core-modules/application/application.ios.js", self.app_name + "/node_modules/tns-core-modules/application/New-application.ios.js") output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL) # Verify case is preserved path = TnsAsserts._get_ios_modules_path(self.app_name) assert File.exists(path + 'application/New-application-common.js') assert File.exists(path + 'application/New-application.js') assert not File.exists(path + 'application/New-application.ios.js')
def test_130_platform_remove_and_platform_add_android_custom_version(self): """Verify platform add supports custom versions""" # Add custom version number Tns.platform_add_android(version="5.0.0", attributes={"--path": self.app_name}) TnsAsserts.package_json_contains(self.app_name, ["\"version\": \"5.0.0\""]) # Add remove Tns.platform_remove(platform=Platform.ANDROID, attributes={"--path": self.app_name}) # Add custom version with tag Tns.platform_add_android(version="rc", attributes={"--path": self.app_name})
def test_200_prepare_additional_appresources(self): # prepare project output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL) # Create new files in AppResources File.copy(self.app_name + "/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png", self.app_name + "/app/App_Resources/iOS/newDefault.png") # prepare project output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.INCREMENTAL) # Verify XCode Project include files from App Resources folder output = run("cat " + self.app_name + "/platforms/ios/TestApp.xcodeproj/project.pbxproj | grep newDefault.png") assert "newDefault.png" in output
def platform_add(platform=Platform.NONE, version=None, attributes={}, assert_success=True, log_trace=False, tns_path=None, measureTime=False): platform_string = Tns.__get_platform_string(platform) if version is not None: platform_string = platform_string + "@" + version output = Tns.run_tns_command("platform add " + platform_string, attributes=attributes, log_trace=log_trace, tns_path=tns_path, measureTime=measureTime) # Verify platforms added app_name = Tns.__get_app_name_from_attributes(attributes) if assert_success: TnsAsserts.platform_added(app_name=app_name, platform=platform, output=output) return output
def get_app_id(app_name, platform=Platform.NONE): """ Get application id from package.json :param app_name: Folder where application is located. :return: Application id. """ json = TnsAsserts.get_package_json(app_name) return json.get('nativescript').get('id')
def get_app_id(app_name, platform=Platform.NONE): """ Get application id from package.json :param app_name: Folder where application is located. :return: Application id. """ json = TnsAsserts.get_package_json(app_name) return json.get('nativescript').get('id')
def create_app(app_name, attributes={}, log_trace=False, assert_success=True, update_modules=True, force_clean=True, measureTime=False): if force_clean: if File.exists(app_name): Folder.cleanup(app_name) path = app_name attributes_to_string = "" for k, v in attributes.iteritems(): if "--path" in k: path = v attributes_to_string = "".join("{0} {1}".format(k, v)) attr = {} if not any(s in attributes_to_string for s in ("--ng", "--template", "--tsc", "--vue")): if BRANCH == "master": attr = { "--template": SUT_FOLDER + os.path.sep + "tns-template-hello-world.tgz" } else: attr = {"--template": "tns-template-hello-world"} attr.update(attributes) if app_name is None: output = Tns.run_tns_command("create ", attributes=attr, log_trace=log_trace, measureTime=measureTime) else: output = Tns.run_tns_command("create \"" + app_name + "\"", attributes=attr, log_trace=log_trace, measureTime=measureTime) if assert_success: TnsAsserts.created(app_name=app_name, output=output) if update_modules: Tns.update_modules(path) # Tns.ensure_app_resources(path) return output
def tearDown(self): # Verify application state at the end of the test is correct if File.exists(self.app_name): data = TnsAsserts.get_package_json(self.app_name) assert "tns-android" in data["nativescript"], "'tns-android' not found under `nativescript` in package.json" assert "tns-android" not in data["dependencies"], "'tns-android' found under `dependencies` in package.json" BaseClass.tearDown(self) Folder.cleanup(self.platforms_android + '/build/outputs') Folder.cleanup("with space")
def tearDown(self): # Verify application state at the end of the test is correct if File.exists(self.app_name): data = TnsAsserts.get_package_json(self.app_name) assert "tns-android" in data[ "nativescript"], "'tns-android' not found under `nativescript` in package.json" assert "tns-android" not in data[ "dependencies"], "'tns-android' found under `dependencies` in package.json" BaseClass.tearDown(self) Folder.cleanup(self.platforms_android + '/build/outputs') Folder.cleanup("with space")
def test_310_tns_run_ios_emulator_should_run_only_on_emulator(self): """ `tns run ios --emulator` should start emulator even if physical device is connected """ self.SIMULATOR_ID = Simulator.ensure_available( simulator_name=SIMULATOR_NAME) output = Tns.run_ios(attributes={ '--path': self.app_name, '--emulator': '', '--justlaunch': '' }, assert_success=False) TnsAsserts.prepared(app_name=self.app_name, output=output, platform=Platform.IOS, prepare=Prepare.INCREMENTAL) app_id = Tns.get_app_id(self.app_name) assert app_id + " on device " + self.SIMULATOR_ID in output, "App not deployed on iOS Simulator!" for device_id in self.DEVICES: assert app_id + " on device " + device_id not in output, 'App is deployed on {0} device.'.format( device_id)
def test_390_platform_list(self): """Platform list command should list installed platforms and if app is prepared for those platforms""" # issue with v2 of templates - workaround with remove ios platform Tns.platform_remove(platform=Platform.IOS, attributes={"--path": self.app_name}, assert_success=False) # `tns platform list` on brand new project output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.NONE, added=Platform.NONE) # `tns platform list` when android is added Tns.platform_add_android(attributes={ "--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE }) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.NONE, added=Platform.ANDROID) # `tns platform list` when android is prepared Tns.prepare_android(attributes={"--path": self.app_name}) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.ANDROID, added=Platform.ANDROID)
def test_230_tns_update(self): """ Default `tns platform add` command""" Tns.platform_add_android(attributes={"--path": self.app_name}, version="latest") output = Tns.update(attributes={"--path": self.app_name}) if USE_YARN == "False": self.verify_update(output) modules_version = Npm.get_version("tns-core-modules") TnsAsserts.package_json_contains(self.app_name, [modules_version]) output = Tns.update(attributes={ "5.0.0": "", "--path": self.app_name }) self.verify_update(output) TnsAsserts.package_json_contains(self.app_name, ["5.0.0"]) Tns.update(attributes={"next": "", "--path": self.app_name}) self.verify_update(output) modules_version = Npm.get_version("tns-android@next") android_version = Npm.get_version("tns-core-modules@next") TnsAsserts.package_json_contains( self.app_name, [modules_version, android_version]) else: self.verify_update(output)
def test_320_platform_add_ios_custom_bundle_id(self): # Create project with different appId Folder.cleanup(self.app_name) output = Tns.create_app( self.app_name, attributes={"--appid": "org.nativescript.MyApp"}, assert_success=False) TnsAsserts.created(self.app_name, output=output, full_check=False) output = File.read(self.app_name + os.sep + "package.json") assert "\"id\": \"org.nativescript.MyApp\"" in output # Add iOS platform Tns.platform_add_ios(attributes={ "--path": self.app_name, "--frameworkPath": IOS_PACKAGE }) # Verify plist file in native project (after prepare) Tns.prepare_ios(attributes={"--path": self.app_name}) output = File.read(self.app_name + "/platforms/ios/TestApp/TestApp-Info.plist") assert "org.nativescript.MyApp" in output
def create_app_ts(app_name, attributes={}, log_trace=False, assert_success=True, update_modules=True): """ Create TypeScript application based on hello-world-ts template in GitHub (branch is respected) :param app_name: Application name. :param attributes: Additional attributes for `tns create` command. :param log_trace: If true runs with `--log trace`. :param assert_success: If true application is verified once it is created. :param update_modules: If true update modules (branch is respected). :return: output of `tns create command` """ if BRANCH is "master": attr = {"--template": SUT_FOLDER + os.path.sep + "tns-template-hello-world-ts.tgz"} else: attr = {"--template": "tns-template-hello-world-ts"} attributes.update(attr) output = Tns.create_app(app_name=app_name, attributes=attributes, log_trace=log_trace, assert_success=assert_success, update_modules=update_modules) if update_modules: Tns.update_typescript(path=app_name) if assert_success: TnsAsserts.created_ts(app_name=app_name, output=output) return output
def build_android(attributes={}, assert_success=True, tns_path=None, log_trace=False, measureTime=False): output = Tns.run_tns_command("build android", attributes=attributes, tns_path=tns_path, log_trace=log_trace, measureTime=measureTime) if assert_success: # Verify output of build command assert "Project successfully built" in output, "Build failed!" + os.linesep + output assert "FAILURE" not in output assert "NOT FOUND" not in output # Test for https://github.com/NativeScript/android-runtime/issues/390 if log_trace: assert "BUILD SUCCESSFUL" in output, "Build failed!" + os.linesep + output else: assert "BUILD SUCCESSFUL" not in output, "Native build out is displayed even without --log trace" # Verify apk packages app_name = Tns.__get_app_name_from_attributes(attributes=attributes) Tns.__get_platform_string(platform=Platform.ANDROID) android_version_string = str(TnsAsserts.get_platform_version(app_name=app_name, platform='android')) android_major_version = int(android_version_string.split('-')[0].split('.')[0]) if android_major_version > 3: apk_name = "app" debug_app_path = os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APK_DEBUG_PATH, apk_name) release_app_path = os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APK_RELEASE_PATH, apk_name) else: apk_name = Tns.__get_final_package_name(app_name, platform=Platform.ANDROID) debug_app_path = os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APK_PATH, apk_name) release_app_path = os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APK_PATH, apk_name) if "--release" in attributes.keys(): apk_path = release_app_path + "-release.apk" else: apk_path = debug_app_path + "-debug.apk" apk_path = apk_path.replace("\"", "") # Handle projects with space assert File.exists(apk_path), "Apk file does not exist at " + apk_path # Verify final package contains right modules (or verify bundle when it is used) if "--bundle" not in attributes.keys(): assert "Webpack compilation complete" not in output else: assert "Webpack compilation complete" in output assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "bundle.js")) assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "package.json")) assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "starter.js")) assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "vendor.js")) assert not Folder.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_NPM_MODULES_PATH)) return output
def test_101_prepare_android(self): # Initial prepare should be full. output = Tns.prepare_android(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.FULL) # If no file is touched next time prepare should be skipped at all. output = Tns.prepare_android(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.SKIP) # If some JS/CSS/XML is changed incremental prepare should be done. ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS) output = Tns.prepare_android(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.INCREMENTAL)
def test_390_platform_list(self): """Platform list command should list installed platforms and if app is prepared for those platforms""" # issue with v2 of templates - workaround with remove ios platform Tns.platform_remove(platform=Platform.IOS, attributes={"--path": self.app_name}, assert_success=False) # `tns platform list` on brand new project output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.NONE, added=Platform.NONE) # `tns platform list` when android is added Tns.platform_add_android(attributes={"--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE}) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.NONE, added=Platform.ANDROID) # `tns platform list` when android is prepared Tns.prepare_android(attributes={"--path": self.app_name}) output = Tns.platform_list(attributes={"--path": self.app_name}) TnsAsserts.platform_list_status(output=output, prepared=Platform.ANDROID, added=Platform.ANDROID)
def test_230_tns_update(self): """ Default `tns platform add` command""" Tns.platform_add_android(attributes={"--path": self.app_name}, version="latest") output = Tns.update(attributes={"--path": self.app_name}) if USE_YARN == "False": self.verify_update(output) modules_version = Npm.get_version("tns-core-modules") TnsAsserts.package_json_contains(self.app_name, [modules_version]) output = Tns.update(attributes={"5.0.0": "", "--path": self.app_name}) self.verify_update(output) TnsAsserts.package_json_contains(self.app_name, ["5.0.0"]) Tns.update(attributes={"next": "", "--path": self.app_name}) self.verify_update(output) modules_version = Npm.get_version("tns-android@next") android_version = Npm.get_version("tns-core-modules@next") TnsAsserts.package_json_contains(self.app_name, [modules_version, android_version]) else: self.verify_update(output)
def test_120_platform_add_android_inside_project(self): """ Add platform inside project folder (not using --path)""" Folder.navigate_to(self.app_name) output = Tns.platform_add_android(tns_path=os.path.join("..", TNS_PATH), assert_success=False) Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False) TnsAsserts.platform_added(self.app_name, platform=Platform.ANDROID, output=output)
def test_100_prepare_ios(self): Tns.platform_add_android(attributes={ "--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE }) # Initial prepare should be full. output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL) # If no file is touched next time prepare should be skipped at all. output = Tns.prepare_ios(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.SKIP) # If some JS/CSS/XML is changed incremental prepare should be done. ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS) output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.INCREMENTAL) # Verify Xcode Schemes output = run("xcodebuild -project " + self.app_name + "/platforms/ios/TestApp.xcodeproj/ -list") assert "This project contains no schemes." not in output result = re.search("Targets:\n\s*TestApp", output) assert result is not None result = re.search("Schemes:\n\s*TestApp", output) assert result is not None # Initial prepare for other platform (Android) should be full. output = Tns.prepare_android(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.FULL) # Prepare original platform (iOS) should be skipped. output = Tns.prepare_ios(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.SKIP) # Initial prepare for other platform (Android) should be skipped. output = Tns.prepare_android(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.SKIP)
def build_android(attributes={}, assert_success=True, tns_path=None, log_trace=False, measureTime=False): output = Tns.run_tns_command("build android", attributes=attributes, tns_path=tns_path, log_trace=log_trace, measureTime=measureTime) if assert_success: # Verify output of build command assert "Project successfully built" in output, "Build failed!" + os.linesep + output assert "FAILURE" not in output assert "NOT FOUND" not in output # Test for https://github.com/NativeScript/android-runtime/issues/390 if log_trace: assert "BUILD SUCCESSFUL" in output, "Build failed!" + os.linesep + output else: assert "BUILD SUCCESSFUL" not in output, "Native build out is displayed even without --log trace" # Verify apk packages app_name = Tns.__get_app_name_from_attributes( attributes=attributes) Tns.__get_platform_string(platform=Platform.ANDROID) android_version_string = str( TnsAsserts.get_platform_version(app_name=app_name, platform='android')) android_major_version = int( android_version_string.split('-')[0].split('.')[0]) if android_major_version > 3: apk_name = "app" debug_app_path = os.path.join( app_name, TnsAsserts.PLATFORM_ANDROID_APK_DEBUG_PATH, apk_name) release_app_path = os.path.join( app_name, TnsAsserts.PLATFORM_ANDROID_APK_RELEASE_PATH, apk_name) else: apk_name = Tns.__get_final_package_name( app_name, platform=Platform.ANDROID) debug_app_path = os.path.join( app_name, TnsAsserts.PLATFORM_ANDROID_APK_PATH, apk_name) release_app_path = os.path.join( app_name, TnsAsserts.PLATFORM_ANDROID_APK_PATH, apk_name) if "--release" in attributes.keys(): apk_path = release_app_path + "-release.apk" else: apk_path = debug_app_path + "-debug.apk" apk_path = apk_path.replace("\"", "") # Handle projects with space assert File.exists( apk_path), "Apk file does not exist at " + apk_path # Verify final package contains right modules (or verify bundle when it is used) if "--bundle" not in attributes.keys(): assert "Webpack compilation complete" not in output else: assert "Webpack compilation complete" in output assert File.exists( os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "bundle.js")) assert File.exists( os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "package.json")) assert File.exists( os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "starter.js")) assert File.exists( os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "vendor.js")) assert not Folder.exists( os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_NPM_MODULES_PATH)) return output
def test_102_prepare_android_inside_project(self): Folder.navigate_to(self.app_name) output = Tns.prepare_android(tns_path=os.path.join("..", TNS_PATH), assert_success=False) Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.FULL)
def test_201_build_android_with_additional_prepare(self): """Verify that manually running prepare does not break next build command.""" ReplaceHelper.replace(self.app_name, file_change=ReplaceHelper.CHANGE_JS) output = Tns.prepare_android(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.INCREMENTAL) Tns.build_android(attributes={"--path": self.app_name})
def test_210_platform_update_android_when_platform_not_added(self): """`platform update` should work even if platform is not added""" output = Tns.platform_update(platform=Platform.ANDROID, attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.platform_added(self.app_name, platform=Platform.ANDROID, output=output)
def test_201_prepare_ios_platform_not_added(self): Tns.platform_remove(platform=Platform.IOS, attributes={"--path": self.app_name}, assert_success=False) output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FIRST_TIME)
def test_200_prepare_android_platform_not_added(self): Tns.platform_remove(platform=Platform.ANDROID, attributes={"--path": self.app_name}, assert_success=False) output = Tns.prepare_android(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.FIRST_TIME)
def test_100_prepare_ios(self): Tns.platform_add_android(attributes={"--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE}) # Initial prepare should be full. output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL) # If no file is touched next time prepare should be skipped at all. output = Tns.prepare_ios(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.SKIP) # If some JS/CSS/XML is changed incremental prepare should be done. ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS) output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.INCREMENTAL) # Verify Xcode Schemes output = run("xcodebuild -project " + self.app_name + "/platforms/ios/TestApp.xcodeproj/ -list") assert "This project contains no schemes." not in output result = re.search("Targets:\n\s*TestApp", output) assert result is not None result = re.search("Schemes:\n\s*TestApp", output) assert result is not None # Initial prepare for other platform (Android) should be full. output = Tns.prepare_android(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.FULL) # Prepare original platform (iOS) should be skipped. output = Tns.prepare_ios(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.SKIP) # Initial prepare for other platform (Android) should be skipped. output = Tns.prepare_android(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.SKIP)