def setUpClass(cls): TnsTest.setUpClass() Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME)) Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_NG.local_package) json = App.get_package_json(app_name=APP_NAME) cls.app_id = json['nativescript']['id'] devices = Adb.get_ids(include_emulators=False) device_id = None for device in devices: device_id = device if device_id is not None: cls.device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, version=Adb.get_version(device_id)) Adb.uninstall(cls.app_id, device_id, assert_success=False)
def test_012_create_project_with_named_app(self): """Create app named 'app' should not be possible without --force option""" Tns.create(app_name=Settings.AppName.APP_NAME, template=Template.HELLO_WORLD_JS.local_package, app_data=Apps.HELLO_WORLD_JS, force=True, update=False) json = App.get_package_json(app_name=Settings.AppName.APP_NAME) assert json['nativescript']['id'] == 'org.nativescript.{0}'.format( Settings.AppName.APP_NAME) # Create project should fail without --force # webpack - remove template after merge result = Tns.create(app_name=Settings.AppName.APP_NAME, verify=False, template=Template.HELLO_WORLD_JS.local_package, update=False) assert "You cannot build applications named '" + Settings.AppName.APP_NAME + "' in Xcode." in result.output
def test_390_code_cache_option(self): """ CodeCache option is broken since Android Runtime 4.1.0 https://github.com/NativeScript/android-runtime/issues/1235 """ source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1235', 'package.json') target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'package.json') File.copy(source=source_js, target=target_js, backup_files=True) # `tns run android` and wait until app is deployed log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False) strings = ['Successfully synced application'] test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300, period=5) assert test_result, 'Application not build successfully!' code_cache_files = ['bundle.js.cache', 'vendor.js.cache'] json = App.get_package_json(app_name=APP_NAME) app_id = json['nativescript']['id'] # Check that for each .js file, there's a corresponding .js.cache file created on the device for code_cache_file in code_cache_files: error_message = '{0} file is not found on {1}'.format( code_cache_file, self.emulator.id) assert Adb.file_exists( device_id=self.emulator.id, package_id=app_id, file_name='app/{0}'.format(code_cache_file)), error_message # Verify app looks correct inside emulator Device.wait_for_text(self.emulator, text=TAP_THE_BUTTON)
def setUpClass(cls): TnsTest.setUpClass() cls.emulator = DeviceManager.Emulator.ensure_available( Emulators.DEFAULT) Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME)) Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_NG.local_package, update=True) json = App.get_package_json(app_name=APP_NAME) cls.app_id = json['nativescript']['id'] devices = Adb.get_ids(include_emulators=False) device_id = None for device in devices: device_id = device if device_id is not None: cls.device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, version=Adb.get_version(device_id)) Adb.uninstall(cls.app_id, device_id, assert_success=False) Tns.platform_add_android(APP_NAME, framework_path=Android.FRAMEWORK_PATH)
def create(app_name=Settings.AppName.DEFAULT, template=None, path=None, app_id=None, force=False, default=False, update=True, force_clean=True, log_trace=False, verify=True, app_data=None): """ Create {N} application. :param app_name: Application name (TestApp by default). :param template: Template string (it can be everything that can be npm installed - npm package, git url ...) :param path: Path where app to be created (Passes `--path <value>` to tns command. None by default). :param app_id: Application identifier. :param force: If true passes '--force' to tns command. :param default: If true passes '--default' to tns command. :param update: If True update the app (modules and plugins). :param force_clean: If True clean app folder before creating a project. :param log_trace: If True runs tns command with '--log trace'. :param verify: If True assert app is created properly. :param app_data: AppInfo object with expected data (used to verify app is created properly). """ # Cleanup app folder if force_clean: Folder.clean(TnsPaths.get_app_path(app_name=app_name)) # Create app normalized_app_name = app_name if ' ' in app_name: normalized_app_name = '"' + app_name + '"' command = 'create ' + normalized_app_name if template is not None: command = command + ' --template ' + template if path is not None: command = command + ' --path ' + path if app_id is not None: # noinspection SpellCheckingInspection command = command + ' --appid ' + app_id if force: command += ' --force' if default: command += ' --default' result = Tns.exec_command(command, log_trace=log_trace) # Update the app (if specified) if update: App.update(app_name=app_name) # Let TestContext know app is created TestContext.TEST_APP_NAME = app_name # Verify app is created properly if verify is not False: # Usually we do not pass path on tns create, which actually equals to cwd. # In such cases pass correct path to TnsAssert.created() if path is None: path = Settings.TEST_RUN_HOME TnsAssert.created(app_name=app_name, output=result.output, app_data=app_data, path=path) return result
def create_app(app_data, shared, sample, theme, style, prefix, source_dir, webpack): # Create shared project with sample data result = NG.new(collection=NS_SCHEMATICS, project=NGNewTests.app_name, theme=theme, shared=shared, sample=sample, style=style, prefix=prefix, source_dir=source_dir, webpack=webpack) # Verify valid {N} app is created TnsAssert.created(app_name=NGNewTests.app_name, app_data=app_data, theme=theme, webpack=webpack) assert 'Directory is already under version control. Skipping initialization of git.' in result.output, \ 'Git init should be skipped because app is created already existing repo (the one with tests).' # Check sample if sample: # TODO: Implement it pass # Check theme if theme: assert App.is_dependency(app_name=NGNewTests.app_name, dependency='nativescript-theme-core') else: assert not App.is_dependency(app_name=NGNewTests.app_name, dependency='nativescript-theme-core') # Check styling if style is None or style is StylingType.CSS: assert 'app.css' in result.output else: assert 'app.android.scss' in result.output assert 'app.ios.scss' in result.output assert '_app-common.scss' in result.output assert '_app-variables.scss' in result.output # Check webpack if webpack: assert App.is_dev_dependency(app_name=NGNewTests.app_name, dependency='nativescript-dev-webpack') else: assert not App.is_dev_dependency( app_name=NGNewTests.app_name, dependency='nativescript-dev-webpack') # Check prefix if prefix is None: prefix = 'app' path = os.path.join(Settings.TEST_RUN_HOME, NGNewTests.app_name, 'angular.json') actual_prefix = JsonUtils.read( file_path=path)['projects'][NGNewTests.app_name]['prefix'] assert str(actual_prefix) == prefix, 'Prefix not set in angular.json' # Check source dir exists (applicable only for shared projects). if shared: if source_dir is None: source_dir = 'src' assert Folder.exists( os.path.join(Settings.TEST_RUN_HOME, NGNewTests.app_name, source_dir))