|
| 1 | +""" |
| 2 | +Test for `tns run android` command (on real devices). |
| 3 | +
|
| 4 | +Verify `tns run android` |
| 5 | +- Run on all available devices |
| 6 | +- Changes are synced on physical devices |
| 7 | +- Emulator is not started if physical device is attached |
| 8 | +- `tns run android --emulator` starts emulator even if device is connected |
| 9 | +- `tns run android --emulator` should deploy only on emulator |
| 10 | +- `tns run android --device` should deploy only on specified device |
| 11 | +
|
| 12 | +TODO: Add tests for: |
| 13 | +`tns run android --device <avd-name>` -> Should be able to start avd image |
| 14 | +`tns run android --device --emulator` -> We should throw nice error |
| 15 | +`--available-devices` and `-timeout` options |
| 16 | +""" |
| 17 | + |
| 18 | +import os |
| 19 | + |
| 20 | +from core.base_class.BaseClass import BaseClass |
| 21 | +from core.device.device import Device |
| 22 | +from core.device.emulator import Emulator |
| 23 | +from core.device.simulator import Simulator |
| 24 | +from core.settings.settings import ANDROID_RUNTIME_PATH, IOS_RUNTIME_PATH, SIMULATOR_NAME |
| 25 | +from core.tns.replace_helper import ReplaceHelper |
| 26 | +from core.tns.tns import Tns |
| 27 | +from core.tns.tns_platform_type import Platform |
| 28 | + |
| 29 | + |
| 30 | +class RunBothPlatformsTests(BaseClass): |
| 31 | + SIMULATOR_ID = '' |
| 32 | + ANDROID_DEVICES = Device.get_ids(platform=Platform.ANDROID, include_emulators=True) |
| 33 | + IOS_DEVICES = Device.get_ids(platform=Platform.IOS) |
| 34 | + DEVICE_ID = Device.get_id(platform=Platform.ANDROID) |
| 35 | + |
| 36 | + @classmethod |
| 37 | + def setUpClass(cls): |
| 38 | + logfile = os.path.join('out', cls.__name__ + '.txt') |
| 39 | + BaseClass.setUpClass(logfile) |
| 40 | + Emulator.ensure_available() |
| 41 | + cls.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME) |
| 42 | + Device.ensure_available(platform=Platform.ANDROID) |
| 43 | + Device.ensure_available(platform=Platform.IOS) |
| 44 | + Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.ANDROID) |
| 45 | + Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.IOS) |
| 46 | + |
| 47 | + Tns.create_app(cls.app_name, |
| 48 | + attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')}, |
| 49 | + update_modules=True) |
| 50 | + Tns.platform_add_android(attributes={'--path': cls.app_name, '--frameworkPath': ANDROID_RUNTIME_PATH}) |
| 51 | + Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_RUNTIME_PATH}) |
| 52 | + |
| 53 | + def setUp(self): |
| 54 | + BaseClass.setUp(self) |
| 55 | + Tns.kill() |
| 56 | + |
| 57 | + def tearDown(self): |
| 58 | + Tns.kill() |
| 59 | + BaseClass.tearDown(self) |
| 60 | + |
| 61 | + @classmethod |
| 62 | + def tearDownClass(cls): |
| 63 | + BaseClass.tearDownClass() |
| 64 | + Emulator.stop() |
| 65 | + |
| 66 | + def test_001_tns_run_on_all_devices(self): |
| 67 | + |
| 68 | + # Build to speed up run after that |
| 69 | + Tns.build_android(attributes={'--path': self.app_name}) |
| 70 | + Tns.build_ios(attributes={'--path': self.app_name}) |
| 71 | + |
| 72 | + # `tns run` should deploy on all devices, emulators and simulators |
| 73 | + log = Tns.run(attributes={'--path': self.app_name}, wait=False, assert_success=False) |
| 74 | + strings = ['Successfully installed on device with identifier', self.SIMULATOR_ID] |
| 75 | + for android_device_id in self.ANDROID_DEVICES: |
| 76 | + strings.append(android_device_id) |
| 77 | + for ios_device_id in self.ANDROID_DEVICES: |
| 78 | + strings.append(ios_device_id) |
| 79 | + Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False) |
| 80 | + |
| 81 | + # Verify app is deployed and running on all available android devices |
| 82 | + for device_id in self.ANDROID_DEVICES: |
| 83 | + Device.wait_until_app_is_running(app_id=Tns.get_app_id(self.app_name), device_id=device_id, timeout=30) |
| 84 | + |
| 85 | + # Change JS and wait until app is synced |
| 86 | + ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10) |
| 87 | + strings = ['Successfully transferred main-view-model.js', 'Successfully synced application'] |
| 88 | + Tns.wait_for_log(log_file=log, string_list=strings) |
| 89 | + for device_id in self.ANDROID_DEVICES: |
| 90 | + text_changed = Device.wait_for_text(device_id=device_id, text='42 clicks left', timeout=20) |
| 91 | + assert text_changed, 'Changes in JS file not applied (UI is not refreshed) on ' + device_id |
| 92 | + |
| 93 | + # Change XML and wait until app is synced |
| 94 | + ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3) |
| 95 | + strings = ['Successfully transferred main-page.xml', 'Successfully synced application'] |
| 96 | + Tns.wait_for_log(log_file=log, string_list=strings) |
| 97 | + for device_id in self.ANDROID_DEVICES: |
| 98 | + text_changed = Device.wait_for_text(device_id=device_id, text='TEST', timeout=20) |
| 99 | + assert text_changed, 'Changes in JS file not applied (UI is not refreshed) on ' + device_id |
| 100 | + |
| 101 | + # Change CSS and wait until app is synced |
| 102 | + ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3) |
| 103 | + strings = ['Successfully transferred app.css', 'Successfully synced application'] |
| 104 | + Tns.wait_for_log(log_file=log, string_list=strings) |
0 commit comments