コード例 #1
0
    def test_389_add_swift_files_to_xcode_project(self):
        """
        Test that users are be able to add swift files and use it
        https://github.com/NativeScript/ios-runtime/issues/1131
        """

        Folder.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1131', 'src'),
            os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'), True)

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1131', 'main-page.js'),
            os.path.join(APP_PATH, 'app', 'main-page.js'), True)
        log = Tns.run_ios(app_name=APP_NAME, emulator=True)

        # Verify app is running on device
        Device.wait_for_text(self.sim, text='Tap the button')

        strings = ['Swift class property: 123', 'Swift class method: GREAT!']
        result = Wait.until(lambda: all(string in File.read(log.log_file)
                                        for string in strings),
                            timeout=300,
                            period=5)
        assert result, 'It seems that there\'s a problem with using swift files that are added in App_Resources'
コード例 #2
0
    def test_392_tns_run_ios_console_dir(self):
        # NOTE: This test depends on creation of app in test_391_tns_run_ios_console_time
        # Replace app.component.ts to use console.time() and console.timeEnd()

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-875', 'items.component.ts'),
            os.path.join(APP_PATH, 'src', 'app', 'item', 'items.component.ts'),
            True)

        # `tns run ios` and wait until app is deployed
        result = Tns.run_ios(app_name=APP_NAME,
                             emulator=True,
                             wait=False,
                             verify=False)

        # Verify sync and initial state of the app
        strings = [
            'name: Ter Stegen', 'role: Goalkeeper', 'object dump end',
            self.sim.id
        ]
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=90,
                             check_interval=10)
コード例 #3
0
    def test_384_check_for_native_and_js_callstacks(self):
        """
        https://github.com/NativeScript/ios-runtime/pull/1144
        """
        # Replace main-page.js so there is an error
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-pr-1144', 'main-page.js'),
            os.path.join(APP_PATH, 'app', 'main-page.js'), True)

        result = Tns.run_ios(app_name=APP_NAME,
                             emulator=True,
                             wait=False,
                             verify=False)
        strings = [
            'Native Stack:', 'sig_handler(int)', 'JS Stack:',
            '1   @[native code]',
            '2   onNavigatingTo@file:///app/main-page.js:34:0'
        ]
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=150,
                             check_interval=10)

        # Verify app is NOT running on device
        test_result = Wait.until(lambda: Simctl.is_process_running(
            self.sim, 'org.nativescript.' + APP_NAME) is False,
                                 timeout=120,
                                 period=5)
        assert test_result, "It seems that " + APP_NAME + " is still running when it should not!"
コード例 #4
0
    def test_385_methods_with_same_name_and_different_parameters(self):
        """
        https://github.com/NativeScript/ios-runtime/issues/877
        PR https://github.com/NativeScript/ios-runtime/pull/1013
        """
        # Replace main-page.js to call methods with the same name but different parameters count
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-877', 'main-page.js'),
            os.path.join(APP_PATH, 'app', 'main-page.js'), True)

        result = Tns.run_ios(app_name=APP_NAME,
                             emulator=True,
                             wait=False,
                             verify=False)
        strings = [
            'Successfully synced application', 'SayName no param!',
            'SayName with 1 param!', 'SayName with 2 params!'
        ]
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=150,
                             check_interval=10)

        # Verify app is running on device
        Device.wait_for_text(self.sim, text=TAP_THE_BUTTON)
    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_454_support_Kotlin_with_jar_without_use_kotlin(self):
        """
        Support gradle.properties file for enable Kotlin
        https://github.com/NativeScript/android-runtime/issues/1459
        https://github.com/NativeScript/android-runtime/issues/1463
        """
        Tns.plugin_remove("sample-plugin-2", verify=False, path=APP_NAME)
        Adb.clear_logcat(self.emulator.id)
        source_app_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files',
                                         'android-runtime-1463-1459', 'test-jar-1.0-SNAPSHOT.jar')
        target_app_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'libs')
        Folder.create(target_app_gradle)
        File.copy(source=source_app_gradle, target=target_app_gradle, backup_files=True)
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1463-1459',
                                 'main-view-model.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-view-model.js')
        File.copy(source=source_js, target=target_js, backup_files=True)
        log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False)

        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', self.emulator.id,
                   'Successfully synced application']

        test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300,
                                 period=5)
        messages = "App with Kotlin enabled and kotlin jar not build correctly! Logs: "
        assert test_result, messages + File.read(log.log_file)
        self.assert_kotlin_is_working(self.emulator)
    def test_313_check_minsdk_could_be_set_in_app_gradle(self):
        """
         Test minSdk works in app.gradle
         https://github.com/NativeScript/android-runtime/issues/1104
        """

        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle')
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104',
                                 'app.gradle')
        File.copy(source=source_js, target=target_js, backup_files=True)
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104',
                                 'main-page.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-page.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
        plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104',
                                   "plugin", 'src')
        output = Tns.plugin_add(plugin_path, path=APP_NAME, verify=False)
        assert "Successfully installed plugin mylib" in output.output, "mylib plugin not installed correctly!"

        log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False)

        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', self.emulator.id,
                   'Successfully synced application', '### TEST SHOULD NOT CRASH ###']

        test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300,
                                 period=5)
        assert test_result, 'Minsdk set in app.gradle is not working! Logs: ' + File.read(log.log_file)
        Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
    def test_314_check_minsdk_set_in_app_gradle_18(self):
        """
         Test minSdk in app.gradle set to 18
         https://github.com/NativeScript/android-runtime/issues/1104
        """
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle')
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104',
                                 'api18_gradle', 'app.gradle')
        File.copy(source=source_js, target=target_js, backup_files=True)
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104',
                                 'main-page.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-page.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
        plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104',
                                   "plugin", 'src')
        output = Tns.plugin_add(plugin_path, path=APP_NAME, verify=False)
        assert "Successfully installed plugin mylib" in output.output, "mylib plugin not installed correctly!"

        log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False)

        strings = ['Manifest merger failed : uses-sdk:minSdkVersion 18',
                   'cannot be smaller than version 23 declared in library ',
                   'as the library might be using APIs not available in 18']

        test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300,
                                 period=5)
        error_message = 'Test minSdk in AndroidManifest set to 23 and app.gradle set to 17 fails! Logs: '
        assert test_result, error_message + File.read(log.log_file)
        Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
    def test_312_check_minsdk_error_when_building_plugin_with_api23(self):
        """
         Test plugin with minSdk(23) fails when build with default minSdk(17)
         https://github.com/NativeScript/android-runtime/issues/1104
        """

        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104',
                                 'main-page.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-page.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle')
        if File.exists(target_js):
            File.delete(target_js, True)
        plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1104',
                                   "plugin", 'src')
        Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
        output = Tns.plugin_add(plugin_path, path=APP_NAME, verify=False)
        assert "Successfully installed plugin mylib" in output.output, "mylib plugin not installed correctly!"
        log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False)

        strings = [
            'uses-sdk:minSdkVersion 17 cannot be smaller than version 23 declared in library [:com.tns-release:]',
            'as the library might be using APIs not available in 17',
            'Suggestion: use a compatible library with a minSdk of at most 17',
            'or increase this project\'s minSdk version to at least 23',
            'or use tools:overrideLibrary="com.example.comtns" to force usage (may lead to runtime failures)']

        test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300,
                                 period=5)
        assert test_result, 'Should not be able to build with plugin which minsdk version is 23!'
        Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
    def test_311_native_package_in_arr_plugin(self):
        """
         Test native packages in arr plugin
         https://github.com/NativeScript/android-runtime/issues/993
        """

        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-993',
                                 "plugins",
                                 'with_dependency', 'main-page.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-page.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        # Change app app.gradle so it contains the dependencies to com.github.myinnos:AwesomeImagePicker:1.0.2
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android', 'app.gradle')
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-993',
                                 "plugins", 'app.gradle')
        File.copy(source=source_js, target=target_js, backup_files=True)
        plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-993',
                                   "plugins",
                                   'with_dependency', 'src')
        Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
        output = Tns.plugin_add(plugin_path, path=APP_NAME, verify=False)
        assert "Successfully installed plugin mylib" in output.output, "mylib plugin not installed correctly!"
        log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False)

        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', self.emulator.id,
                   'Successfully synced application', '###TEST ARR PLUGIN PASSED###']

        test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300,
                                 period=5)
        assert test_result, 'Native packages could not be used in arr plugin'
        Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
コード例 #11
0
    def test_392_use_objective_c_plus_plus_file(self):
        """
        https://github.com/NativeScript/ios-runtime/issues/1203
        """

        Folder.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1203', 'src'),
            os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'), True)

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1203', 'main-page.js'),
            os.path.join(APP_PATH, 'app', 'main-page.js'), True)
        log = Tns.run_ios(app_name=APP_NAME, emulator=True)

        strings = ['NativeScript logInfo method called']
        result = Wait.until(lambda: all(string in File.read(log.log_file)
                                        for string in strings),
                            timeout=300,
                            period=5)
        assert result, 'It seems that there\'s a problem with using objective C++ files that are added in App_Resources'

        # Verify app is running on device
        Device.wait_for_text(self.sim, text='Tap the button')
コード例 #12
0
    def test_201_test_init_mocha_js_stacktrace(self):
        # https://github.com/NativeScript/ios-runtime/issues/565
        Npm.install(package='mocha', folder=APP_PATH)
        Tns.exec_command("test init --framework",
                         cwd=APP_PATH,
                         platform='mocha')

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-565', 'example.js'),
            os.path.join(APP_PATH, 'app', 'tests'), True)

        result = File.read(os.path.join(APP_PATH, 'app', 'tests',
                                        'example.js'))
        assert "Mocha test" in result
        assert "Test" in result
        assert "Array" not in result

        result = Tns.exec_command("test ios",
                                  cwd=APP_PATH,
                                  emulator=True,
                                  wait=False)
        # TODO: Bundle: Add path to stack trace assert, (e.g. @file:///app/tests/example.js:5:25')
        # https://github.com/NativeScript/nativescript-cli/issues/4524
        strings = [
            'JavaScript stack trace',
            'JS ERROR AssertionError: expected -1 to equal 1'
        ]
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=90)
コード例 #13
0
    def setUpClass(cls):
        TnsRunTest.setUpClass()

        # Create app
        Tns.create(app_name=cls.app_name,
                   template=Template.HELLO_WORLD_NG.local_package,
                   update=True)
        src = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'logs',
                           'hello-world-ng', 'main.ts')
        target = os.path.join(Settings.TEST_RUN_HOME, cls.app_name, 'src')
        File.copy(source=src, target=target)
        src = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'logs',
                           'hello-world-ng', 'items.component.ts')
        target = os.path.join(Settings.TEST_RUN_HOME, cls.app_name, 'src',
                              'app', 'item')
        File.copy(source=src, target=target)
        Tns.platform_add_android(
            app_name=cls.app_name,
            framework_path=Settings.Android.FRAMEWORK_PATH)
        if Settings.HOST_OS is OSType.OSX:
            Tns.platform_add_ios(app_name=cls.app_name,
                                 framework_path=Settings.IOS.FRAMEWORK_PATH)

        # Copy TestApp to data folder.
        Folder.copy(source=cls.source_project_dir,
                    target=cls.target_project_dir)
コード例 #14
0
    def test_04_delete_with_restore(self):
        TestContext.BACKUP_FILES.clear()
        Folder.clean(Settings.BACKUP_FOLDER)

        # Path to files
        file_name = "app.android.add_style.scss"
        old_scss = os.path.join(self.current_folder, 'resources',
                                'app.android.scss')
        new_scss = os.path.join(self.current_folder, 'resources', file_name)

        # Create new file (so we don't break original one).
        File.copy(source=old_scss, target=new_scss)
        assert len(File.read(
            path=new_scss).splitlines()) == 14, 'Unexpected lines count.'

        # Replace
        File.delete(path=new_scss, backup_files=True)
        assert File.exists(os.path.join(Settings.BACKUP_FOLDER,
                                        file_name)), "File not backup!"
        assert TestContext.BACKUP_FILES.items()[0].__getitem__(
            0) == new_scss, "File path is not correct!"
        assert TestContext.BACKUP_FILES.items()[0].__getitem__(
            1) == file_name, "File name not correct!"

        # Revert
        TnsTest.restore_files()
        content = File.read(path=new_scss)
        assert len(content.splitlines()) == 14, 'Unexpected lines count.'
        assert not File.exists(os.path.join(Settings.BACKUP_FOLDER,
                                            file_name)), "File not deleted!"
        assert not TestContext.BACKUP_FILES, "File object not deleted!"

        File.delete(path=new_scss)
コード例 #15
0
    def test_390_check_correct_name_of_internal_class_is_returned(self):
        """
        Test that NSStringFromClass function returns correct name of iOS internal class
        https://github.com/NativeScript/ios-runtime/issues/1120
        """

        # Delete src folder from the previous test till Folder copy strt to backup folders too
        Folder.clean(
            os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'))

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1120', 'main-page.js'),
            os.path.join(APP_PATH, 'app', 'main-page.js'), True)

        log = Tns.run_ios(app_name=APP_NAME, emulator=True)

        # Verify app is running on device
        Device.wait_for_text(self.sim, text='Tap the button')

        string = ['Internal class: UITableViewCellContentView']
        result = Wait.until(lambda: all(st in File.read(log.log_file)
                                        for st in string),
                            timeout=60,
                            period=5)
        assert result, 'NSStringFromClass function returns INCORRECT name of iOS internal class!'
コード例 #16
0
    def test_06_copy_to_not_existing_file_with_restore(self):
        TestContext.BACKUP_FILES.clear()
        Folder.clean(Settings.BACKUP_FOLDER)
        # Path to files
        file_name = "app.android.add_style.scss"
        folder_name = os.path.join(self.current_folder, 'resources', 'new')
        Folder.clean(folder_name)
        Folder.create(folder_name)
        old_scss = os.path.join(self.current_folder, 'resources',
                                'app.android.scss')
        new_scss = os.path.join(folder_name, file_name)

        # Test Copy
        File.copy(source=old_scss, target=new_scss, backup_files=True)
        assert File.exists(new_scss)
        assert len(File.read(
            path=new_scss).splitlines()) == 14, 'Unexpected lines count.'
        assert not File.exists(os.path.join(Settings.BACKUP_FOLDER,
                                            file_name)), "File not backup!"
        assert TestContext.BACKUP_FILES.items()[0].__getitem__(
            0) == new_scss, "File path is not correct!"
        assert TestContext.BACKUP_FILES.items()[0].__getitem__(
            1) == file_name, "File name not correct!"

        # Revert
        TnsTest.restore_files()
        assert not File.exists(new_scss)
        assert not File.exists(os.path.join(Settings.BACKUP_FOLDER,
                                            file_name)), "File not deleted!"
        assert not TestContext.BACKUP_FILES, "File object not deleted!"
コード例 #17
0
    def test_02_replace(self):
        # Path to files
        old_scss = os.path.join(self.current_folder, 'resources',
                                'app.android.scss')
        new_scss = os.path.join(self.current_folder, 'resources',
                                'app.android.add_style.scss')
        old_value = 'Android here'
        new_value = 'Android here\n.page { background-color: red;}'

        # Create new file (so we don't break original one).
        File.copy(source=old_scss, target=new_scss)
        assert len(File.read(
            path=new_scss).splitlines()) == 14, 'Unexpected lines count.'

        # Replace
        File.replace(path=new_scss, old_string=old_value, new_string=new_value)
        content = File.read(path=new_scss)
        assert 'red;' in content, 'Failed to replace string.'
        assert len(content.splitlines()) == 15, 'Unexpected lines count.'

        # Revert
        File.replace(path=new_scss, old_string=new_value, new_string=old_value)
        content = File.read(path=new_scss)
        assert 'red;' not in content, 'Failed to replace string.'
        assert len(content.splitlines()) == 14, 'Unexpected lines count.'

        File.delete(path=new_scss)
コード例 #18
0
    def test_300_verbose_log_android(self):
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                         'files', 'verbose_log', 'app.js'),
            os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js'), True)
        output = File.read(
            os.path.join(TEST_RUN_HOME, APP_NAME, "app", "app.js"))
        assert "__enableVerboseLogging()" in output, "Verbose logging not enabled in app.js"

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', 'TNS.Native',
            'TNS.Java', self.emulator.id
        ]

        Wait.until(lambda: all(string in File.read(log.log_file)
                               for string in strings),
                   timeout=240,
                   period=5)
        log = File.read(log.log_file)
        assert "TNS.Native" in log, "__enableVerboseLogging() do not enable TNS.Native logs!"
        assert "TNS.Java" in log, "__enableVerboseLogging() do not enable TNS.Java logs!"
コード例 #19
0
    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)
コード例 #20
0
    def setUpClass(cls):
        TnsRunTest.setUpClass()
        # Start second emulator for tests
        cls.emu_API24 = DeviceManager.Emulator.ensure_available(
            Settings.Emulators.EMU_API_24)

        # Download Preview and Playground packages
        Preview.get_app_packages()

        # Install Preview and Playground
        Preview.install_preview_app(cls.emu, Platform.ANDROID)
        Preview.install_preview_app(cls.emu_API24, Platform.ANDROID)
        if Settings.HOST_OS is OSType.OSX:
            Preview.install_preview_app(cls.sim, Platform.IOS)
            Preview.install_playground_app(cls.sim, Platform.IOS)

        # Create app
        Tns.create(app_name=cls.app_name,
                   template=Template.HELLO_WORLD_JS.local_package,
                   update=True)
        src = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'logs',
                           'hello-world-js', 'app.js')
        target = os.path.join(Settings.TEST_RUN_HOME, cls.app_name, 'app')
        File.copy(source=src, target=target)

        # Copy TestApp to data folder.
        Folder.copy(source=cls.source_project_dir,
                    target=cls.target_project_dir)
コード例 #21
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
コード例 #22
0
    def setUpClass(cls):
        TnsRunTest.setUpClass()

        # Download Preview and Playground packages
        Preview.get_app_packages()

        # Install Preview and Playground
        Preview.install_preview_app(cls.emu, Platform.ANDROID)
        if Settings.HOST_OS is OSType.OSX:
            Preview.install_preview_app(cls.sim, Platform.IOS)
            Preview.install_playground_app(cls.sim, Platform.IOS)

        # Create app
        Tns.create(app_name=cls.app_name,
                   template=Template.HELLO_WORLD_NG.local_package,
                   update=True)
        src = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'logs',
                           'hello-world-ng', 'main.ts')
        target = os.path.join(Settings.TEST_RUN_HOME, cls.app_name, 'src')
        File.copy(source=src, target=target)
        src = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'logs',
                           'hello-world-ng', 'items.component.ts')
        target = os.path.join(Settings.TEST_RUN_HOME, cls.app_name, 'src',
                              'app', 'item')
        File.copy(source=src, target=target)

        # Copy TestApp to data folder.
        Folder.copy(source=cls.source_project_dir,
                    target=cls.target_project_dir)
コード例 #23
0
    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
コード例 #24
0
 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'))
コード例 #25
0
    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)
コード例 #26
0
    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"))
コード例 #27
0
    def test_303_check_if_class_implements_java_interface_java(self):
        """
         Test if java class implements java interface
         https://github.com/NativeScript/android-runtime/issues/739
        """
        # Change main-page.js so it contains only logging information
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-739', 'java',
                                 'main-page.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'main-page.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = ['Successfully synced application', "### TEST PASSED ###"]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=300,
                                 period=5)
        assert test_result, 'JAVA : Check(instanceof) for java class implements java interface does not work' \
                            '(myRunnable instanceof java.lang.Runnable)'
コード例 #28
0
    def test_391_native_properties_provided_by_internal_classes_are_available(
            self):
        """
        Test native properties provided by internal classes are available
        https://github.com/NativeScript/ios-runtime/issues/1149
        """

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1149', 'main-view-model.js'),
            os.path.join(APP_PATH, 'app', 'main-view-model.js'), True)

        log = Tns.run_ios(app_name=APP_NAME, emulator=True)

        # Verify app is running on device
        Device.wait_for_text(self.sim, text='Tap the button')

        strings = [
            'response1:  <NSHTTPURLResponse:',
            'response2:  <NSHTTPURLResponse:', 'Status Code: 200'
        ]
        result = Wait.until(lambda: all(string in File.read(log.log_file)
                                        for string in strings),
                            timeout=300,
                            period=5)
        assert result, 'It seems that native properties provided by internal classes are not available'
コード例 #29
0
 def setUp(self):
     TnsDeviceTest.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.JSHelloWord.CSS, Changes.JSHelloWord.XML, Changes.JSHelloWord.JS]:
         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)
コード例 #30
0
    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."