Ejemplo n.º 1
0
    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'
            # TODO: Uncomment line above after we release preview app with version of nativescript-geolocation > 5.1.0
            # Notes:
            # Preview command will fail bacause CLI will detect project needs update, see:
            # https://github.com/NativeScript/nativescript-cli/
            # blob/b5f88a45fbde0ef5559dc02e8cee5fb95cefe882/lib/controllers/migrate-controller.ts#L58
        ]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def test_210_tns_preview_on_simulator_and_emulator_livesync(self):
        """
        Preview app on simulator and emulator. Verify livesync.
        """
        # 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(platform=Platform.ANDROID)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

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

        # Preview on simulator
        Preview.run_url(url=url, device=self.sim)
        strings = TnsLogs.preview_initial_messages(platform=Platform.IOS)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Verify 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.sim.wait_for_text(text=Changes.JSHelloWord.JS.new_text)

        # Check changes are not synced more than once per platform
        # Extract the last part of the log
        log = File.read(result.log_file)
        log = File.extract_part_of_text(log, '[VERIFIED]')
        # Verify files are synced once
        TnsAssert.file_is_synced_once(log, Platform.ANDROID,
                                      'main-view-model.js')
        TnsAssert.file_is_synced_once(log, Platform.IOS, 'main-view-model.js')
        # Mark that part of the log as verified before next sync
        File.append(result.log_file, '[VERIFIED]')

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

        # Check changes are not synced more than once per platform
        # Extract the last part of the log
        log = File.read(result.log_file)
        log = File.extract_part_of_text(log, '[VERIFIED]')
        # Verify files are synced once
        TnsAssert.file_is_synced_once(log, Platform.ANDROID, 'main-page.xml')
        TnsAssert.file_is_synced_once(log, Platform.IOS, 'main-page.xml')
Ejemplo n.º 4
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)
 def close_permissions_windows_ios(name, sim):
     samples = ['Instagram_Clone_with_Image_Filters']
     iterations = 1
     if name in samples:
         is_ok_button_visible = PlaygroundMarketSamples.wait_for_text(
             sim, "OK", 10)
         while is_ok_button_visible:
             iterations = iterations + 1
             Preview.dismiss_simulator_alert()
             time.sleep(1)
             is_ok_button_visible = PlaygroundMarketSamples.wait_for_text(
                 sim, "OK", 5)
             if iterations == 5:
                 break
def preview_hello_world_js_ts(app_name,
                              platform,
                              device,
                              bundle=True,
                              hmr=True,
                              instrumented=False,
                              click_open_alert=False):
    result = Preview.run_app(app_name=app_name,
                             bundle=bundle,
                             hmr=hmr,
                             platform=platform,
                             device=device,
                             instrumented=instrumented,
                             click_open_alert=click_open_alert)

    # Verify app looks properly
    device.wait_for_text(text=Changes.JSHelloWord.JS.old_text,
                         timeout=60,
                         retry_delay=5)
    device.wait_for_text(text=Changes.JSHelloWord.XML.old_text, timeout=30)
    device.wait_for_main_color(color=Colors.WHITE)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name,
                                 'initial_state.png')
    device.get_screen(path=initial_state)
    return result
Ejemplo n.º 7
0
def prepare(clone_templates=True,
            install_ng_cli=False,
            get_preivew_packages=False):
    Log.info('================== Prepare Test Run ==================')
    __cleanup()
    __install_ns_cli()
    __get_runtimes()
    if install_ng_cli:
        __install_ng_cli()
        __install_schematics()
    if clone_templates:
        __get_templates()
    if get_preivew_packages:
        Preview.get_app_packages()

    Log.settings()
Ejemplo n.º 8
0
def __preview_vue(app_name, platform, device, bundle, hmr):
    # Execute `tns run` and wait until logs are OK
    return Preview.run_app(app_name=app_name,
                           bundle=bundle,
                           hmr=hmr,
                           platform=platform,
                           device=device,
                           click_open_alert=True)
Ejemplo n.º 9
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 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)
 def setUpClass(cls):
     Market.remove_results_file()
     Settings.Emulators.DEFAULT = Settings.Emulators.EMU_API_28
     TnsRunTest.setUpClass()
     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)
    def test_210_tns_preview_on_simulator_and_emulator_livesync(self):
        """
        Preview app on simulator and emulator. Verify livesync.
        """
        # 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(platform=Platform.ANDROID)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

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

        # Preview on simulator
        Preview.run_url(url=url, device=self.sim)
        strings = TnsLogs.preview_initial_messages(platform=Platform.IOS)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Verify 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.sim.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.sim.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
Ejemplo n.º 13
0
 def test(self, name, url, text):
     link = PlaygroundDocSamples.get_link(self.chrome, url)
     image_name = '{0}_{1}.png'.format(name, str(Platform.ANDROID))
     Preview.run_url(url=link, device=self.emu)
     self.emu.wait_for_text(text=text)
     self.emu.get_screen(os.path.join(Settings.TEST_OUT_IMAGES, image_name))
     if Settings.HOST_OS == OSType.OSX:
         image_name = '{0}_{1}.png'.format(name, str(Platform.IOS))
         Preview.run_url(url=link, device=self.sim)
         time.sleep(2)
         Preview.dismiss_simulator_alert()
         self.sim.wait_for_text(text=text)
         self.sim.get_screen(
             os.path.join(Settings.TEST_OUT_IMAGES, image_name))
Ejemplo n.º 14
0
def preview_hello_world_ng(app_name,
                           device,
                           bundle=False,
                           hmr=False,
                           instrumented=False,
                           click_open_alert=False):
    result = Preview.run_app(app_name=app_name,
                             bundle=bundle,
                             hmr=hmr,
                             device=device,
                             instrumented=instrumented,
                             click_open_alert=click_open_alert)

    # Verify app looks properly
    device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text)
    device.wait_for_main_color(color=Colors.WHITE)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name,
                                 'initial_state.png')
    device.get_screen(path=initial_state)
    return result
Ejemplo n.º 15
0
    def setUpClass(cls):
        TnsRunTest.setUpClass()
        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.VUE_BLANK.local_package,
                   update=True)
        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)
Ejemplo n.º 16
0
 def setUpClass(cls):
     TnsRunTest.setUpClass()
     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)
    def test(self, name, url, text, flavor):
        Log.info(text)
        retries = 1
        original_name = name.replace("_", " ").encode("utf8")
        data = {
            "name": original_name,
            "ios": "False",
            "android": "False",
            "flavor": str(flavor),
            "timeout": "False",
            "slow": "False"
        }
        is_android_fail = True
        is_ios_fail = True

        while retries >= 0:
            # =====================Android RUN========================
            if is_android_fail:
                self.chrome = Chrome()
                link, is_slow = PlaygroundMarketSamples.get_link(
                    self.chrome, url)
                if link == "":
                    Log.info('No Playground URL found in Android stage !!!')
                    data["timeout"] = "True"
                    data["slow"] = "True"
                    retries -= 1
                    continue

                Log.info('Testing Android !!!')
                image_name = '{0}_{1}.png'.format(name.encode("utf8"),
                                                  str(Platform.ANDROID))
                Preview.run_url(url=link, device=self.emu)
                Log.info(' Waiting Android app to load...')
                time.sleep(10)
                PlaygroundMarketSamples.verify_device_is_connected(
                    self.chrome, "Android SDK built")
                emulator_result = PlaygroundMarketSamples.get_error(
                    self.chrome)
                is_android_fail = emulator_result > 0
                android = str(not is_android_fail)
                data["android"] = android
                data["slow"] = str(is_slow)

                if is_android_fail:
                    self.emu.get_screen(
                        os.path.join(Settings.TEST_OUT_IMAGES, image_name))
                self.chrome.kill()

            # =====================iOS RUN========================
            if Settings.HOST_OS == OSType.OSX and is_ios_fail:
                image_name = '{0}_{1}.png'.format(name.encode("utf8"),
                                                  str(Platform.IOS))

                if self.is_ios_fail:
                    Log.info(' Installing Preview app on iOS ...')
                    Preview.install_preview_app_no_unpack(
                        self.sim, Platform.IOS)

                self.chrome = Chrome()
                link, is_slow = PlaygroundMarketSamples.get_link(
                    self.chrome, url)
                if link == "":
                    Log.info('No Playground URL found in iOS stage !!!')
                    data["timeout"] = "True"
                    data["slow"] = "True"
                    retries -= 1
                    continue

                Log.info('Testing iOS !!!')
                Preview.run_url(url=link, device=self.sim)
                if "test_0_" in self._testMethodName or "test_000_" in self._testMethodName:
                    time.sleep(10)
                    PlaygroundMarketSamples.close_popup(self.sim)
                Log.info(' Waiting iOS app to load...')
                Preview.dismiss_simulator_alert()
                time.sleep(10)
                PlaygroundMarketSamples.verify_device_is_connected(
                    self.chrome, self.sim.name)
                Preview.dismiss_simulator_alert()

                if "test_0_" in self._testMethodName or "test_000_" in self._testMethodName:
                    PlaygroundMarketSamples.close_popup(self.sim)

                PlaygroundMarketSamples.close_permissions_windows_ios(
                    name, self.sim)
                simulator_result = PlaygroundMarketSamples.get_error(
                    self.chrome)
                is_app_active = Preview.is_running_on_ios(
                    self.sim, Settings.Packages.PREVIEW_APP_ID)
                self.is_ios_fail = simulator_result > 0 or not is_app_active
                is_ios_fail = self.is_ios_fail
                os.environ["is_ios_fail"] = str(self.is_ios_fail)

                if self.is_ios_fail:
                    self.sim.get_screen(
                        os.path.join(Settings.TEST_OUT_IMAGES, image_name))

                ios = str(not self.is_ios_fail)
                data["ios"] = ios
                data["slow"] = str(is_slow)

            if self.is_ios_fail is False and is_android_fail is False:
                break
            retries -= 1
            self.tearDown()

        Market.preserve_data(data)
Ejemplo n.º 18
0
 def test_01_constants(self):
     text = File.read(path=os.path.join(self.current_folder, 'preview.log'))
     url = Preview.get_url(output=text)
     assert 'nsplay://boot?instanceId=' in url