def __debug_sync_changes(self, platform, device): # Start debug and wait until app is deployed result = Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open sources tab and verify content is loaded self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) # Open JS file and place breakpoint on line 18 self.dev_tools.load_source_file("main-view-model.js") self.dev_tools.breakpoint(18) # Sync JS changes works fine until breakpoint is hit Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS) js_file_name = os.path.basename(Changes.JSHelloWord.JS.file_path) logs = [ js_file_name, 'Webpack build done!', 'Refreshing application', 'Successfully synced application' ] TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs) device.wait_for_text(text=Changes.JSHelloWord.JS.new_text, timeout=30) # Revert changes Sync.revert(app_name=self.app_name, change_set=Changes.JSHelloWord.JS) TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs) device.wait_for_text(text=Changes.JSHelloWord.JS.old_text, timeout=30) # Tap on TAP button in emulator and check it is hit device.click(text="TAP", case_sensitive=True) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=90) assert pause_element is not None, 'Failed to pause on breakpoint.' # Test for https://github.com/NativeScript/nativescript-cli/issues/4227 Sync.replace(app_name=self.app_name, change_set=self.xml_change) xml_file_name = os.path.basename(self.xml_change.file_path) logs = [ xml_file_name, 'Webpack build done!', 'Refreshing application', 'Successfully synced application' ] TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs) sleep(10) # Give it some more time to crash logs = File.read(result.log_file) assert 'Unable to apply changes' not in logs assert 'Stopping webpack watch' not in logs assert 'closed' not in logs assert 'detached' not in logs assert "did not start in time" not in logs # Resume execution self.dev_tools.continue_debug() device.wait_for_text( text='42 taps left', timeout=30) # We tapped but changes synced so number is restarted device.wait_for_text(text=self.xml_change.new_text, timeout=10) # Verify change applied during debug
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 setUp(self): TnsRunTest.setUp(self) Sync.revert(app_name=self.app_name, change_set=self.ts_change, fail_safe=True) Sync.revert(app_name=self.app_name, change_set=self.xml_change, fail_safe=True) self.chrome = Chrome()
def test_100_run_ios_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.IOS, self.sim) # 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) # 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.sim.wait_for_text(text=Changes.JSHelloWord.XML.old_text)
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')
def sync_hello_world_ng(app_name, platform, device, bundle=True, uglify=False, aot=False, hmr=True, instrumented=True): # 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, device=device_id, wait=False, bundle=bundle, aot=aot, uglify=uglify, hmr=hmr) # Check logs strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.UNKNOWN, bundle=bundle, hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) 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) 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) # Apply changes Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS) device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML) if platform == Platform.IOS: for number in ["10", "11"]: device.wait_for_text(text=number) else: for number in ["8", "9"]: device.wait_for_text(text=number) assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='items.component.html', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, aot=aot, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS) device.wait_for_main_color(color=Colors.DARK) if platform == Platform.IOS: for number in ["10", "1"]: device.wait_for_text(text=number) else: for number in ["8", "9"]: device.wait_for_text(text=number) assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) # Revert changes Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.HTML) device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='items.component.html', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, aot=aot, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.TS) device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text) device.wait_for_main_color(color=Colors.DARK) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.CSS) device.wait_for_main_color(color=Colors.WHITE) device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) # Assert final and initial states are same device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
def sync_master_detail_ng(app_name, platform, device, bundle=True, hmr=True, uglify=False, aot=False): run_master_detail_ng(app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr, uglify=uglify, aot=aot) # Edit TS file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.MasterDetailNG.TS) device.wait_for_text(text=Changes.MasterDetailNG.TS.new_text) # Edit HTML file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.MasterDetailNG.HTML) device.wait_for_text(text=Changes.MasterDetailNG.HTML.new_text) device.wait_for_text(text=Changes.MasterDetailNG.TS.new_text) # Edit common SCSS on root level change = Changes.MasterDetailNG.SCSS_ROOT_COMMON Sync.replace(app_name=app_name, change_set=change) assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) > 100), \ 'Common SCSS on root level not applied!' Log.info('Common SCSS on root level applied successfully!') # Edit platform specific SCSS on root level if platform == Platform.ANDROID: change = Changes.MasterDetailNG.SCSS_ROOT_ANDROID elif platform == Platform.IOS: change = Changes.MasterDetailNG.SCSS_ROOT_IOS else: raise ValueError('Invalid platform value!') Sync.replace(app_name=app_name, change_set=change) assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) > 100), \ 'Platform specific SCSS on root level not applied!' Log.info('Platform specific SCSS on root level applied successfully!') # Edit nested common SCSS change = Changes.MasterDetailNG.SCSS_NESTED_COMMON Sync.replace(app_name=app_name, change_set=change) assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) > 100), \ 'Common nested SCSS not applied!' Log.info('Common nested SCSS applied successfully!') # Edit nested platform specific SCSS if platform == Platform.ANDROID: change = Changes.MasterDetailNG.SCSS_NESTED_ANDROID elif platform == Platform.IOS: change = Changes.MasterDetailNG.SCSS_NESTED_IOS else: raise ValueError('Invalid platform value!') Sync.replace(app_name=app_name, change_set=change) assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) > 100), \ 'Platform specific nested SCSS not applied!' Log.info('Platform specific nested SCSS applied successfully!') # Revert TS file and verify changes are applied Sync.revert(app_name=app_name, change_set=Changes.MasterDetailNG.TS) device.wait_for_text(text=Changes.MasterDetailNG.TS.old_text, timeout=120) device.wait_for_text(text=Changes.MasterDetailNG.HTML.new_text) # Revert HTML file and verify changes are applied Sync.revert(app_name=app_name, change_set=Changes.MasterDetailNG.HTML) device.wait_for_text(text=Changes.MasterDetailNG.HTML.old_text, timeout=120) device.wait_for_text(text=Changes.MasterDetailNG.TS.old_text) # Revert common SCSS on root level change = Changes.MasterDetailNG.SCSS_ROOT_COMMON Sync.revert(app_name=app_name, change_set=change) assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) < 100), \ 'Common SCSS on root level not reverted!' Log.info('Common SCSS on root level reverted successfully!') # Revert platform specific SCSS on root level if platform == Platform.ANDROID: change = Changes.MasterDetailNG.SCSS_ROOT_ANDROID elif platform == Platform.IOS: change = Changes.MasterDetailNG.SCSS_ROOT_IOS else: raise ValueError('Invalid platform value!') Sync.revert(app_name=app_name, change_set=change) assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) < 100), \ 'Platform specific SCSS on root level not reverted!' Log.info('Platform specific SCSS on root level reverted successfully!') # Revert nested common SCSS change = Changes.MasterDetailNG.SCSS_NESTED_COMMON Sync.revert(app_name=app_name, change_set=change) assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) < 100), \ 'Common SCSS on root level not applied!' Log.info('Platform specific SCSS on root level reverted successfully!') # Revert nested platform specific SCSS if platform == Platform.ANDROID: change = Changes.MasterDetailNG.SCSS_NESTED_ANDROID elif platform == Platform.IOS: change = Changes.MasterDetailNG.SCSS_NESTED_IOS else: raise ValueError('Invalid platform value!') Sync.revert(app_name=app_name, change_set=change) assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) < 100), \ 'Platform specific SCSS on root level not applied!' # Assert final and initial states are same initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png') device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
def __sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=True, hmr=True, uglify=False, aot=False, snapshot=False, instrumented=False): # Set changes js_file = os.path.basename(Changes.JSHelloWord.JS.file_path) if app_type == AppType.JS: js_change = Changes.JSHelloWord.JS xml_change = Changes.JSHelloWord.XML css_change = Changes.JSHelloWord.CSS elif app_type == AppType.TS: js_file = os.path.basename(Changes.TSHelloWord.TS.file_path) js_change = Changes.TSHelloWord.TS xml_change = Changes.TSHelloWord.XML css_change = Changes.TSHelloWord.CSS else: raise ValueError('Invalid app_type value.') # 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) __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=js_change.old_text) device.wait_for_text(text=xml_change.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) # Edit JS file and verify changes are applied Sync.replace(app_name=app_name, change_set=js_change) device.wait_for_text(text=js_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name=js_file, instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) # Edit XML file and verify changes are applied Sync.replace(app_name=app_name, change_set=xml_change) device.wait_for_text(text=xml_change.new_text) device.wait_for_text(text=js_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='main-page.xml', instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) # Edit CSS file and verify changes are applied Sync.replace(app_name=app_name, change_set=css_change) device.wait_for_color(color=Colors.LIGHT_BLUE, pixel_count=blue_count * 2, delta=25) device.wait_for_text(text=xml_change.new_text) device.wait_for_text(text=js_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='app.css', instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) # Revert all the changes Sync.revert(app_name=app_name, change_set=js_change) device.wait_for_text(text=js_change.old_text) device.wait_for_text(text=xml_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name=js_file, instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) Sync.revert(app_name=app_name, change_set=xml_change) device.wait_for_text(text=xml_change.old_text) device.wait_for_text(text=js_change.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='main-page.xml', instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) Sync.revert(app_name=app_name, change_set=css_change) device.wait_for_color(color=Colors.LIGHT_BLUE, pixel_count=blue_count) device.wait_for_text(text=xml_change.old_text) device.wait_for_text(text=js_change.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='app.css', instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) # Assert final and initial states are same device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
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()
def __sync_tab_navigation_js_ts(app_type, app_name, platform, device, release=False, bundle=True, hmr=True, uglify=False, aot=False, snapshot=False, instrumented=False): # Set changes js_file = os.path.basename(Changes.JSTabNavigation.JS.file_path) if app_type == AppType.JS: js_change = Changes.JSTabNavigation.JS xml_change = Changes.JSTabNavigation.XML scss_change = Changes.JSTabNavigation.SCSS_VARIABLES scss_android = Changes.JSTabNavigation.SCSS_ROOT_ANDROID scss_ios = Changes.JSTabNavigation.SCSS_ROOT_IOS elif app_type == AppType.TS: js_file = os.path.basename(Changes.TSTabNavigation.TS.file_path) js_change = Changes.TSTabNavigation.TS xml_change = Changes.TSTabNavigation.XML scss_change = Changes.TSTabNavigation.SCSS_VARIABLES scss_android = Changes.TSTabNavigation.SCSS_ROOT_ANDROID scss_ios = Changes.TSTabNavigation.SCSS_ROOT_IOS else: raise ValueError('Invalid app_type value.') # 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, release=release) 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=js_change.old_text) device.wait_for_text(text=xml_change.old_text) color_count = device.get_pixels_by_color(color=Colors.ACCENT_DARK) assert color_count > 100, 'Failed to find ACCENT_DARK 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) # Edit JS file and verify changes are applied Sync.replace(app_name=app_name, change_set=js_change) device.wait_for_text(text=js_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name=js_file, device=device, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) # Edit XML file and verify changes are applied Sync.replace(app_name=app_name, change_set=xml_change) device.wait_for_text(text=xml_change.new_text) device.wait_for_text(text=js_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='home-items-page.xml', device=device, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) # Edit SCSS file and verify changes are applied # https://github.com/NativeScript/NativeScript/issues/6953 # Navigate to Browse tab and verify when scss is synced navigation is preserved device.click(text="Browse") assert not device.is_text_visible(text=js_change.new_text) Sync.replace(app_name=app_name, change_set=scss_change) assert Wait.until(lambda: device.get_pixels_by_color(color=Colors.RED) > 100), \ 'SCSS not applied!' # Verify navigation is preserved and you are still on Browse tab assert device.is_text_visible(text="Browse page content goes here"), \ 'Navigation is not preserved when syncing scss/css file!' # Edit platform specific SCSS on root level if platform == Platform.ANDROID: change = scss_android elif platform == Platform.IOS: change = scss_ios else: raise ValueError('Invalid platform value!') Sync.replace(app_name=app_name, change_set=change) assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) > 100), \ 'Platform specific SCSS on root level not applied!' Log.info('Platform specific SCSS on root level applied successfully!') # Revert all the changes in app # Navigate to Home tab again device.click(text="Home") Sync.revert(app_name=app_name, change_set=js_change) device.wait_for_text(text=js_change.old_text) device.wait_for_text(text=xml_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name=js_file, device=device, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) Sync.revert(app_name=app_name, change_set=xml_change) device.wait_for_text(text=xml_change.old_text) device.wait_for_text(text=js_change.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='home-items-page.xml', device=device, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) Sync.revert(app_name=app_name, change_set=scss_change) assert Wait.until(lambda: device.get_pixels_by_color(color=Colors.RED) < 100), \ 'SCSS not applied!' device.wait_for_text(text=xml_change.old_text) device.wait_for_text(text=js_change.old_text) Sync.revert(app_name=app_name, change_set=change) assert Wait.until(lambda: device.get_pixels_by_color(color=change.new_color) < 100), \ 'Platform specific SCSS on root level not reverted!' Log.info('Platform specific SCSS on root level reverted successfully!') # Assert final and initial states are same device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
def __workflow(preview, app_name, platform, device, bundle=True, hmr=True): # Execute tns command if preview: result = __preview_vue( app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr) else: result = __run_vue( app_name=app_name, platform=platform, bundle=bundle, hmr=hmr) if preview: Log.info('Skip logs checks.') else: strings = TnsLogs.run_messages( app_name=app_name, platform=platform, run_type=RunType.FULL, bundle=bundle, hmr=hmr, app_type=AppType.VUE) TnsLogs.wait_for_log( log_file=result.log_file, string_list=strings, timeout=240) # Verify it looks properly device.wait_for_text( text=Changes.BlankVue.VUE_SCRIPT.old_text, timeout=120) device.wait_for_text( text=Changes.BlankVue.VUE_TEMPLATE.old_text, timeout=120) initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png') device.get_screen(path=initial_state) # Edit script in .vue file Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_SCRIPT) if preview: Log.info('Skip logs checks.') else: strings = TnsLogs.run_messages( app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue') TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) device.wait_for_text(text=Changes.BlankVue.VUE_SCRIPT.new_text) # Edit template in .vue file Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_TEMPLATE) if preview: Log.info('Skip logs checks.') else: strings = TnsLogs.run_messages( app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue') TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) device.wait_for_text(text=Changes.BlankVue.VUE_TEMPLATE.new_text) # Edit styling in .vue file Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_STYLE) if preview: Log.info('Skip logs checks.') else: strings = TnsLogs.run_messages( app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.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) > 100) assert style_applied, 'Failed to sync changes in style.' # Revert script in .vue file Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_SCRIPT) if preview: Log.info('Skip logs checks.') else: strings = TnsLogs.run_messages( app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue') TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) device.wait_for_text(text=Changes.BlankVue.VUE_SCRIPT.old_text) # Revert template in .vue file Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_TEMPLATE) if preview: Log.info('Skip logs checks.') else: strings = TnsLogs.run_messages( app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue') TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) device.wait_for_text(text=Changes.BlankVue.VUE_TEMPLATE.old_text) # Revert styling in .vue file Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_STYLE) if preview: Log.info('Skip logs checks.') else: strings = TnsLogs.run_messages( app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue') TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) if hmr: Log.info( 'Skip next steps because of https://github.com/nativescript-vue/nativescript-vue/issues/425' ) else: style_applied = Wait.until(lambda: device.get_pixels_by_color( Colors.RED) == 0) assert style_applied, 'Failed to sync changes in style.' # Assert final and initial states are same device.screen_match( expected_image=initial_state, tolerance=1.0, timeout=30)
def __sync_tab_navigation_js_ts(app_type, app_name, platform, device, release=False, bundle=True, hmr=True, uglify=False, aot=False, snapshot=False, instrumented=False): # Set changes js_file = os.path.basename(Changes.JSTabNavigation.JS.file_path) if app_type == AppType.JS: js_change = Changes.JSTabNavigation.JS xml_change = Changes.JSTabNavigation.XML scss_change = Changes.JSTabNavigation.SCSS_VARIABLES elif app_type == AppType.TS: js_file = os.path.basename(Changes.TSTabNavigation.TS.file_path) js_change = Changes.TSTabNavigation.TS xml_change = Changes.TSTabNavigation.XML scss_change = Changes.TSTabNavigation.SCSS_VARIABLES else: raise ValueError('Invalid app_type value.') # 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, release=release) 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=js_change.old_text) device.wait_for_text(text=xml_change.old_text) color_count = device.get_pixels_by_color(color=Colors.ACCENT_DARK) assert color_count > 100, 'Failed to find ACCENT_DARK 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) # Edit JS file and verify changes are applied Sync.replace(app_name=app_name, change_set=js_change) device.wait_for_text(text=js_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name=js_file, device=device, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) # Edit XML file and verify changes are applied Sync.replace(app_name=app_name, change_set=xml_change) device.wait_for_text(text=xml_change.new_text) device.wait_for_text(text=js_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='home-items-page.xml', device=device, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) # Edit SCSS file and verify changes are applied Sync.replace(app_name=app_name, change_set=scss_change) assert Wait.until(lambda: device.get_pixels_by_color(color=Colors.RED) > 100), \ 'Platform specific SCSS not applied!' device.wait_for_text(text=xml_change.new_text) device.wait_for_text(text=js_change.new_text) # Revert all the changes in app Sync.revert(app_name=app_name, change_set=js_change) device.wait_for_text(text=js_change.old_text) device.wait_for_text(text=xml_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name=js_file, device=device, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) Sync.revert(app_name=app_name, change_set=xml_change) device.wait_for_text(text=xml_change.old_text) device.wait_for_text(text=js_change.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='home-items-page.xml', device=device, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) Sync.revert(app_name=app_name, change_set=scss_change) assert Wait.until(lambda: device.get_pixels_by_color(color=Colors.ACCENT_DARK) > 100), \ 'Platform specific SCSS not applied!' device.wait_for_text(text=xml_change.old_text) device.wait_for_text(text=js_change.old_text) # Assert final and initial states are same device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
def sync_hello_world_ng(app_name, platform, device, bundle=True, uglify=False, aot=False, hmr=True, instrumented=True): result = run_hello_world_ng(app_name=app_name, platform=platform, device=device, uglify=uglify, aot=aot, hmr=hmr) # Verify that application is not restarted on file changes when hmr=true if hmr and Settings.HOST_OS != OSType.WINDOWS: not_existing_string_list = ['Restarting application'] else: not_existing_string_list = None # Apply changes Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS) device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML) if platform == Platform.IOS: for number in ["10", "11"]: device.wait_for_text(text=number) else: for number in ["8", "9"]: device.wait_for_text(text=number) assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='items.component.html', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, aot=aot, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS) if platform == Platform.IOS: for number in ["10", "1"]: device.wait_for_text(text=number) else: for number in ["8", "9"]: device.wait_for_text(text=number) assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) assert Wait.until(lambda: device.get_pixels_by_color(color=Changes.NGHelloWorld.CSS.new_color) > 100), \ 'CSS on root level not applied!' Log.info('CSS on root level applied successfully!') # Revert changes Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.HTML) device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='items.component.html', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, aot=aot, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.TS) device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.CSS) device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) assert Wait.until(lambda: device.get_pixels_by_color(color=Changes.NGHelloWorld.CSS.new_color) < 100), \ 'CSS on root level not applied!' Log.info('CSS on root level applied successfully!') # Assert final and initial states are same initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png') device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
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()
def sync_hello_world_ng(app_name, platform, device, bundle=True, uglify=False, aot=False, hmr=True, instrumented=True): result = run_hello_world_ng(app_name=app_name, platform=platform, device=device, uglify=uglify, aot=aot, hmr=hmr) # Apply changes Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS) device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML) if platform == Platform.IOS: for number in ["10", "11"]: device.wait_for_text(text=number) else: for number in ["8", "9"]: device.wait_for_text(text=number) assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='items.component.html', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, aot=aot, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS) device.wait_for_main_color(color=Colors.DARK) if platform == Platform.IOS: for number in ["10", "1"]: device.wait_for_text(text=number) else: for number in ["8", "9"]: device.wait_for_text(text=number) assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) # Revert changes Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.HTML) device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='items.component.html', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, aot=aot, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.TS) device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text) device.wait_for_main_color(color=Colors.DARK) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.CSS) device.wait_for_main_color(color=Colors.WHITE) device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180) # Assert final and initial states are same initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png') device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
def __sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=True, hmr=True, uglify=False, aot=False, snapshot=False, instrumented=False, default_andr_sdk='29'): # Set changes js_file = os.path.basename(Changes.JSHelloWord.JS.file_path) if app_type == AppType.JS: js_change = Changes.JSHelloWord.JS xml_change = Changes.JSHelloWord.XML css_change = Changes.JSHelloWord.CSS elif app_type == AppType.TS: js_file = os.path.basename(Changes.TSHelloWord.TS.file_path) js_change = Changes.TSHelloWord.TS xml_change = Changes.TSHelloWord.XML css_change = Changes.TSHelloWord.CSS else: raise ValueError('Invalid app_type value.') # Verify that application is not restarted on file changes when hmr=true if hmr and Settings.HOST_OS != OSType.WINDOWS: not_existing_string_list = ['Restarting application'] else: not_existing_string_list = None # Execute `tns run` and wait until logs are OK result = run_hello_world_js_ts(app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr, uglify=uglify, aot=aot, snapshot=snapshot, default_andr_sdk=default_andr_sdk) # Edit CSS file and verify changes are applied blue_count = device.get_pixels_by_color(color=Colors.LIGHT_BLUE) Sync.replace(app_name=app_name, change_set=css_change) device.wait_for_color(color=Colors.RED, pixel_count=blue_count) device.wait_for_text(text=xml_change.old_text) device.wait_for_text(text=js_change.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='app.css', instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, not_existing_string_list=not_existing_string_list) # Edit JS file and verify changes are applied Sync.replace(app_name=app_name, change_set=js_change) device.wait_for_text(text=js_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name=js_file, instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, not_existing_string_list=not_existing_string_list) # Edit XML file and verify changes are applied Sync.replace(app_name=app_name, change_set=xml_change) device.wait_for_text(text=xml_change.new_text) device.wait_for_text(text=js_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='main-page.xml', instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, not_existing_string_list=not_existing_string_list) # Revert all the changes Sync.revert(app_name=app_name, change_set=js_change) device.wait_for_text(text=js_change.old_text) device.wait_for_text(text=xml_change.new_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name=js_file, instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, not_existing_string_list=not_existing_string_list) Sync.revert(app_name=app_name, change_set=xml_change) device.wait_for_text(text=xml_change.old_text) device.wait_for_text(text=js_change.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='main-page.xml', instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, not_existing_string_list=not_existing_string_list) Sync.revert(app_name=app_name, change_set=css_change) device.wait_for_color(color=Colors.LIGHT_BLUE, pixel_count=blue_count) device.wait_for_text(text=xml_change.old_text) device.wait_for_text(text=js_change.old_text) strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, hmr=hmr, file_name='app.css', instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, not_existing_string_list=not_existing_string_list) # Assert final and initial states are same initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png') device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)