Пример #1
0
    def test_200_calling_custom_generated_classes_declared_in_manifest(self):
        File.copy(
            os.path.join(
                TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files',
                'calling_custom_generated_classes_declared_in_manifest',
                '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',
                'calling_custom_generated_classes_declared_in_manifest',
                'my-custom-class.js'),
            os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'my-custom-class.js'),
            True)
        File.copy(
            os.path.join(
                TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files',
                'calling_custom_generated_classes_declared_in_manifest',
                'custom-activity.js'),
            os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'custom-activity.js'),
            True)
        webpack_config = os.path.join(TEST_RUN_HOME, APP_NAME,
                                      'webpack.config.js')
        old_string = '"tns-core-modules/ui/frame/activity",'
        my_custom_class = 'resolve(__dirname, "app/my-custom-class.js")'
        custom_activity = ',resolve(__dirname, "app/custom-activity.js"),'
        new_string = old_string + my_custom_class + custom_activity
        File.replace(path=webpack_config,
                     old_string=old_string,
                     new_string=new_string,
                     backup_files=True)
        Adb.clear_logcat(device_id=self.emulator.id)
        Tns.run_android(APP_NAME,
                        device=self.emulator.id,
                        just_launch=True,
                        wait=True)
        assert_result = Wait.until(
            lambda: 'we got called from onCreate of custom-activity.js' in Adb.
            get_logcat(device_id=self.emulator.id))
        output = Adb.get_logcat(device_id=self.emulator.id)

        # make sure app hasn't crashed
        assert "Displayed org.nativescript.TNSApp/com.tns.ErrorReportActivity" not in output, \
            "App crashed with error activity"
        # check if we got called from custom activity that overrides the default one
        assert assert_result, "Expected output not found! Logs: " + Adb.get_logcat(
            device_id=self.emulator.id)
        assert_result = Wait.until(
            lambda: "we got called from onCreate of my-custom-class.js" in Adb.
            get_logcat(device_id=self.emulator.id))
        # make sure we called custom activity declared in manifest
        assert assert_result, "Expected output not found! Logs: " + Adb.get_logcat(
            device_id=self.emulator.id)
 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
Пример #3
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