示例#1
0
    def test_388_unicode_char_in_xml(self):
        """
        Test app does not crash when xml includes Unicode characters outside of the basic ASCII set
        https://github.com/NativeScript/ios-runtime/issues/1130
        """
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1130', 'main-page.xml'),
            os.path.join(APP_PATH, 'app', 'main-page.xml'), True)

        log = Tns.run_ios(app_name=APP_NAME, emulator=True)
        error = [
            'JS ERROR Error: Invalid autocapitalizationType value:undefined'
        ]
        is_error_thrown = Wait.until(lambda: all(er in File.read(log.log_file)
                                                 for er in error),
                                     timeout=30,
                                     period=5)
        assert is_error_thrown is False, 'App should not crash when xml includes Unicode characters outside of the ' \
                                         'basic ASCII set'

        # Verify app is running on device
        Device.wait_for_text(self.sim, text='Tap the button')
示例#2
0
    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_307_native_package_with_api_app_gradle(self):
        """
         Test that native packages could be used with api in app.gradle
         https://github.com/NativeScript/android-runtime/issues/993
        """

        # Change main-page.js so it contains only logging information
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-993', "api",
                                 '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
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-993', "api",
                                 '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, 'Successfully synced application',
            '###TEST API 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 with api in app.gradle'
示例#4
0
    def test_320_build_ios_with_custom_entitlements(self):
        # Add entitlements in app/App_Resources/iOS/app.entitlements
        source = os.path.join(TEST_RUN_HOME, 'assets', 'entitlements',
                              'app.entitlements')
        target = os.path.join(self.app_name, 'app', 'App_Resources', 'iOS',
                              'app.entitlements')
        File.copy(source, target)

        # Build again and verify entitlements are merged
        Tns.build_ios(self.app_name)
        entitlements_path = os.path.join(
            TnsPaths.get_platforms_ios_folder(self.app_name), self.app_name,
            'TestApp.entitlements')
        assert File.exists(entitlements_path), "Entitlements file is missing!"
        entitlements_content = File.read(entitlements_path)
        assert '<key>aps-environment</key>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<string>development</string>' in entitlements_content, "Entitlements file content is wrong!"

        # Install plugin with entitlements, build again and verify entitlements are merged
        plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'plugins',
                                   'nativescript-test-entitlements-1.0.0.tgz')
        Npm.install(package=plugin_path, option='--save', folder=self.app_name)

        Tns.build_ios(self.app_name)
        entitlements_content = File.read(entitlements_path)
        assert '<key>aps-environment</key>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<string>development</string>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<key>inter-app-audio</key>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<true/>' in entitlements_content, "Entitlements file content is wrong!"

        # Build in release, for device (provision without entitlements)
        result = Tns.build_ios(self.app_name,
                               for_device=True,
                               release=True,
                               verify=False)
        assert "Provisioning profile" in result.output
        assert "doesn't include the aps-environment and inter-app-audio entitlements" in result.output
    def workflow(app_name, device, platform, shared):
        # Create an app
        app_path = TnsPaths.get_app_path(app_name=app_name)
        Folder.clean(app_path)
        NG.new(collection=NS_SCHEMATICS, project=app_name, shared=shared)
        TnsAssert.created(app_name=app_name, app_data=None)

        # Run app initially
        text = 'TAP'
        if shared:
            text = 'Welcome to'
        result = Tns.run(app_name=app_name, platform=platform, emulator=True, hmr=True)
        strings = TnsLogs.run_messages(app_name=app_name, platform=platform, bundle=True, hmr=True, app_type=AppType.NG)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
        device.wait_for_text(text=text)

        # Generate module and component
        NG.exec_command(command='g m module-test', cwd=app_path)
        NG.exec_command(command='g c module-test/component-test', cwd=app_path)

        # Update app.modules.ts
        app_module_name = 'app.module.ts'
        app_module_path = os.path.join(app_path, 'app', app_module_name)
        if shared:
            app_module_name = 'app.module.tns.ts'
            app_module_path = os.path.join(app_path, 'src', 'app', app_module_name)
        old_string = "import { HomeComponent } from './home/home.component';"
        new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';"
        File.replace(path=app_module_path, old_string=old_string, new_string=new_string)
        File.replace(path=app_module_path, old_string='HomeComponent,', new_string='ComponentTestComponent,')

        # Update app-routing.module.ts
        app_routing_module_name = 'app-routing.module.ts'
        app_routing_module_path = os.path.join(app_path, 'app', app_routing_module_name)
        if shared:
            app_routing_module_name = 'app.routes.ts'
            app_routing_module_path = os.path.join(app_path, 'src', 'app', app_routing_module_name)
        old_string = "import { HomeComponent } from './home/home.component';"
        new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';"
        File.replace(path=app_routing_module_path, old_string=old_string, new_string=new_string)
        File.replace(path=app_routing_module_path, old_string='HomeComponent', new_string='ComponentTestComponent')

        # Verify app is updated
        logs = [app_module_name.replace('.tns', ''), app_routing_module_name.replace('.tns', ''),
                'Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs, timeout=120)
        device.wait_for_text(text='component-test works!')
示例#6
0
def __install_ns_cli():
    """
    Install NativeScript CLI locally.
    """

    # Copy NativeScript CLI (if used from local package)
    if '.tgz' in Settings.Packages.NS_CLI:
        cli_package = os.path.join(Settings.TEST_SUT_HOME, 'nativescript.tgz')
        File.copy(source=Settings.Packages.NS_CLI, target=cli_package)
        Settings.Packages.NS_CLI = cli_package

    # Install NativeScript CLI
    output = Npm.install(package=Settings.Packages.NS_CLI,
                         folder=Settings.TEST_RUN_HOME)

    # Verify executable exists after install
    path = os.path.join(Settings.TEST_RUN_HOME, 'node_modules', '.bin', 'tns')
    assert File.exists(path), 'NativeScript executable not found at ' + path
    Settings.Executables.TNS = path

    # Verify installation output
    # noinspection SpellCheckingInspection
    assert 'postinstall.js' in output, 'Post install scripts not executed.'
    assert 'dev-post-install' not in output, 'Dev post install executed on installation.'
    def test_320_check_public_method_in_abstract_interface_could_be_called_api23(
            self):
        """
         Test public method in abstract interface could be called
         https://github.com/NativeScript/android-runtime/issues/1157
        """

        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1157',
                                 '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)
        plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime',
                                   'android', 'files', 'android-runtime-1157',
                                   'API23', '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 CALL PUBLIC METHOD IN ABSTRACT INTERFACE 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, 'Test public method in abstract interface could be called fails for api23!'
示例#8
0
 def test_310_build_ios_with_copy_to(self):
     Tns.platform_remove(self.app_name, platform=Platform.IOS)
     Tns.exec_command(command='build --copy-to ' + TEST_RUN_HOME,
                      path=self.app_name,
                      platform=Platform.IOS,
                      bundle=True)
     assert Folder.exists(os.path.join(TEST_RUN_HOME, 'TestApp.app'))
     Tns.exec_command(command='build --copy-to ' + TEST_RUN_HOME,
                      path=self.app_name,
                      platform=Platform.IOS,
                      bundle=True,
                      for_device=True,
                      release=True,
                      provision=Settings.IOS.PROVISIONING)
     assert File.exists(os.path.join(TEST_RUN_HOME, 'TestApp.ipa'))
    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-debug.aab")

        result = Tns.build_android(self.app_path, aab=True, verify=False)
        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')
示例#10
0
 def test_320_cfbundleurltypes_overridden_from_plugin_ios(self):
     """
     Test for issue https://github.com/NativeScript/nativescript-cli/issues/2936
     """
     Tns.platform_remove(app_name=self.app_name, platform=Platform.IOS)
     plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'plugins',
                                'CFBundleURLName-Plugin.tgz')
     Tns.plugin_add(plugin_path, path=self.app_name)
     Tns.prepare_ios(app_name=self.app_name)
     plist = File.read(
         os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                      self.app_name, self.app_name + '-Info.plist'))
     assert '<key>NSAllowsArbitraryLoads</key>' in plist, \
         'NSAppTransportSecurity from plugin is not found in final Info.plist'
     assert '<string>bar</string>' in plist, 'CFBundleURLTypes from plugin is not found in final Info.plist'
示例#11
0
    def test_304_support_HeapByteBuffer_to_ArrayBuffer(self):
        """
         Test support HeapByteBuffer to ArrayBuffer
         https://github.com/NativeScript/android-runtime/issues/1060
        """
        # Change main-page.js so it contains only logging information
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1060',
                                 '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, 'HeapByteBuffer to ArrayBuffer conversion is not working'
示例#12
0
 def test_01_file_download(self):
     file_name = "nativescript-logo.png"
     file_path_default = TEST_RUN_HOME
     file_path = os.path.join(TEST_RUN_HOME, "test")
     url = "https://www.nativescript.org/images/default-source/logos/nativescript-logo.png"
     File.download(file_name, url)
     Folder.create(file_path)
     assert File.exists(os.path.join(file_path_default, file_name))
     File.download(file_name, url, file_path)
     assert File.exists(os.path.join(file_path, file_name))
 def download(package, output_file):
     output = Npm.run_npm_command('view {0} dist.tarball'.format(package))
     assert '.tgz' in output, 'Failed to find tarball of {0} package.'.format(
         package)
     npm_package = output.split('/')[-1].split('\n')[0]
     src_file = os.path.join(Settings.TEST_SUT_HOME, npm_package)
     File.delete(path=output_file)
     Npm.run_npm_command('pack ' + output, folder=Settings.TEST_SUT_HOME)
     File.copy(source=src_file, target=output_file)
     File.delete(src_file)
示例#14
0
 def restore_files():
     if TestContext.BACKUP_FILES:
         for file_path in TestContext.BACKUP_FILES:
             file_name = TestContext.BACKUP_FILES[file_path]
             file_temp_path = os.path.join(Settings.BACKUP_FOLDER, file_name)
             # delete file not from the original template
             if not File.exists(file_temp_path):
                 File.delete(file_path)
             else:
                 File.copy(file_temp_path, file_path)
                 File.delete(file_temp_path)
         TnsTest.__clean_backup_folder_and_dictionary()
     else:
         Log.info('No files to restore!')
    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_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)
 def sign_apk(apk_path):
     unzip_folder = apk_path.replace(".apk", "")
     File.unzip(apk_path, unzip_folder)
     meta_inf_folder_path = os.path.join(unzip_folder, "META-INF")
     File.delete(os.path.join(meta_inf_folder_path, "MANIFEST.MF"))
     AndroidErrorActivityTests.files_to_delete_in_apk(
         meta_inf_folder_path, ".RSA")
     AndroidErrorActivityTests.files_to_delete_in_apk(
         meta_inf_folder_path, ".SF")
     File.delete(apk_path)
     File.zip(unzip_folder, apk_path)
     command = "jarsigner"
     command = command + " -keystore $ANDROID_KEYSTORE_PATH "
     command = command + "-keypass $ANDROID_KEYSTORE_PASS "
     command = command + "-storepass $ANDROID_KEYSTORE_ALIAS_PASS "
     command = command + apk_path
     command = command + " $ANDROID_KEYSTORE_ALIAS"
     run(cmd=command)
示例#18
0
 def get_logcat(device_id):
     """
     Dump the log and then exit (don't block).
     :param device_id: Device id.
     """
     # sometimes command timeout. Very often on api29. Add a retry that don't wait the process to finish.
     try:
         result = Adb.run_adb_command(command='logcat -d', device_id=device_id, wait=True).output
     except TimeoutExpired:
         Log.info('get_logcat timeout! Retrying...')
         command_result = Adb.run_adb_command(command='logcat -d', device_id=device_id, wait=False)
         time.sleep(15)
         result = File.read(command_result.log_file)
         try:
             os.kill(command_result.pid, 0)
         except OSError:
             Log.info('Process already killed...')
     return result
示例#19
0
    def run_app(app_name, platform, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False):
        result = Tns.preview(app_name=app_name, bundle=bundle, hmr=hmr)

        # Read the log and extract the url to load the app on emulator
        log = File.read(result.log_file)
        url = Preview.get_url(log)
        Preview.run_url(url=url, device=device)
        # When you run preview on ios simulator on first run confirmation dialog is shown.
        if device.type == DeviceType.SIM:
            if click_open_alert is True:
                if SimAuto.find(device_info=device, text="Open"):
                    time.sleep(5)
                    device.click("Open")

        # Verify logs
        strings = TnsLogs.preview_initial_messages(platform=platform, hmr=hmr, bundle=bundle, instrumented=instrumented)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        return result
示例#20
0
    def test_210_tns_preview_android_livesync_on_two_emulators(self):
        """
        Test when preview on second emulator only the current one is refreshed.
        Test changes are synced on both emulators.
        """
        # Preview on emulator
        result = Tns.preview(app_name=self.app_name)

        # Read the log and extract the url to load the app on emulator
        log = File.read(result.log_file)
        url = Preview.get_url(log)
        Preview.run_url(url=url, device=self.emu)
        strings = TnsLogs.preview_initial_messages(device=self.emu)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text,
                               timeout=120)

        # Click on TAP button on emulator
        Adb.click_element_by_text(self.emu.id, 'TAP', case_sensitive=True)

        # Preview on second emulator
        Preview.run_url(url=url, device=self.emu_API24)
        # Here use bundle=False because on consecutive preview build is not executed again
        # and no bundle messages are displayed in log
        strings = TnsLogs.preview_initial_messages(device=self.emu,
                                                   bundle=False)
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=120)
        self.emu_API24.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Verify first emulator is not refreshed, state of app is preserved
        self.emu.wait_for_text(text='41 taps left', timeout=30)

        # Edit JS file and verify changes are applied on both emulators
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
        self.emu_API24.wait_for_text(text=Changes.JSHelloWord.JS.new_text)

        # Edit XML file and verify changes are applied
        Sync.replace(app_name=self.app_name,
                     change_set=Changes.JSHelloWord.XML)
        self.emu.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
        self.emu_API24.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
    def screen_match(self, expected_image, tolerance=0.1, timeout=30):
        """
        Verify screen match expected image.
        :param expected_image: Name of expected image.
        :param tolerance: Tolerance in percents.
        :param timeout: Timeout in seconds.
        """

        if File.exists(expected_image):
            match = False
            error_msg = 'Screen of {0} does NOT match {1}.'.format(
                self.name, expected_image)
            t_end = time.time() + timeout
            diff_image = None
            while time.time() < t_end:
                actual_image = expected_image.replace('.png', '_actual.png')
                self.get_screen(path=actual_image, log_level=logging.DEBUG)
                result = ImageUtils.image_match(actual_image=actual_image,
                                                expected_image=expected_image,
                                                tolerance=tolerance)
                if result[0]:
                    Log.info('Screen of {0} matches {1}.'.format(
                        self.name, expected_image))
                    match = True
                    break
                else:
                    diff_image = result[2]
                    error_msg += ' Diff is {0} %.'.format(result[1])
                    Log.info(error_msg)
                    time.sleep(3)
            if not match:
                if diff_image is not None:
                    diff_image_path = expected_image.replace(
                        '.png', '_diff.png')
                    diff_image.save(diff_image_path)
            assert match, error_msg
        else:
            Log.info('Expected image not found!')
            Log.info('Actual image will be saved as expected: ' +
                     expected_image)
            time.sleep(timeout)
            self.get_screen(path=expected_image, log_level=logging.DEBUG)
            assert False, "Expected image not found!"
示例#22
0
    def setUp(self):
        TnsRunTest.setUp(self)
        # "src" folder of TestApp will be restored before each test.
        # This will ensure failures in one test do not cause common failures.
        for change in [Changes.JSTabNavigation.SCSS_VARIABLES]:
            source_src = os.path.join(self.target_project_dir, 'app',
                                      os.path.basename(change.file_path))
            target_src = os.path.join(self.source_project_dir,
                                      change.file_path)
            File.clean(path=target_src)
            File.copy(source=source_src, target=target_src)

        for change in [
                Changes.JSTabNavigation.XML, Changes.JSTabNavigation.JS
        ]:
            source_src = os.path.join(self.target_project_dir, 'app', 'home',
                                      os.path.basename(change.file_path))
            target_src = os.path.join(self.source_project_dir,
                                      change.file_path)
            File.clean(path=target_src)
            File.copy(source=source_src, target=target_src)
示例#23
0
 def test_410_plugin_remove_should_not_fail_if_plugin_name_has_dot_android(
         self):
     """
     Test for issue https://github.com/NativeScript/nativescript-cli/issues/3451
     """
     Tns.platform_remove(app_name=self.app_name, platform=Platform.ANDROID)
     Tns.plugin_add(plugin_name='[email protected]',
                    path=self.app_name)
     assert Folder.exists(
         os.path.join(self.app_path, 'node_modules',
                      'nativescript-socket.io'))
     result = Tns.plugin_remove(plugin_name='nativescript-socket.io',
                                path=self.app_name,
                                log_trace=True)
     assert 'Successfully removed plugin nativescript-socket.io' in result.output
     assert 'stdout: removed 1 package' in result.output
     assert 'Exec npm uninstall nativescript-socket.io --save' in result.output
     output = File.read(os.path.join(self.app_path, 'package.json'))
     assert 'nativescript-socket.io' not in output
示例#24
0
    def test_300_tns_run_on_specific_device(self):
        Adb.open_home(device_id=self.emu.id)
        Adb.open_home(device_id=self.android_device.id)
        result = Tns.run(app_name=self.app_name,
                         platform=Platform.ANDROID,
                         device=self.android_device.id)
        # Wait for logs
        strings = TnsLogs.run_messages(app_name=self.app_name,
                                       platform=Platform.ANDROID,
                                       run_type=RunType.UNKNOWN)
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=300)

        # Verify it looks properly on device
        self.android_device.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Verify not working on emulator
        assert Changes.JSHelloWord.JS.old_text not in self.emu.get_text()
        assert self.emu.id not in File.read(result.log_file)
    def test_240_tns_preview_android_verify_plugin_warnings(self):
        """Test if correct messages are shown if plugin is missing or versions differ in Preview App."""
        # Add some plugins
        Tns.plugin_add("nativescript-barcodescanner", path=self.app_name)
        Tns.plugin_add("[email protected]", path=self.app_name)

        result = Tns.preview(app_name=self.app_name)

        # Read the log and extract the url to load the app on emulator
        log = File.read(result.log_file)
        url = Preview.get_url(log)
        Preview.run_url(url=url, device=self.emu)

        # Verify warnings for plugins
        strings = [
            'Plugin nativescript-barcodescanner is not included in preview app',
            'Local plugin nativescript-geolocation differs in major version from plugin in preview app',
            'Some features might not work as expected'
        ]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
示例#26
0
 def get_active_services(device_id, service_name=""):
     """
     Get actice services
     :param device_id: Device identifier as float.
     :param service_name: Service name you want to find as string.
     """
     try:
         result = Adb.run_adb_command(command='shell dumpsys activity services {0}'.format(service_name), wait=True,
                                      device_id=device_id).output
     except TimeoutExpired:
         Log.info('get_logcat timeout! Retrying...')
         command_result = Adb.run_adb_command(command='shell dumpsys activity services {0}'.format(service_name),
                                              wait=False, device_id=device_id)
         time.sleep(15)
         result = File.read(command_result.log_file)
         try:
             os.kill(command_result.pid, 0)
         except OSError:
             Log.info('Process already killed...')
     return result
示例#27
0
 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
示例#28
0
    def verify_installed(self, output):
        # Verify output
        assert 'Copying template files' in output
        assert 'Platform android successfully added' in output
        if Settings.HOST_OS == OSType.OSX:
            assert 'Platform ios successfully added' in output

        # Verify files
        assert Folder.exists(
            os.path.join(self.APP_PATH, 'node_modules', 'tns-core-modules'))
        assert Folder.exists(
            os.path.join(self.APP_PATH, 'platforms', 'android'))
        assert File.exists(
            os.path.join(self.APP_PATH, 'platforms', 'android',
                         'build.gradle'))
        if Settings.HOST_OS == OSType.OSX:
            assert Folder.exists(
                os.path.join(self.APP_PATH, 'platforms', 'ios'))
            assert Folder.exists(
                os.path.join(self.APP_PATH, 'platforms', 'ios',
                             'TestApp.xcodeproj'))
 def test_204_test_background_worker_support(self):
     """
      https://github.com/NativeScript/android-runtime/issues/1488
     """
     Adb.clear_logcat(self.emulator.id)
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1488', 'app.js'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js'), True)
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1488',
                      'main-view-model.js'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-view-model.js'),
         True)
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1488', 'app.gradle'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources',
                      'Android', 'app.gradle'), True)
     log = Tns.run_android(APP_NAME,
                           device=self.emulator.id,
                           wait=False,
                           verify=False)
     strings = [
         'Successfully synced application', 'on device', self.emulator.id
     ]
     test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                          for string in strings),
                              timeout=240,
                              period=5)
     assert test_result, "App not build correctly ! Logs: " + File.read(
         log.log_file)
     Device.click(self.emulator, text="TAP", case_sensitive=True)
     time.sleep(5)
     device_log = Adb.get_logcat(self.emulator.id)
     error_message = "Background worker not working as expected. Logs: " + device_log
     assert "WM-WorkerWrapper: Worker result SUCCESS for Work" in device_log, error_message
        def test_100_plugin_add_multiple_pods(self):
            plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                       'plugins', 'CocoaPods', 'carousel.tgz')
            result = Tns.plugin_add(plugin_path, path=Settings.AppName.DEFAULT)
            assert "Successfully installed plugin carousel." in result.output
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'carousel', 'package.json'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'carousel', 'platforms', 'ios', 'Podfile'))
            assert "carousel" in File.read(
                os.path.join(Settings.TEST_RUN_HOME, self.app_name,
                             'package.json'))

            plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                       'plugins', 'CocoaPods', 'keychain.tgz')
            result = Tns.plugin_add(plugin_path, path=Settings.AppName.DEFAULT)
            assert "Successfully installed plugin keychain." in result.output
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'keychain', 'package.json'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'keychain', 'platforms', 'ios', 'Podfile'))
            assert "keychain" in File.read(
                os.path.join(Settings.TEST_RUN_HOME, self.app_name,
                             'package.json'))

            result = Tns.prepare_ios(self.app_name)
            assert "Installing pods..." in result.output
            # These asserts will be available again after we merge the webpack only branch for 6.0.0 release
            # assert "Successfully prepared plugin carousel for ios." in result.output
            # assert "Successfully prepared plugin keychain for ios." in result.output

            output = File.read(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'Podfile'))
            assert "use_frameworks!" in output
            assert "pod 'iCarousel'" in output
            assert "pod 'AFNetworking'" in output
            assert "pod 'UICKeyChainStore'" in output