Пример #1
0
    def test_280_tns_run_android_console_time(self):
        # Copy the app folder (app is modified in order to get some console logs on loaded)
        source = os.path.join('data', 'apps', 'livesync-hello-world-ng', 'src')
        target = os.path.join(self.app_name, 'src')
        Folder.cleanup(target)
        Folder.copy(src=source, dst=target)

        # Replace app.component.ts to use console.time() and console.timeEnd()
        source = os.path.join('data', 'issues', 'ios-runtime-843', 'app.component.ts')
        target = os.path.join(self.app_name, 'src', 'app', 'app.component.ts')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)

        # Verify the app is running
        strings = ['Successfully synced application',
                   'Application loaded!',
                   'Home page loaded!']

        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10, clean_log=False)

        # Verify initial state of the app
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image='ng-hello-world-home-white', tolerance=5.0)

        # Verify console.time() works
        console_time = ['JS: startup:']
        Tns.wait_for_log(log_file=log, string_list=console_time)
    def test_330_tns_run_ios_after_rebuild_of_native_project(self):
        """
        `tns run ios` should work properly after rebuild of native project (test for issue #2860)
        """

        # `tns run ios` and wait until app is deployed
        log = Tns.run_ios(attributes={'--path': self.app_name, '--device': self.DEVICE_ID}, wait=False,
                          assert_success=False, log_trace=True)
        strings = [self.DEVICE_ID, 'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)

        # Verify app is running
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="Tap the button"), "App failed to load!"

        # Update native project
        config_path = os.path.join(self.app_name, 'app', 'App_Resources', 'iOS', 'build.xcconfig')
        File.replace(file_path=config_path, str1='More info', str2='If you need more info')
        strings = ['ARCHIVE SUCCEEDED', 'Successfully synced application', self.DEVICE_ID, 'CONSOLE LOG']
        not_existing_strings = ['Unable to sync files', 'Multiple errors were thrown']
        Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings, timeout=120)

        # Verify app is running
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="Tap the button"), "App failed to load!"

        # Change JS and wait until app is synced
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
        strings = ['Successfully transferred', 'main-view-model.js', 'Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="clicks"), "JS changes not synced on device!"

        # Rollback all the changes and verify files are synced
        ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
        strings = ['Successfully transferred', 'main-view-model.js', 'Restarting application']
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="taps left"), "JS changes not synced on device!"
Пример #3
0
    def apply_changes(app_name, log, platform):

        not_found_list = []
        # Change JS, XML and CSS
        ReplaceHelper.replace(app_name, HelpersHMR.js_change, sleep=10)
        strings = ['HMR: The following modules were updated:', './main-view-model.js', './main-page.js',
                   'Successfully transferred bundle.',
                   'HMR: Successfully applied update with hmr hash ']
        # strings = ['JS: HMR: The following modules were updated:', './main-view-model.js', './main-page.js',
        #            'Successfully transferred bundle.{0}.hot-update.js'.format(hash()),
        #            'JS: HMR: Successfully applied update with hmr hash {0}'.format(hashlib.sha1)]
        Tns.wait_for_log(log_file=log, string_list=strings)
        if platform == Platform.ANDROID:
            text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='42 clicks left', timeout=20)
            assert text_changed, 'Changes in JS file not applied (UI is not refreshed).'

        ReplaceHelper.replace(app_name, HelpersHMR.xml_change, sleep=10)
        strings = ['Refreshing application on device', 'HMR: Checking for updates to the bundle with hmr hash',
                   './main-page.xml', 'HMR: Successfully applied update with hmr hash']
        Tns.wait_for_log(log_file=log, string_list=strings)
        if platform == Platform.ANDROID:
            text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='TEST')
            assert text_changed, 'Changes in XML file not applied (UI is not refreshed).'

        ReplaceHelper.replace(app_name, HelpersHMR.css_change, sleep=10)
        if platform == Platform.ANDROID:
            Tns.wait_for_log(log_file=log, string_list=['app.css'], clean_log=False)

        Tns.wait_for_log(log_file=log, string_list=HelpersHMR.wp_sync, not_existing_string_list=HelpersHMR.wp_errors,
                         timeout=120)

        # Verify application looks correct
        if platform == Platform.ANDROID:
            Helpers.android_screen_match(image=HelpersHMR.image_change, timeout=120)
Пример #4
0
    def revert_changes(app_name, log, platform):
        # Clean old logs
        if CURRENT_OS is not OSType.WINDOWS:
            File.write(file_path=log, text="")

        # Revert XML changes
        ReplaceHelper.rollback(app_name, HelpersHMR.xml_change, sleep=10)
        strings = ['Refreshing application on device', './main-page.xml',
                   'HMR: Checking for updates to the bundle with hmr hash']
        Tns.wait_for_log(log_file=log, string_list=strings)
        if platform == Platform.ANDROID:
            text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
            assert text_changed, 'Changes in XML file not applied (UI is not refreshed).'

        # Revert JS changes
        ReplaceHelper.rollback(app_name, HelpersHMR.js_change, sleep=10)
        strings = ['Refreshing application on device', 'HMR: The following modules were updated:', './main-view-model.js', './main-page.js',
                   'Successfully transferred bundle.', 'HMR: Successfully applied update with hmr hash ']
        Tns.wait_for_log(log_file=log, string_list=strings)
        if platform == Platform.ANDROID:
            text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='42 taps left', timeout=20)
            assert text_changed, 'HMR: The following modules were updated:'

        # Revert CSS changes
        ReplaceHelper.rollback(app_name, HelpersHMR.css_change, sleep=10)
        Tns.wait_for_log(log_file=log, string_list=['app.css'], clean_log=False)

        # Verify application looks correct
        Tns.wait_for_log(log_file=log, string_list=HelpersHMR.wp_sync, not_existing_string_list=HelpersHMR.wp_errors,
                         timeout=60)
        if platform == Platform.ANDROID:
            Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120)
    def wait(device_id, timeout=300):
        """
        Wait until emulator is up and running.
        :param device_id: Device name
        :param timeout: Timeout until device is ready (in seconds).
        :return: True if device is ready before timeout, otherwise - False.
        """
        booted = False
        start_time = time.time()
        end_time = start_time + timeout
        while not booted:
            time.sleep(5)
            booted = Emulator.is_running(device_id=device_id)
            if (booted is True) or (time.time() > end_time):
                break

        # If booted, make sure screen will not lock
        if booted:
            Adb.run(command='shell settings put system screen_off_timeout -1', device_id=device_id)

        # If booted, make sure screen will not lock
        if booted:
            text = Adb.get_page_source(device_id=device_id)
            if "android.process.acore" in text:
                print "Error dialog detected! Try to kill it..."
                Device.click(device_id=device_id, text="OK", timeout=10)
        return booted
    def test_100_debug_ios_simulator_with_livesync(self):
        """
        `tns debug ios` should be able to run with livesync
        """
        log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': '', '--inspector': ''})
        DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log)

        # Verify app starts and do not stop on first line of code
        Device.screen_match(device_name=SIMULATOR_NAME,
                            device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home')

        # Change JS and wait until app is synced
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
        strings = ['Successfully transferred', 'main-view-model.js', 'CONSOLE LOG',
                   'Backend socket closed', 'Frontend socket closed',
                   'Frontend client connected', 'Backend socket created', 'NativeScript debugger attached']
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Change XML and wait until app is synced. App doesn't restart from 5.1.0 version
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3)
        strings = ['Successfully transferred', 'main-page.xml', 'CONSOLE LOG']
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Change CSS and wait until app is synced. App doesn't restart from 5.1.0 version
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3)
        strings = ['Successfully transferred', 'app.css', 'CONSOLE LOG']
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Verify application looks correct
        Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID,
                            expected_image='livesync-hello-world_js_css_xml', tolerance=0.26)

        assert Process.is_running('NativeScript Inspector')
Пример #7
0
    def test_003_debug_ios_simulator_start(self):
        """
        Attach the debug tools to a running app in the iOS Simulator
        """

        # Run the app and ensure it works
        log = Tns.run_ios(attributes={
            '--path': self.app_name,
            '--emulator': '',
            '--justlaunch': ''
        },
                          assert_success=False,
                          timeout=30)
        TnsAsserts.prepared(app_name=self.app_name,
                            platform=Platform.IOS,
                            output=log,
                            prepare=Prepare.SKIP)
        Device.screen_match(device_name=SIMULATOR_NAME,
                            device_id=self.SIMULATOR_ID,
                            expected_image='livesync-hello-world_home')

        # Attach debugger
        log = Tns.debug_ios(
            attributes={
                '--path': self.app_name,
                '--emulator': '',
                '--start': '',
                '--inspector': ''
            })
        DebugiOSInspectorSimulatorTests.__verify_debugger_attach(
            log, app_started=False)
    def test_003_android_run_hmr_wrong_xml(self):
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False,
                              assert_success=False)
        Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr,
                         not_existing_string_list=HelpersHMR.errors_hmr, timeout=240)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image=HelpersHMR.image_original)

        # Break the app with invalid xml changes
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML_INVALID_SYNTAX)

        # Verify console notify user for broken xml
        # strings = ['for activity org.nativescript.TestApp / com.tns.ErrorReportActivity']
        strings = ['com.tns.NativeScriptException', 'Parsing XML at', 'Successfully synced application', EMULATOR_ID]
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)
        assert Adb.wait_for_text(device_id=EMULATOR_ID, text="Exception", timeout=30), "Error activity not found!"

        # Revert changes
        ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_XML_INVALID_SYNTAX)
        strings = ['JS: HMR: Hot Module Replacement Enabled. Waiting for signal.',
                   'Successfully synced application', EMULATOR_ID]
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image=HelpersHMR.image_original)
    def test_370_tns_run_android_with_jar_and_aar_files_in_app_res(self):
        """
        App should not crash when reference .jar or/and .aar file in App_Resources/Android/libs
        https://github.com/NativeScript/android-runtime/issues/899
        """

        # Create libs/ in app/App_resources/, add .jar and .aar files in it and modify the app to reference them
        curr_folder = os.getcwd()
        Folder.navigate_to(os.path.join(self.app_name, 'app', 'App_Resources', 'Android'))
        Folder.create("libs")
        app_res_libs = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'libs')
        Folder.navigate_to(curr_folder)

        custom_jar_file = os.path.join('data', 'issues', 'android-runtime-pr-905', 'customLib.jar')
        custom_aar_file = os.path.join('data', 'issues', 'android-runtime-899', 'mylibrary.aar')

        File.copy(src=custom_jar_file, dest=app_res_libs)
        File.copy(src=custom_aar_file, dest=app_res_libs)

        source = os.path.join('data', 'issues', 'android-runtime-899', 'app.js')
        target = os.path.join(self.app_name, 'app', 'app.js')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', EMULATOR_ID,
                   'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image='livesync-hello-world_home')
Пример #10
0
    def test_002_android_run_hmr_uninstall_app(self):
        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID,
            '--hmr': ''
        },
                              wait=False,
                              assert_success=False)

        Tns.wait_for_log(log_file=log,
                         string_list=HelpersHMR.run_hmr_with_platforms,
                         not_existing_string_list=HelpersHMR.errors_hmr,
                         timeout=240)
        Helpers.android_screen_match(image=HelpersHMR.image_original,
                                     timeout=120)

        HelpersHMR.apply_changes_js(app_name=self.app_name,
                                    log=log,
                                    platform=Platform.ANDROID)

        # Uninstall app while `tns run` is running
        Device.uninstall_app(app_prefix='org.nativescript.',
                             platform=Platform.ANDROID)

        ReplaceHelper.rollback(self.app_name, HelpersHMR.js_change, sleep=10)
        strings = [
            'Restarting application on device',
            'HMR: Hot Module Replacement Enabled. Waiting for signal.'
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)

        Helpers.android_screen_match(image=HelpersHMR.image_original,
                                     timeout=120)
Пример #11
0
    def wait(device_id, timeout=300):
        """
        Wait until emulator is up and running.
        :param device_id: Device name
        :param timeout: Timeout until device is ready (in seconds).
        :return: True if device is ready before timeout, otherwise - False.
        """
        booted = False
        start_time = time.time()
        end_time = start_time + timeout
        while not booted:
            time.sleep(5)
            booted = Emulator.is_running(device_id=device_id)
            if (booted is True) or (time.time() > end_time):
                break

        # If booted, make sure screen will not lock
        if booted:
            Adb.run(command='shell settings put system screen_off_timeout -1',
                    device_id=device_id)

        # If booted, make sure screen will not lock
        if booted:
            text = Adb.get_page_source(device_id=device_id)
            if "android.process.acore" in text:
                print "Error dialog detected! Try to kill it..."
                Device.click(device_id=device_id, text="OK", timeout=10)
        return booted
    def test_360_tns_run_android_with_jar_file_in_plugin(self):
        """
        App should not crash when reference .jar file in some plugin
        https://github.com/NativeScript/android-runtime/pull/905
        """

        # Add .jar file in plugin and modify the app to reference it
        custom_jar_file = os.path.join('data', 'issues', 'android-runtime-pr-905', 'customLib.jar')
        modules_widgets = os.path.join(self.app_name, 'node_modules', 'tns-core-modules-widgets', 'platforms',
                                       'android')
        File.copy(src=custom_jar_file, dest=modules_widgets)

        source = os.path.join('data', 'issues', 'android-runtime-pr-905', 'app.js')
        target = os.path.join(self.app_name, 'app', 'app.js')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', EMULATOR_ID,
                   'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image='livesync-hello-world_home')
 def setUpClass(cls):
     BaseClass.setUpClass(cls.__name__)
     Emulator.stop()
     Device.ensure_available(platform=Platform.ANDROID)
     Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.ANDROID)
     Tns.create_app(cls.app_name,
                    attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')},
                    update_modules=True)
     Tns.platform_add_android(attributes={'--path': cls.app_name, '--frameworkPath': ANDROID_PACKAGE})
    def test_001_debug_ios_simulator(self):
        """
        Default `tns debug ios` starts debugger (do not stop at the first code statement)
        """
        log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': '', '--inspector': ''})
        DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log)

        # Verify app starts and do not stop on first line of code
        Device.screen_match(device_name=SIMULATOR_NAME,
                            device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home')
Пример #15
0
    def setUpClass(cls):
        BaseClass.setUpClass(cls.__name__)
        Emulator.stop()
        Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.ANDROID)
        Emulator.ensure_available()
        Folder.cleanup(cls.app_name)

        # Create default NG app (to get right dependencies from package.json)
        Tns.create_app_ng(cls.app_name)
        Tns.platform_add_android(attributes={'--path': cls.app_name, '--frameworkPath': ANDROID_PACKAGE}) 
Пример #16
0
    def test_003_android_run_hmr_wrong_xml(self):
        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID,
            '--hmr': ''
        },
                              wait=False,
                              assert_success=False)
        Tns.wait_for_log(log_file=log,
                         string_list=HelpersHMR.run_hmr,
                         not_existing_string_list=HelpersHMR.errors_hmr,
                         timeout=240)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME,
                            device_id=EMULATOR_ID,
                            expected_image=HelpersHMR.image_original)

        # Break the app with invalid xml changes
        ReplaceHelper.replace(self.app_name,
                              ReplaceHelper.CHANGE_XML_INVALID_SYNTAX)

        # Verify console notify user for broken xml
        # strings = ['for activity org.nativescript.TestApp / com.tns.ErrorReportActivity']
        strings = [
            'com.tns.NativeScriptException', 'Parsing XML at',
            'Successfully synced application', EMULATOR_ID
        ]
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=120,
                         check_interval=10)
        assert Adb.wait_for_text(device_id=EMULATOR_ID,
                                 text="Exception",
                                 timeout=30), "Error activity not found!"

        # Revert changes
        ReplaceHelper.rollback(self.app_name,
                               ReplaceHelper.CHANGE_XML_INVALID_SYNTAX)
        strings = [
            'JS: HMR: Hot Module Replacement Enabled. Waiting for signal.',
            'Successfully synced application', EMULATOR_ID
        ]
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=120,
                         check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME,
                            device_id=EMULATOR_ID,
                            expected_image=HelpersHMR.image_original)
    def setUpClass(cls):
        BaseClass.setUpClass(cls.__name__)
        Emulator.stop()
        Simulator.stop()
        Device.ensure_available(platform=Platform.IOS)
        Device.uninstall_app(app_prefix='org.nativescript.', platform=Platform.IOS)

        Folder.cleanup(cls.app_name)
        Tns.create_app(cls.app_name,
                       attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')},
                       update_modules=True)
        Folder.copy(src=os.path.join(cls.app_name, 'app'), dst=cls.TEMP_FOLDER)
        Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_PACKAGE})
 def setUpClass(cls):
     BaseClass.setUpClass(cls.__name__)
     Tns.kill()
     Emulator.stop()
     Emulator.ensure_available()
     Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.ANDROID)
     if CURRENT_OS != OSType.WINDOWS:
         Tns.create_app(cls.app_name,
                        attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')},
                        update_modules=True)
         Tns.platform_add_android(attributes={'--path': cls.app_name, '--frameworkPath': ANDROID_PACKAGE})
         Folder.cleanup(cls.temp_app)
         Folder.copy(cls.source_app, cls.temp_app)
Пример #19
0
    def test_370_tns_run_android_with_jar_and_aar_files_in_app_res(self):
        """
        App should not crash when reference .jar or/and .aar file in App_Resources/Android/libs
        https://github.com/NativeScript/android-runtime/issues/899
        """

        # Create libs/ in app/App_resources/, add .jar and .aar files in it and modify the app to reference them
        curr_folder = os.getcwd()
        Folder.navigate_to(
            os.path.join(self.app_name, 'app', 'App_Resources', 'Android'))
        Folder.create("libs")
        app_res_libs = os.path.join(self.app_name, 'app', 'App_Resources',
                                    'Android', 'libs')
        Folder.navigate_to(curr_folder)

        custom_jar_file = os.path.join('data', 'issues',
                                       'android-runtime-pr-905',
                                       'customLib.jar')
        custom_aar_file = os.path.join('data', 'issues', 'android-runtime-899',
                                       'mylibrary.aar')

        File.copy(src=custom_jar_file, dest=app_res_libs)
        File.copy(src=custom_aar_file, dest=app_res_libs)

        source = os.path.join('data', 'issues', 'android-runtime-899',
                              'app.js')
        target = os.path.join(self.app_name, 'app', 'app.js')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID
        },
                              wait=False,
                              assert_success=False)
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', EMULATOR_ID,
            'Successfully synced application'
        ]
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME,
                            device_id=EMULATOR_ID,
                            expected_image='livesync-hello-world_home')
    def test_008_android_run_hmr_console_log(self):
        source_js = os.path.join('data', "issues", 'console-log-hmr', 'main-view-model.js')
        target_js = os.path.join(self.app_name, 'app', 'main-view-model.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False,
                              assert_success=False)

        strings = ['LOG Hello']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image=HelpersHMR.image_original)
    def test_002_debug_ios_simulator_debug_brk(self):
        """
        Starts debugger and stop at the first code statement.
        """

        log = Tns.debug_ios(
            attributes={'--path': self.app_name, '--emulator': '', '--debug-brk': '', '--inspector': ''})
        DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log, app_started=False)
        # In this case `app_started` is False because app is not loaded when using '--debug-brk'.
        # '--debug-brk' stops before app loaded.

        # Verify app starts and do not stop on first line of code
        Device.screen_match(device_name=SIMULATOR_NAME, tolerance=3.0, device_id=self.SIMULATOR_ID,
                            expected_image='livesync-hello-world_debug_brk')
Пример #22
0
    def test_001_debug_ios_simulator(self):
        """
        Default `tns debug ios` starts debugger (do not stop at the first code statement)
        """
        log = Tns.debug_ios(attributes={
            '--path': self.app_name,
            '--emulator': '',
            '--inspector': ''
        })
        DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log)

        # Verify app starts and do not stop on first line of code
        Device.screen_match(device_name=SIMULATOR_NAME,
                            device_id=self.SIMULATOR_ID,
                            expected_image='livesync-hello-world_home')
    def test_003_debug_ios_simulator_start(self):
        """
        Attach the debug tools to a running app in the iOS Simulator
        """

        # Run the app and ensure it works
        log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--justlaunch': ''},
                          assert_success=False, timeout=30)
        TnsAsserts.prepared(app_name=self.app_name, platform=Platform.IOS, output=log, prepare=Prepare.SKIP)
        Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID,
                            expected_image='livesync-hello-world_home')

        # Attach debugger
        log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': '', '--start': '', '--inspector': ''})
        DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log, app_started=False)
Пример #24
0
    def test_200_build_android_app_bundle(self):
        """Build app with android app bundle option. Verify the output(app.aab) and use bundletool to deploy on device"""
        path_to_aab = os.path.join(self.app_name, "platforms", "android",
                                   "app", "build", "outputs", "bundle",
                                   "debug", "app.aab")

        output = Tns.build_android(attributes={
            "--path": self.app_name,
            "--aab": ""
        },
                                   assert_success=False)
        assert "The build result is located at:" in output
        assert path_to_aab in output
        assert File.exists(path_to_aab)

        #Verify app can be deployed on emulator via bundletool
        # Use bundletool to create the .apks file
        self.bundletool_build(self.bundletool_path, path_to_aab,
                              self.path_to_apks)
        assert File.exists(self.path_to_apks)

        # Deploy on device
        self.bundletool_deploy(self.bundletool_path,
                               self.path_to_apks,
                               device_id=EMULATOR_ID)

        # Start the app on device
        Adb.start_app(EMULATOR_ID, "org.nativescript.TestApp")

        # Verify app looks correct inside emulator
        app_started = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
        assert app_started, 'App is not started on device'
Пример #25
0
 def revert_changes_js(app_name, log, platform):
     # Change JS
     ReplaceHelper.rollback(app_name, HelpersHMR.js_change, sleep=10)
     strings = ['Refreshing application on device', 'HMR: Hot Module Replacement Enabled. Waiting for signal.']
     Tns.wait_for_log(log_file=log, string_list=strings)
     if platform == Platform.ANDROID:
         text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='42 taps left', timeout=20)
         assert text_changed, 'Changes in JS file not applied (UI is not refreshed)'
Пример #26
0
 def apply_changes_xml(app_name, log, platform):
     # Change XML after uninstall app from device
     ReplaceHelper.replace(app_name, HelpersHMR.xml_change, sleep=10)
     strings = ['Refreshing application on device', 'JS: HMR: Hot Module Replacement Enabled. Waiting for signal.']
     Tns.wait_for_log(log_file=log, string_list=strings)
     if platform == Platform.ANDROID:
         text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='TEST')
         assert text_changed, 'Changes in XML file not applied (UI is not refreshed).'
Пример #27
0
 def revert_changes_xml(app_name, log, platform):
     # Change XML after uninstall app from device
     ReplaceHelper.rollback(app_name, HelpersHMR.xml_change, sleep=10)
     strings = ['Refreshing application on device', 'HMR: Checking for updates to the bundle with hmr hash']
     Tns.wait_for_log(log_file=log, string_list=strings)
     if platform == Platform.ANDROID:
         text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
         assert text_changed, 'Changes in XML file not applied (UI is not refreshed).'
    def test_002_android_run_hmr_uninstall_app(self):
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False,
                        assert_success=False)

        Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr_with_platforms, not_existing_string_list=HelpersHMR.errors_hmr,
                         timeout=240)
        Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120)

        HelpersHMR.apply_changes_js(app_name=self.app_name, log=log, platform=Platform.ANDROID)

        # Uninstall app while `tns run` is running
        Device.uninstall_app(app_prefix='org.nativescript.', platform=Platform.ANDROID)

        ReplaceHelper.rollback(self.app_name, HelpersHMR.js_change, sleep=10)
        strings = ['Restarting application on device', 'HMR: Hot Module Replacement Enabled. Waiting for signal.']
        Tns.wait_for_log(log_file=log, string_list=strings)

        Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120)
Пример #29
0
 def apply_changes_js(app_name, log, platform):
     # Change JS
     ReplaceHelper.replace(app_name, HelpersHMR.js_change, sleep=10)
     strings = ['Refreshing application on device', 'HMR: The following modules were updated:', './main-view-model.js', './main-page.js',
                'Successfully transferred bundle.',
                'HMR: Successfully applied update with hmr hash ']
     Tns.wait_for_log(log_file=log, string_list=strings)
     if platform == Platform.ANDROID:
         text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='42 clicks left', timeout=20)
         assert text_changed, 'Changes in JS file not applied (UI is not refreshed).'
Пример #30
0
    def test_100_debug_ios_simulator_with_livesync(self):
        """
        `tns debug ios` should be able to run with livesync
        """
        log = Tns.debug_ios(attributes={
            '--path': self.app_name,
            '--emulator': '',
            '--inspector': ''
        })
        DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log)

        # Verify app starts and do not stop on first line of code
        Device.screen_match(device_name=SIMULATOR_NAME,
                            device_id=self.SIMULATOR_ID,
                            expected_image='livesync-hello-world_home')

        # Change JS and wait until app is synced
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
        strings = [
            'Successfully transferred', 'main-view-model.js', 'CONSOLE LOG',
            'Backend socket closed', 'Frontend socket closed',
            'Frontend client connected', 'Backend socket created',
            'NativeScript debugger attached'
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Change XML and wait until app is synced. App doesn't restart from 5.1.0 version
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3)
        strings = ['Successfully transferred', 'main-page.xml', 'CONSOLE LOG']
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Change CSS and wait until app is synced. App doesn't restart from 5.1.0 version
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3)
        strings = ['Successfully transferred', 'app.css', 'CONSOLE LOG']
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Verify application looks correct
        Device.screen_match(device_name=SIMULATOR_NAME,
                            device_id=self.SIMULATOR_ID,
                            expected_image='livesync-hello-world_js_css_xml',
                            tolerance=0.26)

        assert Process.is_running('NativeScript Inspector')
Пример #31
0
    def test_360_tns_run_android_with_jar_file_in_plugin(self):
        """
        App should not crash when reference .jar file in some plugin
        https://github.com/NativeScript/android-runtime/pull/905
        """

        # Add .jar file in plugin and modify the app to reference it
        custom_jar_file = os.path.join('data', 'issues',
                                       'android-runtime-pr-905',
                                       'customLib.jar')
        modules_widgets = os.path.join(self.app_name, 'node_modules',
                                       'tns-core-modules-widgets', 'platforms',
                                       'android')
        File.copy(src=custom_jar_file, dest=modules_widgets)

        source = os.path.join('data', 'issues', 'android-runtime-pr-905',
                              'app.js')
        target = os.path.join(self.app_name, 'app', 'app.js')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID
        },
                              wait=False,
                              assert_success=False)
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', EMULATOR_ID,
            'Successfully synced application'
        ]
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME,
                            device_id=EMULATOR_ID,
                            expected_image='livesync-hello-world_home')
Пример #32
0
    def setUpClass(cls):
        BaseClass.setUpClass(cls.__name__)
        Emulator.stop()
        Simulator.stop()
        Device.ensure_available(platform=Platform.IOS)
        Device.uninstall_app(app_prefix='org.nativescript.',
                             platform=Platform.IOS)

        Folder.cleanup(cls.app_name)
        Tns.create_app(cls.app_name,
                       attributes={
                           '--template':
                           os.path.join('data', 'apps',
                                        'livesync-hello-world.tgz')
                       },
                       update_modules=True)
        Folder.copy(src=os.path.join(cls.app_name, 'app'), dst=cls.TEMP_FOLDER)
        Tns.platform_add_ios(attributes={
            '--path': cls.app_name,
            '--frameworkPath': IOS_PACKAGE
        })
Пример #33
0
 def setUpClass(cls):
     BaseClass.setUpClass(cls.__name__)
     Tns.kill()
     Emulator.stop()
     Emulator.ensure_available()
     Device.uninstall_app(app_prefix="org.nativescript.",
                          platform=Platform.ANDROID)
     if CURRENT_OS != OSType.WINDOWS:
         Tns.create_app(cls.app_name,
                        attributes={
                            '--template':
                            os.path.join('data', 'apps',
                                         'livesync-hello-world.tgz')
                        },
                        update_modules=True)
         Tns.platform_add_android(attributes={
             '--path': cls.app_name,
             '--frameworkPath': ANDROID_PACKAGE
         })
         Folder.cleanup(cls.temp_app)
         Folder.copy(cls.source_app, cls.temp_app)
    def test_400_tns_run_ios_should_not_crash_when_uninstall_app(self):
        """
        `tns run ios` should work properly even if I manually uninstall the app (test for issue #3007)
        """

        # `tns run ios` and wait until app is deployed
        log = Tns.run_ios(attributes={'--path': self.app_name, "--device": self.DEVICE_ID}, wait=False,
                          assert_success=False)
        strings = [self.DEVICE_ID, 'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)

        # Verify app is running
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="taps left"), "App failed to load!"
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="TAP"), "App failed to load!"

        # Change JS and wait until app is synced
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=3)
        strings = ['Successfully transferred', 'main-view-model.js', 'Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="clicks"), "JS changes not synced on device!"

        # Uninstall app while `tns run` is running
        Device.uninstall_app(app_prefix='org.nativescript.', platform=Platform.IOS)
        sleep(10)

        # Change XML and wait until app is synced
        Tns.wait_for_log(log_file=log, string_list=[], timeout=30)  # Just to cleanup log file
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=10)
        strings = ['Successfully installed', 'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="TEST"), "XML changes not synced on device!"
Пример #35
0
    def test_002_debug_ios_simulator_debug_brk(self):
        """
        Starts debugger and stop at the first code statement.
        """

        log = Tns.debug_ios(
            attributes={
                '--path': self.app_name,
                '--emulator': '',
                '--debug-brk': '',
                '--inspector': ''
            })
        DebugiOSInspectorSimulatorTests.__verify_debugger_attach(
            log, app_started=False)
        # In this case `app_started` is False because app is not loaded when using '--debug-brk'.
        # '--debug-brk' stops before app loaded.

        # Verify app starts and do not stop on first line of code
        Device.screen_match(device_name=SIMULATOR_NAME,
                            tolerance=3.0,
                            device_id=self.SIMULATOR_ID,
                            expected_image='livesync-hello-world_debug_brk')
    def test_205_build_android_app_bundle_env_snapshot(self):
        """Build app with android app bundle option with --bundle and optimisations for snapshot.
           Verify the output(app.aab) and use bundletool to deploy on device."""
        # This test will not run on windows because env.snapshot option is not available on that OS
        
        path_to_aab = os.path.join(self.app_name, "platforms", "android", "app", "build", "outputs", "bundle", "release", "app.aab")
      
        #Configure app with snapshot optimisations
        source = os.path.join('data', 'abdoid-app-bundle', 'app.gradle')
        target = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'app.gradle' )
        File.copy(src=source, dest=target)

        source = os.path.join('data', 'abdoid-app-bundle', 'webpack.config.js')
        target = os.path.join(self.app_name, 'webpack.config.js' )
        File.copy(src=source, dest=target)

        #env.snapshot is applicable only in release build 
        output = Tns.build_android(attributes={"--path": self.app_name,
                                      "--keyStorePath": ANDROID_KEYSTORE_PATH,
                                      "--keyStorePassword": ANDROID_KEYSTORE_PASS,
                                      "--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
                                      "--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
                                      "--release": "",
                                      "--aab": "",
                                      "--env.uglify": "",
                                      "--env.snapshot": "",
                                      "--bundle": ""
                                      }, assert_success=False)
        assert "The build result is located at:" in output
        assert path_to_aab in output
        assert File.exists(path_to_aab)

        #Verify app can be deployed on emulator via bundletool
        # Use bundletool to create the .apks file
        self.bundletool_build(self.bundletool_path, path_to_aab, self.path_to_apks)
        assert File.exists(self.path_to_apks)

        # Verify that the correct .so file is included in the package
        File.unzip(self.path_to_apks, os.path.join(self.app_name, 'apks'))
        File.unzip(os.path.join(self.app_name, 'apks', 'splits', 'base-x86.apk'), os.path.join(self.app_name,'base_apk'))
        assert File.exists(os.path.join(self.app_name, 'base_apk', 'lib', 'x86', 'libNativeScript.so'))

        # Deploy on device
        self.bundletool_deploy(self.bundletool_path, self.path_to_apks, device_id=EMULATOR_ID)
        
        # Start the app on device
        Adb.start_app(EMULATOR_ID, "org.nativescript.TestApp")
        
        # Verify app looks correct inside emulator
        app_started = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
        assert app_started, 'App is not started on device'
Пример #37
0
    def test_008_android_run_hmr_console_log(self):
        source_js = os.path.join('data', "issues", 'console-log-hmr',
                                 'main-view-model.js')
        target_js = os.path.join(self.app_name, 'app', 'main-view-model.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID,
            '--hmr': ''
        },
                              wait=False,
                              assert_success=False)

        strings = ['LOG Hello']
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=120,
                         check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME,
                            device_id=EMULATOR_ID,
                            expected_image=HelpersHMR.image_original)
Пример #38
0
    def test_400_tns_run_ios_should_not_crash_when_uninstall_app(self):
        """
        `tns run ios` should work properly even if I manually uninstall the app (test for issue #3007)
        """

        # `tns run ios` and wait until app is deployed
        log = Tns.run_ios(attributes={
            '--path': self.app_name,
            "--device": self.DEVICE_ID
        },
                          wait=False,
                          assert_success=False)
        strings = [self.DEVICE_ID, 'Successfully synced application']
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10)

        # Verify app is running
        assert Device.wait_for_text(device_id=self.DEVICE_ID,
                                    text="taps left"), "App failed to load!"
        assert Device.wait_for_text(device_id=self.DEVICE_ID,
                                    text="TAP"), "App failed to load!"

        # Change JS and wait until app is synced
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=3)
        strings = [
            'Successfully transferred', 'main-view-model.js',
            'Successfully synced application', self.DEVICE_ID
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="clicks"), "JS changes not synced on device!"

        # Uninstall app while `tns run` is running
        Device.uninstall_app(app_prefix='org.nativescript.',
                             platform=Platform.IOS)
        sleep(10)

        # Change XML and wait until app is synced
        Tns.wait_for_log(log_file=log, string_list=[],
                         timeout=30)  # Just to cleanup log file
        ReplaceHelper.replace(self.app_name,
                              ReplaceHelper.CHANGE_XML,
                              sleep=10)
        strings = ['Successfully installed', 'Successfully synced application']
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10)
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="TEST"), "XML changes not synced on device!"
    def test_200_build_android_app_bundle(self):
        """Build app with android app bundle option. Verify the output(app.aab) and use bundletool to deploy on device"""
        path_to_aab = os.path.join(self.app_name, "platforms", "android", "app", "build", "outputs", "bundle", "debug", "app.aab")

        output = Tns.build_android(attributes={"--path": self.app_name, "--aab":""}, assert_success=False)
        assert "The build result is located at:" in output
        assert path_to_aab in output
        assert File.exists(path_to_aab)

        #Verify app can be deployed on emulator via bundletool
        # Use bundletool to create the .apks file
        self.bundletool_build(self.bundletool_path, path_to_aab, self.path_to_apks)
        assert File.exists(self.path_to_apks)

        # Deploy on device
        self.bundletool_deploy(self.bundletool_path, self.path_to_apks, device_id=EMULATOR_ID)
        
        # Start the app on device
        Adb.start_app(EMULATOR_ID, "org.nativescript.TestApp")
        
        # Verify app looks correct inside emulator
        app_started = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
        assert app_started, 'App is not started on device'
Пример #40
0
    # Copy test packages and cleanup
    if CURRENT_OS == OSType.OSX:
        Simulator.stop()
        disable_crash_report()
        get_test_packages(platform=Platform.BOTH)
        Simulator.reset()

        if Xcode.get_version() < 10:
            SIMULATOR_SDK = '11.0'
        if Xcode.get_version() < 9:
            SIMULATOR_SDK = '10.0'

        Simulator.create(SIMULATOR_NAME, SIMULATOR_TYPE, SIMULATOR_SDK)
        Xcode.cleanup_cache()  # Clean Xcode cache folders
        Device.uninstall_app(app_prefix="org.nativescript.",
                             platform=Platform.ANDROID)
        Device.uninstall_app(app_prefix="org.nativescript.",
                             platform=Platform.IOS)
    else:
        get_test_packages(platform=Platform.ANDROID)

    # Install CLI
    Cli.install()
    Tns.disable_reporting()

    # Add local CLI to PATH
    if CURRENT_OS != OSType.WINDOWS:
        base_path = os.path.join(TEST_RUN_HOME, 'node_modules', 'nativescript',
                                 'bin')
        where_command = 'which tns'
    else:
Пример #41
0
    # Copy test packages and cleanup
    if CURRENT_OS == OSType.OSX:
        Simulator.stop()
        disable_crash_report()
        get_test_packages(platform=Platform.BOTH)
        Simulator.reset()

        if Xcode.get_version() < 10:
            SIMULATOR_SDK = '11.0'
        if Xcode.get_version() < 9:
            SIMULATOR_SDK = '10.0'
        

        Simulator.create(SIMULATOR_NAME, SIMULATOR_TYPE, SIMULATOR_SDK)
        Xcode.cleanup_cache()  # Clean Xcode cache folders
        Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.ANDROID)
        Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.IOS)
    else:
        get_test_packages(platform=Platform.ANDROID)

    # Install CLI
    Cli.install()
    Tns.disable_reporting()

    # Add local CLI to PATH
    if CURRENT_OS != OSType.WINDOWS:
        base_path = os.path.join(TEST_RUN_HOME, 'node_modules', 'nativescript', 'bin')
        where_command = 'which tns'
    else:
        base_path = os.path.join(TEST_RUN_HOME, 'node_modules', '.bin')
        where_command = 'where tns'
Пример #42
0
    def test_330_tns_run_ios_after_rebuild_of_native_project(self):
        """
        `tns run ios` should work properly after rebuild of native project (test for issue #2860)
        """

        # `tns run ios` and wait until app is deployed
        log = Tns.run_ios(attributes={
            '--path': self.app_name,
            '--device': self.DEVICE_ID
        },
                          wait=False,
                          assert_success=False,
                          log_trace=True)
        strings = [self.DEVICE_ID, 'Successfully synced application']
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=120,
                         check_interval=10)

        # Verify app is running
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="Tap the button"), "App failed to load!"

        # Update native project
        config_path = os.path.join(self.app_name, 'app', 'App_Resources',
                                   'iOS', 'build.xcconfig')
        File.replace(file_path=config_path,
                     str1='More info',
                     str2='If you need more info')
        strings = [
            'ARCHIVE SUCCEEDED', 'Successfully synced application',
            self.DEVICE_ID, 'CONSOLE LOG'
        ]
        not_existing_strings = [
            'Unable to sync files', 'Multiple errors were thrown'
        ]
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         not_existing_string_list=not_existing_strings,
                         timeout=120)

        # Verify app is running
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="Tap the button"), "App failed to load!"

        # Change JS and wait until app is synced
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
        strings = [
            'Successfully transferred', 'main-view-model.js',
            'Successfully synced application', self.DEVICE_ID
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="clicks"), "JS changes not synced on device!"

        # Rollback all the changes and verify files are synced
        ReplaceHelper.rollback(self.app_name,
                               ReplaceHelper.CHANGE_JS,
                               sleep=10)
        strings = [
            'Successfully transferred', 'main-view-model.js',
            'Restarting application'
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="taps left"), "JS changes not synced on device!"
Пример #43
0
class RunIOSDeviceTests(BaseClass):
    SIMULATOR_ID = ''
    DEVICES = Device.get_ids(platform=Platform.IOS)
    DEVICE_ID = Device.get_id(platform=Platform.IOS)
    TEMP_FOLDER = os.path.join(
        TEST_RUN_HOME, 'out', 'livesync-hello-world_app_' +
        datetime.now().strftime('%Y_%m_%d_%H_%M_%S'))

    @classmethod
    def setUpClass(cls):
        BaseClass.setUpClass(cls.__name__)
        Emulator.stop()
        Simulator.stop()
        Device.ensure_available(platform=Platform.IOS)
        Device.uninstall_app(app_prefix='org.nativescript.',
                             platform=Platform.IOS)

        Folder.cleanup(cls.app_name)
        Tns.create_app(cls.app_name,
                       attributes={
                           '--template':
                           os.path.join('data', 'apps',
                                        'livesync-hello-world.tgz')
                       },
                       update_modules=True)
        Folder.copy(src=os.path.join(cls.app_name, 'app'), dst=cls.TEMP_FOLDER)
        Tns.platform_add_ios(attributes={
            '--path': cls.app_name,
            '--frameworkPath': IOS_PACKAGE
        })

    def setUp(self):
        BaseClass.setUp(self)
        Tns.kill()

        # Replace app folder between tests.
        app_folder = os.path.join(self.app_name, 'app')
        Folder.cleanup(app_folder)
        Folder.copy(src=self.TEMP_FOLDER, dst=app_folder)

    def tearDown(self):
        Tns.kill()
        BaseClass.tearDown(self)

    @classmethod
    def tearDownClass(cls):
        BaseClass.tearDownClass()

    def test_210_tns_run_ios_add_remove_files_and_folders(self):
        """
        New files and folders should be synced properly.
        """

        log = Tns.run_ios(attributes={
            '--path': self.app_name,
            '--device': self.DEVICE_ID
        },
                          wait=False,
                          assert_success=False)
        strings = ['Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=120,
                         check_interval=10)

        # Add new files
        new_file_name = 'app2.css'
        source_file = os.path.join(self.app_name, 'app', 'app.css')
        destination_file = os.path.join(self.app_name, 'app', new_file_name)
        File.copy(source_file, destination_file)
        strings = [
            'Successfully transferred', new_file_name, 'Refreshing application'
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Revert changes(rename file and delete file)
        # File.copy(destination_file, source_file)
        # File.remove(destination_file)
        # strings = ['Successfully transferred', new_file_name]
        # Tns.wait_for_log(log_file=log, string_list=strings)

        # Add folder
        new_folder_name = 'test2'
        source_file = os.path.join(self.app_name, 'app', 'test')
        destination_file = os.path.join(self.app_name, 'app', new_folder_name)
        Folder.copy(source_file, destination_file)
        strings = [
            'Successfully transferred test.txt',
            'Successfully synced application'
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)

    @flaky(max_runs=2)
    def test_300_tns_run_ios_emulator_should_start_emulator_even_if_device_is_connected(
            self):
        """
        `tns run ios --emulator` should start emulator even if physical device is connected
        """
        Simulator.stop()
        Tns.run_ios(attributes={
            '--path': self.app_name,
            '--emulator': '',
            '--justlaunch': ''
        },
                    assert_success=False)
        assert Simulator.wait_for_simulator(
        )[0], 'iOS Simulator not started by `tns run ios`!'

    def test_310_tns_run_ios_emulator_should_run_only_on_emulator(self):
        """
        `tns run ios --emulator` should start emulator even if physical device is connected
        """
        self.SIMULATOR_ID = Simulator.ensure_available(
            simulator_name=SIMULATOR_NAME)
        output = Tns.run_ios(attributes={
            '--path': self.app_name,
            '--emulator': '',
            '--justlaunch': ''
        },
                             assert_success=False)
        TnsAsserts.prepared(app_name=self.app_name,
                            output=output,
                            platform=Platform.IOS,
                            prepare=Prepare.INCREMENTAL)
        app_id = Tns.get_app_id(self.app_name)
        assert app_id + " on device " + self.SIMULATOR_ID in output, "App not deployed on iOS Simulator!"
        for device_id in self.DEVICES:
            assert app_id + " on device " + device_id not in output, 'App is deployed on {0} device.'.format(
                device_id)

    def test_330_tns_run_ios_after_rebuild_of_native_project(self):
        """
        `tns run ios` should work properly after rebuild of native project (test for issue #2860)
        """

        # `tns run ios` and wait until app is deployed
        log = Tns.run_ios(attributes={
            '--path': self.app_name,
            '--device': self.DEVICE_ID
        },
                          wait=False,
                          assert_success=False,
                          log_trace=True)
        strings = [self.DEVICE_ID, 'Successfully synced application']
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=120,
                         check_interval=10)

        # Verify app is running
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="Tap the button"), "App failed to load!"

        # Update native project
        config_path = os.path.join(self.app_name, 'app', 'App_Resources',
                                   'iOS', 'build.xcconfig')
        File.replace(file_path=config_path,
                     str1='More info',
                     str2='If you need more info')
        strings = [
            'ARCHIVE SUCCEEDED', 'Successfully synced application',
            self.DEVICE_ID, 'CONSOLE LOG'
        ]
        not_existing_strings = [
            'Unable to sync files', 'Multiple errors were thrown'
        ]
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         not_existing_string_list=not_existing_strings,
                         timeout=120)

        # Verify app is running
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="Tap the button"), "App failed to load!"

        # Change JS and wait until app is synced
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
        strings = [
            'Successfully transferred', 'main-view-model.js',
            'Successfully synced application', self.DEVICE_ID
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="clicks"), "JS changes not synced on device!"

        # Rollback all the changes and verify files are synced
        ReplaceHelper.rollback(self.app_name,
                               ReplaceHelper.CHANGE_JS,
                               sleep=10)
        strings = [
            'Successfully transferred', 'main-view-model.js',
            'Restarting application'
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="taps left"), "JS changes not synced on device!"

    def test_400_tns_run_ios_should_not_crash_when_uninstall_app(self):
        """
        `tns run ios` should work properly even if I manually uninstall the app (test for issue #3007)
        """

        # `tns run ios` and wait until app is deployed
        log = Tns.run_ios(attributes={
            '--path': self.app_name,
            "--device": self.DEVICE_ID
        },
                          wait=False,
                          assert_success=False)
        strings = [self.DEVICE_ID, 'Successfully synced application']
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10)

        # Verify app is running
        assert Device.wait_for_text(device_id=self.DEVICE_ID,
                                    text="taps left"), "App failed to load!"
        assert Device.wait_for_text(device_id=self.DEVICE_ID,
                                    text="TAP"), "App failed to load!"

        # Change JS and wait until app is synced
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=3)
        strings = [
            'Successfully transferred', 'main-view-model.js',
            'Successfully synced application', self.DEVICE_ID
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="clicks"), "JS changes not synced on device!"

        # Uninstall app while `tns run` is running
        Device.uninstall_app(app_prefix='org.nativescript.',
                             platform=Platform.IOS)
        sleep(10)

        # Change XML and wait until app is synced
        Tns.wait_for_log(log_file=log, string_list=[],
                         timeout=30)  # Just to cleanup log file
        ReplaceHelper.replace(self.app_name,
                              ReplaceHelper.CHANGE_XML,
                              sleep=10)
        strings = ['Successfully installed', 'Successfully synced application']
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10)
        assert Device.wait_for_text(
            device_id=self.DEVICE_ID,
            text="TEST"), "XML changes not synced on device!"
Пример #44
0
    def test_205_build_android_app_bundle_env_snapshot(self):
        """Build app with android app bundle option with --bundle and optimisations for snapshot.
           Verify the output(app.aab) and use bundletool to deploy on device."""
        # This test will not run on windows because env.snapshot option is not available on that OS

        path_to_aab = os.path.join(self.app_name, "platforms", "android",
                                   "app", "build", "outputs", "bundle",
                                   "release", "app.aab")

        #Configure app with snapshot optimisations
        source = os.path.join('data', 'abdoid-app-bundle', 'app.gradle')
        target = os.path.join(self.app_name, 'app', 'App_Resources', 'Android',
                              'app.gradle')
        File.copy(src=source, dest=target)

        source = os.path.join('data', 'abdoid-app-bundle', 'webpack.config.js')
        target = os.path.join(self.app_name, 'webpack.config.js')
        File.copy(src=source, dest=target)

        #env.snapshot is applicable only in release build
        output = Tns.build_android(attributes={
            "--path": self.app_name,
            "--keyStorePath": ANDROID_KEYSTORE_PATH,
            "--keyStorePassword": ANDROID_KEYSTORE_PASS,
            "--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
            "--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
            "--release": "",
            "--aab": "",
            "--env.uglify": "",
            "--env.snapshot": "",
            "--bundle": ""
        },
                                   assert_success=False)
        assert "The build result is located at:" in output
        assert path_to_aab in output
        assert File.exists(path_to_aab)

        #Verify app can be deployed on emulator via bundletool
        # Use bundletool to create the .apks file
        self.bundletool_build(self.bundletool_path, path_to_aab,
                              self.path_to_apks)
        assert File.exists(self.path_to_apks)

        # Verify that the correct .so file is included in the package
        File.unzip(self.path_to_apks, os.path.join(self.app_name, 'apks'))
        File.unzip(
            os.path.join(self.app_name, 'apks', 'splits', 'base-x86.apk'),
            os.path.join(self.app_name, 'base_apk'))
        assert File.exists(
            os.path.join(self.app_name, 'base_apk', 'lib', 'x86',
                         'libNativeScript.so'))

        # Deploy on device
        self.bundletool_deploy(self.bundletool_path,
                               self.path_to_apks,
                               device_id=EMULATOR_ID)

        # Start the app on device
        Adb.start_app(EMULATOR_ID, "org.nativescript.TestApp")

        # Verify app looks correct inside emulator
        app_started = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
        assert app_started, 'App is not started on device'