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)
Exemple #2
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_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)
 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
Exemple #5
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
Exemple #6
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))
Exemple #7
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 #8
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_kotlin_is_working(emulator):
     assert File.exists(APK_DEBUG_PATH)
     assert File.is_file_in_zip(APK_DEBUG_PATH, os.path.join("kotlin")), "Kotlin is not working!"
     Device.click(emulator, text="TAP", case_sensitive=True)
     error_message = "Kotlin code is not executed correctly! Logs: "
     assert "Kotlin is here!" in Adb.get_logcat(emulator.id), error_message + Adb.get_logcat(emulator.id)