def apply_changes(app_name, log, platform): not_found_list = [] # Change JS, XML and CSS ReplaceHelper.replace(app_name, HelpersHMR.js_change, sleep=10) strings = ['HMR: The following modules were updated:', './main-view-model.js', './main-page.js', 'Successfully transferred bundle.', 'HMR: Successfully applied update with hmr hash '] # strings = ['JS: HMR: The following modules were updated:', './main-view-model.js', './main-page.js', # 'Successfully transferred bundle.{0}.hot-update.js'.format(hash()), # 'JS: HMR: Successfully applied update with hmr hash {0}'.format(hashlib.sha1)] Tns.wait_for_log(log_file=log, string_list=strings) if platform == Platform.ANDROID: text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='42 clicks left', timeout=20) assert text_changed, 'Changes in JS file not applied (UI is not refreshed).' ReplaceHelper.replace(app_name, HelpersHMR.xml_change, sleep=10) strings = ['Refreshing application on device', 'HMR: Checking for updates to the bundle with hmr hash', './main-page.xml', 'HMR: Successfully applied update with hmr hash'] Tns.wait_for_log(log_file=log, string_list=strings) if platform == Platform.ANDROID: text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='TEST') assert text_changed, 'Changes in XML file not applied (UI is not refreshed).' ReplaceHelper.replace(app_name, HelpersHMR.css_change, sleep=10) if platform == Platform.ANDROID: Tns.wait_for_log(log_file=log, string_list=['app.css'], clean_log=False) Tns.wait_for_log(log_file=log, string_list=HelpersHMR.wp_sync, not_existing_string_list=HelpersHMR.wp_errors, timeout=120) # Verify application looks correct if platform == Platform.ANDROID: Helpers.android_screen_match(image=HelpersHMR.image_change, timeout=120)
def test_002_android_run_hmr_uninstall_app(self): log = Tns.run_android(attributes={ '--path': self.app_name, '--device': EMULATOR_ID, '--hmr': '' }, wait=False, assert_success=False) Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr_with_platforms, not_existing_string_list=HelpersHMR.errors_hmr, timeout=240) Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120) HelpersHMR.apply_changes_js(app_name=self.app_name, log=log, platform=Platform.ANDROID) # Uninstall app while `tns run` is running Device.uninstall_app(app_prefix='org.nativescript.', platform=Platform.ANDROID) ReplaceHelper.rollback(self.app_name, HelpersHMR.js_change, sleep=10) strings = [ 'Restarting application on device', 'HMR: Hot Module Replacement Enabled. Waiting for signal.' ] Tns.wait_for_log(log_file=log, string_list=strings) Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120)
def revert_changes(app_name, log, platform): # Clean old logs if CURRENT_OS is not OSType.WINDOWS: File.write(file_path=log, text="") # Revert XML changes ReplaceHelper.rollback(app_name, HelpersHMR.xml_change, sleep=10) strings = ['Refreshing application on device', './main-page.xml', 'HMR: Checking for updates to the bundle with hmr hash'] Tns.wait_for_log(log_file=log, string_list=strings) if platform == Platform.ANDROID: text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP') assert text_changed, 'Changes in XML file not applied (UI is not refreshed).' # Revert JS changes ReplaceHelper.rollback(app_name, HelpersHMR.js_change, sleep=10) strings = ['Refreshing application on device', 'HMR: The following modules were updated:', './main-view-model.js', './main-page.js', 'Successfully transferred bundle.', 'HMR: Successfully applied update with hmr hash '] Tns.wait_for_log(log_file=log, string_list=strings) if platform == Platform.ANDROID: text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='42 taps left', timeout=20) assert text_changed, 'HMR: The following modules were updated:' # Revert CSS changes ReplaceHelper.rollback(app_name, HelpersHMR.css_change, sleep=10) Tns.wait_for_log(log_file=log, string_list=['app.css'], clean_log=False) # Verify application looks correct Tns.wait_for_log(log_file=log, string_list=HelpersHMR.wp_sync, not_existing_string_list=HelpersHMR.wp_errors, timeout=60) if platform == Platform.ANDROID: Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120)
def test_001_android_run_hmr(self): log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False, assert_success=False) Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr, not_existing_string_list=HelpersHMR.errors_hmr, timeout=240) Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120) HelpersHMR.apply_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID) HelpersHMR.revert_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
def test_008_ios_run_hmr_console_log(self): source_js = os.path.join('data', "issues", 'console-log-hmr', 'main-view-model.js') target_js = os.path.join(self.app_name, 'app', 'main-view-model.js') File.copy(src=source_js, dest=target_js) log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--hmr': ''}, wait=False, assert_success=False) strings = ['LOG Hello'] Tns.wait_for_log(log_file=log, string_list=strings) Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120)
def test_002_android_run_hmr_uninstall_app(self): log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False, assert_success=False) Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr_with_platforms, not_existing_string_list=HelpersHMR.errors_hmr, timeout=240) Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120) HelpersHMR.apply_changes_js(app_name=self.app_name, log=log, platform=Platform.ANDROID) # Uninstall app while `tns run` is running Device.uninstall_app(app_prefix='org.nativescript.', platform=Platform.ANDROID) ReplaceHelper.rollback(self.app_name, HelpersHMR.js_change, sleep=10) strings = ['Restarting application on device', 'HMR: Hot Module Replacement Enabled. Waiting for signal.'] Tns.wait_for_log(log_file=log, string_list=strings) Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120)
def test_001_android_run_hmr(self): log = Tns.run_android(attributes={ '--path': self.app_name, '--device': EMULATOR_ID, '--hmr': '' }, wait=False, assert_success=False) Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr, not_existing_string_list=HelpersHMR.errors_hmr, timeout=240) Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120) HelpersHMR.apply_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID) HelpersHMR.revert_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
def test_001_ios_run_hmr(self): log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--hmr': ''}, wait=False, assert_success=False) Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr, not_existing_string_list=HelpersHMR.errors_hmr, timeout=240) Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120) Helpers.wait_webpack_watcher() HelpersHMR.apply_changes(app_name=self.app_name, log=log, platform=Platform.IOS) Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_change, timeout=120) HelpersHMR.revert_changes(app_name=self.app_name, log=log, platform=Platform.IOS) Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120)
def test_003_ios_run_hmr_wrong_xml(self): log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--hmr': ''}, wait=False, assert_success=False) Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr_with_platforms, not_existing_string_list=HelpersHMR.errors_hmr, timeout=240) Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120) Helpers.wait_webpack_watcher() HelpersHMR.apply_changes_js(app_name=self.app_name, log=log, platform=Platform.IOS) # Uninstall app while `tns run` is running Simulator.uninstall("org.nativescript." + self.app_name) HelpersHMR.revert_changes_js(app_name=self.app_name, log=log, platform=Platform.IOS) Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120) Helpers.wait_webpack_watcher()
def test_002_ios_run_hmr_uninstall_app(self): log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--hmr': ''}, wait=False, assert_success=False) Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr_with_platforms, not_existing_string_list=HelpersHMR.errors_hmr, timeout=240) Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120) Helpers.wait_webpack_watcher() HelpersHMR.apply_changes_js(app_name=self.app_name, log=log, platform=Platform.IOS) # Uninstall app while `tns run` is running Simulator.uninstall("org.nativescript." + self.app_name) ReplaceHelper.rollback(self.app_name, HelpersHMR.js_change, sleep=10) strings = ['Restarting application on device', 'HMR: Hot Module Replacement Enabled. Waiting for signal.'] Tns.wait_for_log(log_file=log, string_list=strings) Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120) Helpers.wait_webpack_watcher()
def setUp(self): Tns.kill() Helpers.emulator_cleanup(app_name=self.app_name) BaseClass.setUp(self)