def get_screen(device_id, file_path):
        """
        Save screen of mobile device.
        :param device_id: Device identifier (example: `emulator-5554`).
        :param file_path: Path to image that will be saved.
        """

        File.remove(file_path)
        base_path, file_name = os.path.split(file_path)
        Folder.create(base_path)

        device_type = Device.__get_device_type(device_id)
        if (device_type == DeviceType.EMULATOR) or (device_type == DeviceType.ANDROID):
            Adb.get_screen(device_id=device_id, file_path=file_path)
        if device_type == DeviceType.SIMULATOR:
            Simulator.get_screen(device_id=device_id, file_path=file_path)
        if device_type == DeviceType.IOS:
            IDevice.get_screen(device_id=device_id, file_path=file_path)

        image_saved = False
        if File.exists(file_path):
            size = os.path.getsize(file_path)
            if size > 10:
                image_saved = True
        return image_saved
Beispiel #2
0
 def setUpClass(cls):
     BaseClass.setUpClass(cls.__name__)
     Process.kill('Safari')
     Process.kill('NativeScript Inspector')
     Emulator.stop()
     Simulator.stop()
     cls.SIMULATOR_ID = Simulator.ensure_available(
         simulator_name=SIMULATOR_NAME)
     Folder.cleanup(cls.INSPECTOR_GLOBAL_PATH)
     Tns.create_app(cls.app_name,
                    attributes={
                        '--template':
                        os.path.join('data', 'apps',
                                     'livesync-hello-world.tgz')
                    },
                    update_modules=True)
     Tns.platform_add_ios(attributes={
         '--path': cls.app_name,
         '--frameworkPath': IOS_PACKAGE
     })
     if USE_YARN == "True":
         Npm.install(package=IOS_INSPECTOR_PACKAGE,
                     option='--dev',
                     folder=cls.app_name)
     else:
         Npm.install(package=IOS_INSPECTOR_PACKAGE,
                     option='--save-dev',
                     folder=cls.app_name)
     Tns.build_ios(attributes={"--path": cls.app_name})
 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`!'
Beispiel #4
0
    def get_screen(device_id, file_path):
        """
        Save screen of mobile device.
        :param device_id: Device identifier (example: `emulator-5554`).
        :param file_path: Path to image that will be saved.
        """

        File.remove(file_path)
        base_path, file_name = os.path.split(file_path)
        Folder.create(base_path)

        device_type = Device.__get_device_type(device_id)
        if (device_type == DeviceType.EMULATOR) or (device_type
                                                    == DeviceType.ANDROID):
            Adb.get_screen(device_id=device_id, file_path=file_path)
        if device_type == DeviceType.SIMULATOR:
            Simulator.get_screen(device_id=device_id, file_path=file_path)
        if device_type == DeviceType.IOS:
            IDevice.get_screen(device_id=device_id, file_path=file_path)

        image_saved = False
        if File.exists(file_path):
            size = os.path.getsize(file_path)
            if size > 10:
                image_saved = True
        return image_saved
Beispiel #5
0
    def setUpClass(cls):
        BaseClass.setUpClass(cls.__name__)
        Simulator.stop()
        cls.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME)

        Tns.create_app(cls.app_name, update_modules=True)
        Tns.install_npm(package=WEBPACK_PACKAGE, option='--save-dev', folder=cls.app_name)
        Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_PACKAGE})
 def tearDownClass(cls):
     Tns.kill()
     Emulator.stop()
     Gradle.kill()
     if CURRENT_OS == OSType.OSX:
         Process.kill('NativeScript Inspector')
         Process.kill('Safari')
         Simulator.stop()
Beispiel #7
0
 def tearDownClass(cls):
     Tns.kill()
     Emulator.stop()
     Gradle.kill()
     if CURRENT_OS == OSType.OSX:
         Process.kill('NativeScript Inspector')
         Process.kill('Safari')
         Simulator.stop()
 def setUpClass(cls):
     BaseClass.setUpClass(cls.__name__)
     if CURRENT_OS != OSType.OSX:
         raise NameError("Can not run iOS tests on non OSX OS.")
     else:
         Simulator.stop()
     Tns.create_app(cls.app_name)
     Tns.platform_add_ios(attributes={"--path": cls.app_name, "--frameworkPath": IOS_PACKAGE})
     Folder.copy(TEST_RUN_HOME + "/" + cls.app_name, TEST_RUN_HOME + "/data/TestApp")
Beispiel #9
0
 def install_preview_app(device_id, platform=Platform.BOTH):
     """Installs Preview App on emulator and simulator"""
     package_android = os.path.join(SUT_FOLDER, 'app-universal-release.apk')
     package_ios = os.path.join(SUT_FOLDER, 'nsplaydev.app')
     if platform is Platform.IOS:
         Simulator.install(package_ios)
     elif platform is Platform.ANDROID:
         Adb.install(package_android, device_id)
     elif platform is Platform.BOTH:
         Adb.install(package_android, device_id)
         Simulator.install(package_ios)
 def install_playground_app(device_id, platform=Platform.BOTH):
     """Installs Playground App on emulator and simulator"""
     package_android = os.path.join(SUT_FOLDER, "app-release.apk")
     package_ios = os.path.join(SUT_FOLDER, 'nsplay.app')
     if platform is Platform.IOS:
         Simulator.install(package_ios)
     elif platform is Platform.ANDROID: 
         Adb.install(package_android, device_id)
     elif platform is Platform.BOTH: 
         Adb.install(package_android, device_id)
         Simulator.install(package_ios)
 def install_preview_app(device_id, platform=Platform.BOTH):
     """Installs Preview App on emulator and simulator"""
     package_android = os.path.join(SUT_FOLDER, 'app-universal-release.apk')
     package_ios = os.path.join(SUT_FOLDER, 'nsplaydev.app')
     if platform is Platform.IOS:
         Simulator.install(package_ios)
     elif platform is Platform.ANDROID: 
         Adb.install(package_android, device_id)
     elif platform is Platform.BOTH: 
         Adb.install(package_android, device_id)
         Simulator.install(package_ios)
Beispiel #12
0
 def install_playground_app(device_id, platform=Platform.BOTH):
     """Installs Playground App on emulator and simulator"""
     package_android = os.path.join(SUT_FOLDER, "app-release.apk")
     package_ios = os.path.join(SUT_FOLDER, 'nsplay.app')
     if platform is Platform.IOS:
         Simulator.install(package_ios)
     elif platform is Platform.ANDROID:
         Adb.install(package_android, device_id)
     elif platform is Platform.BOTH:
         Adb.install(package_android, device_id)
         Simulator.install(package_ios)
Beispiel #13
0
    def setUp(self):
        BaseClass.setUp(self)
        Simulator.stop()
        Folder.cleanup(self.app_name_dash)
        Folder.cleanup(self.app_name_space)
        Folder.cleanup(self.app_name_ios)
        Folder.cleanup(self.app_name_no_platform)
        Folder.cleanup(self.app_name_no_platform + '/platforms/ios/build')

        Tns.platform_remove(platform=Platform.IOS,
                            attributes={"--path": self.app_name},
                            assert_success=False)
Beispiel #14
0
 def setUpClass(cls):
     BaseClass.setUpClass(cls.__name__)
     Emulator.stop()
     Simulator.stop()
     cls.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME)
     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)
     Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_PACKAGE})
     Folder.cleanup(TEST_RUN_HOME + "/data/TestApp")
     Folder.copy(TEST_RUN_HOME + "/" + cls.app_name, TEST_RUN_HOME + "/data/TestApp")
    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})
Beispiel #16
0
 def stop_application(device_id, app_id):
     """
     Stop application
     :param device_id: Device identifier
     :param app_id: Bundle identifier (example: org.nativescript.TestApp)
     """
     device_type = Device.__get_device_type(device_id=device_id)
     if device_type is DeviceType.SIMULATOR:
         Simulator.stop_application(app_id=app_id)
     elif device_type is DeviceType.IOS:
         raise NotImplementedError
     else:
         Adb.stop_application(device_id=device_id, app_id=app_id)
Beispiel #17
0
 def setUpClass(cls):
     BaseClass.setUpClass(cls.__name__)
     if CURRENT_OS != OSType.OSX:
         raise NameError("Can not run iOS tests on non OSX OS.")
     else:
         Simulator.stop()
     Tns.create_app(cls.app_name)
     Tns.platform_add_ios(attributes={
         "--path": cls.app_name,
         "--frameworkPath": IOS_PACKAGE
     })
     Folder.copy(TEST_RUN_HOME + "/" + cls.app_name,
                 TEST_RUN_HOME + "/data/TestApp")
 def stop_application(device_id, app_id):
     """
     Stop application
     :param device_id: Device identifier
     :param app_id: Bundle identifier (example: org.nativescript.TestApp)
     """
     device_type = Device.__get_device_type(device_id=device_id)
     if device_type is DeviceType.SIMULATOR:
         Simulator.stop_application(app_id=app_id)
     elif device_type is DeviceType.IOS:
         raise NotImplementedError
     else:
         Adb.stop_application(device_id=device_id, app_id=app_id)
Beispiel #19
0
 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`!'
Beispiel #20
0
    def test_003_ios_run_hmr_wrong_xml(self):
        log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--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.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120)
        Helpers.wait_webpack_watcher()

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

        # Uninstall app while `tns run` is running
        Simulator.uninstall("org.nativescript." + self.app_name)

        HelpersHMR.revert_changes_js(app_name=self.app_name, log=log, platform=Platform.IOS)
        Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120)
        Helpers.wait_webpack_watcher()
 def setUpClass(cls):
     BaseClass.setUpClass(cls.__name__)
     Process.kill('Safari')
     Process.kill('NativeScript Inspector')
     Emulator.stop()
     Simulator.stop()
     cls.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME)
     Folder.cleanup(cls.INSPECTOR_GLOBAL_PATH)
     Tns.create_app(cls.app_name,
                    attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')},
                    update_modules=True)
     Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_PACKAGE})
     if USE_YARN == "True":
         Npm.install(package=IOS_INSPECTOR_PACKAGE, option='--dev', folder=cls.app_name)
     else:
         Npm.install(package=IOS_INSPECTOR_PACKAGE, option='--save-dev', folder=cls.app_name)
     Tns.build_ios(attributes={"--path": cls.app_name})
Beispiel #22
0
    def test_002_ios_run_hmr_uninstall_app(self):
        log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--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.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120)
        Helpers.wait_webpack_watcher()
        
        HelpersHMR.apply_changes_js(app_name=self.app_name, log=log, platform=Platform.IOS)

        # Uninstall app while `tns run` is running
        Simulator.uninstall("org.nativescript." + self.app_name)

        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.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120)
        Helpers.wait_webpack_watcher()
 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)
Beispiel #24
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
        })
Beispiel #25
0
 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 tearDown(self):
     assert not Simulator.is_running()[0], 'iOS Simulator started after prepare!'
Beispiel #27
0
 def setUp(self):
     BaseClass.setUp(self)
     self.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME)
     Folder.cleanup(self.app_name)
     Folder.copy(TEST_RUN_HOME + "/data/TestApp", TEST_RUN_HOME + "/TestApp")
if __name__ == '__main__':

    # Cleanup files and folders created by the test execution
    Folder.cleanup(OUTPUT_FOLDER)
    Folder.create(OUTPUT_FOLDER)
    Folder.cleanup(SUT_FOLDER)
    Folder.cleanup("node_modules")
    Npm.cache_clean()
    Gradle.kill()
    Gradle.cache_clean()
    get_repos()
    Emulator.stop()  # Stop running emulators

    # 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:
Beispiel #29
0
 def tearDown(self):
     BaseClass.tearDown(self)
     assert not Simulator.is_running(
     )[0], "Simulator started after " + self._testMethodName
Beispiel #30
0
 def tearDown(self):
     assert not Simulator.is_running(
     )[0], 'iOS Simulator started after prepare!'
Beispiel #31
0
if __name__ == '__main__':

    # Cleanup files and folders created by the test execution
    Folder.cleanup(OUTPUT_FOLDER)
    Folder.create(OUTPUT_FOLDER)
    Folder.cleanup(SUT_FOLDER)
    Folder.cleanup("node_modules")
    Npm.cache_clean()
    Gradle.kill()
    Gradle.cache_clean()
    get_repos()
    Emulator.stop()  # Stop running emulators

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