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_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'
Exemple #3
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')
Exemple #4
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'
Exemple #5
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!'
Exemple #6
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)
Exemple #7
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 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_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_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 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)
Exemple #12
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)
Exemple #13
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)
 def assert_apk(apk, device, app_id):
     Adb.install(apk, device.id)
     Adb.start_application(device.id, app_id)
     Device.wait_for_text(device, text='Ter Stegen', timeout=90)
     Adb.stop_application(device_id=device.id, app_id=app_id)
     Adb.uninstall(app_id, device.id)
Exemple #15
0
    def test_200_test_foreground_sticky_services_are_working(self):
        """
         https://github.com/NativeScript/android-runtime/issues/1347
        """
        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', 'sticky', '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.wait_for_text(self.emulator, text='TAP', timeout=20)
        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_process(self.emulator.id, "org.nativescript.TestApp")
        services = Adb.get_active_services(self.emulator.id)
        assert service_name in services, "{0} service not found! Logs: {1}".format(
            service_name, services)

        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)
        assert pid not in service_info, "{0} service with id {1} found! Logs: {2}".format(
            service_name, pid, service_info)