コード例 #1
0
    def __debug_elements(self, platform, device):
        # Run `tns debug` wait until app is visible on device
        Tns.debug(app_name=self.app_name, platform=platform, emulator=True)
        device.wait_for_text(text='TAP')

        # Start debug session and verify elements tab
        self.dev_tools = ChromeDevTools(self.chrome,
                                        platform=platform,
                                        tab=ChromeDevToolsTabs.ELEMENTS)
        assert self.dev_tools.wait_element_by_text(
            text=self.xml_change.old_text
        ) is not None, 'Elements tab is empty.'

        # Sync changes and verify elements tab is updated
        Sync.replace(app_name=self.app_name, change_set=self.xml_change)
        device.wait_for_text(text=self.xml_change.new_text)
        assert self.dev_tools.wait_element_by_text(
            text=self.xml_change.new_text
        ) is not None, 'Elements tab not updated.'

        # Update label in CDT and verify it is updated on device
        self.dev_tools.edit_text(old_text=self.xml_change.new_text,
                                 new_text=self.xml_change.old_text)
        element = self.dev_tools.wait_element_by_text(
            text=self.xml_change.old_text, timeout=90)
        assert element is not None, 'Failed to change text in elements tab.'
        device.wait_for_text(text=self.xml_change.old_text)
コード例 #2
0
    def test_100_run_on_all_devices(self):
        result = Tns.run(app_name=self.app_name, platform=Platform.NONE)

        # Wait for logs
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID, run_type=RunType.FULL)
        for device in DeviceManager.get_devices(device_type=any):
            strings.append(device.id)
        strings.append(self.emu.id)
        if Settings.HOST_OS is OSType.OSX:
            strings.append(self.sim.id)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=360)

        # Verify it looks properly
        for device in DeviceManager.get_devices(device_type=any):
            device.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Edit JS file and verify changes are applied
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)

        # Verify logs
        file_name = os.path.basename(Changes.JSHelloWord.JS.file_path)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID, run_type=RunType.INCREMENTAL,
                                       file_name=file_name)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Verify change is applied on all devices
        for device in DeviceManager.get_devices(device_type=any):
            device.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
コード例 #3
0
    def test_300_tns_run_ios_clean(self):
        """
        If  set --clean rebuilds the native project
        """
        # Run the project once so it is build for the first time
        result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim, just_launch=True)

        # Verify run --clean without changes rebuilds native project
        result = Tns.run_ios(app_name=self.app_name, verify=True, device=self.sim.id, clean=True, just_launch=True)
        strings = ['Building project', 'Xcode build...', 'Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=120)
        self.sim.wait_for_text(text=Changes.JSHelloWord.XML.old_text)

        # Verify if changes are applied and then run with clean it will apply changes on device
        # Verify https://github.com/NativeScript/nativescript-cli/issues/2670 run --clean does
        # clean build only the first time
        Sync.replace(self.app_name, Changes.JSHelloWord.XML)
        result = Tns.run_ios(app_name=self.app_name, verify=True, device=self.sim.id, clean=True)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.FULL, device=self.sim)
        strings.append('Xcode build...')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.XML.new_text)

        # Make changes again and verify changes are synced and clean build is not triggered again
        Sync.revert(self.app_name, Changes.JSHelloWord.XML)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.INCREMENTAL, device=self.sim, file_name='main-page.xml')
        not_existing_strings = ['Xcode build...']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings)
コード例 #4
0
 def test_100_prepare_android(self):
     Tns.prepare_android(self.app_name)
     result = Tns.prepare_android(self.app_name)
     # assert "Skipping prepare" in result.output
     Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
     result = Tns.prepare_android(self.app_name)
     assert "Preparing project..." in result.output
コード例 #5
0
 def setUp(self):
     TnsRunTest.setUp(self)
     Sync.revert(app_name=self.app_name,
                 change_set=self.ts_change,
                 fail_safe=True)
     Sync.revert(app_name=self.app_name,
                 change_set=self.xml_change,
                 fail_safe=True)
     self.chrome = Chrome()
コード例 #6
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')
コード例 #7
0
    def test_310_tns_run_ios_sync_changes_in_node_modules(self):
        """
        Verify changes in node_modules are synced during run command
        """
        # Run the project
        result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim, sync_all_files=True)

        # Make code changes in tns-core-modules verify livesync is triggered
        Sync.replace(self.app_name, Changes.NodeModules.TNS_MODULES)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.INCREMENTAL, device=self.emu, file_name='application-common.js')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
コード例 #8
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))
コード例 #9
0
    def test_101(self, title, framework, template, platform):
        # Create app
        Tns.create(app_name=APP_NAME, template=template.local_package)

        # Add platforms
        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))

        # Init tests and run tests
        if Settings.HOST_OS == OSType.WINDOWS and framework == FrameworkType.QUNIT:
            # Hack for qunit on windows (see https://github.com/NativeScript/nativescript-cli/issues/4333)
            Npm.install(package='qunit@2',
                        option='--save-dev',
                        folder=os.path.join(Settings.TEST_RUN_HOME, APP_NAME))
            # Tns test init will still fail with exit code 1, so we use `verify=False` and then assert logs.
            result = Tns.test_init(app_name=APP_NAME,
                                   framework=framework,
                                   verify=False)
            TnsAssert.test_initialized(app_name=APP_NAME,
                                       framework=framework,
                                       output=result.output)
        else:
            Tns.test_init(app_name=APP_NAME, framework=framework)

        # Run Tests
        result = Tns.test(app_name=APP_NAME,
                          platform=platform,
                          emulator=True,
                          just_launch=False,
                          wait=False)
        test_change = None
        if framework == FrameworkType.JASMINE:
            test_change = Changes.JSHelloWord.TEST
        if framework == FrameworkType.MOCHA:
            test_change = Changes.NGHelloWorld.TEST
        Sync.replace(app_name=APP_NAME, change_set=test_change)
        strings = ["log for test"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
コード例 #10
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)
コード例 #11
0
    def test_200_error_activity_shown_on_error(self):
        result = Tns.run_android(app_name=APP_NAME, emulator=True, wait=False)
        self.emu.wait_for_text('TAP', timeout=180, retry_delay=10)

        # Break the app to test error activity
        # add workaround with for-cycle for https://github.com/NativeScript/nativescript-cli/issues/3812
        wait_code = 'var e = new Date().getTime() + 3000; while (new Date().getTime() <= e) {} '
        exception_code = 'throw new Error("Kill the app!");'
        change = ChangeSet(file_path=os.path.join(Settings.TEST_RUN_HOME, APP_NAME, 'app', 'app.js'),
                           old_value='application.run({ moduleName: "app-root" });',
                           new_value=wait_code + exception_code)
        Sync.replace(app_name=APP_NAME, change_set=change)

        # Verify logs and screen
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=['StackTrace:', 'Error: Kill the app!', 'line:', 'column:'])
        self.emu.wait_for_text('Exception')
        self.emu.wait_for_text('Logcat')
        self.emu.wait_for_text('Error: Kill the app!')
コード例 #12
0
    def __debug_elements(self, platform, device):
        # Run `tns debug` wait until app is visible on device
        Tns.debug(app_name=self.app_name, platform=platform, emulator=True)
        device.wait_for_text(text=self.ts_change.old_text, timeout=240)

        # Start debug session and verify elements tab
        self.dev_tools = ChromeDevTools(self.chrome,
                                        platform=platform,
                                        tab=ChromeDevToolsTabs.ELEMENTS)
        assert self.dev_tools.wait_element_by_text(
            text=self.xml_change.old_text
        ) is not None, 'Elements tab is empty.'

        # Sync changes and verify elements tab is updated
        Sync.replace(app_name=self.app_name, change_set=self.xml_change)
        device.wait_for_text(text=self.xml_change.new_text)

        # Elements tab do not auto-update for NG apps and need to be refreshed manually
        self.dev_tools = ChromeDevTools(self.chrome,
                                        platform=platform,
                                        tab=ChromeDevToolsTabs.ELEMENTS)
        assert self.dev_tools.wait_element_by_text(
            text=self.xml_change.new_text
        ) is not None, 'Elements tab not updated.'

        # Update label in CDT and verify it is updated on device
        self.dev_tools.edit_text(old_text=self.xml_change.new_text,
                                 new_text=self.xml_change.old_text)
        element = self.dev_tools.wait_element_by_text(
            text=self.xml_change.old_text)
        assert element is not None, 'Failed to change text in elements tab.'
        device.wait_for_text(text=self.xml_change.old_text)

        # Expand items
        self.dev_tools.doubleclick_line(text='ProxyViewContainer')
        self.dev_tools.doubleclick_line(text='GridLayout')
        time.sleep(3)
        self.dev_tools.doubleclick_line(text='ListView')
        if platform == Platform.ANDROID:
            self.dev_tools.doubleclick_line(text='StackLayout')
            self.dev_tools.wait_element_by_text(text='Label', timeout=10)
        if platform == Platform.IOS:
            self.dev_tools.wait_element_by_text(text='StackLayout', timeout=10)
コード例 #13
0
    def test_100_run_ios_break_and_fix_app(self):
        """
            Make changes in xml that break the app and then changes thet fix the app.
            Add/remove js files thst break the app and then fix it. Verify recovery.
        """
        # Run app and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim)

        # Make changes in xml that will break the app
        Sync.replace(self.app_name, Changes.JSHelloWord.XML_INVALID)
        strings = ['main-page.xml', 'Error: Building UI from XML']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Revert changes
        Sync.revert(self.app_name, Changes.JSHelloWord.XML_INVALID)

        # Verify app is synced and recovered
        strings = ['Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.XML.old_text)
コード例 #14
0
    def test_100_prepare_ios(self):
        Tns.prepare_ios(self.app_name)
        result = Tns.prepare_ios(self.app_name)
        # assert "Skipping prepare" in result.output
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
        result = Tns.prepare_ios(self.app_name)
        assert "Preparing project..." in result.output

        # Verify Xcode Schemes
        result = run("xcodebuild -project " + os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                                                           'TestApp.xcodeproj', ' -list'))
        assert "This project contains no schemes." not in result.output
        result1 = re.search(r"Targets:\n\s*TestApp", result.output)
        assert result1 is not None
        result1 = re.search(r"Schemes:\n\s*TestApp", result.output)
        assert result1 is not None

        Tns.prepare_android(self.app_name)
        Tns.prepare_ios(self.app_name)
        result = Tns.prepare_ios(self.app_name)
コード例 #15
0
    def test_100_run_android_break_and_fix_app(self):
        """
            Make changes in xml that break the app and then changes thet fix the app.
            Add/remove js files thst break the app and then fix it. Verify recovery.
        """
        # Run app and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu)

        # Make changes in xml that will break the app
        Sync.replace(self.app_name, Changes.JSHelloWord.XML_INVALID)
        strings = ['main-page.xml', 'Error: Building UI from XML']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text='Exception')

        # Revert changes
        Sync.revert(self.app_name, Changes.JSHelloWord.XML_INVALID)

        # Verify app is synced and recovered
        strings = ['Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        assert not self.emu.is_text_visible(text='Exception')

        # Delete app.js and verify app crash with error activity dialog
        app_js_origin_path = os.path.join(self.source_project_dir, 'app', 'app.js')
        app_js_backup_path = os.path.join(self.target_project_dir, 'app', 'app.js')
        File.delete(app_js_origin_path)

        # Verify app is synced
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       device=self.emu, run_type=RunType.UNKNOWN)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text='Exception')

        # Restore app.js and verify app is synced and recovered
        File.copy(app_js_backup_path, app_js_origin_path)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.UNKNOWN, 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)
        assert not self.emu.is_text_visible(text='Exception')
コード例 #16
0
    def test_110_tns_run_android_release(self):
        # Run app and verify on device
        result = Tns.run_android(app_name=self.app_name, release=True, verify=True, emulator=True)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.FIRST_TIME, device=self.emu)
        strings.remove('Restarting application on device')
        strings.remove('Successfully synced application org.nativescript.TestApp on device')
        # Verify https://github.com/NativeScript/android-runtime/issues/1024
        not_existing_strings = ['JS:']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings, timeout=120)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        self.emu.wait_for_text(text=Changes.JSHelloWord.XML.old_text)
        blue_count = self.emu.get_pixels_by_color(color=Colors.LIGHT_BLUE)
        assert blue_count > 100, 'Failed to find blue color on {0}'.format(self.emu.name)

        Tns.kill()
        # Make changes in js, css and xml files
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.XML)
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.CSS)

        # Run with --release again and verify changes are deployed on device
        result = Tns.run_android(app_name=self.app_name, release=True, verify=True, emulator=True)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
        self.emu.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
        self.emu.wait_for_color(color=Colors.LIGHT_BLUE, pixel_count=blue_count * 2, delta=25)
コード例 #17
0
    def __debug_sources(self, platform, device):
        # Start debug and wait until app is deployed
        Tns.debug(app_name=self.app_name, platform=platform, emulator=True)
        device.wait_for_text(text=self.ts_change.old_text)

        # Open sources tab and verify content is loaded
        self.dev_tools = ChromeDevTools(self.chrome,
                                        platform=platform,
                                        tab=ChromeDevToolsTabs.SOURCES)

        # Open TS file and place breakpoint on line 21
        self.dev_tools.load_source_file('item-detail.component.ts')
        self.dev_tools.breakpoint(21)

        # Navigate to details page and check breakpoint is hit
        device.click(text=self.ts_change.old_text)
        pause_element = self.dev_tools.wait_element_by_text(
            text="Paused on breakpoint", timeout=10)
        assert pause_element is not None, 'Failed to pause on breakpoint.'

        # Resume execution
        self.dev_tools.continue_debug()
        device.wait_for_text(text='Goalkeeper', timeout=30)

        # Sync changes and verify sources tab is updated
        Sync.replace(app_name=self.app_name, change_set=self.ts_change)
        device.wait_for_text(text=self.ts_change.new_text)
        self.dev_tools.load_source_file('item.service.ts')
        self.dev_tools.wait_element_by_text(text=self.ts_change.new_text,
                                            timeout=10)

        # Navigate to details page and check breakpoint is hit
        device.click(text=self.ts_change.new_text)
        pause_element = self.dev_tools.wait_element_by_text(
            text="Paused on breakpoint", timeout=10)
        assert pause_element is not None, 'Failed to pause on breakpoint.'

        # Resume execution
        self.dev_tools.continue_debug()
        device.wait_for_text(text='Goalkeeper', timeout=30)
コード例 #18
0
    def test_120_tns_run_ios_just_launch(self):
        """
        This test verify following things:
        1. `--justlaunch` option release the console.
        2. Full rebuild and prepare are not trigerred if no changes are done.
        3. Incremental prepare is triggered if js, xml and css files are changed.
        """
        # Run app with --justlaunch and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim, just_launch=True)
        # On some machines it takes time for thr process to die
        time.sleep(5)
        assert not Process.is_running_by_commandline(Settings.Executables.TNS)

        # Execute run with --justlaunch again and verify no rebuild is triggered
        result = Tns.run_ios(app_name=self.app_name, emulator=True, just_launch=True)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.JUST_LAUNCH, device=self.sim, just_launch=True)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Make changes in js, css and xml files
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.XML)
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.CSS)

        # Execute run with --justlaunch again and verify prepare is triggered
        result = Tns.run_ios(app_name=self.app_name, emulator=True, just_launch=True)
        strings = ['Project successfully prepared', 'Webpack compilation complete']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
コード例 #19
0
    def __debug_sync_changes(self, platform, device):
        # Start debug and wait until app is deployed
        result = Tns.debug(app_name=self.app_name,
                           platform=platform,
                           emulator=True)
        device.wait_for_text(text='TAP')

        # Open sources tab and verify content is loaded
        self.dev_tools = ChromeDevTools(self.chrome,
                                        platform=platform,
                                        tab=ChromeDevToolsTabs.SOURCES)

        # Open JS file and place breakpoint on line 18
        self.dev_tools.load_source_file("main-view-model.js")
        self.dev_tools.breakpoint(18)

        # Sync JS changes works fine until breakpoint is hit
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
        js_file_name = os.path.basename(Changes.JSHelloWord.JS.file_path)
        logs = [
            js_file_name, 'Webpack build done!', 'Refreshing application',
            'Successfully synced application'
        ]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs)
        device.wait_for_text(text=Changes.JSHelloWord.JS.new_text, timeout=30)

        # Revert changes
        Sync.revert(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs)
        device.wait_for_text(text=Changes.JSHelloWord.JS.old_text, timeout=30)

        # Tap on TAP button in emulator and check it is hit
        device.click(text="TAP", case_sensitive=True)
        pause_element = self.dev_tools.wait_element_by_text(
            text="Paused on breakpoint", timeout=90)
        assert pause_element is not None, 'Failed to pause on breakpoint.'

        # Test for https://github.com/NativeScript/nativescript-cli/issues/4227
        Sync.replace(app_name=self.app_name, change_set=self.xml_change)
        xml_file_name = os.path.basename(self.xml_change.file_path)
        logs = [
            xml_file_name, 'Webpack build done!', 'Refreshing application',
            'Successfully synced application'
        ]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs)
        sleep(10)  # Give it some more time to crash
        logs = File.read(result.log_file)
        assert 'Unable to apply changes' not in logs
        assert 'Stopping webpack watch' not in logs
        assert 'closed' not in logs
        assert 'detached' not in logs
        assert "did not start in time" not in logs

        # Resume execution
        self.dev_tools.continue_debug()
        device.wait_for_text(
            text='42 taps left',
            timeout=30)  # We tapped but changes synced so number is restarted
        device.wait_for_text(text=self.xml_change.new_text,
                             timeout=10)  # Verify change applied during debug
コード例 #20
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)

        # 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)
コード例 #21
0
def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=True, instrumented=False,
                                click_open_alert=False):
    result = preview_hello_world_ng(app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr,
                                    instrumented=instrumented, click_open_alert=click_open_alert)

    # Edit TS file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS)
    strings = TnsLogs.preview_file_changed_messages(platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
                                                    file_name='item.service.ts', hmr=hmr, instrumented=instrumented)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)
    device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text)

    # Edit HTML file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML)
    strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, file_name='items.component.html',
                                                    hmr=hmr, instrumented=instrumented)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)
    if platform == Platform.IOS:
        for number in ["10", "1"]:
            device.wait_for_text(text=number)
    else:
        for number in ["8", "9"]:
            device.wait_for_text(text=number)
    assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text)

    # Edit CSS file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS)
    strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, file_name='app.css',
                                                    hmr=hmr, instrumented=instrumented)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)
    device.wait_for_main_color(color=Colors.DARK)
    if platform == Platform.IOS:
        for number in ["10", "1"]:
            device.wait_for_text(text=number)
    else:
        for number in ["8", "9"]:
            device.wait_for_text(text=number)
    assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text)
コード例 #22
0
    def test_110_tns_run_ios_release(self):
        # Run app and verify on device
        result = Tns.run_ios(app_name=self.app_name, release=True, verify=True, emulator=True)
        strings = ['Webpack compilation complete', 'Project successfully built', 'Successfully installed on device']
        # Verify console logs are not displayed in release builds
        not_existing_strings = ['JS:']
        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)
        self.sim.wait_for_text(text=Changes.JSHelloWord.XML.old_text)
        blue_count = self.sim.get_pixels_by_color(color=Colors.LIGHT_BLUE)
        assert blue_count > 100, 'Failed to find blue color on {0}'.format(self.sim.name)

        Tns.kill()
        # Make changes in js, css and xml files
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.XML)
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.CSS)

        # Run with --release again and verify changes are deployed on device
        result = Tns.run_ios(app_name=self.app_name, release=True, verify=True, emulator=True)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
        self.sim.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
        self.sim.wait_for_color(color=Colors.LIGHT_BLUE, pixel_count=blue_count * 2, delta=25)
コード例 #23
0
def preview_sync_hello_world_js_ts(app_type,
                                   app_name,
                                   platform,
                                   device,
                                   bundle=True,
                                   hmr=True,
                                   instrumented=False,
                                   click_open_alert=False):
    result = preview_hello_world_js_ts(app_name=app_name,
                                       platform=platform,
                                       device=device,
                                       bundle=bundle,
                                       hmr=hmr,
                                       instrumented=instrumented,
                                       click_open_alert=click_open_alert)

    blue_count = device.get_pixels_by_color(color=Colors.LIGHT_BLUE)
    # Set changes
    js_file = os.path.basename(Changes.JSHelloWord.JS.file_path)
    if app_type == AppType.JS:
        js_change = Changes.JSHelloWord.JS
        xml_change = Changes.JSHelloWord.XML
        css_change = Changes.JSHelloWord.CSS
    elif app_type == AppType.TS:
        js_file = os.path.basename(Changes.TSHelloWord.TS.file_path)
        js_change = Changes.TSHelloWord.TS
        xml_change = Changes.TSHelloWord.XML
        css_change = Changes.TSHelloWord.CSS
    else:
        raise ValueError('Invalid app_type value.')

    if hmr and instrumented:
        not_existing_string_list = ['QA: Application started']

    # Edit JS file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=js_change)
    strings = TnsLogs.preview_file_changed_messages(platform=platform,
                                                    bundle=bundle,
                                                    hmr=hmr,
                                                    file_name=js_file,
                                                    instrumented=instrumented)
    if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS:
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             not_existing_string_list=not_existing_string_list)
    else:
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=90)
    device.wait_for_text(text=js_change.new_text)

    # Edit XML file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=xml_change)
    strings = TnsLogs.preview_file_changed_messages(platform=platform,
                                                    bundle=bundle,
                                                    hmr=hmr,
                                                    file_name='main-page.xml',
                                                    instrumented=instrumented)
    if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS:
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             not_existing_string_list=not_existing_string_list)
    else:
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=90)
    device.wait_for_text(text=xml_change.new_text)
    device.wait_for_text(text=js_change.new_text)

    # Edit CSS file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=css_change)
    strings = TnsLogs.preview_file_changed_messages(platform=platform,
                                                    bundle=bundle,
                                                    hmr=hmr,
                                                    file_name='app.css',
                                                    instrumented=instrumented)
    if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS:
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             not_existing_string_list=not_existing_string_list)
    else:
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=90)
    device.wait_for_color(color=Colors.LIGHT_BLUE,
                          pixel_count=blue_count * 2,
                          delta=25)
    device.wait_for_text(text=xml_change.new_text)
    device.wait_for_text(text=js_change.new_text)
コード例 #24
0
 def test_200_prepare_xml_error(self):
     Tns.platform_remove(self.app_name, platform=Platform.ANDROID)
     Sync.replace(app_name=self.app_name, change_set=Changes.AppFileChanges.CHANGE_XML_INVALID_SYNTAX)
     result = Tns.prepare_android(self.app_name)
     assert "main-page.xml has syntax errors." in result.output
     assert "unclosed xml attribute" in result.output
コード例 #25
0
def __workflow(preview, app_name, platform, device, bundle=True, hmr=True):
    # Execute tns command
    if preview:
        result = __preview_vue(
            app_name=app_name,
            platform=platform,
            device=device,
            bundle=bundle,
            hmr=hmr)
    else:
        result = __run_vue(
            app_name=app_name, platform=platform, bundle=bundle, hmr=hmr)

    if preview:
        Log.info('Skip logs checks.')
    else:
        strings = TnsLogs.run_messages(
            app_name=app_name,
            platform=platform,
            run_type=RunType.FULL,
            bundle=bundle,
            hmr=hmr,
            app_type=AppType.VUE)
        TnsLogs.wait_for_log(
            log_file=result.log_file, string_list=strings, timeout=240)

    # Verify it looks properly
    device.wait_for_text(
        text=Changes.BlankVue.VUE_SCRIPT.old_text, timeout=120)
    device.wait_for_text(
        text=Changes.BlankVue.VUE_TEMPLATE.old_text, timeout=120)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name,
                                 'initial_state.png')
    device.get_screen(path=initial_state)

    # Edit script in .vue file
    Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_SCRIPT)
    if preview:
        Log.info('Skip logs checks.')
    else:
        strings = TnsLogs.run_messages(
            app_name=app_name,
            platform=platform,
            run_type=RunType.INCREMENTAL,
            bundle=bundle,
            hmr=hmr,
            app_type=AppType.VUE,
            file_name='Home.vue')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    device.wait_for_text(text=Changes.BlankVue.VUE_SCRIPT.new_text)

    # Edit template in .vue file
    Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_TEMPLATE)
    if preview:
        Log.info('Skip logs checks.')
    else:
        strings = TnsLogs.run_messages(
            app_name=app_name,
            platform=platform,
            run_type=RunType.INCREMENTAL,
            bundle=bundle,
            hmr=hmr,
            app_type=AppType.VUE,
            file_name='Home.vue')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    device.wait_for_text(text=Changes.BlankVue.VUE_TEMPLATE.new_text)

    # Edit styling in .vue file
    Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_STYLE)
    if preview:
        Log.info('Skip logs checks.')
    else:
        strings = TnsLogs.run_messages(
            app_name=app_name,
            platform=platform,
            run_type=RunType.INCREMENTAL,
            bundle=bundle,
            hmr=hmr,
            app_type=AppType.VUE,
            file_name='Home.vue')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    style_applied = Wait.until(lambda: device.get_pixels_by_color(Colors.RED) >
                               100)
    assert style_applied, 'Failed to sync changes in style.'

    # Revert script in .vue file
    Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_SCRIPT)
    if preview:
        Log.info('Skip logs checks.')
    else:
        strings = TnsLogs.run_messages(
            app_name=app_name,
            platform=platform,
            run_type=RunType.INCREMENTAL,
            bundle=bundle,
            hmr=hmr,
            app_type=AppType.VUE,
            file_name='Home.vue')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    device.wait_for_text(text=Changes.BlankVue.VUE_SCRIPT.old_text)

    # Revert template in .vue file
    Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_TEMPLATE)
    if preview:
        Log.info('Skip logs checks.')
    else:
        strings = TnsLogs.run_messages(
            app_name=app_name,
            platform=platform,
            run_type=RunType.INCREMENTAL,
            bundle=bundle,
            hmr=hmr,
            app_type=AppType.VUE,
            file_name='Home.vue')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    device.wait_for_text(text=Changes.BlankVue.VUE_TEMPLATE.old_text)

    # Revert styling in .vue file
    Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_STYLE)
    if preview:
        Log.info('Skip logs checks.')
    else:
        strings = TnsLogs.run_messages(
            app_name=app_name,
            platform=platform,
            run_type=RunType.INCREMENTAL,
            bundle=bundle,
            hmr=hmr,
            app_type=AppType.VUE,
            file_name='Home.vue')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    if hmr:
        Log.info(
            'Skip next steps because of https://github.com/nativescript-vue/nativescript-vue/issues/425'
        )
    else:
        style_applied = Wait.until(lambda: device.get_pixels_by_color(
            Colors.RED) == 0)
        assert style_applied, 'Failed to sync changes in style.'

    # Assert final and initial states are same
    device.screen_match(
        expected_image=initial_state, tolerance=1.0, timeout=30)
コード例 #26
0
def sync_hello_world_ng(app_name, platform, device, bundle=True, uglify=False, aot=False, hmr=True,
                        instrumented=True):
    # Define if it should be executed on device or emulator
    emulator = True
    device_id = None
    if device.type == DeviceType.ANDROID or device.type == DeviceType.IOS:
        emulator = False
        device_id = device.id

    # Execute tns run command
    result = Tns.run(app_name=app_name, platform=platform, emulator=emulator, device=device_id, wait=False,
                     bundle=bundle, aot=aot, uglify=uglify, hmr=hmr)
    # Check logs
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.UNKNOWN, bundle=bundle,
                                   hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)

    # Verify it 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)

    # Apply changes
    Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS)
    device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
                                   file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

    Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML)
    if platform == Platform.IOS:
        for number in ["10", "11"]:
            device.wait_for_text(text=number)
    else:
        for number in ["8", "9"]:
            device.wait_for_text(text=number)
    assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
                                   file_name='items.component.html', hmr=hmr, instrumented=instrumented,
                                   app_type=AppType.NG, aot=aot, device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

    Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS)
    device.wait_for_main_color(color=Colors.DARK)
    if platform == Platform.IOS:
        for number in ["10", "1"]:
            device.wait_for_text(text=number)
    else:
        for number in ["8", "9"]:
            device.wait_for_text(text=number)
    assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
                                   file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

    # Revert changes
    Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.HTML)
    device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
                                   file_name='items.component.html', hmr=hmr, instrumented=instrumented,
                                   app_type=AppType.NG, aot=aot, device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

    Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.TS)
    device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text)
    device.wait_for_main_color(color=Colors.DARK)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
                                   file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

    Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.CSS)
    device.wait_for_main_color(color=Colors.WHITE)
    device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
                                   file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

    # Assert final and initial states are same
    device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
コード例 #27
0
def sync_master_detail_ng(app_name,
                          platform,
                          device,
                          bundle=True,
                          hmr=True,
                          uglify=False,
                          aot=False):
    run_master_detail_ng(app_name=app_name,
                         platform=platform,
                         device=device,
                         bundle=bundle,
                         hmr=hmr,
                         uglify=uglify,
                         aot=aot)

    # Edit TS file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=Changes.MasterDetailNG.TS)
    device.wait_for_text(text=Changes.MasterDetailNG.TS.new_text)

    # Edit HTML file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=Changes.MasterDetailNG.HTML)
    device.wait_for_text(text=Changes.MasterDetailNG.HTML.new_text)
    device.wait_for_text(text=Changes.MasterDetailNG.TS.new_text)

    # Edit common SCSS on root level
    change = Changes.MasterDetailNG.SCSS_ROOT_COMMON
    Sync.replace(app_name=app_name, change_set=change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) > 100), \
        'Common SCSS on root level not applied!'
    Log.info('Common SCSS on root level applied successfully!')

    # Edit platform specific SCSS on root level
    if platform == Platform.ANDROID:
        change = Changes.MasterDetailNG.SCSS_ROOT_ANDROID
    elif platform == Platform.IOS:
        change = Changes.MasterDetailNG.SCSS_ROOT_IOS
    else:
        raise ValueError('Invalid platform value!')
    Sync.replace(app_name=app_name, change_set=change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) > 100), \
        'Platform specific SCSS on root level not applied!'
    Log.info('Platform specific SCSS on root level applied successfully!')

    # Edit nested common SCSS
    change = Changes.MasterDetailNG.SCSS_NESTED_COMMON
    Sync.replace(app_name=app_name, change_set=change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) > 100), \
        'Common nested SCSS not applied!'
    Log.info('Common nested SCSS applied successfully!')

    # Edit nested platform specific SCSS
    if platform == Platform.ANDROID:
        change = Changes.MasterDetailNG.SCSS_NESTED_ANDROID
    elif platform == Platform.IOS:
        change = Changes.MasterDetailNG.SCSS_NESTED_IOS
    else:
        raise ValueError('Invalid platform value!')
    Sync.replace(app_name=app_name, change_set=change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) > 100), \
        'Platform specific nested SCSS not applied!'
    Log.info('Platform specific nested SCSS applied successfully!')

    # Revert TS file and verify changes are applied
    Sync.revert(app_name=app_name, change_set=Changes.MasterDetailNG.TS)
    device.wait_for_text(text=Changes.MasterDetailNG.TS.old_text, timeout=120)
    device.wait_for_text(text=Changes.MasterDetailNG.HTML.new_text)

    # Revert HTML file and verify changes are applied
    Sync.revert(app_name=app_name, change_set=Changes.MasterDetailNG.HTML)
    device.wait_for_text(text=Changes.MasterDetailNG.HTML.old_text,
                         timeout=120)
    device.wait_for_text(text=Changes.MasterDetailNG.TS.old_text)

    # Revert common SCSS on root level
    change = Changes.MasterDetailNG.SCSS_ROOT_COMMON
    Sync.revert(app_name=app_name, change_set=change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) < 100), \
        'Common SCSS on root level not reverted!'
    Log.info('Common SCSS on root level reverted successfully!')

    # Revert platform specific SCSS on root level
    if platform == Platform.ANDROID:
        change = Changes.MasterDetailNG.SCSS_ROOT_ANDROID
    elif platform == Platform.IOS:
        change = Changes.MasterDetailNG.SCSS_ROOT_IOS
    else:
        raise ValueError('Invalid platform value!')
    Sync.revert(app_name=app_name, change_set=change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) < 100), \
        'Platform specific SCSS on root level not reverted!'
    Log.info('Platform specific SCSS on root level reverted successfully!')

    # Revert nested common SCSS
    change = Changes.MasterDetailNG.SCSS_NESTED_COMMON
    Sync.revert(app_name=app_name, change_set=change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) < 100), \
        'Common SCSS on root level not applied!'
    Log.info('Platform specific SCSS on root level reverted successfully!')

    # Revert nested platform specific SCSS
    if platform == Platform.ANDROID:
        change = Changes.MasterDetailNG.SCSS_NESTED_ANDROID
    elif platform == Platform.IOS:
        change = Changes.MasterDetailNG.SCSS_NESTED_IOS
    else:
        raise ValueError('Invalid platform value!')
    Sync.revert(app_name=app_name, change_set=change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) < 100), \
        'Platform specific SCSS on root level not applied!'

    # Assert final and initial states are same
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name,
                                 'initial_state.png')
    device.screen_match(expected_image=initial_state,
                        tolerance=1.0,
                        timeout=30)
コード例 #28
0
def __sync_tab_navigation_js_ts(app_type,
                                app_name,
                                platform,
                                device,
                                release=False,
                                bundle=True,
                                hmr=True,
                                uglify=False,
                                aot=False,
                                snapshot=False,
                                instrumented=False):
    # Set changes
    js_file = os.path.basename(Changes.JSTabNavigation.JS.file_path)
    if app_type == AppType.JS:
        js_change = Changes.JSTabNavigation.JS
        xml_change = Changes.JSTabNavigation.XML
        scss_change = Changes.JSTabNavigation.SCSS_VARIABLES
        scss_android = Changes.JSTabNavigation.SCSS_ROOT_ANDROID
        scss_ios = Changes.JSTabNavigation.SCSS_ROOT_IOS
    elif app_type == AppType.TS:
        js_file = os.path.basename(Changes.TSTabNavigation.TS.file_path)
        js_change = Changes.TSTabNavigation.TS
        xml_change = Changes.TSTabNavigation.XML
        scss_change = Changes.TSTabNavigation.SCSS_VARIABLES
        scss_android = Changes.TSTabNavigation.SCSS_ROOT_ANDROID
        scss_ios = Changes.TSTabNavigation.SCSS_ROOT_IOS
    else:
        raise ValueError('Invalid app_type value.')

    # Execute `tns run` and wait until logs are OK
    result = Tns.run(app_name=app_name,
                     platform=platform,
                     emulator=True,
                     wait=False,
                     bundle=bundle,
                     hmr=hmr,
                     uglify=uglify,
                     aot=aot,
                     snapshot=snapshot,
                     release=release)

    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.UNKNOWN,
                                   bundle=bundle,
                                   hmr=hmr,
                                   instrumented=instrumented,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file,
                         string_list=strings,
                         timeout=240)

    # Verify it looks properly
    device.wait_for_text(text=js_change.old_text)
    device.wait_for_text(text=xml_change.old_text)
    color_count = device.get_pixels_by_color(color=Colors.ACCENT_DARK)
    assert color_count > 100, 'Failed to find ACCENT_DARK color on {0}'.format(
        device.name)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name,
                                 'initial_state.png')
    device.get_screen(path=initial_state)

    # Edit JS file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=js_change)
    device.wait_for_text(text=js_change.new_text)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   file_name=js_file,
                                   device=device,
                                   instrumented=instrumented)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    # Edit XML file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=xml_change)
    device.wait_for_text(text=xml_change.new_text)
    device.wait_for_text(text=js_change.new_text)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   file_name='home-items-page.xml',
                                   device=device,
                                   instrumented=instrumented)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    # Edit SCSS file and verify changes are applied
    # https://github.com/NativeScript/NativeScript/issues/6953
    # Navigate to Browse tab and verify when scss is synced navigation is preserved
    device.click(text="Browse")
    assert not device.is_text_visible(text=js_change.new_text)
    Sync.replace(app_name=app_name, change_set=scss_change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=Colors.RED) > 100), \
        'SCSS not applied!'
    # Verify navigation is preserved and you are still on Browse tab
    assert device.is_text_visible(text="Browse page content goes here"), \
        'Navigation is not preserved when syncing scss/css file!'

    # Edit platform specific SCSS on root level
    if platform == Platform.ANDROID:
        change = scss_android
    elif platform == Platform.IOS:
        change = scss_ios
    else:
        raise ValueError('Invalid platform value!')
    Sync.replace(app_name=app_name, change_set=change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) > 100), \
        'Platform specific SCSS on root level not applied!'
    Log.info('Platform specific SCSS on root level applied successfully!')

    # Revert all the changes in app
    # Navigate to Home tab again
    device.click(text="Home")
    Sync.revert(app_name=app_name, change_set=js_change)
    device.wait_for_text(text=js_change.old_text)
    device.wait_for_text(text=xml_change.new_text)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   file_name=js_file,
                                   device=device,
                                   instrumented=instrumented)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    Sync.revert(app_name=app_name, change_set=xml_change)
    device.wait_for_text(text=xml_change.old_text)
    device.wait_for_text(text=js_change.old_text)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   file_name='home-items-page.xml',
                                   device=device,
                                   instrumented=instrumented)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    Sync.revert(app_name=app_name, change_set=scss_change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=Colors.RED) < 100), \
        'SCSS not applied!'
    device.wait_for_text(text=xml_change.old_text)
    device.wait_for_text(text=js_change.old_text)

    Sync.revert(app_name=app_name, change_set=change)
    assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) < 100), \
        'Platform specific SCSS on root level not reverted!'
    Log.info('Platform specific SCSS on root level reverted successfully!')

    # Assert final and initial states are same
    device.screen_match(expected_image=initial_state,
                        tolerance=1.0,
                        timeout=30)
コード例 #29
0
def sync_master_detail_vue(app_name, platform, device, bundle=True, hmr=True):
    # Execute tns command
    result = Tns.run(app_name=app_name,
                     platform=platform,
                     emulator=True,
                     wait=False,
                     bundle=bundle,
                     hmr=hmr)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.FULL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   app_type=AppType.VUE,
                                   transfer_all=True)
    TnsLogs.wait_for_log(log_file=result.log_file,
                         string_list=strings,
                         timeout=360)

    # start appium driver (need it on iOS only)
    appium = None
    if platform == Platform.IOS:
        appium = AppiumDriver(platform=platform,
                              device=device,
                              bundle_id=TnsPaths.get_bundle_id(app_name))

    # Verify app home page looks properly
    device.wait_for_text(text="Ford KA")
    device.wait_for_text(text=Changes.MasterDetailVUE.VUE_TEMPLATE.old_text)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name,
                                 'initial_state.png')
    device.get_screen(path=initial_state)

    # Edit template in .vue file
    Sync.replace(app_name=app_name,
                 change_set=Changes.MasterDetailVUE.VUE_TEMPLATE)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   app_type=AppType.VUE,
                                   file_name='CarList.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    device.wait_for_text(text=Changes.MasterDetailVUE.VUE_TEMPLATE.new_text)

    # Edit styling in .vue file
    Sync.replace(app_name=app_name,
                 change_set=Changes.MasterDetailVUE.VUE_STYLE)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   app_type=AppType.VUE,
                                   file_name='CarList.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    style_applied = Wait.until(
        lambda: device.get_pixels_by_color(Colors.RED_DARK) > 200)
    assert style_applied, 'Failed to sync changes in style.'

    # Revert styling in .vue file
    Sync.revert(app_name=app_name,
                change_set=Changes.MasterDetailVUE.VUE_STYLE)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   app_type=AppType.VUE,
                                   file_name='CarList.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    style_applied = Wait.until(
        lambda: device.get_pixels_by_color(Colors.WHITE) > 200)
    assert style_applied, 'Failed to sync changes in style.'

    device.wait_for_text(text="Ford KA")
    if platform == Platform.IOS:
        app_element = appium.driver.find_element(By.ID, "Ford KA")
        app_element.click()
    else:
        device.click(text="Ford KA")
    device.wait_for_text(text="Edit")
    device.wait_for_text(text="Price")
    Sync.replace(app_name=app_name,
                 change_set=Changes.MasterDetailVUE.VUE_DETAIL_PAGE_TEMPLATE)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   app_type=AppType.VUE,
                                   file_name='CarDetails.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    device.wait_for_text(
        text=Changes.MasterDetailVUE.VUE_DETAIL_PAGE_TEMPLATE.new_text)

    # Kill Appium
    if appium is not None:
        appium.stop()
コード例 #30
0
def __sync_hello_world_js_ts(app_type,
                             app_name,
                             platform,
                             device,
                             bundle=True,
                             hmr=True,
                             uglify=False,
                             aot=False,
                             snapshot=False,
                             instrumented=False):
    # Set changes
    js_file = os.path.basename(Changes.JSHelloWord.JS.file_path)
    if app_type == AppType.JS:
        js_change = Changes.JSHelloWord.JS
        xml_change = Changes.JSHelloWord.XML
        css_change = Changes.JSHelloWord.CSS
    elif app_type == AppType.TS:
        js_file = os.path.basename(Changes.TSHelloWord.TS.file_path)
        js_change = Changes.TSHelloWord.TS
        xml_change = Changes.TSHelloWord.XML
        css_change = Changes.TSHelloWord.CSS
    else:
        raise ValueError('Invalid app_type value.')

    # Execute `tns run` and wait until logs are OK
    result = Tns.run(app_name=app_name,
                     platform=platform,
                     emulator=True,
                     wait=False,
                     bundle=bundle,
                     hmr=hmr,
                     uglify=uglify,
                     aot=aot,
                     snapshot=snapshot)
    __verify_snapshot_skipped(snapshot, result)

    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.UNKNOWN,
                                   bundle=bundle,
                                   hmr=hmr,
                                   instrumented=instrumented,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file,
                         string_list=strings,
                         timeout=240)

    # Verify it looks properly
    device.wait_for_text(text=js_change.old_text)
    device.wait_for_text(text=xml_change.old_text)
    blue_count = device.get_pixels_by_color(color=Colors.LIGHT_BLUE)
    assert blue_count > 100, 'Failed to find blue color on {0}'.format(
        device.name)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name,
                                 'initial_state.png')
    device.get_screen(path=initial_state)

    # Edit JS file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=js_change)
    device.wait_for_text(text=js_change.new_text)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   file_name=js_file,
                                   instrumented=instrumented,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    # Edit XML file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=xml_change)
    device.wait_for_text(text=xml_change.new_text)
    device.wait_for_text(text=js_change.new_text)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   file_name='main-page.xml',
                                   instrumented=instrumented,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    # Edit CSS file and verify changes are applied
    Sync.replace(app_name=app_name, change_set=css_change)
    device.wait_for_color(color=Colors.LIGHT_BLUE,
                          pixel_count=blue_count * 2,
                          delta=25)
    device.wait_for_text(text=xml_change.new_text)
    device.wait_for_text(text=js_change.new_text)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   file_name='app.css',
                                   instrumented=instrumented,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    # Revert all the changes
    Sync.revert(app_name=app_name, change_set=js_change)
    device.wait_for_text(text=js_change.old_text)
    device.wait_for_text(text=xml_change.new_text)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   file_name=js_file,
                                   instrumented=instrumented,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    Sync.revert(app_name=app_name, change_set=xml_change)
    device.wait_for_text(text=xml_change.old_text)
    device.wait_for_text(text=js_change.old_text)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   file_name='main-page.xml',
                                   instrumented=instrumented,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    Sync.revert(app_name=app_name, change_set=css_change)
    device.wait_for_color(color=Colors.LIGHT_BLUE, pixel_count=blue_count)
    device.wait_for_text(text=xml_change.old_text)
    device.wait_for_text(text=js_change.old_text)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   file_name='app.css',
                                   instrumented=instrumented,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

    # Assert final and initial states are same
    device.screen_match(expected_image=initial_state,
                        tolerance=1.0,
                        timeout=30)