コード例 #1
0
    def test(self, template_name, template_info):
        TnsRunTest.setUp(self)

        # Create app
        app_name = template_info.name.replace('template-', '')
        Tns.create(app_name=app_name, template='tns-' + template_name, update=False)
        if Settings.ENV != EnvironmentType.LIVE and Settings.ENV != EnvironmentType.PR:
            App.update(app_name=app_name)

        # Run Android
        result = Tns.run_android(app_name=app_name, device=self.emu.id)
        strings = TnsLogs.run_messages(app_name=app_name, run_type=RunType.UNKNOWN, platform=Platform.ANDROID)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
        if template_info.texts is not None:
            for text in template_info.texts:
                self.emu.wait_for_text(text=text, timeout=60)
        else:
            self.emu.wait_for_main_color(color=Colors.WHITE, timeout=60)

        # Run iOS
        if Settings.HOST_OS is OSType.OSX:
            Simctl.uninstall_all(simulator_info=self.sim)
            result = Tns.run_ios(app_name=app_name, device=self.sim.id)
            strings = TnsLogs.run_messages(app_name=app_name, run_type=RunType.UNKNOWN, platform=Platform.IOS)
            TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
            if template_info.texts is not None:
                for text in template_info.texts:
                    self.sim.wait_for_text(text=text, timeout=60)
            else:
                self.sim.wait_for_main_color(color=Colors.WHITE, timeout=60)

        # Cleanup
        TnsRunTest.tearDown(self)
コード例 #2
0
    def get_screen(self, path, log_level=logging.INFO):
        """
        Save screen of mobile device.
        :param path: Path to image that will be saved.
        :param log_level: Log level.
        """

        # Ensure folder to save the screen exists
        File.delete(path)
        Folder.create(folder=os.path.dirname(path))

        if self.type is DeviceType.EMU or self.type is DeviceType.ANDROID:
            Adb.get_screen(device_id=self.id, file_path=path)
        if self.type is DeviceType.SIM:
            Simctl.get_screen(sim_id=self.id, file_path=path)
        if self.type is DeviceType.IOS:
            IDevice.get_screen(device_id=self.id, file_path=path)

        image_saved = False
        if File.exists(path):
            size = os.path.getsize(path)
            if size > 10:
                image_saved = True
        if image_saved:
            message = "Image of {0} saved at {1}".format(self.id, path)
            Log.log(level=log_level, msg=message)
        else:
            message = "Failed to save image of {0} saved at {1}".format(
                self.id, path)
            Log.error(message)
            raise Exception(message)
コード例 #3
0
 def setUpClass(cls):
     TnsTest.setUpClass()
     cls.emu = DeviceManager.Emulator.ensure_available(
         Settings.Emulators.DEFAULT)
     if Settings.HOST_OS is OSType.OSX:
         cls.sim = DeviceManager.Simulator.ensure_available(
             Settings.Simulators.DEFAULT)
         Simctl.uninstall_all(cls.sim)
コード例 #4
0
 def setUpClass(cls):
     TnsTest.setUpClass()
     cls.sim = DeviceManager.Simulator.ensure_available(Simulators.DEFAULT)
     Simctl.uninstall_all(cls.sim)
     Tns.create(app_name=APP_NAME,
                template=Template.HELLO_WORLD_JS.local_package,
                update=True)
     Tns.platform_add_ios(APP_NAME, framework_path=IOS.FRAMEWORK_PATH)
コード例 #5
0
 def setUpClass(cls):
     TnsTest.setUpClass()
     cls.emu = DeviceManager.Emulator.ensure_available(
         Settings.Emulators.DEFAULT)
     if Settings.HOST_OS is OSType.OSX:
         # Run regression tests on older iOS (since old modules might not be compatible with latest iOS).
         cls.sim = DeviceManager.Simulator.ensure_available(
             Settings.Simulators.SIM_IOS11)
         Simctl.uninstall_all(cls.sim)
     LegacyApp.create(app_name=cls.ng_app, app_type=AppType.NG)
コード例 #6
0
 def install_playground_app(device_info, platform):
     """Installs Playground App on emulator and simulator"""
     package_android = os.path.join(TEST_SUT_HOME, "app-release.apk")
     package_ios = os.path.join(TEST_SUT_HOME, 'nsplay.app')
     if platform is Platform.IOS:
         # Unpack the .tgz file to get the nsplay.app
         File.unpack_tar(os.path.join(TEST_SUT_HOME, 'nsplay.tgz'), TEST_SUT_HOME)
         Simctl.install(device_info, package_ios)
     elif platform is Platform.ANDROID:
         Adb.install(package_android, device_info.id)
コード例 #7
0
 def install_preview_app(device_info, platform, timeout=60):
     """Installs Preview App on emulator and simulator"""
     package_android = os.path.join(TEST_SUT_HOME, 'app-universal-release.apk')
     package_ios = os.path.join(TEST_SUT_HOME, 'nsplaydev.app')
     if platform is Platform.IOS:
         # Unpack the .tgz file to get the nsplaydev.app
         File.unpack_tar(os.path.join(TEST_SUT_HOME, 'nsplaydev.tgz'), TEST_SUT_HOME)
         Simctl.install(device_info, package_ios)
     elif platform is Platform.ANDROID:
         Adb.install(package_android, device_info.id, timeout)
コード例 #8
0
 def install_preview_app_no_unpack(device_info, platform, uninstall=True):
     """Installs Preview App on emulator and simulator"""
     package_android = os.path.join(TEST_SUT_HOME, 'app-universal-release.apk')
     package_ios = os.path.join(TEST_SUT_HOME, 'nsplaydev.app')
     if platform is Platform.IOS:
         if uninstall:
             Simctl.uninstall(device_info, Settings.Packages.PREVIEW_APP_ID)
         Simctl.install(device_info, package_ios)
     elif platform is Platform.ANDROID:
         if uninstall:
             Adb.uninstall(Settings.Packages.PREVIEW_APP_ID, device_info.id, False)
         Adb.install(package_android, device_info.id)
コード例 #9
0
    def setUpClass(cls):
        TnsDeviceTest.setUpClass()

        cls.emu = DeviceManager.Emulator.ensure_available(Settings.Emulators.DEFAULT)
        if Settings.HOST_OS is OSType.OSX:
            cls.sim = DeviceManager.Simulator.ensure_available(Settings.Simulators.DEFAULT)
            Simctl.uninstall_all(cls.sim)

        # Create app
        Tns.create(app_name=cls.app_name, template=Template.HELLO_WORLD_JS.local_package, update=True)
        Tns.platform_add_android(app_name=cls.app_name, framework_path=Settings.Android.FRAMEWORK_PATH)
        if Settings.HOST_OS is OSType.OSX:
            Tns.platform_add_ios(app_name=cls.app_name, framework_path=Settings.IOS.FRAMEWORK_PATH)

        # Copy TestApp to data folder.
        Folder.copy(source=cls.source_project_dir, target=cls.target_project_dir)
コード例 #10
0
    def run_url(url, device):
        """
        Runs project in the Preview App.
        :param url: Playground url.
        :param device: DeviceInfo object.
        """
        # Url needs to be escaped before open with adb or simctl
        url = url.replace(r'?', r'\?')
        url = url.replace(r'&', r'\&')

        # Run url
        Log.info('Open "{0}" on {1}.'.format(url, device.name))
        if device.type == DeviceType.EMU or device.type == DeviceType.ANDROID:
            cmd = 'shell am start -a android.intent.action.VIEW -d "{0}" org.nativescript.preview'.format(
                url)
            output = Adb.run_adb_command(command=cmd,
                                         device_id=device.id).output
            assert 'error' not in output, 'Failed to open URL!' + os.linesep + 'Error:' + os.linesep + output
        elif device.type == DeviceType.SIM:
            output = Simctl.run_simctl_command(
                command='openurl {0} {1}.'.format(device.id, url)).output
            assert 'error' not in output, 'Failed to open URL!' + os.linesep + 'Error:' + os.linesep + output
        else:
            raise NotImplementedError(
                'Open url not implemented for real iOS devices.')
コード例 #11
0
    def test_384_check_for_native_and_js_callstacks(self):
        """
        https://github.com/NativeScript/ios-runtime/pull/1144
        """
        # Replace main-page.js so there is an error
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-pr-1144', 'main-page.js'),
            os.path.join(APP_PATH, 'app', 'main-page.js'), True)

        result = Tns.run_ios(app_name=APP_NAME,
                             emulator=True,
                             wait=False,
                             verify=False)
        strings = [
            'Native Stack:', 'sig_handler(int)', 'JS Stack:',
            '1   @[native code]',
            '2   onNavigatingTo@file:///app/main-page.js:34:0'
        ]
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=150,
                             check_interval=10)

        # Verify app is NOT running on device
        test_result = Wait.until(lambda: Simctl.is_process_running(
            self.sim, 'org.nativescript.' + APP_NAME) is False,
                                 timeout=120,
                                 period=5)
        assert test_result, "It seems that " + APP_NAME + " is still running when it should not!"
コード例 #12
0
    def __init__(self, id, name, type, model, version):
        self.id = id
        self.type = type
        self.version = version
        self.model = model
        self.name = name

        if type is DeviceType.IOS:
            type = run(cmd="ideviceinfo | grep ProductType").output
            type = type.replace(',', '')
            type = type.replace('ProductType:', '').strip(' ')
            self.name = type
        if type is DeviceType.SIM:
            self.model = name
        if type is DeviceType.EMU:
            cmd = 'shell getprop ro.product.model'
            model = Adb.run_adb_command(command=cmd,
                                        wait=True,
                                        device_id=self.id).output
            self.model = model.strip('\n\r')
        else:
            self.name = name

        if type is DeviceType.SIM:
            self.device_log_file = Simctl.get_log_file(self.id)
コード例 #13
0
 def is_running_on_ios(device_info, app_id):
     """
     Get preview URL form tns log.
     This is the url you need to load in Preview app in order to see and sync your project.
     :param device_info: Information about the device we will search in.
     :param app_id: the App ID of the process.
     :return: boolean.
     """
     return Simctl.is_process_running(device_info, app_id)
コード例 #14
0
 def clear_log(self):
     """
     Clean device log.
     """
     if self.type is DeviceType.EMU or self.type is DeviceType.ANDROID:
         Adb.clear_logcat(self.id)
     elif self.type is DeviceType.SIM:
         self.device_log_file = Simctl.get_log_file(self.id)
     else:
         raise NotImplementedError('Click not implemented for iOS devices.')
コード例 #15
0
 def create(simulator_info):
     exact_sdk_verson = Simctl.get_max_runtime_version(
         simulator_info.sdk)
     cmd = 'xcrun simctl create {0} "{1}" com.apple.CoreSimulator.SimRuntime.iOS-{2}' \
         .format(simulator_info.name, simulator_info.device_type, str(exact_sdk_verson).replace('.', '-'))
     result = run(cmd=cmd, timeout=60)
     assert result.exit_code == 0, 'Failed to create iOS Simulator with name {0}'.format(
         simulator_info.name)
     assert '-' in result.output, 'Failed to create iOS Simulator with name {0}'.format(
         simulator_info.name)
     simulator_info.id = result.output.splitlines()[0]
     return simulator_info
コード例 #16
0
    def __init__(self, id, name, type, version):
        self.id = id
        self.type = type
        self.version = version

        if type is DeviceType.IOS:
            type = run(cmd="ideviceinfo | grep ProductType").output
            type = type.replace(',', '')
            type = type.replace('ProductType:', '').strip(' ')
            self.name = type
        else:
            self.name = name

        if type is DeviceType.SIM:
            self.device_log_file = Simctl.get_log_file(self.id)
コード例 #17
0
        def start(simulator_info):
            # Start iOS Simulator
            Log.info('Booting {0} ...'.format(simulator_info.name))
            simulator_info = Simctl.start(simulator_info=simulator_info)

            # Start GUI
            if Process.get_proc_by_commandline('Simulator.app') is not None:
                Log.debug('Simulator GUI is already running.')
            else:
                Log.info('Start simulator GUI.')
                run(cmd='open -a Simulator')

            # Return result
            device = Device(id=simulator_info.id, name=simulator_info.name, type=DeviceType.SIM,
                            version=simulator_info.sdk)
            TestContext.STARTED_DEVICES.append(device)
            return device
コード例 #18
0
 def is_running(simulator_info):
     return Simctl.is_running(simulator_info=simulator_info)
コード例 #19
0
 def is_available(simulator_info):
     return Simctl.is_available(simulator_info=simulator_info)
コード例 #20
0
 def setUp(self):
     TnsTest.setUp(self)
     Simctl.stop_all(self.sim)
コード例 #21
0
 def setUp(self):
     TnsTest.setUp(self)
     Adb.open_home(self.emu.id)
     Adb.clear_logcat(self.emu.id)
     if Settings.HOST_OS is OSType.OSX:
         Simctl.stop_all(self.sim)
コード例 #22
0
 def setUpClass(cls):
     TnsTest.setUpClass()
     cls.sim = DeviceManager.Simulator.ensure_available(
         Settings.Simulators.DEFAULT)
     Simctl.uninstall_all(cls.sim)
コード例 #23
0
    def test_scoped_package_only(self, app_name, template_info):
        TnsRunTest.setUp(self)

        # Create app
        app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
        Tns.create(app_name=app_name,
                   template=template_info.local_package,
                   update=True)
        Npm.uninstall(package='tns-core-modules',
                      option='--save',
                      folder=app_path)
        Npm.install(package=Settings.Packages.NATIVESCRIPT_CORE,
                    option='--save --save-exact',
                    folder=app_path)

        # Replace imports
        if template_info == Template.HELLO_WORLD_TS:
            files = File.find_by_extension(folder=os.path.join(
                app_path, 'app'),
                                           extension='ts')
            for file in files:
                File.replace(path=file,
                             old_string='tns-core-modules',
                             new_string='@nativescript/core',
                             fail_safe=True)
        if template_info == Template.MASTER_DETAIL_NG:
            files = File.find_by_extension(folder=os.path.join(
                app_path, 'src'),
                                           extension='ts')
            for file in files:
                File.replace(path=file,
                             old_string='tns-core-modules',
                             new_string='@nativescript/core',
                             fail_safe=True)

        Tns.platform_add_android(
            app_name=app_name, framework_path=Settings.Android.FRAMEWORK_PATH)
        if Settings.HOST_OS is OSType.OSX:
            Tns.platform_add_ios(app_name=app_name,
                                 framework_path=Settings.IOS.FRAMEWORK_PATH)

        # Run Android
        result = Tns.run_android(app_name=app_name,
                                 device=self.emu.id,
                                 aot=True,
                                 uglify=True)
        strings = TnsLogs.run_messages(app_name=app_name,
                                       run_type=RunType.UNKNOWN,
                                       platform=Platform.ANDROID)
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=300)
        for text in template_info.texts:
            self.emu.wait_for_text(text=text, timeout=60)

        # Run iOS
        Tns.kill()
        if Settings.HOST_OS is OSType.OSX:
            Simctl.uninstall_all(simulator_info=self.sim)
            result = Tns.run_ios(app_name=app_name,
                                 device=self.sim.id,
                                 aot=True,
                                 uglify=True)
            strings = TnsLogs.run_messages(app_name=app_name,
                                           run_type=RunType.UNKNOWN,
                                           platform=Platform.IOS)
            TnsLogs.wait_for_log(log_file=result.log_file,
                                 string_list=strings,
                                 timeout=300)
            for text in template_info.texts:
                self.sim.wait_for_text(text=text, timeout=60)

        # Cleanup
        Folder.clean(os.path.join(Settings.TEST_RUN_HOME, app_name))
        TnsRunTest.tearDown(self)