|
| 1 | +import os |
| 2 | +import unittest |
| 3 | + |
| 4 | +from core.base_class.BaseClass import BaseClass |
| 5 | +from core.device.device import Device |
| 6 | +from core.device.emulator import Emulator |
| 7 | +from core.device.helpers.adb import Adb |
| 8 | +from core.osutils.file import File |
| 9 | +from core.settings.settings import EMULATOR_ID, ANDROID_PACKAGE, WEBPACK_PACKAGE, EMULATOR_NAME |
| 10 | +from core.tns.replace_helper import ReplaceHelper |
| 11 | +from core.tns.tns import Tns |
| 12 | +from core.tns.tns_platform_type import Platform |
| 13 | +from tests.hmr.helpers_hmr import HelpersHMR |
| 14 | +from tests.webpack.helpers.helpers import Helpers |
| 15 | +# import hashlib |
| 16 | +# import re |
| 17 | + |
| 18 | + |
| 19 | +class HelloWorldJSHMRAndroid(BaseClass): |
| 20 | + |
| 21 | + |
| 22 | + @classmethod |
| 23 | + def setUpClass(cls): |
| 24 | + BaseClass.setUpClass(cls.__name__) |
| 25 | + Emulator.stop() |
| 26 | + Emulator.ensure_available() |
| 27 | + |
| 28 | + Tns.create_app(cls.app_name, update_modules=True) |
| 29 | + Tns.install_npm(package=WEBPACK_PACKAGE, option='--save-dev', folder=cls.app_name) |
| 30 | + Tns.platform_add_android(attributes={"--path": cls.app_name, "--frameworkPath": ANDROID_PACKAGE}) |
| 31 | + |
| 32 | + def setUp(self): |
| 33 | + Tns.kill() |
| 34 | + Helpers.emulator_cleanup(app_name=self.app_name) |
| 35 | + BaseClass.setUp(self) |
| 36 | + |
| 37 | + def tearDown(self): |
| 38 | + Tns.kill() |
| 39 | + BaseClass.tearDown(self) |
| 40 | + |
| 41 | + @classmethod |
| 42 | + def tearDownClass(cls): |
| 43 | + BaseClass.tearDownClass() |
| 44 | + |
| 45 | + def test_001_android_run_hmr(self): |
| 46 | + log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False, |
| 47 | + assert_success=False) |
| 48 | + |
| 49 | + Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr, not_existing_string_list=HelpersHMR.errors_hmr, |
| 50 | + timeout=240) |
| 51 | + Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120) |
| 52 | + |
| 53 | + HelpersHMR.apply_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID) |
| 54 | + HelpersHMR.revert_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID) |
| 55 | + |
| 56 | + def test_002_android_run_hmr_uninstall_app(self): |
| 57 | + log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False, |
| 58 | + assert_success=False) |
| 59 | + |
| 60 | + Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr_with_platforms, not_existing_string_list=HelpersHMR.errors_hmr, |
| 61 | + timeout=240) |
| 62 | + Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120) |
| 63 | + |
| 64 | + HelpersHMR.apply_changes_js(app_name=self.app_name, log=log, platform=Platform.ANDROID) |
| 65 | + |
| 66 | + # Uninstall app while `tns run` is running |
| 67 | + Device.uninstall_app(app_prefix='org.nativescript.', platform=Platform.ANDROID) |
| 68 | + |
| 69 | + HelpersHMR.revert_changes_js(app_name=self.app_name, log=log, platform=Platform.ANDROID) |
| 70 | + Helpers.android_screen_match(image=HelpersHMR.image_original, timeout=120) |
| 71 | + |
| 72 | + @unittest.skip("https://github.com/NativeScript/nativescript-cli/issues/4123") |
| 73 | + def test_003_android_run_hmr_wrong_xml(self): |
| 74 | + log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False, |
| 75 | + assert_success=False) |
| 76 | + Tns.wait_for_log(log_file=log, string_list=HelpersHMR.run_hmr, |
| 77 | + not_existing_string_list=HelpersHMR.errors_hmr, timeout=240) |
| 78 | + |
| 79 | + # Verify app looks correct inside emulator |
| 80 | + Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, |
| 81 | + expected_image=HelpersHMR.image_original) |
| 82 | + |
| 83 | + # Break the app with invalid xml changes |
| 84 | + ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML_INVALID_SYNTAX) |
| 85 | + |
| 86 | + # Verify console notify user for broken xml |
| 87 | + # strings = ['for activity org.nativescript.TestApp / com.tns.ErrorReportActivity'] |
| 88 | + strings = ['com.tns.NativeScriptException', 'Parsing XML at', 'Successfully synced application', EMULATOR_ID] |
| 89 | + Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) |
| 90 | + assert Adb.wait_for_text(device_id=EMULATOR_ID, text="Exception", timeout=30), "Error activity not found!" |
| 91 | + |
| 92 | + # Revert changes |
| 93 | + ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_XML_INVALID_SYNTAX) |
| 94 | + strings = ['JS: HMR: Sync...', 'JS: HMR: Hot Module Replacement Enabled. Waiting for signal.', |
| 95 | + 'Successfully synced application', EMULATOR_ID] |
| 96 | + Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) |
| 97 | + |
| 98 | + # Verify app looks correct inside emulator |
| 99 | + Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, |
| 100 | + expected_image=HelpersHMR.image_original) |
| 101 | + |
| 102 | + def test_008_android_run_hmr_console_log(self): |
| 103 | + source_js = os.path.join('data', "issues", 'console-log-hmr', 'main-view-model.js') |
| 104 | + target_js = os.path.join(self.app_name, 'app', 'main-view-model.js') |
| 105 | + File.copy(src=source_js, dest=target_js) |
| 106 | + |
| 107 | + log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False, |
| 108 | + assert_success=False) |
| 109 | + |
| 110 | + strings = ['LOG Hello'] |
| 111 | + Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) |
| 112 | + |
| 113 | + # Verify app looks correct inside emulator |
| 114 | + Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, |
| 115 | + expected_image=HelpersHMR.image_original) |
| 116 | + |
| 117 | + @unittest.skip("Don't clear behavior") |
| 118 | + def test_009_android_run_hmr_delete_file(self): |
| 119 | + log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False, |
| 120 | + assert_success=False) |
| 121 | + |
| 122 | + Tns.wait_for_log(log_file=log, string_list=HelpersHMR.wp_run, not_existing_string_list=HelpersHMR.wp_errors, |
| 123 | + timeout=240) |
| 124 | + HelpersHMR.android_screen_match(image=self.image_original, timeout=120) |
| 125 | + File.remove(self.app_name + 'app', 'main-view-model.js') |
| 126 | + |
| 127 | + self.apply_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID) |
| 128 | + self.revert_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID) |
0 commit comments