def test_389_add_swift_files_to_xcode_project(self):
        """
        Test that users are be able to add swift files and use it
        https://github.com/NativeScript/ios-runtime/issues/1131
        """

        Folder.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1131', 'src'),
            os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'), True)

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1131', 'main-page.js'),
            os.path.join(APP_PATH, 'app', 'main-page.js'), True)
        log = Tns.run_ios(app_name=APP_NAME, emulator=True)

        # Verify app is running on device
        Device.wait_for_text(self.sim, text='Tap the button')

        strings = ['Swift class property: 123', 'Swift class method: GREAT!']
        result = Wait.until(lambda: all(string in File.read(log.log_file)
                                        for string in strings),
                            timeout=300,
                            period=5)
        assert result, 'It seems that there\'s a problem with using swift files that are added in App_Resources'
Example #2
0
    def get_devices(device_type=any):
        devices = []
        # Get Android devices
        if device_type is DeviceType.ANDROID or device_type is any:
            for device_id in Adb.get_ids(include_emulators=False):
                version = Adb.get_version(device_id=device_id)
                device = Device(id=device_id,
                                name=device_id,
                                type=DeviceType.ANDROID,
                                version=version,
                                model=None)
                devices.append(device)
        # Get iOS devices
        if device_type is DeviceType.IOS or device_type is any:
            for device_id in IDevice.get_devices():
                device = Device(id=device_id,
                                name=device_id,
                                type=DeviceType.IOS,
                                version=None,
                                model=None)
                devices.append(device)

        for device in devices:
            TestContext.STARTED_DEVICES.append(device)
        return devices
Example #3
0
    def test_390_check_correct_name_of_internal_class_is_returned(self):
        """
        Test that NSStringFromClass function returns correct name of iOS internal class
        https://github.com/NativeScript/ios-runtime/issues/1120
        """

        # Delete src folder from the previous test till Folder copy strt to backup folders too
        Folder.clean(
            os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'))

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1120', 'main-page.js'),
            os.path.join(APP_PATH, 'app', 'main-page.js'), True)

        log = Tns.run_ios(app_name=APP_NAME, emulator=True)

        # Verify app is running on device
        Device.wait_for_text(self.sim, text='Tap the button')

        string = ['Internal class: UITableViewCellContentView']
        result = Wait.until(lambda: all(st in File.read(log.log_file)
                                        for st in string),
                            timeout=60,
                            period=5)
        assert result, 'NSStringFromClass function returns INCORRECT name of iOS internal class!'
Example #4
0
    def test_392_use_objective_c_plus_plus_file(self):
        """
        https://github.com/NativeScript/ios-runtime/issues/1203
        """

        Folder.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1203', 'src'),
            os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'), True)

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1203', 'main-page.js'),
            os.path.join(APP_PATH, 'app', 'main-page.js'), True)
        log = Tns.run_ios(app_name=APP_NAME, emulator=True)

        strings = ['NativeScript logInfo method called']
        result = Wait.until(lambda: all(string in File.read(log.log_file)
                                        for string in strings),
                            timeout=300,
                            period=5)
        assert result, 'It seems that there\'s a problem with using objective C++ files that are added in App_Resources'

        # Verify app is running on device
        Device.wait_for_text(self.sim, text='Tap the button')
Example #5
0
    def test_391_native_properties_provided_by_internal_classes_are_available(
            self):
        """
        Test native properties provided by internal classes are available
        https://github.com/NativeScript/ios-runtime/issues/1149
        """

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1149', 'main-view-model.js'),
            os.path.join(APP_PATH, 'app', 'main-view-model.js'), True)

        log = Tns.run_ios(app_name=APP_NAME, emulator=True)

        # Verify app is running on device
        Device.wait_for_text(self.sim, text='Tap the button')

        strings = [
            'response1:  <NSHTTPURLResponse:',
            'response2:  <NSHTTPURLResponse:', 'Status Code: 200'
        ]
        result = Wait.until(lambda: all(string in File.read(log.log_file)
                                        for string in strings),
                            timeout=300,
                            period=5)
        assert result, 'It seems that native properties provided by internal classes are not available'
    def test_385_methods_with_same_name_and_different_parameters(self):
        """
        https://github.com/NativeScript/ios-runtime/issues/877
        PR https://github.com/NativeScript/ios-runtime/pull/1013
        """
        # Replace main-page.js to call methods with the same name but different parameters count
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-877', '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 = [
            'Successfully synced application', 'SayName no param!',
            'SayName with 1 param!', 'SayName with 2 params!'
        ]
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=150,
                             check_interval=10)

        # Verify app is running on device
        Device.wait_for_text(self.sim, text=TAP_THE_BUTTON)
    def test_202_test_foreground_service_without_oncreate_method_is_working(
            self):
        """
         https://github.com/NativeScript/android-runtime/issues/1373
        """
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                         'files', 'android-runtime-1347',
                         'AndroidManifest.xml'),
            os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources',
                         'Android', 'src', 'main', 'AndroidManifest.xml'),
            True)
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                         'files', 'android-runtime-1347',
                         'without_oncreate_method', 'app.js'),
            os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js'), True)
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                         'files', 'android-runtime-1347',
                         'main-view-model.js'),
            os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-view-model.js'),
            True)
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)
        strings = [
            'Successfully synced application', 'on device', self.emulator.id
        ]
        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=240,
                                 period=5)
        assert test_result, "App not build correctly ! Logs: " + File.read(
            log.log_file)

        Device.click(self.emulator, text="TAP", case_sensitive=True)
        time.sleep(5)
        test_result = Wait.until(
            lambda: "Create Foreground Service!" in File.read(log.log_file),
            timeout=30,
            period=5)
        assert test_result, "OnCreate foreground service log not found! Logs: " + File.read(
            log.log_file)

        service_name = "com.nativescript.location.BackgroundService"
        service_info = Adb.get_active_services(self.emulator.id, service_name)
        assert service_name in service_info, "{0} service not found! Logs: {1}".format(
            service_name, service_info)

        pid = Adb.get_process_pid(self.emulator.id, "org.nativescript.TestApp")
        Adb.kill_application(self.emulator.id, "org.nativescript.TestApp", pid)

        service_info = Adb.get_active_services(self.emulator.id, service_name)
        assert service_name not in service_info, "{0} service found! Logs: {1}".format(
            service_name, service_info)
        assert pid not in service_info, "{0} service with id {1} found! Logs: {2}".format(
            service_name, pid, service_info)
Example #8
0
    def test_500_test_ES6_support(self):
        """
         https://github.com/NativeScript/android-runtime/issues/1375
        """
        Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.create(
            app_name=APP_NAME,
            template="https://github.com/NativeScript/es6-syntax-app.git",
            update=True)

        Tns.platform_add_android(APP_NAME,
                                 framework_path=Android.FRAMEWORK_PATH)
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)
        strings = [
            'Successfully synced application', 'on device', self.emulator.id
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=120,
                                 period=5)
        assert test_result, "App not build correctly after updating tns-core modules! Logs: " + File.read(
            log.log_file)
        button_text = "Use ES6 language features"

        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, button_text),
            timeout=30,
            period=5)
        message = "Use ES6 language features Button is missing on the device! The app has crashed!"
        assert test_result, message

        Device.click(self.emulator, text=button_text, case_sensitive=False)
        test_result = Wait.until(
            lambda: "class com.js.NativeList" in File.read(log.log_file),
            timeout=25,
            period=5)
        assert test_result, "com.js.NativeList not found! Logs: " + File.read(
            log.log_file)

        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, button_text),
            timeout=30,
            period=5)
        assert test_result, message
 def test_13_get_run_messages_sync_js_bundle_uglify(self):
     logs = TnsLogs.run_messages(app_name=Settings.AppName.DEFAULT,
                                 platform=Platform.ANDROID,
                                 run_type=RunType.INCREMENTAL,
                                 file_name='main-view-model.js',
                                 bundle=True,
                                 uglify=True,
                                 hmr=False,
                                 device=Device(id='123',
                                               name='Emu',
                                               type=DeviceType.EMU,
                                               version=4.4,
                                               model=None))
     assert 'Skipping prepare.' not in logs
     assert 'File change detected.' in logs
     assert 'main-view-model.js' in logs
     assert 'Webpack compilation complete.' in logs
     assert 'Successfully transferred bundle.js' in logs
     assert 'Successfully transferred vendor.js' in logs
     assert 'Restarting application on device' in logs
     assert 'Successfully synced application org.nativescript.TestApp on device' in logs
     assert 'ActivityManager: Start proc' in logs
     assert 'activity org.nativescript.TestApp/com.tns.NativeScriptActivity' in logs
     assert 'Refreshing application on device' not in logs
     assert 'hot-update.json on device' not in logs
        def start(emulator):
            # Define emulator start options and command
            emulator_path = os.path.join(ANDROID_HOME, 'emulator', 'emulator')
            options = '-port {0} -wipe-data -no-snapshot-save -no-boot-anim -no-audio -netspeed lte'.format(
                emulator.port)

            # Check if clean snapshot is available and use it
            snapshot_name = 'clean_boot'
            home = os.path.expanduser("~")
            snapshot = os.path.join(home, '.android', 'avd', '{0}.avd'.format(emulator.avd), 'snapshots', snapshot_name)
            if Folder.exists(snapshot):
                Log.info('{0} has clean boot snapshot! Will user it.'.format(emulator.avd))
                options = '-port {0} -no-snapshot-save -no-boot-anim -no-audio -snapshot {1}'.format(emulator.port,
                                                                                                     snapshot_name)

            command = '{0} @{1} {2}'.format(emulator_path, emulator.avd, options)
            Log.info('Booting {0} with cmd:'.format(emulator.avd))
            Log.info(command)
            run(cmd=command, wait=False, register=False)
            booted = Adb.wait_until_boot(device_id=emulator.emu_id)
            if booted:
                Log.info('{0} is up and running!'.format(emulator.avd))
                device = Device(id=emulator.emu_id, name=emulator.avd, type=DeviceType.EMU, version=emulator.os_version)
                TestContext.STARTED_DEVICES.append(device)
                return device
            else:
                raise Exception('Failed to boot {0}!'.format(emulator.avd))
 def test_205_test_foreground__intent_service_without_oncreate_method_is_working_api28(
         self):
     """
      https://github.com/NativeScript/android-runtime/issues/1426
     """
     DeviceManager.Emulator.stop()
     self.emulator = DeviceManager.Emulator.ensure_available(
         Emulators.EMU_API_28)
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1426',
                      'AndroidManifest.xml'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources',
                      'Android', 'src', 'main', 'AndroidManifest.xml'),
         True)
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1426', 'app.js'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js'), True)
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1426',
                      'main-view-model.js'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-view-model.js'),
         True)
     log = Tns.run_android(APP_NAME,
                           device=self.emulator.id,
                           wait=False,
                           verify=False)
     strings = [
         'Successfully synced application', 'on device', self.emulator.id
     ]
     test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                          for string in strings),
                              timeout=240,
                              period=5)
     assert test_result, "App not build correctly ! Logs: " + File.read(
         log.log_file)
     Device.click(self.emulator, text="TAP", case_sensitive=True)
     time.sleep(5)
     test_result = Wait.until(
         lambda: "Intent Handled!" in File.read(log.log_file),
         timeout=30,
         period=5)
     assert test_result, "Intent service is not working! Missing Log! Logs: " + File.read(
         log.log_file)
Example #12
0
    def test_390_code_cache_option(self):
        """
        CodeCache option is broken since Android Runtime 4.1.0

        https://github.com/NativeScript/android-runtime/issues/1235
        """
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1235',
                                 'package.json')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'package.json')
        File.copy(source=source_js, target=target_js, backup_files=True)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = ['Successfully synced application']
        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=300,
                                 period=5)

        assert test_result, 'Application not build successfully!'

        code_cache_files = ['bundle.js.cache', 'vendor.js.cache']
        json = App.get_package_json(app_name=APP_NAME)
        app_id = json['nativescript']['id']

        # Check that for each .js file, there's a corresponding .js.cache file created on the device
        for code_cache_file in code_cache_files:
            error_message = '{0} file is not found on {1}'.format(
                code_cache_file, self.emulator.id)
            assert Adb.file_exists(
                device_id=self.emulator.id,
                package_id=app_id,
                file_name='app/{0}'.format(code_cache_file)), error_message

        # Verify app looks correct inside emulator
        Device.wait_for_text(self.emulator, text=TAP_THE_BUTTON)
Example #13
0
    def test_398_tns_run_ios_console_time(self):
        # Delete src folder from the previous test till Folder copy strt to backup folders too
        Folder.clean(
            os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'))

        Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.create(app_name=APP_NAME,
                   template=Template.HELLO_WORLD_NG.local_package,
                   update=True)
        Tns.platform_add_ios(APP_NAME, framework_path=IOS.FRAMEWORK_PATH)
        # Replace app.component.ts to use console.time() and console.timeEnd()

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-843', 'app.component.ts'),
            os.path.join(APP_PATH, 'src', 'app', 'app.component.ts'), True)

        # `tns run ios` and wait until app is deployed
        result = Tns.run_ios(app_name=APP_NAME,
                             emulator=True,
                             wait=False,
                             verify=False)

        # Verify initial state of the app
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', self.sim.id
        ]
        assert_result = Wait.until(lambda: all(st in File.read(result.log_file)
                                               for st in strings),
                                   timeout=200,
                                   period=5)

        assert assert_result, 'App not build correctly! Logs: ' + File.read(
            result.log_file)

        Device.wait_for_text(self.sim, text="Ter Stegen", timeout=30)

        # Verify console.time() works - issue https://github.com/NativeScript/ios-runtime/issues/843
        console_time = ['CONSOLE INFO startup:']
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=console_time)
 def ensure_available(simulator_info):
     if DeviceManager.Simulator.is_running(simulator_info=simulator_info):
         return Device(id=simulator_info.id,
                       name=simulator_info.name,
                       type=DeviceType.SIM,
                       version=simulator_info.sdk)
     elif DeviceManager.Simulator.is_available(simulator_info=simulator_info):
         return DeviceManager.Simulator.start(simulator_info)
     else:
         simulator_info = DeviceManager.Simulator.create(simulator_info=simulator_info)
         return DeviceManager.Simulator.start(simulator_info)
    def test_440_verify_no_class_not_found_exception_is_thrown(self):
        """
        ClassNotFound exception when calling nested static class with correct argument
        https://github.com/NativeScript/android-runtime/issues/1195
        """
        source_app_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime',
                                         'android', 'files',
                                         'android-runtime-1195', 'app.gradle')
        target_app_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                         'App_Resources', 'Android',
                                         'app.gradle')
        File.copy(source=source_app_gradle,
                  target=target_app_gradle,
                  backup_files=True)

        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1195', 'app.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier',
            self.emulator.id, 'Successfully synced application'
        ]
        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=300,
                                 period=5)
        assert test_result, 'Application not build correctly!'

        # Verify app looks correct inside emulator
        Device.wait_for_text(self.emulator, text=TAP_THE_BUTTON)
 def test_204_test_background_worker_support(self):
     """
      https://github.com/NativeScript/android-runtime/issues/1488
     """
     Adb.clear_logcat(self.emulator.id)
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1488', 'app.js'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js'), True)
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1488',
                      'main-view-model.js'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-view-model.js'),
         True)
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1488', 'app.gradle'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources',
                      'Android', 'app.gradle'), True)
     log = Tns.run_android(APP_NAME,
                           device=self.emulator.id,
                           wait=False,
                           verify=False)
     strings = [
         'Successfully synced application', 'on device', self.emulator.id
     ]
     test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                          for string in strings),
                              timeout=240,
                              period=5)
     assert test_result, "App not build correctly ! Logs: " + File.read(
         log.log_file)
     Device.click(self.emulator, text="TAP", case_sensitive=True)
     time.sleep(5)
     device_log = Adb.get_logcat(self.emulator.id)
     error_message = "Background worker not working as expected. Logs: " + device_log
     assert "WM-WorkerWrapper: Worker result SUCCESS for Work" in device_log, error_message
Example #17
0
    def test_443_build_app_and_assert_that_tns_core_modules_could_be_updated(
            self):
        """
         Test update of tns-core-modules works correctly if you have build the app first
         https://github.com/NativeScript/android-runtime/issues/1257
        """
        Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.create(app_name=APP_NAME,
                   template=Template.HELLO_WORLD_JS.local_package)
        Tns.platform_add_android(APP_NAME,
                                 framework_path=Android.FRAMEWORK_PATH)
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = [
            'Successfully synced application', 'on device', self.emulator.id
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=240,
                                 period=5)
        assert test_result, "App not build correctly ! Logs: " + File.read(
            log.log_file)
        Npm.install(package=Packages.MODULES,
                    folder=os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.plugin_add(plugin_name="[email protected]",
                       path=os.path.join(TEST_RUN_HOME, APP_NAME))
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = [
            'Successfully synced application', 'on device', self.emulator.id
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=120,
                                 period=5)
        assert test_result, "App not build correctly after updating tns-core modules! Logs: " + File.read(
            log.log_file)
        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, "TAP", True),
            timeout=90,
            period=5)
        assert test_result, "TAP Button is missing on the device! Update of tns-core-modules not successful!"
 def setUpClass(cls):
     TnsTest.setUpClass()
     Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
     Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_NG.local_package)
     json = App.get_package_json(app_name=APP_NAME)
     cls.app_id = json['nativescript']['id']
     devices = Adb.get_ids(include_emulators=False)
     device_id = None
     for device in devices:
         device_id = device
     if device_id is not None:
         cls.device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID,
                             version=Adb.get_version(device_id))
     Adb.uninstall(cls.app_id, device_id, assert_success=False)
    def test_388_unicode_char_in_xml(self):
        """
        Test app does not crash when xml includes Unicode characters outside of the basic ASCII set
        https://github.com/NativeScript/ios-runtime/issues/1130
        """
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1130', 'main-page.xml'),
            os.path.join(APP_PATH, 'app', 'main-page.xml'), True)

        log = Tns.run_ios(app_name=APP_NAME, emulator=True)
        error = [
            'JS ERROR Error: Invalid autocapitalizationType value:undefined'
        ]
        is_error_thrown = Wait.until(lambda: all(er in File.read(log.log_file)
                                                 for er in error),
                                     timeout=30,
                                     period=5)
        assert is_error_thrown is False, 'App should not crash when xml includes Unicode characters outside of the ' \
                                         'basic ASCII set'

        # Verify app is running on device
        Device.wait_for_text(self.sim, text='Tap the button')
    def test_386_check_native_crash_will_not_crash_when_discardUncaughtJsExceptions_used(
            self):
        """
            Test native crash will not crash the app when discardUncaughtJsExceptions used
            https://github.com/NativeScript/ios-runtime/issues/1051
        """
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1051', 'app.js'),
            os.path.join(APP_PATH, 'app', 'app.js'), True)
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1051', 'main-view-model.js'),
            os.path.join(APP_PATH, 'app', 'main-view-model.js'), True)
        # Change app package.json so it contains the options for discardUncaughtJsExceptions
        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-1051', 'package.json'),
            os.path.join(APP_PATH, 'app', 'package.json'), True)

        log = Tns.run_ios(app_name=APP_NAME, emulator=True)

        strings = [
            'CONSOLE LOG file:///app/app.js:47:0 The folder “not-existing-path” doesn’t exist.',
            'JS: 1   contentsOfDirectoryAtPathError@file:///app/main-view-model.js:6:0'
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=300,
                                 period=5)

        # Verify app is running on device
        Device.wait_for_text(self.sim, text=TAP_THE_BUTTON)

        message = 'Native crash should not crash the app when discardUncaughtJsExceptions is used! Logs'
        assert test_result, message + File.read(log.log_file)
    def test_380_tns_run_ios_plugin_dependencies(self):
        """
        issue https://github.com/NativeScript/ios-runtime/issues/890
        Check app is running when reference plugin A - plugin A depends on plugin B which depends on plugin C.
        Plugin A has dependency only to plugin B.
        Old behavior (version < 4.0.0) was in plugin A to reference plugin B and C.
        """
        # Add plugin with specific dependencies
        Tns.plugin_add(self.plugin_path, path=APP_NAME)

        # `tns run ios` and wait until app is deployed
        result = Tns.run_ios(app_name=APP_NAME,
                             emulator=True,
                             wait=False,
                             verify=False)
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', self.sim.id
        ]
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=150,
                             check_interval=10)

        # Verify app is running on device
        Device.wait_for_text(self.sim, text=TAP_THE_BUTTON)

        tns_core_framework = 'TNSCore.framework'
        path_to_file = os.path.join(APP_PATH, 'platforms', 'ios',
                                    'TestApp.xcodeproj', 'project.pbxproj')
        if tns_core_framework in File.read(path_to_file):
            Log.info("{0} found in {1}".format(tns_core_framework,
                                               path_to_file))
            assert True
        else:
            assert False, "Cannot find {0} in {1}".format(
                tns_core_framework, path_to_file)
 def setUpClass(cls):
     TnsTest.setUpClass()
     cls.emulator = DeviceManager.Emulator.ensure_available(Emulators.DEFAULT)
     Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
     Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_NG.local_package, update=True)
     json = App.get_package_json(app_name=APP_NAME)
     cls.app_id = json['nativescript']['id']
     devices = Adb.get_ids(include_emulators=False)
     device_id = None
     for device in devices:
         device_id = device
     if device_id is not None:
         cls.device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID,
                             version=Adb.get_version(device_id))
     Adb.uninstall(cls.app_id, device_id, assert_success=False)
     Tns.platform_add_android(APP_NAME, framework_path=Android.FRAMEWORK_PATH)
Example #23
0
 def test_11_get_run_messages_sync_js(self):
     logs = TnsLogs.run_messages(app_name=Settings.AppName.DEFAULT,
                                 platform=Platform.ANDROID,
                                 run_type=RunType.INCREMENTAL,
                                 file_name='main-view-model.js',
                                 bundle=False,
                                 hmr=False,
                                 device=Device(id='123',
                                               name='Emu',
                                               type=DeviceType.EMU,
                                               version=8.0))
     assert 'Successfully transferred main-view-model.js' in logs
     assert 'Restarting application on device' in logs
     assert 'Successfully synced application org.nativescript.TestApp on device' in logs
     assert 'ActivityManager: Start proc' not in logs
     assert 'activity org.nativescript.TestApp/com.tns.NativeScriptActivity' not in logs
        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
Example #25
0
 def test_444_test_useV8Symbols_flag_in_package_json(self):
     """
      https://github.com/NativeScript/android-runtime/issues/1368
     """
     log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME))
     # check the default value for v8 symbols
     strings = [
         'adding nativescript runtime package dependency: nativescript-optimized-with-inspector'
     ]
     test_result = Wait.until(lambda: all(string in log.output
                                          for string in strings),
                              timeout=240,
                              period=5)
     assert test_result, "Missing nativescript runtime package dependency! Logs: " + log.output
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1368', 'package.json'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'package.json'), True)
     # check useV8Symbols flag is working
     log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME))
     strings = [
         'adding nativescript runtime package dependency: nativescript-regular'
     ]
     test_result = Wait.until(lambda: all(string in log.output
                                          for string in strings),
                              timeout=240,
                              period=5)
     assert test_result, "Missing nativescript runtime package dependency! Logs: " + log.output
     # check app is working
     Tns.run_android(APP_NAME,
                     device=self.emulator.id,
                     wait=False,
                     verify=False)
     test_result = Wait.until(
         lambda: Device.is_text_visible(self.emulator, "TAP", True),
         timeout=50,
         period=5)
     assert test_result, "TAP Button is missing on the device! V8 with debug symbols is making the app crash!"
Example #26
0
 def test_10_get_run_messages_first_run(self):
     logs = TnsLogs.run_messages(app_name='QAApp',
                                 platform=Platform.ANDROID,
                                 run_type=RunType.FIRST_TIME,
                                 file_name=None,
                                 device=Device(id='123',
                                               name='Emu',
                                               type=DeviceType.EMU,
                                               version=6.0))
     assert 'Skipping prepare.' not in logs
     assert 'Preparing project...' in logs
     assert 'Project successfully prepared (android)' in logs
     assert 'Building project...' in logs
     assert 'Gradle build...' in logs
     assert 'Xcode build...' not in logs
     assert 'Project successfully built.' in logs
     assert 'Installing on device' in logs
     assert 'Successfully installed' in logs
     assert 'Restarting application on device' in logs
     assert 'Refreshing application on device' not in logs
     assert 'Successfully synced application org.nativescript.QAApp on device' in logs
     assert 'ActivityManager: Start proc' in logs
     assert 'activity org.nativescript.QAApp/com.tns.NativeScriptActivity' in logs
Example #27
0
    def test_446_test_print_stack_trace_in_release_and_debug(self):
        """
         https://github.com/NativeScript/android-runtime/issues/1359
        """

        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1359',
                                 'main-view-model.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'main-view-model.js')
        File.copy(source=source_js, target=target_js, backup_files=True)
        Adb.clear_logcat(self.emulator.id)
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)
        strings = [
            'Successfully synced application',
            'Successfully installed on device with identifier'
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=300,
                                 period=5)
        assert test_result, 'Build was not successful! Logs:' + File.read(
            log.log_file)
        Device.click(self.emulator, text="TAP", case_sensitive=True)
        error_message_tns_logs = [
            """System.err: An uncaught Exception occurred on "main" thread.
System.err: Calling js method onClick failed
System.err: Error: test!""", """System.err: StackTrace:"""
        ]
        test_result = Wait.until(
            lambda: all(log_message in File.read(log.log_file)
                        for log_message in error_message_tns_logs),
            timeout=45,
            period=5)
        assert test_result, 'Error message in tns logs not found! Logs:' + File.read(
            log.log_file)

        system_error_message = [
            'System.err: An uncaught Exception occurred on "main" thread.',
            'System.err: StackTrace:'
        ]
        log_cat = Adb.get_logcat(self.emulator.id)
        test_result = Wait.until(
            lambda: all(message in log_cat
                        for message in system_error_message),
            timeout=15,
            period=5)
        assert test_result, 'Error message in tns log cat not found! Logs:' + log_cat
        Adb.clear_logcat(self.emulator.id)
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False,
                              release=True)
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier'
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=300,
                                 period=5)
        assert test_result, 'Build was not successful! Logs:' + File.read(
            log.log_file)
        Device.click(self.emulator, text="TAP", case_sensitive=True)
        test_result = Wait.until(
            lambda: all(message not in File.read(log.log_file)
                        for message in system_error_message),
            timeout=45,
            period=5)
        assert test_result, 'Error message in tns logs not found! Logs:' + File.read(
            log.log_file)

        log_cat = Adb.get_logcat(self.emulator.id)
        if self.emulator.version < 10.0:
            test_result = Wait.until(
                lambda: all(message not in log_cat
                            for message in system_error_message),
                timeout=15,
                period=5)
        else:
            test_result = Wait.until(
                lambda: all(message in log_cat
                            for message in system_error_message),
                timeout=15,
                period=5)
        assert test_result, 'Error message in log cat should be shown! Logs:' + log_cat
Example #28
0
    def test_440_tns_run_android_new_date_work_as_expected_when_changing_timezone(
            self):
        """
         Test new date is working as expected. Test in different timezones
        """
        output = Adb.run_adb_command(
            "shell settings put global auto_time_zone 0",
            self.emulator.id,
            wait=True)
        assert output.output == '', "Failed to change auto timezone!"

        output = Adb.run_adb_command("shell settings put system time_12_24 24",
                                     self.emulator.id,
                                     wait=True)
        assert output.output == '', "Failed to change system format to 24!"

        output = Adb.run_adb_command("shell settings put global time_zone UTC",
                                     self.emulator.id,
                                     wait=True)
        assert output.output == '', "Failed to change timezone!"
        if self.emulator.version < 10.0:
            output = Adb.run_adb_command(
                "shell setprop persist.sys.timezone Atlantic/Reykjavik",
                self.emulator.id,
                wait=True)
            assert output.output == '', "Failed to change timezone!"
        else:
            # Open Date and time settings to change the timezone
            output = Adb.run_adb_command(
                "shell am start -a android.settings.DATE_SETTINGS",
                self.emulator.id,
                wait=True)
            assert_text = 'Starting: Intent { act=android.settings.DATE_SETTINGS }'
            assert assert_text in output.output, "Failed to start Date and Time settings activity!"
            Device.click(self.emulator, text="Time zone", case_sensitive=True)
            Device.click(self.emulator, text="Region")
            Adb.run_adb_command("shell input keyevent \"KEYCODE_I\"",
                                self.emulator.id,
                                wait=True)
            Adb.run_adb_command("shell input keyevent \"KEYCODE_C\"",
                                self.emulator.id,
                                wait=True)
            Device.click(self.emulator, text="Iceland")
        # Change main-page.js so it contains only logging information
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-961',
                                 'main-page.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'main-page.js')
        File.copy(source=source_js, target=target_js, backup_files=True)
        # Change main-view-model.js so it contains the new date logging functionality
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-961',
                                 'main-view-model.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'main-view-model.js')
        File.copy(source=source_js, target=target_js, backup_files=True)
        # Change app package.json so it contains the options for remove V8 date cache
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-961',
                                 'package.json')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'package.json')

        File.copy(source=source_js, target=target_js, backup_files=True)

        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = ['Successfully synced application', '### TEST END ###']
        assert_result = Wait.until(
            lambda: all(string in File.read(log.log_file)
                        for string in strings),
            timeout=240,
            period=5)
        assert assert_result, "Application not build correct! Logs: " + File.read(
            log.log_file)
        # Get UTC date and time
        time_utc = datetime.datetime.utcnow()

        # Generate regex for asserting date and time
        date_to_find_gmt = time_utc.strftime(
            r'%a %b %d %Y %H:.{2}:.{2}') + r" GMT\+0000 \(GMT\)"
        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, "TAP", True),
            timeout=200,
            period=5)
        assert test_result, "TAP Button is missing on the device"
        Device.click(self.emulator, text="TAP", case_sensitive=True)
        assert_result = Wait.until(
            lambda: "GMT+0000 (GMT)" in File.read(log.log_file),
            timeout=30,
            period=5)
        assert assert_result, "Missing log for time! Logs: " + File.read(
            log.log_file)
        # Assert date time is correct
        assert_result = Wait.until(
            lambda: re.search(date_to_find_gmt, File.read(log.log_file)),
            timeout=20,
            period=5)
        assert assert_result, 'Date {0} was not found! \n Log: \n {1}'.format(
            date_to_find_gmt, File.read(log.log_file))
        # Get Los Angeles date and time
        los_angeles_time = time_utc.replace(tzinfo=pytz.utc).astimezone(
            pytz.timezone("America/Los_Angeles"))

        # Open Date and time settings to change the timezone
        output = Adb.run_adb_command(
            "shell am start -a android.settings.DATE_SETTINGS",
            self.emulator.id,
            wait=True)
        assert_text = 'Starting: Intent { act=android.settings.DATE_SETTINGS }'
        assert assert_text in output.output, "Failed to start Date and Time settings activity!"
        # Change TimeZone
        if self.emulator.version < 10.0:
            test_result = Wait.until(lambda: Device.is_text_visible(
                self.emulator, "Select time zone", True),
                                     timeout=30,
                                     period=5)
            assert test_result, "Select time zone Button is missing on the device"
            Device.click(self.emulator, text="Select time zone")
            test_result = Wait.until(lambda: Device.is_text_visible(
                self.emulator, "Pacific Daylight Time", True),
                                     timeout=30,
                                     period=5)
            assert test_result, "Pacific Daylight Time Button is missing on the device"
            Device.click(self.emulator, text="Pacific Daylight Time")

        else:
            output = Adb.run_adb_command(
                "shell am start -a android.settings.DATE_SETTINGS",
                self.emulator.id,
                wait=True)
            assert_text = 'Starting: Intent { act=android.settings.DATE_SETTINGS }'
            assert assert_text in output.output, "Failed to start Date and Time settings activity!"
            Device.click(self.emulator, text="Region")
            Adb.run_adb_command("shell input keyevent \"KEYCODE_U\"",
                                self.emulator.id,
                                wait=True)
            Adb.run_adb_command("shell input keyevent \"KEYCODE_S\"",
                                self.emulator.id,
                                wait=True)
            Device.click(self.emulator, text="United States")
            Device.click(self.emulator, text="Los Angeles")

        # Open the test app again
        output = Adb.run_adb_command(
            "shell am start -n org.nativescript.TestApp/com.tns.NativeScriptActivity",
            self.emulator.id,
            wait=True)
        assert_text = 'Starting: Intent { cmp=org.nativescript.TestApp/com.tns.NativeScriptActivity }'
        assert assert_text in output.output, "Failed to start Nativescript test app activity!"
        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, "TAP", True),
            timeout=30,
            period=5)
        assert test_result, "TAP Button is missing on the device"
        Device.click(self.emulator, text="TAP", case_sensitive=True)
        assert_result = Wait.until(
            lambda: "GMT-0700 (PDT)" in File.read(log.log_file),
            timeout=240,
            period=5)
        assert assert_result, "Missing log for time! Logs: " + File.read(
            log.log_file)
        # Generate regex for asserting date and time
        date_to_find_los_angeles = los_angeles_time.strftime(
            r'%a %b %d %Y %H:.{2}:.{2}') + r" GMT\-0700 \(PDT\)"
        # Assert date time is correct
        assert_result = Wait.until(lambda: re.search(date_to_find_los_angeles,
                                                     File.read(log.log_file)),
                                   timeout=20,
                                   period=5)
        assert assert_result, 'Date {0} was not found! \n Log: \n {1}'.format(
            date_to_find_los_angeles, File.read(log.log_file))
Example #29
0
    def test_317_check_native_crash_will_not_crash_when_discardUncaughtJsExceptions_used(
            self):
        """
         Test native crash will not crash the app when discardUncaughtJsExceptions used
         https://github.com/NativeScript/android-runtime/issues/1119
         https://github.com/NativeScript/android-runtime/issues/1354
        """
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1119',
                                 'main-page.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'main-page.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1119', 'app.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1119',
                                 'main-view-model.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'main-view-model.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        # Change app package.json so it contains the options for discardUncaughtJsExceptions
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1119',
                                 'package.json')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'package.json')
        File.copy(source=source_js, target=target_js, backup_files=True)

        Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = ['Successfully synced application']

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=300,
                                 period=5)
        assert test_result, 'Application is not build successfully! Logs: ' + File.read(
            log.log_file)
        Device.click(self.emulator, "TAP", True)
        if self.emulator.version == 6.0:
            stack_trace_first_part = r"""### Stack Trace Start
JS: 	viewModel\.onTap\(file:\/\/\/app\/main-view-model\.js:\d+:\d+\)
JS: 	at push\.\.\.\/node_modules\/tns-core-modules\/data\/observable\/observable\.js\.Observable\.notify\(file:\/\/\/node_modules\/tns-core-modules\/data\/observable\/observable\.js:\d+:\d+\)
JS: 	at push\.\.\.\/node_modules\/tns-core-modules\/data\/observable\/observable\.js\.Observable\._emit\(file:\/\/\/node_modules\/tns-core-modules\/data\/observable\/observable\.js:\d+:\d+\)
JS: 	at ClickListenerImpl\.onClick\(file:\/\/\/node_modules\/tns-core-modules\/ui\/button\/button\.js:\d+:\d+\)
JS: 	at com\.tns\.Runtime\.callJSMethodNative\(Native Method\)
JS: 	at com\.tns\.Runtime\.dispatchCallJSMethodNative\(Runtime\.java:\d+\)
JS: 	at com\.tns\.Runtime\.callJSMethodImpl\(Runtime\.java:\d+\)
JS: 	at com\.tns\.Runtime\.callJSMethod\(Runtime\.java:\d+\)
JS: 	at com\.tns\.Runtime\.callJSMethod\(Runtime\.java:\d+\)
JS: 	at com\.tns\.Runtime\.callJSMethod\(Runtime\.java:\d+\)
JS: 	at com\.tns\.gen\.java\.lang\.Object_vendor_\d+_\d+_ClickListenerImpl\.onClick\(Object_vendor_\d+_\d+_ClickListenerImpl\.java:\d+\)
JS: 	at android\.view\.View\.performClick\(View\.java:\d+\)
JS: 	at android\.view\.View\$PerformClick\.run\(View\.java:\d+\)
JS: 	at android\.os\.Handler\.handleCallback\(Handler\.java:\d+\)
JS: 	at android\.os\.Handler\.dispatchMessage\(Handler\.java:\d+\)
JS: 	at android\.os\.Looper\.loop\(Looper\.java:148\)
JS: 	at android\.app\.ActivityThread\.main\(ActivityThread\.java:\d+\)
JS: 	at java\.lang\.reflect\.Method\.invoke\(Native Method\)
JS: 	at com\.android\.internal\.os\.ZygoteInit\$MethodAndArgsCaller\.run\(ZygoteInit\.java:\d+\)
JS: 	at com\.android\.internal\.os\.ZygoteInit\.main\(ZygoteInit\.java:\d+\)
JS: Caused by: java\.lang\.Exception: Failed resolving method createTempFile on class java\.io\.File
JS: 	at com\.tns\.Runtime\.resolveMethodOverload\(Runtime\.java:\d+\)
JS: 	\.\.\. \d+ more
JS: ### Stack Trace End"""  # noqa: E501
        else:
            stack_trace_first_part = r"""### Stack Trace Start
JS: 	viewModel\.onTap\(file:\/\/\/app\/main-view-model\.js:\d+:\d+\)
JS: 	at push\.\.\.\/node_modules\/tns-core-modules\/data\/observable\/observable\.js\.Observable\.notify\(file:\/\/\/node_modules\/tns-core-modules\/data\/observable\/observable\.js:\d+:\d+\)
JS: 	at push\.\.\.\/node_modules\/tns-core-modules\/data\/observable\/observable\.js\.Observable\._emit\(file:\/\/\/node_modules\/tns-core-modules\/data\/observable\/observable\.js:\d+:\d+\)
JS: 	at ClickListenerImpl\.onClick\(file:\/\/\/node_modules\/tns-core-modules\/ui\/button\/button\.js:\d+:\d+\)
JS: 	at com\.tns\.Runtime\.callJSMethodNative\(Native Method\)
JS: 	at com\.tns\.Runtime\.dispatchCallJSMethodNative\(Runtime\.java:\d+\)
JS: 	at com\.tns\.Runtime\.callJSMethodImpl\(Runtime\.java:\d+\)
JS: 	at com\.tns\.Runtime\.callJSMethod\(Runtime\.java:\d+\)
JS: 	at com\.tns\.Runtime\.callJSMethod\(Runtime\.java:\d+\)
JS: 	at com\.tns\.Runtime\.callJSMethod\(Runtime\.java:\d+\)
JS: 	at com\.tns\.gen\.java\.lang\.Object_vendor_\d+_\d+_ClickListenerImpl\.onClick\(Object_vendor_\d+_\d+_ClickListenerImpl\.java:\d+\)
JS: 	at android\.view\.View\.performClick\(View\.java:\d+\)
JS: 	at android\.view\.View\.performClickInternal\(View.java:\d+\)
JS: 	at android\.view\.View\.access\$\d+\(View\.java:\d+\)
JS: 	at android\.view\.View\$PerformClick\.run\(View\.java:\d+\)
JS: 	at android\.os\.Handler\.handleCallback\(Handler\.java:\d+\)
JS: 	at android\.os\.Handler\.dispatchMessage\(Handler\.java:\d+\)
JS: 	at android\.os\.Looper\.loop\(Looper\.java:\d+\)
JS: 	at android\.app\.ActivityThread\.main\(ActivityThread\.java:\d+\)
JS: 	at java\.lang\.reflect\.Method\.invoke\(Native Method\)
JS: 	at com\.android\.internal\.os\.RuntimeInit\$MethodAndArgsCaller\.run\(RuntimeInit\.java:\d+\)
JS: 	at com\.android\.internal\.os\.ZygoteInit\.main\(ZygoteInit\.java:\d+\)
JS: Caused by: java\.lang\.Exception: Failed resolving method createTempFile on class java\.io\.File
JS: 	at com\.tns\.Runtime\.resolveMethodOverload\(Runtime\.java:\d+\)
JS: 	\.\.\. \d+ more
JS: ### Stack Trace End"""  # noqa: E501
        strings = [
            "Error: java.lang.Exception: Failed resolving method createTempFile on class java.io.File",
            "Caused by: java.lang.Exception: Failed resolving method createTempFile on class java.io.File"
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=20,
                                 period=5)
        Assert.assert_with_regex(File.read(log.log_file),
                                 stack_trace_first_part)
        message = 'Native crash should not crash the app when discardUncaughtJsExceptions used fails! Logs: '
        assert test_result, message + File.read(log.log_file)
        Device.wait_for_text(self.emulator, text=TAP_THE_BUTTON)
Example #30
0
    def test_317_check_native_crash_will_not_crash_when_discardUncaughtJsExceptions_used(
            self):
        """
         Test native crash will not crash the app when discardUncaughtJsExceptions used
         https://github.com/NativeScript/android-runtime/issues/1119
         https://github.com/NativeScript/android-runtime/issues/1354
        """
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1119',
                                 'main-page.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'main-page.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1119', 'app.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'app.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1119',
                                 'main-view-model.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'main-view-model.js')
        File.copy(source=source_js, target=target_js, backup_files=True)

        # Change app package.json so it contains the options for discardUncaughtJsExceptions
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1119',
                                 'package.json')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'package.json')
        File.copy(source=source_js, target=target_js, backup_files=True)

        Tns.plugin_remove("mylib", verify=False, path=APP_NAME)
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = ['Successfully synced application']

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=300,
                                 period=5)
        assert test_result, 'Application is not build successfully! Logs: ' + File.read(
            log.log_file)
        Device.wait_for_text(self.emulator, "TAP")
        Adb.is_text_visible(self.emulator.id, "TAP", True)
        Device.click(self.emulator, "TAP", True)
        stack_trace_first_part = """### Stack Trace Start
JS: 	Frame: function:'viewModel.onTap', file:'file:///app/main-view-model.js:18:0
JS: 	Frame: function:'push.../node_modules/tns-core-modules/data/observable/observable.js.Observable.notify', file:'file:///node_modules/tns-core-modules/data/observable/observable.js:107:0
JS: 	Frame: function:'push.../node_modules/tns-core-modules/data/observable/observable.js.Observable._emit', file:'file:///node_modules/tns-core-modules/data/observable/observable.js:127:0
JS: 	Frame: function:'ClickListenerImpl.onClick', file:'file:///node_modules/tns-core-modules/ui/button/button.js:29:0
JS: 	at com.tns.Runtime.callJSMethodNative(Native Method)
JS: 	at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1242)
JS: 	at com.tns.Runtime.callJSMethodImpl(Runtime.java:1122)
JS: 	at com.tns.Runtime.callJSMethod(Runtime.java:1109)
JS: 	at com.tns.Runtime.callJSMethod(Runtime.java:1089)
JS: 	at com.tns.Runtime.callJSMethod(Runtime.java:1081)
"""  # noqa: E501
        stack_trace_second_part = """JS: 	at android.view.View.performClick(View.java:5198)
JS: 	at android.view.View$PerformClick.run(View.java:21147)
JS: 	at android.os.Handler.handleCallback(Handler.java:739)
JS: 	at android.os.Handler.dispatchMessage(Handler.java:95)
JS: 	at android.os.Looper.loop(Looper.java:148)
JS: 	at android.app.ActivityThread.main(ActivityThread.java:5417)
JS: 	at java.lang.reflect.Method.invoke(Native Method)
JS: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
JS: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
JS: Caused by: java.lang.Exception: Failed resolving method createTempFile on class java.io.File
JS: 	at com.tns.Runtime.resolveMethodOverload(Runtime.java:1201)
JS: 	... 16 more
JS: ### Stack Trace End"""  # noqa: E501
        strings = [
            "Error: java.lang.Exception: Failed resolving method createTempFile on class java.io.File",
            "Caused by: java.lang.Exception: Failed resolving method createTempFile on class java.io.File",
            stack_trace_first_part, stack_trace_second_part
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=20,
                                 period=5)
        message = 'Native crash should not crash the app when discardUncaughtJsExceptions used fails! Logs: '
        assert test_result, message + File.read(log.log_file)
        Device.wait_for_text(self.emulator, text=TAP_THE_BUTTON)