예제 #1
0
    def test_100_run_on_all_devices(self):
        result = Tns.run(app_name=self.app_name, platform=Platform.NONE)

        # Wait for logs
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID, run_type=RunType.FULL)
        for device in DeviceManager.get_devices(device_type=any):
            strings.append(device.id)
        strings.append(self.emu.id)
        if Settings.HOST_OS is OSType.OSX:
            strings.append(self.sim.id)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=360)

        # Verify it looks properly
        for device in DeviceManager.get_devices(device_type=any):
            device.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Edit JS file and verify changes are applied
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)

        # Verify logs
        file_name = os.path.basename(Changes.JSHelloWord.JS.file_path)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID, run_type=RunType.INCREMENTAL,
                                       file_name=file_name)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Verify change is applied on all devices
        for device in DeviceManager.get_devices(device_type=any):
            device.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
예제 #2
0
    def test_300_tns_run_ios_clean(self):
        """
        If  set --clean rebuilds the native project
        """
        # Run the project once so it is build for the first time
        result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim, just_launch=True)

        # Verify run --clean without changes rebuilds native project
        result = Tns.run_ios(app_name=self.app_name, verify=True, device=self.sim.id, clean=True, just_launch=True)
        strings = ['Building project', 'Xcode build...', 'Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=120)
        self.sim.wait_for_text(text=Changes.JSHelloWord.XML.old_text)

        # Verify if changes are applied and then run with clean it will apply changes on device
        # Verify https://github.com/NativeScript/nativescript-cli/issues/2670 run --clean does
        # clean build only the first time
        Sync.replace(self.app_name, Changes.JSHelloWord.XML)
        result = Tns.run_ios(app_name=self.app_name, verify=True, device=self.sim.id, clean=True)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.FULL, device=self.sim)
        strings.append('Xcode build...')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.XML.new_text)

        # Make changes again and verify changes are synced and clean build is not triggered again
        Sync.revert(self.app_name, Changes.JSHelloWord.XML)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.INCREMENTAL, device=self.sim, file_name='main-page.xml')
        not_existing_strings = ['Xcode build...']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings)
    def test(self, template_name, template_info):
        TnsRunTest.setUp(self)

        # Create app
        app_name = template_info.name.replace('template-', '')
        Tns.create(app_name=app_name, template='tns-' + template_name, update=False)
        if Settings.ENV != EnvironmentType.LIVE and Settings.ENV != EnvironmentType.PR:
            App.update(app_name=app_name)

        # Run Android
        result = Tns.run_android(app_name=app_name, device=self.emu.id)
        strings = TnsLogs.run_messages(app_name=app_name, run_type=RunType.UNKNOWN, platform=Platform.ANDROID)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
        if template_info.texts is not None:
            for text in template_info.texts:
                self.emu.wait_for_text(text=text, timeout=60)
        else:
            self.emu.wait_for_main_color(color=Colors.WHITE, timeout=60)

        # Run iOS
        if Settings.HOST_OS is OSType.OSX:
            Simctl.uninstall_all(simulator_info=self.sim)
            result = Tns.run_ios(app_name=app_name, device=self.sim.id)
            strings = TnsLogs.run_messages(app_name=app_name, run_type=RunType.UNKNOWN, platform=Platform.IOS)
            TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
            if template_info.texts is not None:
                for text in template_info.texts:
                    self.sim.wait_for_text(text=text, timeout=60)
            else:
                self.sim.wait_for_main_color(color=Colors.WHITE, timeout=60)

        # Cleanup
        TnsRunTest.tearDown(self)
def sync_plugin_platform_spec(app_name,
                              app_type,
                              log_result,
                              platform,
                              device,
                              hmr=True):
    # Setting the application Identifier depending on app_type except for TS
    if app_type is not AppType.TS:
        app_name = app_name + str(app_type)
    # Edit platform specific file and verify change is applied on device
    if platform == platform.ANDROID:
        platform_change_set = Changes.DateTimePicker.ANDROID_TS
    else:
        platform_change_set = Changes.DateTimePicker.IOS_TS
    File.replace(
        path=platform_change_set.file_path,
        old_string=platform_change_set.old_value,
        new_string=platform_change_set.new_value,
        fail_safe=True)
    strings = TnsLogs.run_messages(
        app_name=app_name,
        platform=platform,
        run_type=RunType.INCREMENTAL,
        hmr=hmr,
        app_type=app_type)
    TnsLogs.wait_for_log(
        log_file=log_result.log_file, string_list=strings, timeout=60)
    device.click(text="DatePickerField")
    device.wait_for_text("select date")
    device.click(text="select date")
    device.click(text="OK")
    date = datetime.date.today().replace(year=2010)
    date = date.strftime("%b %-d, %Y")
    device.wait_for_text(str(date))
def sync_plugin_common(app_name,
                       app_type,
                       platform,
                       device,
                       log_result,
                       hmr=True):
    # Setting the application Identifier depending on app_type except for TS
    if app_type is not AppType.TS:
        app_name = app_name + str(app_type)
    # Edit common file in SRC
    change_set = Changes.DateTimePicker.COMMON_TS
    File.replace(
        path=change_set.file_path,
        old_string=change_set.old_value,
        new_string=change_set.new_value,
        fail_safe=True)

    strings = TnsLogs.run_messages(
        app_name=app_name,
        platform=platform,
        run_type=RunType.INCREMENTAL,
        hmr=hmr,
        app_type=app_type)

    TnsLogs.wait_for_log(
        log_file=log_result.log_file, string_list=strings, timeout=60)
    # Click on datepicker field and verify new value of picker is applied
    device.click(text="DatePickerField")
    today = datetime.date.today().strftime("%b %-d, %Y")
    device.wait_for_text(today)
예제 #6
0
def run_hello_world_js_ts(app_name, platform, device, bundle=True, hmr=True, uglify=False, release=False,
                          aot=False, snapshot=False, instrumented=False, sync_all_files=False, just_launch=False,
                          default_andr_sdk='29', timeout=240):
    # Execute `tns run` and wait until logs are OK
    result = Tns.run(app_name=app_name, platform=platform, emulator=True, wait=False, bundle=bundle, hmr=hmr,
                     release=release, uglify=uglify, aot=aot, snapshot=snapshot, sync_all_files=sync_all_files,
                     just_launch=just_launch)

    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.UNKNOWN, bundle=bundle,
                                   hmr=hmr, instrumented=instrumented, device=device, release=release,
                                   snapshot=snapshot)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=timeout)

    # Verify it looks properly
    device.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
    device.wait_for_text(text=Changes.JSHelloWord.XML.old_text)
    blue_count = device.get_pixels_by_color(color=Colors.LIGHT_BLUE)
    assert blue_count > 100, 'Failed to find blue color on {0}'.format(device.name)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png')
    device.get_screen(path=initial_state)
    if platform == Platform.ANDROID:
        # Verify android sdk the app is built with
        if release:
            apk_path = TnsPaths.get_apk_path(app_name=app_name, release=True)
        else:
            apk_path = TnsPaths.get_apk_path(app_name=app_name, release=False)
        TnsAssert.string_in_android_manifest(apk_path, 'compileSdkVersion="{0}"'.format(default_andr_sdk))
    if snapshot and Settings.HOST_OS != OSType.WINDOWS:
        TnsAssert.snapshot_build(TnsPaths.get_apk_path(app_name=app_name, release=True), Settings.TEST_OUT_TEMP)
    return result
 def test_13_get_run_messages_sync_js_bundle_uglify(self):
     logs = TnsLogs.run_messages(app_name=Settings.AppName.DEFAULT,
                                 platform=Platform.ANDROID,
                                 run_type=RunType.INCREMENTAL,
                                 file_name='main-view-model.js',
                                 bundle=True,
                                 uglify=True,
                                 hmr=False,
                                 device=Device(id='123',
                                               name='Emu',
                                               type=DeviceType.EMU,
                                               version=4.4,
                                               model=None))
     assert 'Skipping prepare.' not in logs
     assert 'File change detected.' in logs
     assert 'main-view-model.js' in logs
     assert 'Webpack compilation complete.' in logs
     assert 'Successfully transferred bundle.js' in logs
     assert 'Successfully transferred vendor.js' in logs
     assert 'Restarting application on device' in logs
     assert 'Successfully synced application org.nativescript.TestApp on device' in logs
     assert 'ActivityManager: Start proc' in logs
     assert 'activity org.nativescript.TestApp/com.tns.NativeScriptActivity' in logs
     assert 'Refreshing application on device' not in logs
     assert 'hot-update.json on device' not in logs
예제 #8
0
    def test_110_tns_run_android_release(self):
        # Run app and verify on device
        result = Tns.run_android(app_name=self.app_name, release=True, verify=True, emulator=True)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.FIRST_TIME, device=self.emu)
        strings.remove('Restarting application on device')
        strings.remove('Successfully synced application org.nativescript.TestApp on device')
        # Verify https://github.com/NativeScript/android-runtime/issues/1024
        not_existing_strings = ['JS:']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings, timeout=120)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        self.emu.wait_for_text(text=Changes.JSHelloWord.XML.old_text)
        blue_count = self.emu.get_pixels_by_color(color=Colors.LIGHT_BLUE)
        assert blue_count > 100, 'Failed to find blue color on {0}'.format(self.emu.name)

        Tns.kill()
        # Make changes in js, css and xml files
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.XML)
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.CSS)

        # Run with --release again and verify changes are deployed on device
        result = Tns.run_android(app_name=self.app_name, release=True, verify=True, emulator=True)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
        self.emu.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
        self.emu.wait_for_color(color=Colors.LIGHT_BLUE, pixel_count=blue_count * 2, delta=25)
예제 #9
0
    def test_120_tns_run_ios_just_launch(self):
        """
        This test verify following things:
        1. `--justlaunch` option release the console.
        2. Full rebuild and prepare are not trigerred if no changes are done.
        3. Incremental prepare is triggered if js, xml and css files are changed.
        """
        # Run app with --justlaunch and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim, just_launch=True)
        # On some machines it takes time for thr process to die
        time.sleep(5)
        assert not Process.is_running_by_commandline(Settings.Executables.TNS)

        # Execute run with --justlaunch again and verify no rebuild is triggered
        result = Tns.run_ios(app_name=self.app_name, emulator=True, just_launch=True)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.JUST_LAUNCH, device=self.sim, just_launch=True)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Make changes in js, css and xml files
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.XML)
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.CSS)

        # Execute run with --justlaunch again and verify prepare is triggered
        result = Tns.run_ios(app_name=self.app_name, emulator=True, just_launch=True)
        strings = ['Project successfully prepared', 'Webpack compilation complete']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
예제 #10
0
def run_demo_app(app_name, app_type, plugin_name, platform, hmr=True):
    """
        Change plugin in src and verify demo is updated.
        :param app_name: The name of the App. for example: demo, demo-angular, demo-vue
        :param app_type: Application type: js,ts,ng,vue.
        :param plugin_name: The name of the plugin. for example: nativescript-datetimepicker
        :param platform: The platform type Platform.IOS or Platform.ANDROID
        :param hmr: HMR flag boolean.
    """
    # Navigate to demo folder and run the demo app
    app_folder = 'demo'
    if app_type == AppType.NG:
        app_folder = 'demo-angular'
        app_name = app_name + 'ng'
    elif app_type == AppType.VUE:
        app_folder = 'demo-vue'
        app_name = app_name + 'vue'
    app_path = os.path.join(Settings.TEST_SUT_HOME, plugin_name, app_folder)

    if Settings.HOST_OS is OSType.OSX:
        Tns.platform_add_ios(app_name=app_path, framework_path=Settings.IOS.FRAMEWORK_PATH)
    else:
        Tns.platform_add_android(app_name=app_path, framework_path=Settings.Android.FRAMEWORK_PATH)

    App.update(app_path)

    result = Tns.run(app_name=app_path, platform=platform, emulator=True, wait=False, hmr=hmr)
    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.FULL, hmr=hmr,
                                   app_type=app_type)

    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)
    return result
예제 #11
0
 def test_18_get_run_messages_sync_ts(self):
     logs = TnsLogs.run_messages(app_name=Settings.AppName.DEFAULT,
                                 platform=Platform.ANDROID,
                                 run_type=RunType.INCREMENTAL,
                                 file_name='main-view-model.ts',
                                 bundle=False,
                                 hmr=False)
     assert 'Skipping prepare.' not in logs
     assert 'Successfully transferred main-view-model.js' in logs
예제 #12
0
    def test_115_tns_run_android_add_remove_files_and_folders(self):
        """
        Add/delete files and folders should be synced properly
        """
        # Run app and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu)

        # Add new file
        # To verify that file is synced on device we have to refer some function
        # from it and verify it is executed. We will use console.log
        app_folder = os.path.join(self.source_project_dir, 'app')
        new_file = os.path.join(app_folder, 'test.js')
        renamed_file = os.path.join(app_folder, 'test_2.js')
        app_js_file = os.path.join(app_folder, 'app.js')
        File.write(new_file, "console.log('test.js synced!!!');")
        File.append(app_js_file, "require('./test.js');")
        strings = ["JS: test.js synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Rename file

        os.rename(new_file, renamed_file)
        File.replace(renamed_file, 'test.js', 'renamed file')
        time.sleep(1)
        File.replace(app_js_file, 'test.js', 'test_2.js')
        strings = ["JS: renamed file synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Delete file
        File.delete(renamed_file)
        strings = ["Module build failed", "Error: ENOENT: no such file or directory",
                   'Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text='Exception')

        File.replace(app_js_file, "require('./test_2.js');", ' ')
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       device=self.emu, run_type=RunType.UNKNOWN)
        not_existing_strings = ['12345']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Add folder
        folder_name = os.path.join(app_folder, 'test_folder')
        new_file = os.path.join(folder_name, 'test_in_folder.js')
        Folder.create(folder_name)
        File.write(new_file, "console.log('test_in_folder.js synced!!!');")
        File.append(app_js_file, "require('./test_folder/test_in_folder.js');")
        strings = ["JS: test_in_folder.js synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Delete folder
        Folder.clean(folder_name)
        strings = ["Module build failed", "Error: ENOENT: no such file or directory"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text='Exception')
예제 #13
0
 def test_15_get_run_messages_sync_xml_bundle_no_hmr(self):
     logs = TnsLogs.run_messages(app_name=Settings.AppName.DEFAULT,
                                 platform=Platform.ANDROID,
                                 run_type=RunType.INCREMENTAL,
                                 bundle=True,
                                 hmr=False,
                                 file_name='main-page.xml',
                                 instrumented=True)
     assert 'Refreshing application on device' not in logs
     assert 'Restarting application on device' in logs
예제 #14
0
    def test_105_tns_run_android_changes_in_app_resounces(self):
        """
            Make changes in AndroidManifest.xml in App_Resources and verify this triggers rebuild of the app.
            Verify that when run on android changes in AppResources/iOS do not trigger rebuild
        """
        # Run app and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu)

        # Make changes in AndroidManifest.xml
        manifest_path = os.path.join(self.app_resources_android, 'src', 'main', 'AndroidManifest.xml')
        File.replace(manifest_path, 'largeScreens="true"', 'largeScreens="false"')

        # Verify rebuild is triggered and app is synced
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.UNKNOWN, device=self.emu)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=120)

        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        self.emu.wait_for_text(text=Changes.JSHelloWord.XML.old_text)

        # Make changes in AppResources/Android
        File.copy(os.path.join(Settings.TEST_RUN_HOME, 'assets', 'resources', 'android', 'drawable-hdpi', 'icon.png'),
                  os.path.join(self.app_resources_android, 'src', 'main', 'res', 'drawable-hdpi', 'icon.png'))
        # Verify only build for android is triggered
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.UNKNOWN, device=self.emu)
        not_existing_strings = ['Xcode build']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings, timeout=120)

        # https://github.com/NativeScript/nativescript-cli/issues/3658
        Tns.kill()
        # Make changes in AppResources/iOS
        File.copy(os.path.join('assets', 'resources', 'ios', 'Default.png'),
                  os.path.join(self.app_resources_ios, 'Assets.xcassets', 'LaunchScreen.Center.imageset',
                               'Default.png'))
        result = Tns.run_android(app_name=self.app_name, device=self.emu.id)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.UNKNOWN, device=self.emu)
        # Verify no build is triggered
        not_existing_strings = ['Xcode build', 'Gradle build']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings)
예제 #15
0
    def test_115_tns_run_ios_add_remove_files_and_folders(self):
        """
        Add/delete files and folders should be synced properly
        """
        # Run app and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim)

        # Add new file
        # To verify that file is synced on device we have to refer some function
        # from it and verify it is executed. We will use console.log
        app_folder = os.path.join(self.source_project_dir, 'app')
        new_file = os.path.join(app_folder, 'test.js')
        renamed_file = os.path.join(app_folder, 'test_2.js')
        app_js_file = os.path.join(app_folder, 'main-view-model.js')
        File.write(new_file, "console.log('test.js synced!!!');")
        File.append(app_js_file, "require('./test.js');")
        strings = ["test.js synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Rename file
        os.rename(new_file, renamed_file)
        File.replace(renamed_file, 'test.js', 'renamed file')
        time.sleep(1)
        File.replace(app_js_file, 'test.js', 'test_2.js')
        strings = ["renamed file synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Delete file
        File.delete(renamed_file)
        strings = ["Module build failed: Error: ENOENT", "NativeScript debugger detached"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        File.replace(app_js_file, "require('./test_2.js');", ' ')
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       device=self.sim, run_type=RunType.UNKNOWN)
        not_existing_strings = ['123']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Add folder
        folder_name = os.path.join(app_folder, 'test_folder')
        new_file = os.path.join(folder_name, 'test_in_folder.js')
        Folder.create(folder_name)
        File.write(new_file, "console.log('test_in_folder.js synced!!!');")
        File.append(app_js_file, "require('./test_folder/test_in_folder.js');")
        strings = ["test_in_folder.js synced!!!"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Delete folder
        Folder.clean(folder_name)
        strings = ["Module build failed: Error: ENOENT"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
예제 #16
0
    def test_105_tns_run_ios_changes_in_app_resounces(self):
        """
            Make changes in AndroidManifest.xml in App_Resources and verify this triggers rebuild of the app.
            Verify that when run on android changes in AppResources/iOS do not trigger rebuild
        """
        # Run app and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim)

        # Make changes in app resources, add aditional icon
        File.copy(os.path.join(Settings.TEST_RUN_HOME, 'assets', 'resources', 'ios', 'Default.png'),
                  os.path.join(self.app_resources_ios, 'Assets.xcassets', 'icon.png'))

        # Verify rebuild is triggered and app is synced
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.UNKNOWN, device=self.sim)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        self.sim.wait_for_text(text=Changes.JSHelloWord.XML.old_text)

        # Make changes in AppResources/IOS
        File.copy(os.path.join(os.path.join(Settings.TEST_RUN_HOME, 'assets', 'resources', 'ios', 'Default.png')),
                  os.path.join(self.app_resources_ios, 'Assets.xcassets', 'AppIcon.appiconset', 'icon-20.png'))
        # Verify only build for ios is triggered
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.UNKNOWN, device=self.sim)
        not_existing_strings = ['Gradle build']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings)

        # https://github.com/NativeScript/nativescript-cli/issues/3658
        Tns.kill()
        # Make changes in AppResources/Android
        File.copy(os.path.join(Settings.TEST_RUN_HOME, 'assets', 'resources', 'android', 'drawable-hdpi', 'icon.png'),
                  os.path.join(self.app_resources_android, 'src', 'main', 'res', 'drawable-hdpi', 'icon.png'))
        result = Tns.run_ios(app_name=self.app_name, emulator=True, provision=False)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.UNKNOWN, device=self.sim)
        # Verify no build is triggered
        not_existing_strings = ['Xcode build', 'Gradle build']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
                             not_existing_string_list=not_existing_strings)
예제 #17
0
    def test_100_run_android_break_and_fix_app(self):
        """
            Make changes in xml that break the app and then changes thet fix the app.
            Add/remove js files thst break the app and then fix it. Verify recovery.
        """
        # Run app and verify on device
        result = run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu)

        # Make changes in xml that will break the app
        Sync.replace(self.app_name, Changes.JSHelloWord.XML_INVALID)
        strings = ['main-page.xml', 'Error: Building UI from XML']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text='Exception')

        # Revert changes
        Sync.revert(self.app_name, Changes.JSHelloWord.XML_INVALID)

        # Verify app is synced and recovered
        strings = ['Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        assert not self.emu.is_text_visible(text='Exception')

        # Delete app.js and verify app crash with error activity dialog
        app_js_origin_path = os.path.join(self.source_project_dir, 'app', 'app.js')
        app_js_backup_path = os.path.join(self.target_project_dir, 'app', 'app.js')
        File.delete(app_js_origin_path)

        # Verify app is synced
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       device=self.emu, run_type=RunType.UNKNOWN)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text='Exception')

        # Restore app.js and verify app is synced and recovered
        File.copy(app_js_backup_path, app_js_origin_path)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.UNKNOWN, device=self.emu)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
        assert not self.emu.is_text_visible(text='Exception')
예제 #18
0
    def test_310_tns_run_ios_sync_changes_in_node_modules(self):
        """
        Verify changes in node_modules are synced during run command
        """
        # Run the project
        result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim, sync_all_files=True)

        # Make code changes in tns-core-modules verify livesync is triggered
        Sync.replace(self.app_name, Changes.NodeModules.TNS_MODULES)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.INCREMENTAL, device=self.emu, file_name='application-common.js')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
예제 #19
0
    def test_19_get_run_messages_incremental_prepare(self):
        logs = TnsLogs.run_messages(app_name=Settings.AppName.DEFAULT,
                                    platform=Platform.ANDROID,
                                    run_type=RunType.INCREMENTAL,
                                    bundle=False,
                                    hmr=False,
                                    file_name=os.path.basename(
                                        Changes.JSHelloWord.JS.file_path))

        assert 'Building project...' not in logs
        assert 'Project successfully built.' not in logs
        assert 'Skipping prepare.' not in logs
        assert 'Successfully transferred main-view-model.js' in logs
예제 #20
0
def run_hello_world_ng(app_name,
                       platform,
                       device,
                       bundle=True,
                       uglify=False,
                       aot=False,
                       hmr=True,
                       instrumented=True,
                       release=False,
                       snapshot=False):
    # Define if it should be executed on device or emulator
    emulator = True
    device_id = None
    if device.type == DeviceType.ANDROID or device.type == DeviceType.IOS:
        emulator = False
        device_id = device.id

    # Execute tns run command
    result = Tns.run(app_name=app_name,
                     platform=platform,
                     emulator=emulator,
                     bundle=bundle,
                     aot=aot,
                     uglify=uglify,
                     hmr=hmr,
                     release=release,
                     snapshot=snapshot,
                     device=device_id)

    # Check logs
    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.UNKNOWN,
                                   bundle=bundle,
                                   release=release,
                                   hmr=hmr,
                                   instrumented=instrumented,
                                   app_type=AppType.NG,
                                   device=device,
                                   snapshot=snapshot)
    TnsLogs.wait_for_log(log_file=result.log_file,
                         string_list=strings,
                         timeout=300)

    # Verify it looks properly
    device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text, timeout=180)
    device.wait_for_main_color(color=Colors.WHITE)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name,
                                 'initial_state.png')
    device.get_screen(path=initial_state)
    return result
예제 #21
0
    def test_290_tns_run_android_should_refresh_images(self):
        """
        Test for https://github.com/NativeScript/nativescript-cli/issues/2981
        """
        # Update app to reference picture from app folder
        source_file = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'issues', 'nativescript-cli-2981', 'main-page.xml')
        dest_file = os.path.join(self.app_path, 'app', 'main-page.xml')
        File.copy(source_file, dest_file)

        # Copy image file to app folder
        source_file = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'resources', 'star.png')
        dest_file = os.path.join(self.app_path, 'app', 'test.png')
        File.copy(source_file, dest_file)
        result = Tns.run_android(app_name=self.app_name, verify=True, device=self.emu.id)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.FIRST_TIME, device=self.emu)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
        yellow_count = self.emu.get_pixels_by_color(color=Colors.YELLOW_ICON)
        green_count = self.emu.get_pixels_by_color(color=Colors.GREEN_ICON)

        # Verify the referenced image file is displayed on device screen
        assert yellow_count > 0, 'Failed to find yellow color on {0}'.format(self.emu.name)
        assert green_count == 0, 'Found green color on {0}'.format(self.emu.name)

        # Change the image file
        source_file = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'resources', 'android',
                                   'drawable-hdpi', 'background.png')
        dest_file = os.path.join(self.app_path, 'app', 'test.png')
        File.copy(source_file, dest_file)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.UNKNOWN, device=self.emu)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Verify the new image is synced and displayed on device screen
        yellow_count = self.emu.get_pixels_by_color(color=Colors.YELLOW_ICON)
        green_count = self.emu.get_pixels_by_color(color=Colors.GREEN_ICON)
        assert green_count > 0, 'Failed to find green color on {0}'.format(self.emu.name)
        assert yellow_count == 0, 'Found yellow color on {0}'.format(self.emu.name)
예제 #22
0
    def test_300_tns_run_on_specific_device(self):
        Adb.open_home(device_id=self.emu.id)
        Adb.open_home(device_id=self.android_device.id)
        result = Tns.run(app_name=self.app_name, platform=Platform.ANDROID, device=self.android_device.id)
        # Wait for logs
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID, run_type=RunType.UNKNOWN)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)

        # Verify it looks properly on device
        self.android_device.wait_for_text(text=Changes.JSHelloWord.JS.old_text)

        # Verify not working on emulator
        assert Changes.JSHelloWord.JS.old_text not in self.emu.get_text()
        assert self.emu.id not in File.read(result.log_file)
예제 #23
0
 def test_12_get_run_messages_sync_js_bundle(self):
     logs = TnsLogs.run_messages(app_name=Settings.AppName.DEFAULT,
                                 platform=Platform.ANDROID,
                                 run_type=RunType.INCREMENTAL,
                                 bundle=True,
                                 hmr=False,
                                 file_name='main-view-model.js')
     assert 'File change detected.' in logs
     assert 'main-view-model.js' in logs
     assert 'Webpack compilation complete.' in logs
     assert 'Successfully transferred bundle.js' in logs
     assert 'Successfully transferred vendor.js' not in logs
     assert 'Restarting application on device' in logs
     assert 'Successfully synced application org.nativescript.TestApp on device' in logs
     assert 'Refreshing application on device' not in logs
     assert 'hot-update.json on device' not in logs
예제 #24
0
 def test_11_get_run_messages_sync_js(self):
     logs = TnsLogs.run_messages(app_name=Settings.AppName.DEFAULT,
                                 platform=Platform.ANDROID,
                                 run_type=RunType.INCREMENTAL,
                                 file_name='main-view-model.js',
                                 bundle=False,
                                 hmr=False,
                                 device=Device(id='123',
                                               name='Emu',
                                               type=DeviceType.EMU,
                                               version=8.0))
     assert 'Successfully transferred main-view-model.js' in logs
     assert 'Restarting application on device' in logs
     assert 'Successfully synced application org.nativescript.TestApp on device' in logs
     assert 'ActivityManager: Start proc' not in logs
     assert 'activity org.nativescript.TestApp/com.tns.NativeScriptActivity' not in logs
예제 #25
0
 def test_325_tns_run_ios_should_start_simulator(self):
     """
     `tns run android` should start emulator if device is not connected.
     """
     # Run the test only if there are no connected devices
     conected_devices = DeviceManager.get_devices(device_type=DeviceType.IOS)
     if conected_devices.__len__() == 0:
         DeviceManager.Simulator.stop()
         result = Tns.run_ios(self.app_name)
         strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                        run_type=RunType.FULL, device=self.sim)
         TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=120)
         DeviceManager.Simulator.stop()
         DeviceManager.Simulator.ensure_available(Settings.Simulators.DEFAULT)
     else:
         raise nose.SkipTest('This test is not valid when devices are connected.')
    def workflow(app_name, device, platform, shared):
        # Create an app
        app_path = TnsPaths.get_app_path(app_name=app_name)
        Folder.clean(app_path)
        NG.new(collection=NS_SCHEMATICS, project=app_name, shared=shared)
        TnsAssert.created(app_name=app_name, app_data=None)

        # Run app initially
        text = 'TAP'
        if shared:
            text = 'Welcome to'
        result = Tns.run(app_name=app_name, platform=platform, emulator=True, hmr=True)
        strings = TnsLogs.run_messages(app_name=app_name, platform=platform, bundle=True, hmr=True, app_type=AppType.NG)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
        device.wait_for_text(text=text)

        # Generate module and component
        NG.exec_command(command='g m module-test', cwd=app_path)
        NG.exec_command(command='g c module-test/component-test', cwd=app_path)

        # Update app.modules.ts
        app_module_name = 'app.module.ts'
        app_module_path = os.path.join(app_path, 'app', app_module_name)
        if shared:
            app_module_name = 'app.module.tns.ts'
            app_module_path = os.path.join(app_path, 'src', 'app', app_module_name)
        old_string = "import { HomeComponent } from './home/home.component';"
        new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';"
        File.replace(path=app_module_path, old_string=old_string, new_string=new_string)
        File.replace(path=app_module_path, old_string='HomeComponent,', new_string='ComponentTestComponent,')

        # Update app-routing.module.ts
        app_routing_module_name = 'app-routing.module.ts'
        app_routing_module_path = os.path.join(app_path, 'app', app_routing_module_name)
        if shared:
            app_routing_module_name = 'app.routes.ts'
            app_routing_module_path = os.path.join(app_path, 'src', 'app', app_routing_module_name)
        old_string = "import { HomeComponent } from './home/home.component';"
        new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';"
        File.replace(path=app_routing_module_path, old_string=old_string, new_string=new_string)
        File.replace(path=app_routing_module_path, old_string='HomeComponent', new_string='ComponentTestComponent')

        # Verify app is updated
        logs = [app_module_name.replace('.tns', ''), app_routing_module_name.replace('.tns', ''),
                'Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs, timeout=120)
        device.wait_for_text(text='component-test works!')
예제 #27
0
 def test_14_get_run_messages_sync_js_hmr(self):
     logs = TnsLogs.run_messages(app_name=Settings.AppName.DEFAULT,
                                 platform=Platform.ANDROID,
                                 run_type=RunType.INCREMENTAL,
                                 file_name='main-view-model.js',
                                 hmr=True)
     assert 'Preparing project...' not in logs
     assert 'File change detected.' in logs
     assert 'main-view-model.js' in logs
     assert 'Webpack compilation complete.' in logs
     assert 'hot-update.json' in logs
     assert 'HMR: The following modules were updated:' in logs
     assert 'HMR: Successfully applied update with hmr hash' in logs
     assert 'Refreshing application on device' in logs
     assert 'Successfully synced application org.nativescript.TestApp on device' in logs
     assert 'Successfully transferred bundle.js on device' not in logs
     assert 'Restarting application on device' not in logs
def run_hello_world_js_ts(app_name,
                          platform,
                          device,
                          bundle=True,
                          hmr=True,
                          uglify=False,
                          aot=False,
                          snapshot=False,
                          instrumented=False,
                          sync_all_files=False,
                          just_launch=False):
    # Execute `tns run` and wait until logs are OK
    result = Tns.run(app_name=app_name,
                     platform=platform,
                     emulator=True,
                     wait=False,
                     bundle=bundle,
                     hmr=hmr,
                     uglify=uglify,
                     aot=aot,
                     snapshot=snapshot,
                     sync_all_files=sync_all_files,
                     just_launch=just_launch)
    __verify_snapshot_skipped(snapshot, result)

    strings = TnsLogs.run_messages(app_name=app_name,
                                   platform=platform,
                                   run_type=RunType.UNKNOWN,
                                   bundle=bundle,
                                   hmr=hmr,
                                   instrumented=instrumented,
                                   device=device)
    TnsLogs.wait_for_log(log_file=result.log_file,
                         string_list=strings,
                         timeout=240)

    # Verify it looks properly
    device.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
    device.wait_for_text(text=Changes.JSHelloWord.XML.old_text)
    blue_count = device.get_pixels_by_color(color=Colors.LIGHT_BLUE)
    assert blue_count > 100, 'Failed to find blue color on {0}'.format(
        device.name)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name,
                                 'initial_state.png')
    device.get_screen(path=initial_state)
    return result
예제 #29
0
    def test_315_tns_run_android_sync_changes_in_aar_files(self):
        """
        Livesync should sync aar file changes inside a plugin
        https://github.com/NativeScript/nativescript-cli/issues/3610
        """
        # Add plugin and run the project
        Tns.plugin_add('nativescript-camera', self.app_name)
        result = run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu)

        # Make  changes in nativescript-camera .aar file and  verify livesync is triggered
        new_aar = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'issues', 'nativescript-cli-3932',
                               'nativescript-ui-listview', 'platforms', 'android', 'TNSListView-release.aar')
        target_aar = os.path.join(self.app_name, 'node_modules', 'nativescript-camera', 'platforms', 'android')
        File.copy(new_aar, target_aar)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.ANDROID,
                                       run_type=RunType.UNKNOWN, device=self.emu)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=120)
        self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
예제 #30
0
    def test_345_tns_run_ios_source_code_in_ios_part_plugin(self):
        """
        https://github.com/NativeScript/nativescript-cli/issues/3650
        """
        # Add plugin with source code in iOS part of the plugin
        plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'plugins', 'sample-plugin', 'src')
        Tns.plugin_add(plugin_path, path=self.app_name, verify=True)

        # Call method from the source code of the plugin in main-view-model.js
        old_value = 'viewModel.counter = 42;'
        new_value = 'viewModel.counter = 42;\n var objTC = new TestClass();\n console.log(objTC.sayHey());'
        target_js = os.path.join(Settings.TEST_RUN_HOME, self.app_name, 'app', 'main-view-model.js')
        File.replace(target_js, old_value, new_value)
        result = Tns.run_ios(self.app_name, emulator=True)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.FIRST_TIME, device=self.sim)
        strings.append('Hey!')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Verify app looks correct inside simulator
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)