Exemplo n.º 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
Exemplo n.º 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
    def test_100_build_app_with_abi_split_and_snapshot(self):
        """
         Test build with abi split and snapshot. Also check if the apk for emulator is working
         https://github.com/NativeScript/android-runtime/issues/1234
        """
        Adb.clear_logcat(device_id=self.emulator.id)
        old_string = "webpackConfig: config,"
        new_string = ""

        if platform == "linux" or platform == "linux2":
            new_string = "webpackConfig: config,\
                        targetArchs: [ \"arm\", \"arm64\", \"ia32\" ],\
                        useLibs: true,\
                        androidNdkPath: \"/tns-official/NDK/android-ndk-r18b-linux/\""

        elif platform == "darwin":
            new_string = "webpackConfig: config,\
                        targetArchs: [ \"arm\", \"arm64\", \"ia32\" ],\
                        useLibs: true,\
                        androidNdkPath: \"/tns-official/NDK/android-ndk-r18b-mac/\""

        target_file = os.path.join(TEST_RUN_HOME, APP_NAME,
                                   'webpack.config.js')
        File.replace(target_file, old_string, new_string)
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-1234', 'app.gradle')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'App_Resources',
                                 'Android', 'app.gradle')
        File.copy(source=source_js, target=target_js)
        log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME),
                                verify=False,
                                bundle=True,
                                release=True,
                                snapshot=True)

        test_result = Wait.until(
            lambda: "Project successfully built" in log.output,
            timeout=100,
            period=5)
        assert test_result, 'Build with abi split is not successful! Logs:' + log.output

        assert File.exists(
            os.path.join(TEST_RUN_HOME, APP_NAME,
                         PLATFORM_ANDROID_APK_RELEASE_PATH,
                         "app-arm64-v8a-release.apk"))
        assert File.exists(
            os.path.join(TEST_RUN_HOME, APP_NAME,
                         PLATFORM_ANDROID_APK_RELEASE_PATH,
                         "app-armeabi-v7a-release.apk"))
        assert File.exists(
            os.path.join(TEST_RUN_HOME, APP_NAME,
                         PLATFORM_ANDROID_APK_RELEASE_PATH,
                         "app-universal-release.apk"))
        assert File.exists(
            os.path.join(TEST_RUN_HOME, APP_NAME,
                         PLATFORM_ANDROID_APK_RELEASE_PATH,
                         "app-x86-release.apk"))

        AbiSplitHelper.assert_apk(
            os.path.join(TEST_RUN_HOME, APP_NAME,
                         PLATFORM_ANDROID_APK_RELEASE_PATH,
                         "app-x86-release.apk"), self.emulator, self.app_id)

        AbiSplitHelper.assert_apk(
            os.path.join(TEST_RUN_HOME, APP_NAME,
                         PLATFORM_ANDROID_APK_RELEASE_PATH,
                         "app-universal-release.apk"), self.emulator,
            self.app_id)
    def test_100_build_app_with_abi_split_and_snapshot(self):
        """
         Test build with abi split and snapshot. Also check if the apk for emulator is working
         https://github.com/NativeScript/android-runtime/issues/1234
        """
        Adb.clear_logcat(device_id=self.emulator.id)
        old_string = "webpackConfig: config,"
        new_string = ""

        if platform == "linux" or platform == "linux2":
            new_string = "webpackConfig: config,\
                        targetArchs: [ \"arm\", \"arm64\", \"ia32\", \"ia64\" ],\
                        useLibs: true,\
                        androidNdkPath: \"/tns-official/NDK/android-ndk-r19c-linux/\","
        elif platform == "darwin":
            new_string = "webpackConfig: config,\
                        targetArchs: [ \"arm\", \"arm64\", \"ia32\", \"ia64\" ],\
                        useLibs: true,\
                        androidNdkPath: \"/tns-official/NDK/android-ndk-r19c-mac/\","

        target_file = os.path.join(TEST_RUN_HOME, APP_NAME, 'webpack.config.js')
        File.replace(target_file, old_string, new_string)
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1234',
                                 'app.gradle')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'App_Resources', 'Android', 'app.gradle')
        File.copy(source=source_js, target=target_js)
        log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=False, bundle=True, release=True,
                                snapshot=True)

        test_result = Wait.until(lambda: "Project successfully built" in log.output, timeout=100, period=5)
        assert test_result, 'Build with abi split is not successful! Logs:' + log.output

        app_x86_64_release_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH,
                                               "app-x86_64-release.apk")
        assert File.is_file_in_zip(app_x86_64_release_path, os.path.join("x86_64", "libNativeScript.so"))
        assert File.exists(app_x86_64_release_path)

        app_arm64_v8a_release_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH,
                                                  "app-arm64-v8a-release.apk")
        assert File.exists(app_arm64_v8a_release_path)
        assert File.is_file_in_zip(app_arm64_v8a_release_path, os.path.join("arm64-v8a", "libNativeScript.so"))

        app_armeabi_v7a_release_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH,
                                                    "app-armeabi-v7a-release.apk")
        assert File.exists(app_armeabi_v7a_release_path)
        assert File.is_file_in_zip(app_armeabi_v7a_release_path, os.path.join("armeabi-v7a", "libNativeScript.so"))

        app_x86_release_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH,
                                            "app-x86-release.apk")
        assert File.exists(app_x86_release_path)
        assert File.is_file_in_zip(app_x86_release_path, os.path.join("x86", "libNativeScript.so"))

        app_universal_release_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH,
                                                  "app-universal-release.apk")
        assert File.exists(app_universal_release_path)
        assert File.is_file_in_zip(app_universal_release_path, os.path.join("arm64-v8a", "libNativeScript.so"))
        assert File.is_file_in_zip(app_universal_release_path, os.path.join("armeabi-v7a", "libNativeScript.so"))
        assert File.is_file_in_zip(app_universal_release_path, os.path.join("x86", "libNativeScript.so"))
        assert File.is_file_in_zip(app_universal_release_path, os.path.join("x86_64", "libNativeScript.so"))

        AbiSplitHelper.assert_apk(
            os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-x86-release.apk"),
            self.emulator, self.app_id)

        AbiSplitHelper.assert_apk(
            os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-universal-release.apk"),
            self.emulator, self.app_id)
        with self.assertRaises(AssertionError) as error:
            AbiSplitHelper.assert_apk(
                os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-x86_64-release.apk"),
                self.emulator, self.app_id)
        error_message = "x86_64 should not be installed on x86 emulator!Logs:" + str(error.exception)
        assert "INSTALL_FAILED_NO_MATCHING_ABIS" in str(error.exception), error_message
        with self.assertRaises(AssertionError) as error:
            AbiSplitHelper.assert_apk(
                os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-arm64-v8a-release.apk"),
                self.emulator, self.app_id)
        error_message = "arm64-v8a should not be installed on x86 emulator!Logs:" + str(error.exception)
        assert "INSTALL_FAILED_NO_MATCHING_ABIS" in str(error.exception), error_message
        with self.assertRaises(AssertionError) as error:
            AbiSplitHelper.assert_apk(
                os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_RELEASE_PATH, "app-armeabi-v7a-release.apk"),
                self.emulator, self.app_id)
        error_message = "armeabi-v7a should not be installed on x86 emulator!Logs:" + str(error.exception)
        assert "INSTALL_FAILED_NO_MATCHING_ABIS" in str(error.exception), error_message