예제 #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)
예제 #2
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')
예제 #3
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))
예제 #4
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 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)
    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)