Esempio n. 1
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!'
Esempio n. 2
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!"
Esempio n. 3
0
    def test_300_install_packages_and_prepare_after_install(self):
        Tns.create(app_name=self.app_name,
                   template=Template.HELLO_WORLD_JS.local_package,
                   update=True)
        Tns.platform_add_android(
            app_name=self.app_name,
            framework_path=Settings.Android.FRAMEWORK_PATH)
        if Settings.HOST_OS == OSType.OSX:
            Tns.platform_add_ios(app_name=self.app_name,
                                 framework_path=Settings.IOS.FRAMEWORK_PATH)

        # Add packages
        Npm.install(package='lodash', option='--save', folder=self.APP_PATH)
        Npm.install(package='gulp', option='--save-dev', folder=self.APP_PATH)
        assert App.is_dependency(app_name=self.app_name, dependency='lodash')
        assert App.is_dev_dependency(app_name=self.app_name, dependency='gulp')

        # Clean node modules
        Folder.clean(os.path.join(self.APP_PATH, 'node_modules'))
        Folder.clean(os.path.join(self.APP_PATH, 'platforms'))

        # Install and verify common packages
        result = Tns.exec_command(command='install', path=self.APP_PATH)
        self.verify_installed(output=result.output)

        # Verify external packages are also installed
        assert Folder.exists(
            os.path.join(self.APP_PATH, 'node_modules', 'lodash'))
        assert Folder.exists(
            os.path.join(self.APP_PATH, 'node_modules', 'gulp'))

        # Prepare project
        Tns.prepare_android(app_name=self.app_name)
        if Settings.HOST_OS == OSType.OSX:
            Tns.prepare_ios(app_name=self.app_name)
Esempio n. 4
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)
Esempio n. 5
0
 def test_009_create_app_default(self):
     # webpack - remove template after merge
     Folder.clean(os.path.join(Settings.AppName.APP_NAME))
     Tns.create(app_name=Settings.AppName.DEFAULT,
                default=True,
                template=Template.HELLO_WORLD_JS.local_package,
                update=False)
Esempio n. 6
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'))
    def setUpClass(cls):
        TnsTest.setUpClass()
        NG.kill()
        Folder.clean(cls.app_path)

        # Create app
        NG.new(collection=NS_SCHEMATICS, project=cls.app_name, shared=False)
        TnsAssert.created(app_name=cls.app_name, app_data=None)
Esempio n. 8
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.
     source_src = os.path.join(self.target_project_dir, 'src')
     target_src = os.path.join(self.source_project_dir, 'src')
     Folder.clean(target_src)
     Folder.copy(source=source_src, target=target_src)
Esempio n. 9
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."
Esempio n. 10
0
    def test_115_tns_run_android_add_remove_files_and_folders(self):
        """
        Add/delete files and folders should be synced properly
        """
        # Run app and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu)

        # Add new file
        # To verify that file is synced on device we have to refer some function
        # from it and verify it is executed. We will use console.log
        app_folder = os.path.join(self.source_project_dir, 'app')
        new_file = os.path.join(app_folder, 'test.js')
        renamed_file = os.path.join(app_folder, 'test_2.js')
        app_js_file = os.path.join(app_folder, 'app.js')
        File.write(new_file, "console.log('test.js synced!!!');")
        File.append(app_js_file, "require('./test.js');")
        strings = ["JS: test.js synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Rename file

        os.rename(new_file, renamed_file)
        File.replace(renamed_file, 'test.js', 'renamed file')
        time.sleep(1)
        File.replace(app_js_file, 'test.js', 'test_2.js')
        strings = ["JS: renamed file synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Delete file
        File.delete(renamed_file)
        strings = ["Module build failed", "Error: ENOENT: no such file or directory",
                   'Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text='Exception')

        File.replace(app_js_file, "require('./test_2.js');", ' ')
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       device=self.emu, run_type=RunType.UNKNOWN)
        not_existing_strings = ['12345']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Add folder
        folder_name = os.path.join(app_folder, 'test_folder')
        new_file = os.path.join(folder_name, 'test_in_folder.js')
        Folder.create(folder_name)
        File.write(new_file, "console.log('test_in_folder.js synced!!!');")
        File.append(app_js_file, "require('./test_folder/test_in_folder.js');")
        strings = ["JS: test_in_folder.js synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Delete folder
        Folder.clean(folder_name)
        strings = ["Module build failed", "Error: ENOENT: no such file or directory"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text='Exception')
Esempio n. 11
0
 def tearDownClass(cls):
     """
     Logic executed after all core_tests in class.
     """
     Tns.kill()
     TnsTest.kill_emulators()
     Process.kill_all_in_context()
     Folder.clean(Settings.TEST_OUT_TEMP)
     Log.test_class_end(TestContext.CLASS_NAME)
    def setUpClass(cls):
        TnsTest.setUpClass()
        NG.kill()
        Folder.clean(cls.app_path)

        # Create app
        NG.new(collection=NS_SCHEMATICS, project=cls.app_name, shared=False)
        # TODO: Rollback theme=False when schematics use @nativescript/theme
        TnsAssert.created(app_name=cls.app_name, app_data=None, theme=False)
Esempio n. 13
0
 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_JS.local_package,
                update=True)
     Tns.platform_add_android(APP_NAME,
                              framework_path=Android.FRAMEWORK_PATH)
Esempio n. 14
0
    def test_115_tns_run_ios_add_remove_files_and_folders(self):
        """
        Add/delete files and folders should be synced properly
        """
        # Run app and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim)

        # Add new file
        # To verify that file is synced on device we have to refer some function
        # from it and verify it is executed. We will use console.log
        app_folder = os.path.join(self.source_project_dir, 'app')
        new_file = os.path.join(app_folder, 'test.js')
        renamed_file = os.path.join(app_folder, 'test_2.js')
        app_js_file = os.path.join(app_folder, 'main-view-model.js')
        File.write(new_file, "console.log('test.js synced!!!');")
        File.append(app_js_file, "require('./test.js');")
        strings = ["test.js synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Rename file
        os.rename(new_file, renamed_file)
        File.replace(renamed_file, 'test.js', 'renamed file')
        time.sleep(1)
        File.replace(app_js_file, 'test.js', 'test_2.js')
        strings = ["renamed file synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Delete file
        File.delete(renamed_file)
        strings = ["Module build failed: Error: ENOENT", "NativeScript debugger detached"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        File.replace(app_js_file, "require('./test_2.js');", ' ')
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       device=self.sim, run_type=RunType.UNKNOWN)
        not_existing_strings = ['123']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Add folder
        folder_name = os.path.join(app_folder, 'test_folder')
        new_file = os.path.join(folder_name, 'test_in_folder.js')
        Folder.create(folder_name)
        File.write(new_file, "console.log('test_in_folder.js synced!!!');")
        File.append(app_js_file, "require('./test_folder/test_in_folder.js');")
        strings = ["test_in_folder.js synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Delete folder
        Folder.clean(folder_name)
        strings = ["Module build failed: Error: ENOENT"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
Esempio n. 15
0
 def setUpClass(cls):
     Folder.clean(Settings.TEST_OUT_HOME)
     Folder.create(Settings.TEST_OUT_LOGS)
     Folder.create(Settings.TEST_OUT_IMAGES)
     Folder.create(Settings.TEST_OUT_TEMP)
     Process.kill(proc_name="adb")
     TnsRunAndroidTest.setUpClass()
     url = "https://github.com/webdriverio/native-demo-app/releases/download/0.2.1/Android-NativeDemoApp-0.2.1.apk"
     cls.apk_path = os.path.join(Settings.TEST_RUN_HOME, "test.apk")
     File.delete(path=cls.apk_path)
     File.download(file_name='test.apk', url=url, destination_dir=Settings.TEST_RUN_HOME)
Esempio n. 16
0
    def new(collection=NS_SCHEMATICS,
            project=Settings.AppName.DEFAULT,
            shared=False,
            sample=False,
            prefix=None,
            source_dir=None,
            theme=True,
            style=None,
            webpack=True):
        """
        Execute `ng new`
        :param collection: Schematics collection.
        :param project: Project name.
        :param shared: If true pass --shared flag.
        :param sample: If true pass --sample flag.
        :param prefix: The prefix to apply to generated selectors (default value is `app`)
        :param source_dir: The name of the source directory (default value is `src`)
        :param theme: If false pass --no-theme flag.
        :param style: If style is not None pass --style flag (default value is `css`)
        :param webpack: If false pass --no-webpack flag.
        :return: ProcessInfo object.
        :rtype: core.utils.process_info.ProcessInfo
        """

        # Ensure old app do not exists
        project_path = os.path.join(Settings.TEST_RUN_HOME, project)
        Folder.clean(project_path)

        # Generate ng new command
        command = 'new'
        if collection is not None:
            command = command + ' --collection={0}'.format(collection)
        command = command + ' ' + project
        if shared:
            command = command + ' --shared'
        if sample:
            command = command + ' --sample'
        if prefix is not None:
            command = command + ' --prefix={0}'.format(str(prefix))
        if source_dir is not None:
            command = command + ' --sourceDir={0}'.format(str(source_dir))
        if style is not None:
            command = command + ' --style={0}'.format(str(style))
        if not webpack:
            command = command + ' --no-webpack'
        if not theme:
            command = command + ' --no-theme'

        # Execute the command and add current app to context
        TestContext.TEST_APP_NAME = project
        return NG.exec_command(command)
Esempio n. 17
0
    def prepare_and_build(template, platform, change_set, result_file):
        prepare_initial = 0
        build_initial = 0
        build_incremental = 0
        for _ in range(RETRY_COUNT):
            Tns.kill()
            Gradle.kill()
            Npm.cache_clean()
            Xcode.cache_clean()
            Folder.clean(folder=os.path.join(Settings.TEST_RUN_HOME, APP_NAME))
            Tns.create(app_name=APP_NAME, template=template, update=True)
            if platform == Platform.ANDROID:
                Tns.platform_add_android(
                    app_name=APP_NAME,
                    framework_path=Settings.Android.FRAMEWORK_PATH)
            elif platform == Platform.IOS:
                Tns.platform_add_ios(
                    app_name=APP_NAME,
                    framework_path=Settings.IOS.FRAMEWORK_PATH)
            else:
                raise Exception('Unknown platform: ' + str(platform))

            # Prepare
            time = Tns.prepare(app_name=APP_NAME,
                               platform=platform,
                               bundle=True).duration
            prepare_initial = prepare_initial + time

            # Build
            time = Tns.build(app_name=APP_NAME, platform=platform,
                             bundle=True).duration
            build_initial = build_initial + time
            Sync.replace(app_name=APP_NAME, change_set=change_set)
            time = Tns.build(app_name=APP_NAME, platform=platform,
                             bundle=True).duration
            build_incremental = build_incremental + time

        # Calculate averages
        result = PrepareBuildInfo()
        result.prepare_initial = prepare_initial / RETRY_COUNT
        result.build_initial = build_initial / RETRY_COUNT
        result.build_incremental = build_incremental / RETRY_COUNT

        # Save to results file
        File.delete(path=result_file)
        result_json = json.dumps(result,
                                 default=lambda o: o.__dict__,
                                 sort_keys=True,
                                 indent=4)
        File.write(path=result_file, text=str(result_json))
Esempio n. 18
0
 def setUpClass(cls):
     TnsRunTest.setUpClass()
     app_folder = os.path.join(Settings.TEST_RUN_HOME, cls.app_name)
     Folder.clean(app_folder)
     Git.clone(
         repo_url='https://github.com/NativeScript/chrome-devtools-test-app',
         local_folder=app_folder)
     Tns.platform_add_android(
         app_name=cls.app_name,
         framework_path=Settings.Android.FRAMEWORK_PATH)
     if Settings.HOST_OS == OSType.OSX:
         Tns.platform_add_ios(app_name=cls.app_name,
                              framework_path=Settings.IOS.FRAMEWORK_PATH)
     App.update(app_name=cls.app_name)
    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 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)
Esempio n. 21
0
 def clone(repo_url, local_folder, branch='master'):
     """Clone GitHub repo to local folder.
     :param repo_url: HTTPs url of the repo.
     :param branch: Branch.
     :param local_folder: Local folder to clone the repo.
     """
     if Folder.exists(folder=local_folder):
         Folder.clean(folder=local_folder)
     repo_url = get_repo_url(repo_url=repo_url, ssh_clone=Settings.SSH_CLONE)
     command = 'git clone --depth 1 {0} -b {1} "{2}"'.format(repo_url, branch, str(local_folder))
     Log.info(command)
     result = run(cmd=command)
     assert "fatal" not in result.output, "Failed to clone: " + repo_url
     assert result.exit_code == 0, "Failed to clone: " + repo_url
    def setUpClass(cls):
        TnsTest.setUpClass()
        cls.emu = DeviceManager.Emulator.ensure_available(
            Settings.Emulators.DEFAULT)
        if Settings.HOST_OS is OSType.OSX:
            cls.sim = DeviceManager.Simulator.ensure_available(
                Settings.Simulators.DEFAULT)

        for app in cls.test_data:
            org = app[1]
            repo = app[0]
            Folder.clean(os.path.join(Settings.TEST_RUN_HOME, repo))
            Git.clone(repo_url='https://github.com/{0}/{1}'.format(org, repo),
                      local_folder=repo)
Esempio n. 23
0
 def test_010_create_app_remove_app_resources(self):
     # creates valid project from local directory template
     tns_ts_template_path = os.path.join(Settings.TEST_SUT_HOME,
                                         'templates', 'packages',
                                         'template-hello-world-ts')
     Folder.clean(os.path.join(Settings.AppName.DEFAULT))
     Folder.clean(os.path.join(tns_ts_template_path, 'app',
                               'App_Resources'))
     file_path = os.path.join(tns_ts_template_path, 'package.json')
     File.replace(path=file_path,
                  old_string="tns-template-hello-world-ts",
                  new_string="test-tns-template-hello-world-ts")
     Tns.create(app_name=Settings.AppName.DEFAULT,
                template=tns_ts_template_path)
Esempio n. 24
0
    def test_07_copy_to_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)
        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.'

        # Test Copy
        File.copy(source=old_scss, target=new_scss, backup_files=True)
        content = File.read(path=new_scss)
        assert 'red;' not in content, 'Failed to copy file!'
        assert len(content.splitlines()) == 14, 'Unexpected lines count.'
        assert File.exists(new_scss)
        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()
        assert File.exists(new_scss)
        content = File.read(path=new_scss)
        assert 'red;' in content, 'Failed to replace string.'
        assert len(content.splitlines()) == 15, '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)
Esempio n. 25
0
    def test_443_build_app_and_assert_that_tns_core_modules_could_be_updated(
            self):
        """
         Test update of tns-core-modules works correctly if you have build the app first
         https://github.com/NativeScript/android-runtime/issues/1257
        """
        Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.create(app_name=APP_NAME,
                   template=Template.HELLO_WORLD_JS.local_package)
        Tns.platform_add_android(APP_NAME,
                                 framework_path=Android.FRAMEWORK_PATH)
        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)
        Npm.install(package=Packages.MODULES,
                    folder=os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.plugin_add(plugin_name="[email protected]",
                       path=os.path.join(TEST_RUN_HOME, APP_NAME))
        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=120,
                                 period=5)
        assert test_result, "App not build correctly after updating tns-core modules! Logs: " + File.read(
            log.log_file)
        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, "TAP", True),
            timeout=90,
            period=5)
        assert test_result, "TAP Button is missing on the device! Update of tns-core-modules not successful!"
Esempio n. 26
0
    def test_355_tns_run_android_delete_node_modules(self):
        """
        Run should not fail if node_modules folder is deleted
        https://github.com/NativeScript/nativescript-cli/issues/3944
        """
        # Run the project with --justLaunch
        run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu, just_launch=True)

        # Delete node_modules
        node_modules = os.path.join(Settings.TEST_RUN_HOME, self.app_name, 'node_modules')
        Folder.clean(node_modules)

        # Run the project again, verify it is build and node_modules folder exists
        run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu, just_launch=True)
        assert Folder.exists(node_modules)
Esempio n. 27
0
    def test_500_test_ES6_support(self):
        """
         https://github.com/NativeScript/android-runtime/issues/1375
        """
        Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.create(
            app_name=APP_NAME,
            template="https://github.com/NativeScript/es6-syntax-app.git",
            update=True)

        Tns.platform_add_android(APP_NAME,
                                 framework_path=Android.FRAMEWORK_PATH)
        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=120,
                                 period=5)
        assert test_result, "App not build correctly after updating tns-core modules! Logs: " + File.read(
            log.log_file)
        button_text = "Use ES6 language features"

        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, button_text),
            timeout=30,
            period=5)
        message = "Use ES6 language features Button is missing on the device! The app has crashed!"
        assert test_result, message

        Device.click(self.emulator, text=button_text, case_sensitive=False)
        test_result = Wait.until(
            lambda: "class com.js.NativeList" in File.read(log.log_file),
            timeout=25,
            period=5)
        assert test_result, "com.js.NativeList not found! Logs: " + File.read(
            log.log_file)

        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, button_text),
            timeout=30,
            period=5)
        assert test_result, message
 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 test_001_build_ios(self):
        Tns.platform_remove(self.app_name, platform=Platform.ANDROID)
        Tns.build_ios(self.app_name)
        Tns.build_ios(self.app_name, release=True)
        Tns.build_ios(self.app_name, for_device=True)
        Tns.build_ios(self.app_name, for_device=True, release=True)
        assert not File.exists(os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name), '*.aar'))
        assert not File.exists(os.path.join(TnsPaths.get_platforms_ios_npm_modules(self.app_name), '*.framework'))

        # Verify ipa has both armv7 and arm64 archs
        ipa_path = TnsPaths.get_ipa_path(app_name=self.app_name, release=True, for_device=True)
        run("mv " + ipa_path + " TestApp-ipa.tgz")
        run("unzip -o TestApp-ipa.tgz")
        result = run("lipo -info Payload/TestApp.app/TestApp")
        Folder.clean("Payload")
        assert "Architectures in the fat file: Payload/TestApp.app/TestApp are: armv7 arm64" in result.output
Esempio n. 30
0
 def __init__(self, kill_old=True, implicitly_wait=20):
     if kill_old:
         self.kill()
     path = ChromeDriverManager().install()
     Log.info('Starting Google Chrome ...')
     profile_path = os.path.join(Settings.TEST_OUT_TEMP, 'chrome_profile')
     Folder.clean(profile_path)
     options = webdriver.ChromeOptions()
     options.add_argument('user-data-dir={0}'.format(profile_path))
     self.driver = webdriver.Chrome(executable_path=path,
                                    chrome_options=options)
     self.implicitly_wait = implicitly_wait
     self.driver.implicitly_wait(self.implicitly_wait)
     self.driver.maximize_window()
     self.focus()
     Log.info('Google Chrome started!')