Example #1
0
    def test_300_deploy_list_and_run_applications(self):
        # Deploy test application
        app_id = TnsPaths.get_bundle_id(app_name=APP_NAME)
        result = Tns.deploy(app_name=APP_NAME,
                            platform=Platform.ANDROID,
                            just_launch=True,
                            wait=True)
        for device in self.ANDROID_DEVICES:
            assert device.id in result.output
        if Settings.HOST_OS == OSType.OSX:
            result = Tns.deploy(app_name=APP_NAME,
                                platform=Platform.IOS,
                                just_launch=True,
                                wait=True)
            for device in self.IOS_DEVICES:
                assert device.id in result.output

        # Verify list-applications command list default android apps and the app we've just deployed
        for device in self.ANDROID_DEVICES:
            result = Tns.exec_command(
                'device list-applications --device {0}'.format(device.id))
            assert 'com.android' in result.output
            assert app_id in result.output

        # Verify `device run <bundle-id>` will start the app
        device = self.ANDROID_DEVICES[0]
        Adb.stop_application(device_id=device.id, app_id=app_id)
        assert not device.is_text_visible(
            text=Changes.JSHelloWord.JS.old_value), 'Failed to stop the app.'
        Tns.exec_command(command='device run {0}'.format(app_id),
                         device=device.id,
                         wait=True,
                         just_launch=True)
        device.wait_for_text(text=Changes.JSHelloWord.JS.old_value)

        # Get Android device logs
        result = Tns.exec_command(command='device log',
                                  device=device.id,
                                  wait=False)
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=['beginning of'],
                             timeout=120)
        assert 'I' or 'D' or 'W' in File.read(
            result.log_file
        ), 'Log does not contain INFO, DEBUG or WARN messages.'

        # Get iOS device logs
        if Settings.HOST_OS == OSType.OSX:
            device = self.IOS_DEVICES[0]
            result = Tns.exec_command(command='device log',
                                      device=device.id,
                                      wait=False)
            TnsLogs.wait_for_log(log_file=result.log_file,
                                 string_list=['>:'],
                                 timeout=120)
            assert "<Notice>:" or "<Error>:" in File.read(
                result.log_file), 'tns device log fails to get ios logs.'
Example #2
0
 def __app_restart_messages(app_name, platform, instrumented, app_type, device, just_launch=False):
     logs = ['Restarting application on device']
     if platform == Platform.ANDROID:
         app_id = TnsPaths.get_bundle_id(app_name)
         if device is not None and device.version < 7.0 and just_launch is False:
             logs.append('ActivityManager: Start proc')
             logs.append('activity {0}/com.tns.NativeScriptActivity'.format(app_id))
     if instrumented:
         logs.append('QA: Application started')
         if app_type == AppType.NG:
             logs.append('QA: items component on init')
     return logs
Example #3
0
    def test_365_tns_run_android_should_respect_adb_errors(self):
        """
        If device memory is full and error is thrown during deploy cli should respect it
        https://github.com/NativeScript/nativescript-cli/issues/2170
        """
        # Deploy the app to make sure we have something at /data/data/org.nativescript.TestApp
        result = run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu, just_launch=True)

        # Use all the disk space on emulator
        dest_file = '/data/data/' + TnsPaths.get_bundle_id(self.app_name)
        for index in range(1, 3000):
            command = "shell 'su 0 cp -r {0} {0}{1}'".format(dest_file, str(index))
            result = Adb.run_adb_command(device_id=self.emu.id, command=command)
            Log.info(result.output)
            if "No space left on device" in result.output:
                break

        # Create new app
        Tns.create(app_name='TestApp2', template=Template.HELLO_WORLD_JS.local_package, update=True)

        # Run the app and verify there is appropriate error
        result = Tns.run_android('TestApp2', verify=True, device=self.emu.id, just_launch=True)
        strings = ['No space left on device']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=120)
Example #4
0
    def run_messages(app_name, platform, run_type=RunType.FULL, bundle=True, hmr=True, uglify=False, app_type=None,
                     file_name=None, instrumented=False, plugins=None, aot=False, device=None, just_launch=False,
                     transfer_all=False, release=False, snapshot=False):
        """
        Get log messages that should be present when running a project.
        :param app_name: Name of the app (for example TestApp).
        :param platform: Platform.ANDROID or Platform.IOS.
        :param run_type: RunType enum value (None when it can not be defined strictly).
        :param bundle: True if `--bundle is specified.`
        :param hmr: True if `--hmr is specified.`
        :param uglify: True if `--env.uglify is specified.`
        :param app_type: AppType enum value.
        :param file_name: Name of changed file.
        :param instrumented: If true it will return logs we place inside app (see files in assets/logs).
        :param plugins: List of plugins.
        :param aot: True if `--env.aot is specified.`
        :param device: Device object.
        :param transfer_all: different strings for transfer of files depends on their count - 10 or more
        :return: Array of strings.
        """
        if plugins is None:
            plugins = []
        logs = []
        if hmr:
            bundle = True

        # Generate prepare messages
        if run_type in [RunType.FIRST_TIME, RunType.FULL]:
            logs.extend(TnsLogs.prepare_messages(platform=platform, plugins=plugins))

        # Generate build messages
        # TODO: Check if file is in app resources and require native build
        logs.extend(TnsLogs.build_messages(platform=platform, run_type=run_type))

        # App install messages
        if run_type in [RunType.FIRST_TIME, RunType.FULL]:
            logs.append('Installing on device')
            logs.append('Successfully installed')

        # File transfer messages
        logs.extend(TnsLogs.__file_changed_messages(run_type=run_type, file_name=file_name, platform=platform,
                                                    bundle=bundle, hmr=hmr, uglify=uglify, aot=aot, app_type=app_type,
                                                    transfer_all=transfer_all))

        if run_type == RunType.JUST_LAUNCH:
            logs.append('Preparing project...')
            logs.append('Webpack compilation complete.')
            logs.append('Project successfully prepared')
            logs.append('Restarting application on device')

        # App restart messages:
        if run_type in [RunType.UNKNOWN, RunType.JUST_LAUNCH]:
            Log.info('Can not define if app should be restarted or not.')
        else:
            if TnsLogs.__should_restart(run_type=run_type, bundle=bundle, hmr=hmr, file_name=file_name):
                logs.extend(TnsLogs.__app_restart_messages(app_name=app_name, platform=platform,
                                                           instrumented=instrumented, app_type=app_type,
                                                           device=device, just_launch=just_launch))
            else:
                logs.extend(TnsLogs.__app_refresh_messages(instrumented=instrumented, app_type=app_type,
                                                           file_name=file_name, hmr=hmr))

        # Add message for successful sync
        if not release:
            app_id = TnsPaths.get_bundle_id(app_name)
            logs.append('Successfully synced application {0} on device'.format(app_id))

        if app_type == AppType.NG and not release:
            logs.append('Angular is running in the development mode. Call enableProdMode() to enable '
                        'the production mode.')
            # If you are in NG with hmr project changes of app.css should not cause angular reload
            if file_name is not None:
                if hmr and 'app.css' in file_name:
                    logs.remove('Angular is running in the development mode. Call enableProdMode() to enable '
                                'the production mode.')

        # Add message for snapshot
        if snapshot and release:
            logs.append('Successfully generated snapshots')
            logs.append('Snapshot enabled')

        # Return logs
        return logs
Example #5
0
def sync_master_detail_vue(app_name, platform, device, bundle=True, hmr=True):
    # Execute tns command
    result = Tns.run(app_name=app_name,
                     platform=platform,
                     emulator=True,
                     wait=False,
                     bundle=bundle,
                     hmr=hmr)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.FULL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   app_type=AppType.VUE,
                                   transfer_all=True)
    TnsLogs.wait_for_log(log_file=result.log_file,
                         string_list=strings,
                         timeout=360)

    # start appium driver (need it on iOS only)
    appium = None
    if platform == Platform.IOS:
        appium = AppiumDriver(platform=platform,
                              device=device,
                              bundle_id=TnsPaths.get_bundle_id(app_name))

    # Verify app home page looks properly
    device.wait_for_text(text="Ford KA")
    device.wait_for_text(text=Changes.MasterDetailVUE.VUE_TEMPLATE.old_text)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name,
                                 'initial_state.png')
    device.get_screen(path=initial_state)

    # Edit template in .vue file
    Sync.replace(app_name=app_name,
                 change_set=Changes.MasterDetailVUE.VUE_TEMPLATE)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   app_type=AppType.VUE,
                                   file_name='CarList.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    device.wait_for_text(text=Changes.MasterDetailVUE.VUE_TEMPLATE.new_text)

    # Edit styling in .vue file
    Sync.replace(app_name=app_name,
                 change_set=Changes.MasterDetailVUE.VUE_STYLE)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   app_type=AppType.VUE,
                                   file_name='CarList.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    style_applied = Wait.until(
        lambda: device.get_pixels_by_color(Colors.RED_DARK) > 200)
    assert style_applied, 'Failed to sync changes in style.'

    # Revert styling in .vue file
    Sync.revert(app_name=app_name,
                change_set=Changes.MasterDetailVUE.VUE_STYLE)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   app_type=AppType.VUE,
                                   file_name='CarList.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    style_applied = Wait.until(
        lambda: device.get_pixels_by_color(Colors.WHITE) > 200)
    assert style_applied, 'Failed to sync changes in style.'

    device.wait_for_text(text="Ford KA")
    if platform == Platform.IOS:
        app_element = appium.driver.find_element(By.ID, "Ford KA")
        app_element.click()
    else:
        device.click(text="Ford KA")
    device.wait_for_text(text="Edit")
    device.wait_for_text(text="Price")
    Sync.replace(app_name=app_name,
                 change_set=Changes.MasterDetailVUE.VUE_DETAIL_PAGE_TEMPLATE)
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.INCREMENTAL,
                                   bundle=bundle,
                                   hmr=hmr,
                                   app_type=AppType.VUE,
                                   file_name='CarDetails.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
    device.wait_for_text(
        text=Changes.MasterDetailVUE.VUE_DETAIL_PAGE_TEMPLATE.new_text)

    # Kill Appium
    if appium is not None:
        appium.stop()
Example #6
0
def sync_master_detail_vue(app_name, platform, device):
    # workaraund for appium restarting application when attaching
    if platform == Platform.IOS:
        result = Tns.run(app_name=app_name, emulator=True, platform=platform, just_launch=True)
        strings = TnsLogs.run_messages(app_name=app_name, platform=platform,
                                       run_type=RunType.JUST_LAUNCH, device=device, just_launch=True)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=360)
        device.wait_for_text(text="Ford KA")
        # start appium driver (need it on iOS only)
        appium = AppiumDriver(platform=platform, device=device, bundle_id=TnsPaths.get_bundle_id(app_name))

    result = Tns.run(app_name=app_name, platform=platform, emulator=True, wait=False)
    if platform == Platform.IOS:
        # because of workaround for appium this run is not first run on ios
        strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
                                       app_type=AppType.VUE, transfer_all=True)
        strings.remove('Refreshing application on device')
        strings.append('Restarting application on device')
    else:
        strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.FULL,
                                       app_type=AppType.VUE, transfer_all=True)

    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=360)

    # Verify app home page looks properly
    device.wait_for_text(text="Ford KA")
    device.wait_for_text(text=Changes.MasterDetailVUE.VUE_TEMPLATE.old_text)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png')
    device.get_screen(path=initial_state)

    # Verify that application is not restarted on file changes when hmr=true
    if Settings.HOST_OS != OSType.WINDOWS:
        not_existing_string_list = ['Restarting application']
    else:
        not_existing_string_list = None

    # Edit template in .vue file
    Sync.replace(app_name=app_name, change_set=Changes.MasterDetailVUE.VUE_TEMPLATE)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
                                   app_type=AppType.VUE, file_name='CarList.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                         not_existing_string_list=not_existing_string_list)
    device.wait_for_text(text=Changes.MasterDetailVUE.VUE_TEMPLATE.new_text)

    # Edit styling in .vue file
    Sync.replace(app_name=app_name, change_set=Changes.MasterDetailVUE.VUE_STYLE)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
                                   app_type=AppType.VUE, file_name='CarList.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                         not_existing_string_list=not_existing_string_list)
    style_applied = Wait.until(lambda: device.get_pixels_by_color(Colors.LIGHT_BLUE) > 200)
    assert style_applied, 'Failed to sync changes in style.'

    # Revert styling in .vue file
    Sync.revert(app_name=app_name, change_set=Changes.MasterDetailVUE.VUE_STYLE)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
                                   app_type=AppType.VUE, file_name='CarList.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                         not_existing_string_list=not_existing_string_list)
    style_applied = Wait.until(lambda: device.get_pixels_by_color(Colors.LIGHT_BLUE) < 200)
    assert style_applied, 'Failed to sync changes in style.'

    device.wait_for_text(text="Ford KA")
    if platform == Platform.IOS:
        app_element = appium.driver.find_element(By.ID, "Ford KA")
        app_element.click()
    else:
        device.click(text="Ford KA")
    device.wait_for_text(text="Edit")
    device.wait_for_text(text="Price")
    Sync.replace(app_name=app_name, change_set=Changes.MasterDetailVUE.VUE_DETAIL_PAGE_TEMPLATE)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
                                   app_type=AppType.VUE, file_name='CarDetails.vue')
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                         not_existing_string_list=not_existing_string_list)
    device.wait_for_text(text=Changes.MasterDetailVUE.VUE_DETAIL_PAGE_TEMPLATE.new_text)

    # Kill Appium
    if platform == Platform.IOS:
        # Kill Appium
        if appium is not None:
            appium.stop()
Example #7
0
import unittest

from selenium.webdriver.common.by import By

from core.base_test.tns_run_test import TnsRunTest
from core.enums.os_type import OSType
from core.enums.platform_type import Platform
from core.settings import Settings
from core.utils.appium.appium_driver import AppiumDriver
from data.sync.hello_world_js import sync_hello_world_js
from data.templates import Template
from products.nativescript.tns import Tns
from products.nativescript.tns_paths import TnsPaths

APP_NAME = Settings.AppName.DEFAULT
BUNDLE_ID = TnsPaths.get_bundle_id(APP_NAME)


class TnsSmokeTests(TnsRunTest):
    appium = None

    @classmethod
    def setUpClass(cls):
        TnsRunTest.setUpClass()
        Tns.create(app_name=APP_NAME,
                   template=Template.HELLO_WORLD_JS.local_package,
                   update=True)
        Tns.platform_add_android(
            app_name=APP_NAME, framework_path=Settings.Android.FRAMEWORK_PATH)
        if Settings.HOST_OS is OSType.OSX:
            Tns.platform_add_ios(app_name=APP_NAME,