def setUpClass(cls, class_name):

        print ""
        print "_________________________________CLASS START_______________________________________"
        print "Class Name: {0}".format(class_name)
        print "Start Time:  {0}".format(time.strftime("%X"))
        print ""

        Tns.kill()
        Gradle.kill()
        Process.kill('node')
        Process.kill('adb')
        if CURRENT_OS == OSType.OSX:
            Process.kill('NativeScript Inspector')
            Process.kill('Safari')
            Process.kill('Xcode')

        if class_name is not None:
            logfile = os.path.join('out', class_name + '.txt')
        else:
            logfile = os.path.join(OUTPUT_FOLDER, cls.__name__ + ".txt")

        File.remove(logfile)
        sys.stdout = sys.stderr = Logger.Logger(logfile)

        Folder.cleanup(cls.app_name)
Beispiel #2
0
    def test_280_tns_run_android_console_time(self):
        # Copy the app folder (app is modified in order to get some console logs on loaded)
        source = os.path.join('data', 'apps', 'livesync-hello-world-ng', 'src')
        target = os.path.join(self.app_name, 'src')
        Folder.cleanup(target)
        Folder.copy(src=source, dst=target)

        # Replace app.component.ts to use console.time() and console.timeEnd()
        source = os.path.join('data', 'issues', 'ios-runtime-843', 'app.component.ts')
        target = os.path.join(self.app_name, 'src', 'app', 'app.component.ts')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)

        # Verify the app is running
        strings = ['Successfully synced application',
                   'Application loaded!',
                   'Home page loaded!']

        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10, clean_log=False)

        # Verify initial state of the app
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image='ng-hello-world-home-white', tolerance=5.0)

        # Verify console.time() works
        console_time = ['JS: startup:']
        Tns.wait_for_log(log_file=log, string_list=console_time)
    def test_301_build_project_with_space_release(self):
        Tns.create_app(self.app_name_space)
        Tns.platform_add_android(
            attributes={"--path": "\"" + self.app_name_space + "\"", "--frameworkPath": ANDROID_PACKAGE})

        # Ensure ANDROID_KEYSTORE_PATH contain spaces (verification for CLI issue 2650)
        Folder.create("with space")
        base_path, file_name = os.path.split(ANDROID_KEYSTORE_PATH)
        cert_with_space_path = os.path.join("with space", file_name)
        File.copy(src=ANDROID_KEYSTORE_PATH, dest=cert_with_space_path)

        # Verify project builds
        Tns.build_android(attributes={"--path": "\"" + self.app_name_space + "\"",
                                      "--keyStorePath": "\"" + cert_with_space_path + "\"",
                                      "--keyStorePassword": ANDROID_KEYSTORE_PASS,
                                      "--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
                                      "--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
                                      "--release": ""
                                      })

        output = File.read(self.app_name_space + os.sep + "package.json")
        assert app_identifier in output.lower()

        output = File.read(
            self.app_name_space + "/" + TnsAsserts.PLATFORM_ANDROID_SRC_MAIN_PATH + "AndroidManifest.xml")
        assert app_identifier in output.lower()
    def created(app_name, output=None, full_check=True):
        """
        Assert application is created properly.
        :param app_name: App name
        :param output: Output of `tns create command`
        :param full_check: If true everything will be checked. If false only console output will be checked.
        """

        # Assert console output is ok
        if output is not None:
            app = app_name.rsplit('/')[-1]
            if USE_YARN != "True":
                if Npm.version() < 5:
                    assert 'nativescript-theme-core' in output
            assert 'Project {0} was successfully created'.format(app) in output, 'Failed to create {0}'.format(app)

        if full_check:
            # Assert files are ok
            assert File.exists(app_name)
            assert File.exists(app_name + '/node_modules/tns-core-modules/package.json')
            assert File.exists(app_name + '/node_modules/tns-core-modules/LICENSE')
            assert File.exists(app_name + '/node_modules/tns-core-modules/xml/xml.js')
            assert File.exists(app_name + '/node_modules/nativescript-theme-core')

            # Assert content of package.json
            app_id = app_name.replace(' ', '').replace('_', '').replace('-', '').rsplit('/')[-1]
            strings = ['org.nativescript.{0}'.format(app_id), 'tns-core-modules', 'nativescript-theme-core']
            TnsAsserts.package_json_contains(app_name, string_list=strings)
Beispiel #5
0
    def test_200_prepare_additional_appresources(self):
        # prepare project
        output = Tns.prepare_ios(attributes={"--path": self.app_name})
        TnsAsserts.prepared(self.app_name,
                            platform=Platform.IOS,
                            output=output,
                            prepare=Prepare.FULL)

        # Create new files in AppResources
        File.copy(
            self.app_name +
            "/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png",
            self.app_name + "/app/App_Resources/iOS/newDefault.png")

        # prepare project
        output = Tns.prepare_ios(attributes={"--path": self.app_name})
        TnsAsserts.prepared(self.app_name,
                            platform=Platform.IOS,
                            output=output,
                            prepare=Prepare.INCREMENTAL)

        # Verify XCode Project include files from App Resources folder
        output = run(
            "cat " + self.app_name +
            "/platforms/ios/TestApp.xcodeproj/project.pbxproj | grep newDefault.png"
        )
        assert "newDefault.png" in output
Beispiel #6
0
    def test_301_build_project_with_space_release(self):
        Tns.create_app(self.app_name_space)
        Tns.platform_add_android(
            attributes={
                "--path": "\"" + self.app_name_space + "\"",
                "--frameworkPath": ANDROID_PACKAGE
            })

        # Ensure ANDROID_KEYSTORE_PATH contain spaces (verification for CLI issue 2650)
        Folder.create("with space")
        base_path, file_name = os.path.split(ANDROID_KEYSTORE_PATH)
        cert_with_space_path = os.path.join("with space", file_name)
        File.copy(src=ANDROID_KEYSTORE_PATH, dest=cert_with_space_path)

        # Verify project builds
        Tns.build_android(
            attributes={
                "--path": "\"" + self.app_name_space + "\"",
                "--keyStorePath": "\"" + cert_with_space_path + "\"",
                "--keyStorePassword": ANDROID_KEYSTORE_PASS,
                "--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
                "--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
                "--release": ""
            })

        output = File.read(self.app_name_space + os.sep + "package.json")
        assert app_identifier in output.lower()

        output = File.read(self.app_name_space + "/" +
                           TnsAsserts.PLATFORM_ANDROID_SRC_MAIN_PATH +
                           "AndroidManifest.xml")
        assert app_identifier in output.lower()
    def test_360_tns_run_android_with_jar_file_in_plugin(self):
        """
        App should not crash when reference .jar file in some plugin
        https://github.com/NativeScript/android-runtime/pull/905
        """

        # Add .jar file in plugin and modify the app to reference it
        custom_jar_file = os.path.join('data', 'issues', 'android-runtime-pr-905', 'customLib.jar')
        modules_widgets = os.path.join(self.app_name, 'node_modules', 'tns-core-modules-widgets', 'platforms',
                                       'android')
        File.copy(src=custom_jar_file, dest=modules_widgets)

        source = os.path.join('data', 'issues', 'android-runtime-pr-905', 'app.js')
        target = os.path.join(self.app_name, 'app', 'app.js')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', EMULATOR_ID,
                   'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image='livesync-hello-world_home')
    def start(emulator_name=EMULATOR_NAME, port=EMULATOR_PORT, timeout=300, wipe_data=True):
        """
        Start emulator.
        :param wipe_data: If true it will wipe emulator date.
        :param emulator_name: Name of android emulator image (avd).
        :param port: Port for Android emulator.
        :param timeout: Time to wait until emulator boot.
        """
        print 'Starting emulator {0}'.format(emulator_name)

        if CURRENT_OS == OSType.WINDOWS:
            start_command = 'START /B ' + EMULATOR_PATH + ' -avd ' + emulator_name + ' -port ' + port
        else:
            start_command = EMULATOR_PATH + ' -avd ' + emulator_name + ' -port ' + port

        if wipe_data:
            start_command += ' -wipe-data'
        log_file = run(start_command, timeout=timeout, wait=False, log_level=CommandLogLevel.COMMAND_ONLY)

        # Check if emulator is running
        device_name = 'emulator-' + port
        if Emulator.wait(device_name, timeout):
            print 'Emulator started successfully.'
        else:
            print 'Emulator failed to boot!'
            print File.read(log_file)
            raise Exception('Wait for emulator failed!')
Beispiel #9
0
    def test_181_tns_run_ios_console_dir(self):
        """
         Test console.dir() of different objects.
        """

        # Change main-page.js so it contains console logging
        source_js = os.path.join('data', 'console-dir', 'main-page.js')
        target_js = os.path.join(self.app_name, 'app', 'main-page.js')
        File.copy(src=source_js, dest=target_js)

        john_obj = "==== object dump start ====\n" \
                   "name: John\n" \
                   "age: 34\n" \
                   "==== object dump end ===="

        log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', self.SIMULATOR_ID,
                   "true",
                   "false",
                   "null",
                   "undefined",
                   "-1",
                   "text",
                   self.max_long_string,
                   john_obj
                   ]

        Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10)
        assert self.very_long_string not in log
Beispiel #10
0
    def setUpClass(cls, class_name):

        print ""
        print "_________________________________CLASS START_______________________________________"
        print "Class Name: {0}".format(class_name)
        print "Start Time:  {0}".format(time.strftime("%X"))
        print ""

        Tns.kill()
        Gradle.kill()
        Process.kill('node')
        Process.kill('adb')
        if CURRENT_OS == OSType.OSX:
            Process.kill('NativeScript Inspector')
            Process.kill('Safari')
            Process.kill('Xcode')

        if class_name is not None:
            logfile = os.path.join('out', class_name + '.txt')
        else:
            logfile = os.path.join(OUTPUT_FOLDER, cls.__name__ + ".txt")

        File.remove(logfile)
        sys.stdout = sys.stderr = Logger.Logger(logfile)

        Folder.cleanup(cls.app_name)
    def test_210_tns_run_ios_add_remove_files_and_folders(self):
        """
        New files and folders should be synced properly.
        """

        log = Tns.run_ios(attributes={'--path': self.app_name, '--device': self.DEVICE_ID}, wait=False,
                          assert_success=False)
        strings = ['Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)

        # Add new files
        new_file_name = 'app2.css'
        source_file = os.path.join(self.app_name, 'app', 'app.css')
        destination_file = os.path.join(self.app_name, 'app', new_file_name)
        File.copy(source_file, destination_file)
        strings = ['Successfully transferred', new_file_name, 'Refreshing application']
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Revert changes(rename file and delete file)
        # File.copy(destination_file, source_file)
        # File.remove(destination_file)
        # strings = ['Successfully transferred', new_file_name]
        # Tns.wait_for_log(log_file=log, string_list=strings)

        # Add folder
        new_folder_name = 'test2'
        source_file = os.path.join(self.app_name, 'app', 'test')
        destination_file = os.path.join(self.app_name, 'app', new_folder_name)
        Folder.copy(source_file, destination_file)
        strings = ['Successfully transferred test.txt', 'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings)
    def create_app_ng(app_name, attributes={}, log_trace=False, assert_success=True, update_modules=True,
                      template_version=None):
        if template_version is not None:
            template = "tns-template-hello-world-ng@" + template_version
            attr = {"--template": template}
        else:
            if BRANCH is "master":
                attr = {"--template": SUT_FOLDER + os.path.sep + "tns-template-hello-world-ng.tgz"}
            else:
                attr = {"--template": "tns-template-hello-world-ng"}
        attributes.update(attr)
        output = Tns.create_app(app_name=app_name, attributes=attributes, log_trace=log_trace,
                                assert_success=assert_success,
                                update_modules=update_modules)
        if update_modules:
            Tns.update_angular(path=app_name)
            Tns.update_typescript(path=app_name)

        if assert_success:
            if USE_YARN != "True":
                if Npm.version() < 5:
                    assert "nativescript-angular" in output
                assert File.exists(os.path.join(app_name, 'node_modules', 'nativescript-theme-core'))
                package_json = File.read(os.path.join(app_name, 'package.json'))
                assert "tns-core-modules" in package_json
                assert "nativescript-angular" in package_json
                assert "nativescript-dev-typescript" in package_json

        return output
Beispiel #13
0
    def revert_changes(app_name, log, platform):
        # Clean old logs
        if CURRENT_OS is not OSType.WINDOWS:
            File.write(file_path=log, text="")

        # Revert XML changes
        ReplaceHelper.rollback(app_name, HelpersHMR.xml_change, sleep=10)
        strings = ['Refreshing application on device', './main-page.xml',
                   'HMR: Checking for updates to the bundle with hmr hash']
        Tns.wait_for_log(log_file=log, string_list=strings)
        if platform == Platform.ANDROID:
            text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
            assert text_changed, 'Changes in XML file not applied (UI is not refreshed).'

        # Revert JS changes
        ReplaceHelper.rollback(app_name, HelpersHMR.js_change, sleep=10)
        strings = ['Refreshing application on device', 'HMR: The following modules were updated:', './main-view-model.js', './main-page.js',
                   'Successfully transferred bundle.', 'HMR: Successfully applied update with hmr hash ']
        Tns.wait_for_log(log_file=log, string_list=strings)
        if platform == Platform.ANDROID:
            text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='42 taps left', timeout=20)
            assert text_changed, 'HMR: The following modules were updated:'

        # Revert CSS changes
        ReplaceHelper.rollback(app_name, HelpersHMR.css_change, sleep=10)
        Tns.wait_for_log(log_file=log, string_list=['app.css'], clean_log=False)

        # Verify application looks correct
        Tns.wait_for_log(log_file=log, string_list=HelpersHMR.wp_sync, not_existing_string_list=HelpersHMR.wp_errors,
                         timeout=60)
        if platform == Platform.ANDROID:
            Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120)
Beispiel #14
0
    def get_screen(device_id, file_path):
        """
        Save screen of mobile device.
        :param device_id: Device identifier (example: `emulator-5554`).
        :param file_path: Path to image that will be saved.
        """

        File.remove(file_path)
        base_path, file_name = os.path.split(file_path)
        Folder.create(base_path)

        device_type = Device.__get_device_type(device_id)
        if (device_type == DeviceType.EMULATOR) or (device_type
                                                    == DeviceType.ANDROID):
            Adb.get_screen(device_id=device_id, file_path=file_path)
        if device_type == DeviceType.SIMULATOR:
            Simulator.get_screen(device_id=device_id, file_path=file_path)
        if device_type == DeviceType.IOS:
            IDevice.get_screen(device_id=device_id, file_path=file_path)

        image_saved = False
        if File.exists(file_path):
            size = os.path.getsize(file_path)
            if size > 10:
                image_saved = True
        return image_saved
    def get_screen(device_id, file_path):
        """
        Save screen of mobile device.
        :param device_id: Device identifier (example: `emulator-5554`).
        :param file_path: Path to image that will be saved.
        """

        File.remove(file_path)
        base_path, file_name = os.path.split(file_path)
        Folder.create(base_path)

        device_type = Device.__get_device_type(device_id)
        if (device_type == DeviceType.EMULATOR) or (device_type == DeviceType.ANDROID):
            Adb.get_screen(device_id=device_id, file_path=file_path)
        if device_type == DeviceType.SIMULATOR:
            Simulator.get_screen(device_id=device_id, file_path=file_path)
        if device_type == DeviceType.IOS:
            IDevice.get_screen(device_id=device_id, file_path=file_path)

        image_saved = False
        if File.exists(file_path):
            size = os.path.getsize(file_path)
            if size > 10:
                image_saved = True
        return image_saved
Beispiel #16
0
    def test_001_usage_reporting_enable(self):
        output = Tns.run_tns_command("usage-reporting enable")
        assert enabled.format(usage_reporting, "now ") in output
        assert "GA_TRACKING_ID" in File.read(self.config)
        assert "UA-111455-44" in File.read(self.config)

        # Check there is message for tracking in Google Analytics
        output = Tns.run_tns_command("doctor", timeout=180, log_trace=True)
        assert "Will send the following information to Google Analytics" in output

        output = Tns.run_tns_command("usage-reporting status")
        assert enabled.format(usage_reporting, "") in output

        # https://github.com/NativeScript/nativescript-cli/issues/3595
        output = Tns.create_app(self.app_name,
                                attributes={
                                    '--template':
                                    os.path.join('data', 'apps',
                                                 'livesync-hello-world.tgz')
                                },
                                log_trace=True,
                                force_clean=False,
                                update_modules=True)
        assert "label: 'data/apps/livesync-hello-world.tgz'" not in output
        assert "label: 'localTemplate_tns-template-hello-world'" in output
Beispiel #17
0
    def test_300_build_project_with_dash_and_ios_inspector_added(self):
        """
        Verify we can build projects with dashes.
        Verify we can build android when inspector is added (test for CLI issue 2467)
        """
        Tns.create_app(self.app_name_dash)
        Tns.platform_add_android(attributes={
            "--path": self.app_name_dash,
            "--frameworkPath": ANDROID_PACKAGE
        })
        if USE_YARN == "True":
            Npm.install(package="tns-ios-inspector",
                        option='--dev',
                        folder=self.app_name_dash)
        else:
            Npm.install(package="tns-ios-inspector",
                        option='--save-dev',
                        folder=self.app_name_dash)
        Tns.build_android(attributes={"--path": self.app_name_dash})

        # Verify project id
        output = File.read(self.app_name_dash + "/package.json")
        assert app_identifier in output.lower()

        # Verify AndroidManifest.xml
        output = File.read(self.app_name_dash + "/" +
                           TnsAsserts.PLATFORM_ANDROID_SRC_MAIN_PATH +
                           "AndroidManifest.xml")
        assert app_identifier in output.lower()
    def test_330_tns_run_ios_after_rebuild_of_native_project(self):
        """
        `tns run ios` should work properly after rebuild of native project (test for issue #2860)
        """

        # `tns run ios` and wait until app is deployed
        log = Tns.run_ios(attributes={'--path': self.app_name, '--device': self.DEVICE_ID}, wait=False,
                          assert_success=False, log_trace=True)
        strings = [self.DEVICE_ID, 'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)

        # Verify app is running
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="Tap the button"), "App failed to load!"

        # Update native project
        config_path = os.path.join(self.app_name, 'app', 'App_Resources', 'iOS', 'build.xcconfig')
        File.replace(file_path=config_path, str1='More info', str2='If you need more info')
        strings = ['ARCHIVE SUCCEEDED', 'Successfully synced application', self.DEVICE_ID, 'CONSOLE LOG']
        not_existing_strings = ['Unable to sync files', 'Multiple errors were thrown']
        Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings, timeout=120)

        # Verify app is running
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="Tap the button"), "App failed to load!"

        # Change JS and wait until app is synced
        ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
        strings = ['Successfully transferred', 'main-view-model.js', 'Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="clicks"), "JS changes not synced on device!"

        # Rollback all the changes and verify files are synced
        ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
        strings = ['Successfully transferred', 'main-view-model.js', 'Restarting application']
        Tns.wait_for_log(log_file=log, string_list=strings)
        assert Device.wait_for_text(device_id=self.DEVICE_ID, text="taps left"), "JS changes not synced on device!"
Beispiel #19
0
    def start(emulator_name=EMULATOR_NAME,
              port=EMULATOR_PORT,
              timeout=300,
              wipe_data=True):
        """
        Start emulator.
        :param wipe_data: If true it will wipe emulator date.
        :param emulator_name: Name of android emulator image (avd).
        :param port: Port for Android emulator.
        :param timeout: Time to wait until emulator boot.
        """
        print 'Starting emulator {0}'.format(emulator_name)

        if CURRENT_OS == OSType.WINDOWS:
            start_command = 'START /B ' + EMULATOR_PATH + ' -avd ' + emulator_name + ' -port ' + port
        else:
            start_command = EMULATOR_PATH + ' -avd ' + emulator_name + ' -port ' + port

        if wipe_data:
            start_command += ' -wipe-data'
        log_file = run(start_command,
                       timeout=timeout,
                       wait=False,
                       log_level=CommandLogLevel.COMMAND_ONLY)

        # Check if emulator is running
        device_name = 'emulator-' + port
        if Emulator.wait(device_name, timeout):
            print 'Emulator started successfully.'
        else:
            print 'Emulator failed to boot!'
            print File.read(log_file)
            raise Exception('Wait for emulator failed!')
Beispiel #20
0
    def platform_clean(platform=Platform.NONE,
                       attributes={},
                       assert_success=True,
                       log_trace=False,
                       tns_path=None):
        platform_string = Tns.__get_platform_string(platform)
        output = Tns.run_tns_command("platform clean " + platform_string,
                                     attributes=attributes,
                                     log_trace=log_trace,
                                     tns_path=tns_path)

        app_name = Tns.__get_app_name_from_attributes(attributes)
        if assert_success:
            assert "Platform {0} successfully removed".format(
                platform_string) in output
            assert "error" not in output
            if platform is Platform.ANDROID:
                assert File.exists(
                    os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID))
            if platform is Platform.IOS:
                assert File.exists(
                    os.path.join(app_name, TnsAsserts.PLATFORM_IOS))
            assert "Platform {0} successfully added".format(
                platform_string) in output
        return output
    def platform_added(app_name, platform=Platform.NONE, output=None):
        """
        Assert platform is added.
        :param app_name: Application name (folder where app is located).
        :param platform: Platforms that should be available.
        :param output: output of `tns platform add` command
        """

        # Verify console output is correct
        if output is not None:
            if platform is Platform.ANDROID:
                assert 'Platform android successfully added' in output
            if platform is Platform.IOS and CURRENT_OS == OSType.OSX:
                assert 'Platform ios successfully added' in output
            else: 
                assert 'Applications for platform ios can not be built on this OS'
            assert 'Project successfully created.' not in output

        # This is to handle test for app with space.
        # In this case we put app name inside ''.
        app_name = app_name.replace('\'', '')
        app_name = app_name.replace('\"', '')

        # Verify file and folder content
        if platform is Platform.NONE:
            assert not File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_IOS))
            assert not File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID))
        if platform is Platform.ANDROID or platform is Platform.BOTH:
            assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID))
        if platform is Platform.IOS or platform is Platform.BOTH:
            if CURRENT_OS == OSType.OSX:
                assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_IOS))
            else: 
                assert not File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_IOS))
Beispiel #22
0
    def test_200_build_android_app_bundle(self):
        """Build app with android app bundle option. Verify the output(app.aab) and use bundletool to deploy on device"""
        path_to_aab = os.path.join(self.app_name, "platforms", "android",
                                   "app", "build", "outputs", "bundle",
                                   "debug", "app.aab")

        output = Tns.build_android(attributes={
            "--path": self.app_name,
            "--aab": ""
        },
                                   assert_success=False)
        assert "The build result is located at:" in output
        assert path_to_aab in output
        assert File.exists(path_to_aab)

        #Verify app can be deployed on emulator via bundletool
        # Use bundletool to create the .apks file
        self.bundletool_build(self.bundletool_path, path_to_aab,
                              self.path_to_apks)
        assert File.exists(self.path_to_apks)

        # Deploy on device
        self.bundletool_deploy(self.bundletool_path,
                               self.path_to_apks,
                               device_id=EMULATOR_ID)

        # Start the app on device
        Adb.start_app(EMULATOR_ID, "org.nativescript.TestApp")

        # Verify app looks correct inside emulator
        app_started = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
        assert app_started, 'App is not started on device'
    def test_181_tns_run_android_console_dir(self):
        """
         Test console.dir() of different objects.
        """

        # Change main-page.js so it contains console logging
        source_js = os.path.join('data', 'console-dir', 'main-page.js')
        target_js = os.path.join(self.app_name, 'app', 'main-page.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', EMULATOR_ID,
                   'Successfully synced application',
                   "true",
                   "false",
                   "null",
                   "undefined",
                   "-1",
                   "text",
                   "==== object dump start ====",
                   "name: \"John\"",
                   "age: \"34\"",
                   "==== object dump end ====",
                   self.max_long_string
                   ]

        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)
        assert self.very_long_string not in log
Beispiel #24
0
    def test_181_tns_run_android_console_dir(self):
        """
         Test console.dir() of different objects.
        """

        # Change main-page.js so it contains console logging
        source_js = os.path.join('data', 'console-dir', 'main-page.js')
        target_js = os.path.join(self.app_name, 'app', 'main-page.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID
        },
                              wait=False,
                              assert_success=False)
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', EMULATOR_ID,
            'Successfully synced application', "true", "false", "null",
            "undefined", "-1", "text", "==== object dump start ====",
            "name: \"John\"", "age: \"34\"", "==== object dump end ====",
            self.max_long_string
        ]

        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10)
        assert self.very_long_string not in log
    def wait_for_log(log_file, string_list, not_existing_string_list=None, timeout=45, check_interval=3,
                     clean_log=True):
        """
        Wait until log file contains list of string.
        :param log_file: Path to log file.
        :param string_list: List of strings.
        :param not_existing_string_list: List of string that should not be in logs.
        :param timeout: Timeout.
        :param check_interval: Check interval.
        :param clean_log: Specify if content of log file should be delete after check.
        """
        t_end = time.time() + timeout
        all_items_found = False
        not_found_list = []
        log = ""
        while time.time() < t_end:
            not_found_list = []
            log = File.read(log_file)
            log = str(log.decode('utf8').encode('utf8')).strip()
            for item in string_list:
                if item in log:
                    print "'{0}' found.".format(item)
                else:
                    not_found_list.append(item)
            if not_found_list == []:
                all_items_found = True
                print "Log contains: {0}".format(string_list)
                break
            else:
                print "'{0}' NOT found. Wait...".format(not_found_list)
                time.sleep(check_interval)
            if 'BUILD FAILED' in log:
                print 'BUILD FAILED. No need to wait more time!'
                break
            if 'Unable to sync files' in log:
                print 'Sync process failed. No need to wait more time!'
                break
            if '????????????????????????????' in log:
                print 'Log seems to be corrupted. No need to wait more time!'
                break
            if 'errors were thrown' in log:
                print 'Multiple errors were thrown. No need to wait more time!'
                break

        if clean_log and (CURRENT_OS is not OSType.WINDOWS) and all_items_found:
            File.write(file_path=log_file, text="")

        if all_items_found:
            if not_existing_string_list is None:
                pass
            else:
                for item in not_existing_string_list:
                    assert item not in log, "{0} found! It should not be in logs.\nLog:\n{1}".format(item, log)
        else:
            print "##### OUTPUT BEGIN #####\n"
            print log
            print "##### OUTPUT END #####\n"
            print ""
            assert False, "Output does not contain {0}".format(not_found_list)
 def get_app_packages():
     """Copy Preview App packages from Shares to local folder"""
     shutil.copy2(PREVIEW_APP_PATH_ANDROID.strip(), SUT_FOLDER)        
     shutil.copy2(PREVIEW_APP_PATH_IOS.strip(), SUT_FOLDER)
     shutil.copy2(PLAYGROUND_APP_PATH_IOS.strip(), SUT_FOLDER)
     """Unpack the .tgz file to get the nsplaydev.app"""
     File.unpack_tar(os.path.join(SUT_FOLDER, 'nsplaydev.tgz'), SUT_FOLDER)
     File.unpack_tar(os.path.join(SUT_FOLDER, 'nsplay.tgz'), SUT_FOLDER)
Beispiel #27
0
    def tearDownClass(cls):
        Folder.cleanup("TestApp.app")
        File.remove("TestApp.ipa")

        Folder.cleanup(cls.app_name)
        Folder.cleanup(cls.app_name_no_platform)
        Folder.cleanup(cls.app_name_dash)
        Folder.cleanup(cls.app_name_space)
Beispiel #28
0
 def get_app_packages():
     """Copy Preview App packages from Shares to local folder"""
     shutil.copy2(PREVIEW_APP_PATH_ANDROID.strip(), SUT_FOLDER)
     shutil.copy2(PREVIEW_APP_PATH_IOS.strip(), SUT_FOLDER)
     shutil.copy2(PLAYGROUND_APP_PATH_IOS.strip(), SUT_FOLDER)
     """Unpack the .tgz file to get the nsplaydev.app"""
     File.unpack_tar(os.path.join(SUT_FOLDER, 'nsplaydev.tgz'), SUT_FOLDER)
     File.unpack_tar(os.path.join(SUT_FOLDER, 'nsplay.tgz'), SUT_FOLDER)
Beispiel #29
0
 def test_330_prepare_android_next(self):
     Tns.platform_remove(platform=Platform.ANDROID, attributes={"--path": self.app_name}, assert_success=False)
     Tns.platform_add_android(attributes={"--path": self.app_name}, version="next")
     Folder.cleanup(os.path.join(self.app_name, "node_modules"))
     Folder.cleanup(os.path.join(self.app_name, "platforms"))
     android_version = Npm.get_version("tns-android@next")
     File.replace(file_path=os.path.join(self.app_name, "package.json"), str1=android_version, str2="next")
     output = Tns.prepare_android(attributes={"--path": self.app_name})
     TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.FIRST_TIME)
 def pack(folder, output_file):
     try:
         Folder.navigate_to(folder)
         run('npm pack', log_level=CommandLogLevel.SILENT)
         src_file = File.find_by_extension('tgz')[0]
         File.copy(src=src_file, dest=output_file)
         File.remove(src_file)
     except:
         print 'Failed to pack {0}'.format(folder)
     Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False)
Beispiel #31
0
 def install():
     package = File.find(base_path=SUT_FOLDER, file_name="nativescript")
     output = Npm.install(package=package, folder=TEST_RUN_HOME)
     message = "NativeScript CLI installation failed - \"{e}\" found in output."
     assert "dev-post-install" not in output, message.format(
         e="dev-post-install")
     cli_path = os.path.join(TEST_RUN_HOME, "node_modules", ".bin", "tns")
     assert File.exists(
         cli_path
     ), "NativeScript CLI installation failed - tns does not exist."
Beispiel #32
0
 def pack(folder, output_file):
     try:
         Folder.navigate_to(folder)
         run('npm pack', log_level=CommandLogLevel.SILENT)
         src_file = File.find_by_extension('tgz')[0]
         File.copy(src=src_file, dest=output_file)
         File.remove(src_file)
     except:
         print 'Failed to pack {0}'.format(folder)
     Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False)
    def test_301_platform_update_ios(self):
        Tns.platform_add_ios(version="2.2.0", attributes={"--path": self.app_name})
        output = File.read(self.app_name + os.sep + "package.json")
        assert "\"version\": \"2.2.0\"" in output

        Tns.platform_update("[email protected]", attributes={"--path": self.app_name, " <  data/keys/enter_key.txt": ""})
        output = File.read(self.app_name + os.sep + "package.json")
        assert "\"version\": \"2.3.0\"" in output

        Tns.build_ios(attributes={"--path": self.app_name})
Beispiel #34
0
    def test_300_prepare_ios_preserve_case(self):
        File.copy(
            self.app_name +
            "/node_modules/tns-core-modules/application/application-common.js",
            self.app_name +
            "/node_modules/tns-core-modules/application/New-application-common.js"
        )
        File.copy(
            self.app_name +
            "/node_modules/tns-core-modules/application/application.android.js",
            self.app_name +
            "/node_modules/tns-core-modules/application/New-application.android.js"
        )
        File.copy(
            self.app_name +
            "/node_modules/tns-core-modules/application/application.ios.js",
            self.app_name +
            "/node_modules/tns-core-modules/application/New-application.ios.js"
        )

        output = Tns.prepare_ios(attributes={"--path": self.app_name})
        TnsAsserts.prepared(self.app_name,
                            platform=Platform.IOS,
                            output=output,
                            prepare=Prepare.FULL)

        # Verify case is preserved
        path = TnsAsserts._get_ios_modules_path(self.app_name)
        assert File.exists(path + 'application/New-application-common.js')
        assert File.exists(path + 'application/New-application.js')
        assert not File.exists(path + 'application/New-application.ios.js')
    def test_009_android_run_hmr_delete_file(self):
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False,
                        assert_success=False)

        Tns.wait_for_log(log_file=log, string_list=HelpersHMR.wp_run, not_existing_string_list=HelpersHMR.wp_errors,
                         timeout=240)
        HelpersHMR.android_screen_match(image=self.image_original, timeout=120)
        File.remove(self.app_name + 'app', 'main-view-model.js')

        self.apply_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
        self.revert_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
    def test_321_build_with_copy_to_option(self):
        # TODO: Remove those lines after https://github.com/NativeScript/nativescript-cli/issues/2547 is fixed.
        # This is required when build with different SDK
        Folder.cleanup(self.app_name)
        Tns.create_app(self.app_name)
        Tns.platform_add_android(attributes={"--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE})

        File.remove(self.debug_apk)
        Tns.build_android(attributes={"--path": self.app_name, "--copy-to": "./"})
        assert File.exists(self.debug_apk)
        File.remove(self.debug_apk)
Beispiel #37
0
    def test_008_ios_run_hmr_console_log(self):
        source_js = os.path.join('data', "issues", 'console-log-hmr', 'main-view-model.js')
        target_js = os.path.join(self.app_name, 'app', 'main-view-model.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--hmr': ''}, wait=False,
                                assert_success=False)
        strings = ['LOG Hello']
        Tns.wait_for_log(log_file=log, string_list=strings)

        Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120)
Beispiel #38
0
    def test_004_android_run_hmr_delete_file(self):
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False,
                        assert_success=False)

        Tns.wait_for_log(log_file=log, string_list=HelpersHMR.wp_run, not_existing_string_list=HelpersHMR.wp_errors,
                         timeout=240)
        HelpersHMR.android_screen_match(image=self.image_original, timeout=120)
        File.remove(self.app_name + 'app', 'main-view-model.js')

        self.apply_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
        self.revert_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
    def test_002_build_android_release(self):
        Tns.build_android(attributes={"--path": self.app_name,
                                      "--keyStorePath": ANDROID_KEYSTORE_PATH,
                                      "--keyStorePassword": ANDROID_KEYSTORE_PASS,
                                      "--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
                                      "--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
                                      "--release": ""
                                      }, log_trace=True)

        # Configs are respected
        assert 'release' in File.read(os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, 'config.json'))
        assert File.exists(os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_APK_RELEASE_PATH, self.release_apk))
Beispiel #40
0
    def setUpClass(cls):
        BaseClass.setUpClass(cls.__name__)
        Tns.create_app(cls.app_name)
        Tns.platform_add_ios(attributes={
            "--path": cls.app_name,
            "--frameworkPath": IOS_PACKAGE
        })

        Folder.cleanup("TestApp.app")
        File.remove("TestApp.ipa")

        Xcode.cleanup_cache()
    def test_002_usage_reporting_disable(self):
        output = Tns.run_tns_command("usage-reporting disable")
        assert disabled.format(usage_reporting, "now ") in output
        assert "GA_TRACKING_ID" in File.read(self.config)
        assert "UA-111455-44" in File.read(self.config)

        # Check there is no any message for tracking in Google Analytics
        output = Tns.run_tns_command("doctor", timeout=180, log_trace=True)
        assert "Will send the following information to Google Analytics" not in output

        output = Tns.run_tns_command("usage-reporting status")
        assert disabled.format(usage_reporting, "") in output
Beispiel #42
0
    def test_002_usage_reporting_disable(self):
        output = Tns.run_tns_command("usage-reporting disable")
        assert disabled.format(usage_reporting, "now ") in output
        assert "GA_TRACKING_ID" in File.read(self.config)
        assert "UA-111455-44" in File.read(self.config)

        # Check there is no any message for tracking in Google Analytics
        output = Tns.run_tns_command("doctor", timeout=180, log_trace=True)
        assert "Will send the following information to Google Analytics" not in output

        output = Tns.run_tns_command("usage-reporting status")
        assert disabled.format(usage_reporting, "") in output
Beispiel #43
0
    def plugin_create(name,
                      attributes={},
                      log_trace=False,
                      assert_success=True,
                      tns_path=None,
                      force_clean=True):
        # Detect folder where plugin should be created
        path = attributes.get("--path")
        # noinspection PyUnusedLocal
        folder = path
        if path is None:
            path = name
            folder = name
        else:
            folder = path + os.sep + name

        # Clean target location
        if force_clean:
            Folder.cleanup(folder=path)

        # Execute plugin create command
        output = Tns.run_tns_command(
            "plugin create --includeTypeScriptDemo=y " + name,
            attributes=attributes,
            log_trace=log_trace,
            tns_path=tns_path)

        if assert_success:
            # Verify command output
            assert "Will now rename some files" in output, "Post clone script not executed."
            assert "Screenshots removed" in output, "Post clone script not executed."
            assert "Solution for {0}".format(
                name
            ) + " was successfully created" in output, 'Missing message in output.'
            assert "https://docs.nativescript.org/plugins/building-plugins" in output, 'Link to docs is missing.'

            # Verify created files and folders
            plugin_root = os.path.join(TEST_RUN_HOME, folder)
            readme = os.path.join(plugin_root, "README.md")
            src = os.path.join(plugin_root, "src")
            demo = os.path.join(plugin_root, "demo")
            post_clone_script = os.path.join(src, "scripts", "postclone.js")
            assert File.exists(readme), 'README.md do not exists.'
            assert not Folder.is_empty(
                src), 'src folder should exists and should not be empty.'
            assert not Folder.is_empty(
                demo), 'demo folder should exists and should not be empty.'
            assert not File.exists(
                post_clone_script
            ), 'Post clone script should not exists in plugin src folder.'
        return output
    def platform_remove(platform=Platform.NONE, attributes={}, assert_success=True, log_trace=False, tns_path=None):
        platform_string = Tns.__get_platform_string(platform)
        output = Tns.run_tns_command("platform remove " + platform_string, attributes=attributes, log_trace=log_trace,
                                     tns_path=tns_path)

        app_name = Tns.__get_app_name_from_attributes(attributes)
        if assert_success:
            assert "Platform {0} successfully removed".format(platform_string) in output
            assert "error" not in output
            if platform is Platform.ANDROID:
                assert not File.exists(app_name + TnsAsserts.PLATFORM_ANDROID)
            if platform is Platform.IOS:
                assert not File.exists(app_name + TnsAsserts.PLATFORM_IOS)
        return output
    def test_008_android_run_hmr_console_log(self):
        source_js = os.path.join('data', "issues", 'console-log-hmr', 'main-view-model.js')
        target_js = os.path.join(self.app_name, 'app', 'main-view-model.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False,
                              assert_success=False)

        strings = ['LOG Hello']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image=HelpersHMR.image_original)
 def get_screen_text(device_id):
     """
     Get text of current screen on mobile device.
     :param device_id: Device identifier (example: `emulator-5554`).
     :return: All the text visible on screen as string
     """
     img_name = "actual_{0}_{1}.png".format(device_id, time.time())
     actual_image_path = os.path.join(OUTPUT_FOLDER, "images", device_id, img_name)
     if File.exists(actual_image_path):
         File.remove(actual_image_path)
     Device.get_screen(device_id=device_id, file_path=actual_image_path)
     image = Image.open(actual_image_path).convert('LA')
     text = pytesseract.image_to_string(image)
     return text
Beispiel #47
0
    def get_screen(device_id, file_path):
        """
        Save screen of mobile device.
        :param device_id: Device identifier (example: `emulator-5554`).
        :param file_path: Name of image that will be saved.
        """

        base_path, file_name = os.path.split(file_path)
        file_name = file_name.rsplit('.', 1)[0]

        run(command="idevicescreenshot -u {0} {1}.tiff".format(device_id, file_name), log_level=CommandLogLevel.SILENT)
        run(command="sips -s format png {0}.tiff --out {1}".format(file_name, file_path),
            log_level=CommandLogLevel.SILENT)
        File.remove("{0}.tiff".format(file_name))
 def get_screen_text():
     """
     Get text of current screen of host machine.
     :return: All the text visible on screen as string
     """
     base_path = os.path.join(OUTPUT_FOLDER, "images", "host")
     if not File.exists(base_path):
         Folder.create(base_path)
     actual_image_path = os.path.join(base_path, "host_{0}.png".format(time.time()))
     if File.exists(actual_image_path):
         File.remove(actual_image_path)
     Screen.save_screen(path=actual_image_path)
     image = Image.open(actual_image_path)
     text = pytesseract.image_to_string(image.convert('L'))
     return text
Beispiel #49
0
    def test_301_platform_update_ios(self):
        Tns.platform_add_ios(version="2.2.0",
                             attributes={"--path": self.app_name})
        output = File.read(self.app_name + os.sep + "package.json")
        assert "\"version\": \"2.2.0\"" in output

        Tns.platform_update("[email protected]",
                            attributes={
                                "--path": self.app_name,
                                " <  data/keys/enter_key.txt": ""
                            })
        output = File.read(self.app_name + os.sep + "package.json")
        assert "\"version\": \"2.3.0\"" in output

        Tns.build_ios(attributes={"--path": self.app_name})
Beispiel #50
0
 def get_screen_text(device_id):
     """
     Get text of current screen on mobile device.
     :param device_id: Device identifier (example: `emulator-5554`).
     :return: All the text visible on screen as string
     """
     img_name = "actual_{0}_{1}.png".format(device_id, time.time())
     actual_image_path = os.path.join(OUTPUT_FOLDER, "images", device_id,
                                      img_name)
     if File.exists(actual_image_path):
         File.remove(actual_image_path)
     Device.get_screen(device_id=device_id, file_path=actual_image_path)
     image = Image.open(actual_image_path).convert('LA')
     text = pytesseract.image_to_string(image)
     return text
Beispiel #51
0
    def test_100_plugin_add_sandbox_pod_can_write_in_app_folder(self):
        Tns.create_app(self.app_name)
        Tns.platform_add_ios(attributes={"--path": self.app_name,
                                         "--frameworkPath": IOS_PACKAGE})

        plugin = os.path.join(TEST_RUN_HOME, "data", "CocoaPods", "nativescript-ios-working-with-sandbox-plugin.tgz")
        output = Tns.plugin_add(plugin, attributes={"--path": self.app_name}, assert_success=False)
        assert "Successfully installed plugin nativescript-ios-working-with-sandbox-plugin." in output
        assert "nativescript-ios-working-with-sandbox-plugin" in File.read(self.app_name + "/package.json")

        output = Tns.prepare_ios(attributes={"--path": self.app_name})
        assert "Successfully prepared plugin " + \
               "nativescript-ios-working-with-sandbox-plugin for ios." in output

        assert "content" in File.read(self.app_name + "/platforms/ios/TestApp/app/I_MADE_THIS_FILE.txt")
    def create_app(app_name, attributes={}, log_trace=False, assert_success=True, update_modules=True,
                   force_clean=True, measureTime=False):

        if force_clean:
            if File.exists(app_name):
                Folder.cleanup(app_name)

        path = app_name
        attributes_to_string = ""
        for k, v in attributes.iteritems():
            if "--path" in k:
                path = v
            attributes_to_string = "".join("{0} {1}".format(k, v))
        attr = {}
        if not any(s in attributes_to_string for s in ("--ng", "--template", "--tsc", "--vue")):
            if BRANCH == "master":
                attr = {"--template": SUT_FOLDER + os.path.sep + "tns-template-hello-world.tgz"}
            else:
                attr = {"--template": "tns-template-hello-world"}
        attr.update(attributes)
        if app_name is None:
            output = Tns.run_tns_command("create ", attributes=attr, log_trace=log_trace, measureTime=measureTime)
        else:
            output = Tns.run_tns_command("create \"" + app_name + "\"", attributes=attr, log_trace=log_trace,
                                         measureTime=measureTime)
        if assert_success:
            TnsAsserts.created(app_name=app_name, output=output)
        if update_modules:
            Tns.update_modules(path)
        # Tns.ensure_app_resources(path)
        return output
Beispiel #53
0
 def get_screen_text():
     """
     Get text of current screen of host machine.
     :return: All the text visible on screen as string
     """
     base_path = os.path.join(OUTPUT_FOLDER, "images", "host")
     if not File.exists(base_path):
         Folder.create(base_path)
     actual_image_path = os.path.join(base_path,
                                      "host_{0}.png".format(time.time()))
     if File.exists(actual_image_path):
         File.remove(actual_image_path)
     Screen.save_screen(path=actual_image_path)
     image = Image.open(actual_image_path)
     text = pytesseract.image_to_string(image.convert('L'))
     return text
Beispiel #54
0
 def run_android(attributes={},
                 assert_success=True,
                 log_trace=False,
                 timeout=COMMAND_TIMEOUT,
                 tns_path=None,
                 wait=True):
     output = Tns.run_tns_command("run android",
                                  attributes=attributes,
                                  log_trace=log_trace,
                                  timeout=timeout,
                                  tns_path=tns_path,
                                  wait=wait)
     if assert_success:
         assert "Project successfully built" in output
         assert "Successfully installed on device with identifier" in output
         app_name = Tns.__get_app_name_from_attributes(
             attributes=attributes)
         # apk_name = Tns.__get_final_package_name(app_name, platform=Platform.ANDROID)
         apk_name = "app"
         debug_app_path = os.path.join(
             app_name, TnsAsserts.PLATFORM_ANDROID_APK_DEBUG_PATH, apk_name)
         release_app_path = os.path.join(
             app_name, TnsAsserts.PLATFORM_ANDROID_APK_RELEASE_PATH,
             apk_name)
         if "--release" in attributes.keys():
             apk_path = release_app_path + "-release.apk"
         else:
             apk_path = debug_app_path + "-debug.apk"
         apk_path = apk_path.replace("\"", "")  # Handle projects with space
         assert File.exists(
             apk_path), "Apk file does not exist at " + apk_path
     return output