Ejemplo n.º 1
0
    def test_400_no_error_activity_in_release_builds(self):
        # Break the app to test error activity
        # add workaround with for-cycle for https://github.com/NativeScript/nativescript-cli/issues/3812
        Adb.clear_logcat(self.emulator.id)
        wait_code = 'var e = new Date().getTime() + 3000; while (new Date().getTime() <= e) {} '
        exception_code = 'throw new Error("Kill the app!");'
        file_path = os.path.join(Settings.TEST_RUN_HOME, APP_NAME, 'app', 'app.js')
        old_value = 'application.run({ moduleName: "app-root" });'
        new_value = wait_code + exception_code
        File.replace(path=file_path, old_string=old_value, new_string=new_value, backup_files=True)
        Tns.run_android(app_name=APP_NAME, release=True, emulator=True, wait=False)
        if self.emulator.version < 10.0:
            self.emulator.wait_for_text('Unfortunately', timeout=180, retry_delay=10)
            self.emulator.is_text_visible('Exception')
        else:
            regex_to_check = r"""System\.err: Error: Kill the app!
.+System\.err: File: \(file:\/\/\/]data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\)
.+System\.err:.+
.+System\.err: StackTrace:.+
.+System\.err:.+\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\)
.+System\.err:.+at \.\/app\.js\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\)
.+System\.err:.+at __webpack_require__\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/runtime\.js:\d+:\d+\)
.+System\.err:.+at checkDeferredModules\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/runtime\.js:\d+:\d+\)
.+System\.err:.+at webpackJsonpCallback\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/runtime\.js:\d+:\d+\)
.+System\.err:.+at \(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\)
.+System\.err:.+at require\(:\d+:\d+\)"""  # noqa: E501, E261, W291
            Wait.until(lambda: "Error: Kill the app!" in Adb.get_logcat(self.emulator.id), timeout=240,
                       period=5)
            Assert.assert_with_regex(Adb.get_logcat(self.emulator.id),
                                     regex_to_check)
Ejemplo n.º 2
0
 def test_assert_with_regex_fails_with_error_message(self):
     expected_number = "dd"
     actual_data = "test " + expected_number + " test"
     expected_data = r"test \d+ test"
     exception_message = "Error Message!"
     with self.assertRaises(AssertionError) as error:
         Assert.assert_with_regex(actual_data, expected_data, exception_message)
     assertion_error_message = "Error message is wrong! Log: " + str(error.exception)
     assert exception_message == str(error.exception), assertion_error_message
Ejemplo n.º 3
0
 def test_assert_with_regex_fails_without_error_message(self):
     expected_number = "dd"
     actual_data = "test " + expected_number + " test"
     expected_data = r"test \d+ test"
     exception_message = "Expected Result: 'test \\d+ test' not found! Actual Data: test dd test"
     with self.assertRaises(AssertionError) as error:
         Assert.assert_with_regex(actual_data, expected_data)
     assertion_error_message = "Default error message is wrong! Log: " + str(error.exception)
     assert exception_message == str(error.exception), assertion_error_message
    def test_200_error_activity_shown_on_error(self):
        result = Tns.run_android(app_name=APP_NAME, emulator=True, wait=False)
        self.emulator.wait_for_text('TAP', timeout=180, retry_delay=10)

        # Break the app to test error activity
        # add workaround with for-cycle for https://github.com/NativeScript/nativescript-cli/issues/3812
        wait_code = 'var e = new Date().getTime() + 3000; while (new Date().getTime() <= e) {} '
        exception_code = 'throw new Error("Kill the app!");'
        file_path = os.path.join(Settings.TEST_RUN_HOME, APP_NAME, 'app',
                                 'app.js')
        old_value = 'application.run({ moduleName: "app-root" });'
        new_value = wait_code + exception_code
        File.replace(path=file_path,
                     old_string=old_value,
                     new_string=new_value,
                     backup_files=True)
        # Verify logs and screen
        TnsLogs.wait_for_log(
            log_file=result.log_file,
            string_list=['StackTrace:', 'Error: Kill the app!'])

        if self.emulator.version < 10.0:
            regex_to_check = r"""System\.err: Error: Kill the app!
System\.err: File: \(file: app\/app\.js:\d+:\d+\)
System\.err: StackTrace: 
System\.err:.+\(file: app\/app.js:\d+:\d+\)
System\.err:.+at \.\/app\.js\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\)
System\.err:.+at __webpack_require__\(file: app\/webpack\/bootstrap:\d+:\d+\)
System\.err:.+at checkDeferredModules\(file: app\/webpack\/bootstrap:\d+:\d+\)
System\.err:.+at webpackJsonpCallback\(file: app\/webpack\/bootstrap:\d+:\d+\)
System\.err:.+at \(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\)
System\.err:.+at require\(:\d+:\d+\)""" # noqa: E501, E261, W291
        else:
            regex_to_check = r"""System\.err: Error: Kill the app!
System\.err: File: \(file: app\/app\.js:\d+:\d+\)
System\.err:.+
System\.err: StackTrace:.+
System\.err:.+\(file: app\/app\.js:\d+:\d+\)
System\.err:.+at \.\/app\.js\(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\)
System\.err:.+at __webpack_require__\(file: app\/webpack\/bootstrap:\d+:\d+\)
System\.err:.+at checkDeferredModules\(file: app\/webpack\/bootstrap:\d+:\d+\)
System\.err:.+at webpackJsonpCallback\(file: app\/webpack\/bootstrap:\d+:\d+\)
System\.err:.+at \(file:\/\/\/data\/data\/org\.nativescript\.TestApp\/files\/app\/bundle\.js:\d+:\d+\)
System\.err:.+at require\(:\d+:\d+\)"""  # noqa: E501, E261, W291

        Assert.assert_with_regex(File.read(result.log_file), regex_to_check)
        self.emulator.wait_for_text('Exception')
        self.emulator.wait_for_text('Logcat')
        self.emulator.wait_for_text('Error: Kill the app!')
    def test_455_gradle_hooks(self):
        """
        Test gradle hooks works correctly
        https://docs.nativescript.org/core-concepts/android-runtime/advanced-topics/gradle-hooks
        """
        source_app_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files',
                                         'android-runtime-gradle-hooks', '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_build_script_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files',
                                                  'android-runtime-gradle-hooks', 'buildscript.gradle')
        target_build_script_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android')
        File.copy(source=source_build_script_gradle, target=target_build_script_gradle, backup_files=True)

        source_build_script_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files',
                                                  'android-runtime-gradle-hooks', 'before-plugins.gradle')
        target_build_script_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android')
        File.copy(source=source_build_script_gradle, target=target_build_script_gradle, backup_files=True)

        source_build_script_gradle = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files',
                                                  'android-runtime-gradle-hooks', 'gradle.properties')
        target_build_script_gradle = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'App_Resources', 'Android')
        File.copy(source=source_build_script_gradle, target=target_build_script_gradle, backup_files=True)

        plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files',
                                   'sample-plugin', 'src')
        Tns.plugin_add(plugin_path, path=APP_NAME, verify=False)

        result = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=True).output
        log_regex = r"""MESSAGE: buildscript\.gradle in app is applied!
.+
MESSAGE: buildscript\.gradle in plugin is applied!
.+
.+
MESSAGE: before-plugins\.gradle is applied!
Test variable is set to true in plugin before-plugins\.gradle
MESSAGE: Plugin include gradle is applied!
Test variable is set to true in plugin include\.gradle
.+
MESSAGE: app\.gradle is applied!
Test variable is set to true in plugin app\.gradle"""  # noqa: E501
        Assert.assert_with_regex(result, log_regex)

        Tns.plugin_remove("sample-plugin", verify=False, path=APP_NAME)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def test_assert_with_regex(self):
     expected_number = "33"
     actual_data = "test " + expected_number + " test"
     expected_data = r"test \d+ test"
     case_actual_data = "TEST " + expected_number + " TEST"
     multi_line_actual_data = """
     test
     test
     test 33 test
     test
     test
     """
     Assert.assert_with_regex(actual_data, expected_data)
     Assert.assert_with_regex(actual_data, actual_data)
     Assert.assert_with_regex(actual_data, expected_number)
     Assert.assert_with_regex(actual_data, r"\d+")
     Assert.assert_with_regex(case_actual_data, actual_data)
     Assert.assert_with_regex(multi_line_actual_data, r"\d+")
     Assert.assert_with_regex(multi_line_actual_data, actual_data)