|
| 1 | +""" |
| 2 | +Test for `tns run ios` command with Angular apps (on real devices). |
| 3 | +""" |
| 4 | + |
| 5 | +import os |
| 6 | +from time import sleep |
| 7 | + |
| 8 | +from core.base_class.BaseClass import BaseClass |
| 9 | +from core.device.device import Device |
| 10 | +from core.device.emulator import Emulator |
| 11 | +from core.device.simulator import Simulator |
| 12 | +from core.osutils.folder import Folder |
| 13 | +from core.settings.settings import IOS_RUNTIME_PATH |
| 14 | +from core.tns.replace_helper import ReplaceHelper |
| 15 | +from core.tns.tns import Tns |
| 16 | +from core.tns.tns_platform_type import Platform |
| 17 | + |
| 18 | + |
| 19 | +class RunIOSDeviceTestsNG(BaseClass): |
| 20 | + SIMULATOR_ID = '' |
| 21 | + DEVICES = Device.get_ids(platform=Platform.IOS) |
| 22 | + DEVICE_ID = Device.get_id(platform=Platform.IOS) |
| 23 | + |
| 24 | + @classmethod |
| 25 | + def setUpClass(cls): |
| 26 | + logfile = os.path.join('out', cls.__name__ + '.txt') |
| 27 | + BaseClass.setUpClass(logfile) |
| 28 | + Emulator.stop() |
| 29 | + Simulator.stop() |
| 30 | + Device.ensure_available(platform=Platform.IOS) |
| 31 | + Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.IOS) |
| 32 | + |
| 33 | + # Create default NG app (to get right dependencies from package.json) |
| 34 | + Tns.create_app_ng(cls.app_name) |
| 35 | + Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_RUNTIME_PATH}) |
| 36 | + |
| 37 | + # Copy the app folder (app is modified in order to get some console logs on loaded) |
| 38 | + source = os.path.join('data', 'apps', 'livesync-hello-world-ng', 'app') |
| 39 | + target = os.path.join(cls.app_name, 'app') |
| 40 | + Folder.cleanup(target) |
| 41 | + Folder.copy(src=source, dst=target) |
| 42 | + |
| 43 | + def setUp(self): |
| 44 | + BaseClass.setUp(self) |
| 45 | + Tns.kill() |
| 46 | + |
| 47 | + def tearDown(self): |
| 48 | + Tns.kill() |
| 49 | + BaseClass.tearDown(self) |
| 50 | + |
| 51 | + @classmethod |
| 52 | + def tearDownClass(cls): |
| 53 | + BaseClass.tearDownClass() |
| 54 | + Simulator.stop() |
| 55 | + |
| 56 | + def test_001_tns_run_ios_ts_css_html(self): |
| 57 | + """Make valid changes in JS,CSS and XML""" |
| 58 | + |
| 59 | + # `tns run ios` and wait until app is deployed |
| 60 | + log = Tns.run_ios(attributes={'--path': self.app_name, '--device': self.DEVICE_ID}, wait=False, |
| 61 | + assert_success=False) |
| 62 | + strings = ['Project successfully built', |
| 63 | + 'Successfully installed on device with identifier', self.DEVICE_ID, |
| 64 | + 'Successfully synced application', |
| 65 | + 'Application loaded!', |
| 66 | + 'Home page loaded!'] |
| 67 | + Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10) |
| 68 | + |
| 69 | + # Verify initial state of the app |
| 70 | + assert Device.wait_for_text(device_id=self.DEVICE_ID, text="Ter Stegen", |
| 71 | + timeout=20), 'Hello-world NG App failed to start or it does not look correct!' |
| 72 | + |
| 73 | + # Change TS and wait until app is synced |
| 74 | + ReplaceHelper.replace(self.app_name, ReplaceHelper.NG_CHANGE_TS, sleep=10) |
| 75 | + strings = ['Successfully transferred', 'item.service.js', 'Successfully synced application', |
| 76 | + 'Application loaded!', # This is to verify app is restarted. |
| 77 | + 'Home page loaded!'] |
| 78 | + Tns.wait_for_log(log_file=log, string_list=strings) |
| 79 | + text_changed = Device.wait_for_text(device_id=self.DEVICE_ID, text="Stegen Ter", timeout=20) |
| 80 | + assert text_changed, 'Changes in TS file not applied (UI is not refreshed).' |
| 81 | + |
| 82 | + # Change HTML and wait until app is synced |
| 83 | + ReplaceHelper.replace(self.app_name, ReplaceHelper.NG_CHANGE_HTML, sleep=10) |
| 84 | + strings = ['items.component.html', 'Successfully synced application', 'Home page loaded!'] |
| 85 | + not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted. |
| 86 | + Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings) |
| 87 | + sleep(15) |
| 88 | + text_changed = Device.wait_for_text(device_id=self.DEVICE_ID, text="Stegen Ter", timeout=5) |
| 89 | + assert not text_changed, 'Changes in HTML file not applied (UI is not refreshed).' |
| 90 | + |
| 91 | + # Change CSS and wait until app is synced |
| 92 | + ReplaceHelper.replace(self.app_name, ReplaceHelper.NG_CHANGE_CSS, sleep=10) |
| 93 | + strings = ['Successfully transferred', 'app.css', 'Successfully synced application', 'Home page loaded!'] |
| 94 | + not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted. |
| 95 | + Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings) |
| 96 | + Device.screen_match(device_name="iPhone5", device_id=self.DEVICE_ID, expected_image='ng-hello-world-home-dark', |
| 97 | + tolerance=5.0) |
| 98 | + |
| 99 | + # Revert HTML and wait until app is synced |
| 100 | + ReplaceHelper.rollback(self.app_name, ReplaceHelper.NG_CHANGE_HTML, sleep=10) |
| 101 | + strings = ['items.component.html', 'Successfully synced application', 'Home page loaded!'] |
| 102 | + not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted. |
| 103 | + Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings) |
| 104 | + text_changed = Device.wait_for_text(device_id=self.DEVICE_ID, text="Stegen Ter", timeout=20) |
| 105 | + assert text_changed, 'Changes in HTML file not applied (UI is not refreshed).' |
| 106 | + |
| 107 | + # Revert TS and wait until app is synced |
| 108 | + ReplaceHelper.rollback(self.app_name, ReplaceHelper.NG_CHANGE_TS, sleep=10) |
| 109 | + strings = ['Successfully transferred', 'item.service.js', 'Successfully synced application', |
| 110 | + 'Application loaded!', # This is to verify app is restarted. |
| 111 | + 'Home page loaded!'] |
| 112 | + Tns.wait_for_log(log_file=log, string_list=strings) |
| 113 | + text_changed = Device.wait_for_text(device_id=self.DEVICE_ID, text="Ter Stegen", timeout=20) |
| 114 | + assert text_changed, 'Changes in TS file not applied (UI is not refreshed).' |
| 115 | + |
| 116 | + # Revert CSS and wait until app is synced |
| 117 | + ReplaceHelper.rollback(self.app_name, ReplaceHelper.NG_CHANGE_CSS, sleep=10) |
| 118 | + strings = ['Successfully transferred', 'app.css', 'Successfully synced application'] |
| 119 | + not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted. |
| 120 | + Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings) |
| 121 | + Device.screen_match(device_name="iPhone5", device_id=self.DEVICE_ID, expected_image='ng-hello-world-home-white', |
| 122 | + tolerance=5.0) |
0 commit comments