diff --git a/tests/emulator/run_android_ng_tests.py b/tests/emulator/run_android_ng_tests.py index 0d1051a2..ed251391 100644 --- a/tests/emulator/run_android_ng_tests.py +++ b/tests/emulator/run_android_ng_tests.py @@ -46,112 +46,6 @@ def tearDownClass(cls): BaseClass.tearDownClass() Emulator.stop() - @flaky(max_runs=3) - def test_001_tns_run_android_ts_css_html(self): - """Make valid changes in JS,CSS and XML""" - - # Copy the app folder (app is modified in order to get some console logs on loaded) - source = os.path.join('data', 'apps', 'livesync-hello-world-ng', 'src') - target = os.path.join(self.app_name, 'src') - Folder.cleanup(target) - Folder.copy(src=source, dst=target) - - # `tns run android` and wait until app is deployed - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - strings = ['Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID, - 'Successfully synced application', - 'Application loaded!', - 'Home page loaded!'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=240, check_interval=10) - - # Verify initial state of the app - assert Device.wait_for_text(device_id=EMULATOR_ID, text="Ter Stegen", - timeout=20), 'Hello-world NG App failed to start or it does not look correct!' - - # Change TS and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.NG_CHANGE_TS, sleep=10) - strings = ['Successfully transferred', 'item.service.js', 'Successfully synced application', - 'Application loaded!', # This is to verify app is restarted. - 'Home page loaded!'] - Tns.wait_for_log(log_file=log, string_list=strings, clean_log=False) - text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text="Stegen Ter", timeout=20) - assert text_changed, 'Changes in TS file not applied (UI is not refreshed).' - log_content = File.read(log) - assert 'item.service.ts' not in log_content, "CLI should NOT transfer TS files!" - - # Clean log (this will not work on windows since file is locked) - if CURRENT_OS != OSType.WINDOWS: - File.write(file_path=log, text="") - - # Change HTML and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.NG_CHANGE_HTML, sleep=10) - - # Verify app is synced and it is not restarted - strings = ['items.component.html', 'Successfully synced application', 'Home page loaded!'] - if CURRENT_OS == OSType.WINDOWS: - not_existing_strings = None # We can not verify this on windows, because log is not clean - else: - not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted. - Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings) - text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='9', timeout=30) - assert text_changed, 'Changes in HTML file not applied (UI is not refreshed).' - - # Clean log (this will not work on windows since file is locked) - if CURRENT_OS != OSType.WINDOWS: - File.write(file_path=log, text="") - - # Change CSS and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.NG_CHANGE_CSS, sleep=10) - - # Verify app is synced and it is not restarted - strings = ['Successfully transferred', 'app.css', 'Successfully synced application', 'Home page loaded!'] - if CURRENT_OS == OSType.WINDOWS: - not_existing_strings = None # We can not verify this on windows, because log is not clean - else: - not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted. - - Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings) - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image='ng-hello-world-home-dark', - tolerance=5.0) - - # Revert HTML and wait until app is synced - ReplaceHelper.rollback(self.app_name, ReplaceHelper.NG_CHANGE_HTML, sleep=10) - - # Verify app is synced and it is not restarted - strings = ['items.component.html', 'Successfully synced application', 'Home page loaded!'] - if CURRENT_OS == OSType.WINDOWS: - not_existing_strings = None # We can not verify this on windows, because log is not clean - else: - not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted. - Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings) - text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text="Stegen Ter", timeout=30) - assert text_changed, 'Changes in HTML file not applied (UI is not refreshed).' - - # Revert TS and wait until app is synced - ReplaceHelper.rollback(self.app_name, ReplaceHelper.NG_CHANGE_TS, sleep=10) - strings = ['Successfully transferred', 'item.service.js', 'Successfully synced application', - 'Application loaded!', # This is to verify app is restarted. - 'Home page loaded!'] - Tns.wait_for_log(log_file=log, string_list=strings) - text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text="Ter Stegen", timeout=30) - assert text_changed, 'Changes in TS file not applied (UI is not refreshed).' - - # Revert CSS and wait until app is synced - ReplaceHelper.rollback(self.app_name, ReplaceHelper.NG_CHANGE_CSS, sleep=10) - - # Verify app is synced and it is not restarted - strings = ['Successfully transferred', 'app.css', 'Successfully synced application', 'Home page loaded!'] - if CURRENT_OS == OSType.WINDOWS: - not_existing_strings = None # We can not verify this on windows, because log is not clean - else: - not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted. - - Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings) - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='ng-hello-world-home-white', tolerance=5.0) - def test_200_tns_run_android_extending_class_inside_file_containing_dots(self): """Test for https://github.com/NativeScript/android-runtime/issues/761""" @@ -211,27 +105,3 @@ def test_280_tns_run_android_console_time(self): # Verify console.time() works console_time = ['JS: startup:'] Tns.wait_for_log(log_file=log, string_list=console_time) - - def test_290_tns_run_android_delete_node_modules(self): - #https://github.com/NativeScript/nativescript-cli/issues/3944 - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - - # Verify the app is running - strings = ['Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=240, check_interval=10) - - Tns.kill() - node_modules = os.path.join(self.app_name + '/' + 'node_modules') - Folder.cleanup(node_modules) - - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - - # Verify the app is running - strings = ['Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID, - 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=240, check_interval=10) - assert "Cannot find module 'nativescript-angular/hooks/before-livesync'" not in log - diff --git a/tests/emulator/run_android_tests.py b/tests/emulator/run_android_tests.py index 01313ffb..65e069c9 100644 --- a/tests/emulator/run_android_tests.py +++ b/tests/emulator/run_android_tests.py @@ -92,187 +92,6 @@ def tearDownClass(cls): Emulator.stop() # We need this because of test_400_tns_run_android_respect_adb_errors Folder.cleanup(cls.temp_app) - def test_001_tns_run_android_js_css_xml_manifest(self): - """Make valid changes in JS,CSS and XML""" - - # `tns run android` and wait until app is deployed - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - strings = ['Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID, - 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Change JS and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10) - strings = ['Successfully transferred main-view-model.js', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - 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).' - - # Change XML and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3) - strings = ['Successfully transferred main-page.xml', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - 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).' - - # Change CSS and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3) - strings = ['Successfully transferred app.css', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify application looks correct - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_js_css_xml') - - # Rollback all the changes - ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10) - strings = ['Successfully transferred main-view-model.js', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3) - strings = ['Successfully transferred app.css', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3) - strings = ['Successfully transferred main-page.xml', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Changes in App_Resources should rebuild native project - res_path = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'AndroidManifest.xml') - File.replace(res_path, '17', '19') - strings = ['Preparing project', 'Building project', 'Gradle build', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=60) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - def test_100_tns_run_android_release(self): - """Make valid changes in JS,CSS and HTML""" - - # `tns run android --release` and wait until app is deployed - # IMPORTANT NOTE: `tns run android --release` Do NOT livesync by design! - Device.uninstall_app(app_prefix="org.nativescript", platform=Platform.ANDROID) - log = Tns.run_android(attributes={'--path': self.app_name, - '--device': EMULATOR_ID, - '--keyStorePath': ANDROID_KEYSTORE_PATH, - '--keyStorePassword': ANDROID_KEYSTORE_PASS, - '--keyStoreAlias': ANDROID_KEYSTORE_ALIAS, - '--keyStoreAliasPassword': ANDROID_KEYSTORE_ALIAS_PASS, - '--release': ''}, wait=False, assert_success=False) - - strings = ['Project successfully prepared', 'Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, - device_id=EMULATOR_ID, expected_image='livesync-hello-world_home') - - # Kills `tns run android --release` - Tns.kill() - - # Replace files - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS) - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS) - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML) - - # Run `tns run android --release` again and make sure changes above are applied - log = Tns.run_android(attributes={'--path': self.app_name, - '--device': EMULATOR_ID, - '--keyStorePath': ANDROID_KEYSTORE_PATH, - '--keyStorePassword': ANDROID_KEYSTORE_PASS, - '--keyStoreAlias': ANDROID_KEYSTORE_ALIAS, - '--keyStoreAliasPassword': ANDROID_KEYSTORE_ALIAS_PASS, - '--release': ''}, wait=False, assert_success=False) - - strings = ['Project successfully prepared', 'Project successfully built', - 'Successfully installed on device with identifier', - 'Successfully started on device with identifier', EMULATOR_ID] - - # https://github.com/NativeScript/android-runtime/issues/1024 - not_existing_log = ['JS:'] - Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_log, timeout=120, - clean_log=False) - - # Verify app looks is update after changes in js, css and xml - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_js_css_xml') - - def test_101_tns_run_android_release_without_changes(self): - """Make valid changes in JS,CSS and HTML""" - - # `tns run android --release` and wait until app is deployed - # IMPORTANT NOTE: `tns run android --release` Do NOT livesync by design! - Device.uninstall_app(app_prefix="org.nativescript", platform=Platform.ANDROID) - log = Tns.run_android(attributes={'--path': self.app_name, - '--device': EMULATOR_ID, - '--keyStorePath': ANDROID_KEYSTORE_PATH, - '--keyStorePassword': ANDROID_KEYSTORE_PASS, - '--keyStoreAlias': ANDROID_KEYSTORE_ALIAS, - '--keyStoreAliasPassword': ANDROID_KEYSTORE_ALIAS_PASS, - '--release': ''}, wait=False, assert_success=False) - - strings = ['Project successfully prepared', 'Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, - device_id=EMULATOR_ID, expected_image='livesync-hello-world_home') - - # Kills `tns run android --release` - Tns.kill() - - # Run `tns run android --release` again and make sure project doesn't build - log = Tns.run_android(attributes={'--path': self.app_name, - '--device': EMULATOR_ID, - '--keyStorePath': ANDROID_KEYSTORE_PATH, - '--keyStorePassword': ANDROID_KEYSTORE_PASS, - '--keyStoreAlias': ANDROID_KEYSTORE_ALIAS, - '--keyStoreAliasPassword': ANDROID_KEYSTORE_ALIAS_PASS, - '--release': ''}, wait=False, assert_success=False) - - strings = ['Project successfully prepared', 'Skipping package build', - 'No changes detected on the native side. This will be fast!', - 'Successfully installed on device with identifier', - 'Successfully started on device with identifier', EMULATOR_ID] - - # Verify app looks is update after changes in js, css and xml - Device.screen_match(device_name=EMULATOR_NAME, - device_id=EMULATOR_ID, expected_image='livesync-hello-world_home') - - def test_120_tns_run_android_delete_file_check_platforms(self): - # https://github.com/NativeScript/nativescript-cli/issues/3984 - # Files are not deleted from platforms folder on `tns run` command - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - strings = ['Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID, - 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - file_delete = os.path.join(self.app_name + '/' + 'app', 'main-view-model.js') - File.remove(file_delete) - assert not File.exists(file_delete) - platform_file = os.path.join(self.app_name + '/' + 'platforms', 'android', 'app', 'src', 'main', 'assets', - 'app', 'main-view-model.js') - time.sleep(5) - assert not File.exists(platform_file) def test_180_tns_run_android_console_logging(self): """ @@ -352,506 +171,6 @@ def test_181_tns_run_android_console_dir(self): Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10) assert self.very_long_string not in log - @unittest.skip("Problems with CI") - def test_182_tns_run_android_new_date_work_as_expected_when_changing_timezone(self): - """ - Test new date is working as expected. Test in different timezones - """ - output = Adb.run("shell settings put global auto_time_zone 0", EMULATOR_ID) - assert '' in output, "Failed to change auto timezone!" - - output = Adb.run("shell settings put system time_12_24 24", EMULATOR_ID) - assert '' in output, "Failed to change system format to 24!" - - output = Adb.run("shell settings put global time_zone UTC", EMULATOR_ID) - assert '' in output, "Failed to change timezone!" - output = Adb.run("shell setprop persist.sys.timezone UTC", EMULATOR_ID) - assert '' in output, "Failed to change timezone!" - - # Change main-page.js so it contains only logging information - source_js = os.path.join('data', "issues", 'android-runtime-961', 'main-page.js') - target_js = os.path.join(self.app_name, 'app', 'main-page.js') - File.copy(src=source_js, dest=target_js) - # Change main-view-model.js so it contains the new date logging functionality - source_js = os.path.join('data', "issues", 'android-runtime-961', '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) - # Change app package.json so it contains the options for remove V8 date cache - source_js = os.path.join('data', "issues", 'android-runtime-961', 'package.json') - target_js = os.path.join(self.app_name, 'app', 'package.json') - - File.copy(src=source_js, dest=target_js) - - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - - strings = ['Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID, - 'Successfully synced application', - "### TEST END ###" - ] - - Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10, clean_log=False) - - # Get UTC date and time - time_utc = datetime.datetime.utcnow() - - # Generate regex for asserting date and time - date_to_find_gmt = time_utc.strftime('%a %b %d %Y %H:.{2}:.{2}') + " GMT\+0000 \(UTC\)" - - Device.click(device_id=EMULATOR_ID, text="TAP", timeout=30) - Tns.wait_for_log(log_file=log, string_list=["GMT+0000 (UTC)"], timeout=180, check_interval=10, clean_log=False) - - # Assert date time is correct - if re.search(date_to_find_gmt, str(file.read(file(log)))): - print "Date was correct!" - else: - assert 1 == 2, 'Date {0} was not found! \n Log: \n {1}'.format(date_to_find_gmt, file.read(file(log))) - - # Get Los Angeles date and time - los_angeles_time = time_utc.replace(tzinfo=pytz.utc).astimezone(pytz.timezone("America/Los_Angeles")) - - # Open Date and time settings to change the timezone - output = Adb.run("shell am start -a android.settings.DATE_SETTINGS", EMULATOR_ID) - assert 'Starting: Intent { act=android.settings.DATE_SETTINGS }' in output, \ - "Failed to start Date and Time settings activity!" - - # Change TimeZone - time.sleep(20) - Device.click(device_id=EMULATOR_ID, text="Select time zone", timeout=15) - time.sleep(25) - Device.click(device_id=EMULATOR_ID, text="Pacific Daylight Time", timeout=60) - time.sleep(10) - - # Open the test app again - output = Adb.run("shell am start -n org.nativescript.TestApp/com.tns.NativeScriptActivity", EMULATOR_ID) - assert 'Starting: Intent { cmp=org.nativescript.TestApp/com.tns.NativeScriptActivity }' in output, \ - "Failed to start Nativescript test app activity!" - - time.sleep(15) - - Device.click(device_id=EMULATOR_ID, text="TAP", timeout=30) - Tns.wait_for_log(log_file=log, string_list=["GMT-0700 (PDT)"], timeout=180, check_interval=10, - clean_log=False) - # Generate regex for asserting date and time - date_to_find_los_angeles = los_angeles_time.strftime('%a %b %d %Y %H:.{2}:.{2}') + " GMT\-0700 \(PDT\)" - - # Assert date time is correct - if re.search(date_to_find_los_angeles, str(file.read(file(log)))): - print "Date was correct!" - else: - assert 1 == 2, 'Date {0} was not found! \n Log: \n {1}'.format(date_to_find_los_angeles, - file.read(file(log))) - - def test_200_tns_run_android_break_and_fix_app(self): - """ - Make changes in xml that break the app and then changes that fix the app. - Add/remove js files that break the app and then fix it. - """ - - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - strings = ['Project successfully prepared', 'Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Break the app with invalid xml changes - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML_INVALID_SYNTAX) - - # Verify console notify user for broken xml - strings = ['main-page.xml has syntax errors', 'unclosed xml attribute', - 'Successfully synced application', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - assert Adb.wait_for_text(device_id=EMULATOR_ID, text="Exception", timeout=30), "Error activity not found!" - - # Revert changes - ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_XML_INVALID_SYNTAX) - strings = ['Successfully transferred main-page.xml', 'Successfully synced application', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Delete app.js and verify app crash with error activiry dialog - app_js_original_path = os.path.join(self.app_name, 'app', 'app.js') - app_js_new_path = os.path.join(TEST_RUN_HOME, 'app.js') - File.copy(src=app_js_original_path, dest=app_js_new_path) - File.remove(file_path=app_js_original_path) - strings = ['Successfully synced application', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=30, check_interval=10) - assert Adb.wait_for_text(device_id=EMULATOR_ID, text="Exception", timeout=30), "Error activity not found!" - - # Restore js file and verify app - File.copy(src=app_js_new_path, dest=app_js_original_path) - verify_app_loaded = 'JS: Page loaded' - strings = ['Successfully synced application', 'app.js', EMULATOR_ID, verify_app_loaded] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=30, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - def test_210_run_android_add_remove_files_and_folders(self): - """ - New files and folders should be synced properly. - """ - - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - strings = ['Project successfully prepared', 'Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Add new files - new_file_name = 'main-page2.xml' - source_file = os.path.join(self.app_name, 'app', 'main-page.xml') - destination_file = os.path.join(self.app_name, 'app', new_file_name) - File.copy(source_file, destination_file) - strings = ['Successfully transferred main-page2.xml', 'Successfully synced application', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify new file is synced and available on device. - error_message = 'Newly created file {0} not found on {1}'.format(new_file_name, EMULATOR_ID) - app_id = Tns.get_app_id(app_name=self.app_name) - path = 'app/{0}'.format(new_file_name) - assert Adb.path_exists(device_id=EMULATOR_ID, package_id=app_id, path=path), error_message - - # Revert changes(rename file and delete file) - File.copy(destination_file, source_file) - File.remove(destination_file) - strings = ['Successfully transferred main-page.xml', 'Successfully synced application', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify new file is synced and available on device. - error_message = '{0} was deleted, but still available on {1}'.format(new_file_name, EMULATOR_ID) - assert Adb.path_does_not_exist(device_id=EMULATOR_ID, package_id=app_id, path=path), error_message - - # Add folder - new_folder_name = 'test2' - source_file = os.path.join(self.app_name, 'app', 'test') - destination_file = os.path.join(self.app_name, 'app', new_folder_name) - Folder.copy(source_file, destination_file) - strings = ['Successfully transferred test.txt', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify new folder is synced and available on device. - error_message = 'Newly created folder {0} not found on {1}'.format(new_folder_name, EMULATOR_ID) - path = 'app/{0}'.format(new_folder_name) - assert Adb.path_exists(device_id=EMULATOR_ID, package_id=app_id, path=path), error_message - - # Delete folder - if CURRENT_OS == OSType.OSX: - # Due to unknown reason this fails on Linux and Windows - # It might be related to https://github.com/NativeScript/nativescript-cli/issues/2657. - Folder.cleanup(destination_file) - strings = ['Successfully synced application', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify new folder is synced and available on device. - error_message = 'Deleted folder {0} is still available on {1}'.format(new_folder_name, EMULATOR_ID) - assert Adb.path_does_not_exist(device_id=EMULATOR_ID, package_id=app_id, path=path), error_message - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - @unittest.skipIf(CURRENT_OS != OSType.OSX, "Run only on macOS.") - def test_290_tns_run_android_should_refresh_images(self): - """Test for https://github.com/NativeScript/nativescript-cli/issues/2981""" - - # Ensure app with image - run("cp -R data/issues/nativescript-cli-2981/* " + self.app_name + "/app/") - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - strings = ['Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID, - 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image='issue_2981_logo_image', - tolerance=3.0, timeout=30) - - # Change the image - old_image = os.path.join(self.app_name, 'app', 'img', 'logo.png') - new_image = os.path.join(self.app_name, 'app', 'img', 'icon.png') - File.copy(src=new_image, dest=old_image) - Tns.wait_for_log(log_file=log, string_list=['Successfully transferred', 'Successfully synced application']) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image='issue_2981_icon_image', - tolerance=3.0, timeout=30) - - def test_300_tns_run_android_just_launch_and_incremental_builds(self): - """ - This test verify following things: - 1. `--justlaunch` option release the console. - 2. Prepare is not triggered if no changed are done. - 3. Incremental prepare is triggered if js, xml and css files are changed. - """ - - # Execute `tns run android --path TNS_App --justlaunch` and verify app looks correct on emulator - Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--justlaunch': ''}) - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Execute `tns run android --path TNS_App --justlaunch` again - # without any changes on app under test and verify incremental prepare works - output = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--justlaunch': ''}, - assert_success=False) - TnsAsserts.prepared(app_name=self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.SKIP) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Replace JS, XML and CSS files - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS) - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS) - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML) - - # Run `tns run android` after file changes (this should trigger incremental prepare). - output = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--justlaunch': ''}, - assert_success=False) - TnsAsserts.prepared(app_name=self.app_name, platform=Platform.ANDROID, output=output, - prepare=Prepare.INCREMENTAL) - - # Verify app looks is update after changes in js, css and xml - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_js_css_xml') - - def test_310_tns_run_android_clean_builds(self): - """ - * --clean - If set, forces rebuilding the native application. - """ - - Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--justlaunch': ''}) - - # Verify `--clean` without any changes skip prepare and rebuild native project (and runs properly) - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, - '--justlaunch': '', '--clean': ''}) - assert 'Skipping prepare' in log, "Prepare NOT skipped when no files are changed and `tns run android --clean`" - assert 'Building project...' in log, "Full rebuild not triggered when --clean is used" - assert 'Gradle build' in log, "Full rebuild not triggered when --clean is used" - - Device.wait_for_text(device_id=EMULATOR_ID, text='42 taps left') - - # Verify if changes are applied and then build with `--clean` it will apply changes on attached device - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS) - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, - '--justlaunch': '', '--clean': ''}) - assert 'Skipping prepare' not in log, "Prepare skipped when change files and run `tns run android --clean`" - assert 'Gradle build' in log, "Full rebuild not triggered when --clean is used" - - Device.wait_for_text(device_id=EMULATOR_ID, text='52 taps left') - - # Verify if changes are applied and then build with `--clean` it will apply changes on attached device - ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_JS) - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, - '--justlaunch': '', '--clean': ''}) - assert 'Skipping prepare' not in log - assert 'Gradle build' in log, "Full rebuild not triggered when --clean is used" - - Device.wait_for_text(device_id=EMULATOR_ID, text='42 taps left') - - def test_311_tns_run_android_clean_livesync(self): - # remove skip after check issue - # https://github.com/NativeScript/nativescript-cli/issues/2670 - Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--justlaunch': ''}) - - # Verify `--clean` without any changes rebuild native project (and runs properly) - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--clean': ''}, - wait=False, assert_success=False) - strings = ['Gradle clean...'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False) - time.sleep(10) - - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML) - strings = ['Skipping prepare.'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False) - assert "Gradle clean..." not in log - - def test_315_tns_run_android_change_appResources_check_per_platform(self): - # https://github.com/NativeScript/nativescript-cli/pull/3619 - if CURRENT_OS != OSType.WINDOWS: - Folder.cleanup(self.source_app) - Folder.copy(self.temp_app, self.source_app) - else: - Tns.create_app(self.app_name, - attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')}, - update_modules=True) - Tns.platform_add_android(attributes={'--path': self.app_name, '--frameworkPath': ANDROID_PACKAGE}) - - output = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, - wait=False, assert_success=False) - strings = ['Successfully installed on device with identifier', - 'Successfully synced application', EMULATOR_ID, ] - Tns.wait_for_log(log_file=output, string_list=strings, timeout=120, check_interval=10) - - source = os.path.join('data', 'issues', 'nativescript-cli-3619', 'hello.png') - target = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'drawable-hdpi') - File.copy(source, target) - strings = ['Gradle build'] - Tns.wait_for_log(log_file=output, string_list=strings, clean_log=False) - assert "Xcode build" not in output - - def test_320_tns_run_android_no_watch(self): - """ - * --no-watch - If set, changes in your code will not be reflected during the execution of this command. - """ - - # `tns run android --no-watch` and wait until app is deployed - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--no-watch': ''}, - wait=False, assert_success=False) - strings = ['Successfully installed on device with identifier', - 'Successfully synced application', - EMULATOR_ID, # Verify device id - 'JS:'] # Verify console log messages are shown. - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - - # Add new files - new_file_name = 'main-page3.xml' - old_file_name = 'main-page.xml' - source_file = os.path.join(self.app_name, 'app', old_file_name) - destination_file = os.path.join(self.app_name, 'app', new_file_name) - File.copy(source_file, destination_file) - time.sleep(20) # Give it some time to sync the changes - - # Verify new file is synced and available on device. - error_message = 'Newly created file {0} found on {1}'.format(new_file_name, EMULATOR_ID) - app_id = Tns.get_app_id(app_name=self.app_name) - new_file_path = 'app/{0}'.format(new_file_name) - old_file_path = 'app/{0}'.format(old_file_name) - assert Adb.path_does_not_exist(device_id=EMULATOR_ID, package_id=app_id, path=new_file_path), error_message - assert not Adb.path_does_not_exist(device_id=EMULATOR_ID, package_id=app_id, path=old_file_path) - # Last line is just to be very sure we have no bug in Adb.path_does_not_exist() - - def test_330_tns_run_android_sync_all_files(self): - """ - Verify '--syncAllFiles' option will sync all files, including node modules. - """ - Tns.build_android(attributes={'--path': self.app_name}) - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--syncAllFiles': ''}, - wait=False, assert_success=False) - strings = ['Successfully synced application', EMULATOR_ID, 'JS:'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=60, check_interval=10) - - ReplaceHelper.replace(app_name=self.app_name, file_change=ReplaceHelper.CHANGE_TNS_MODULES) - - strings = ['Successfully transferred application-common.js', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - @unittest.skipIf(CURRENT_OS == OSType.WINDOWS, "Delete log during livesync not possible on Windows.") - def test_340_tns_run_should_not_sync_hidden_files(self): - """ - Adding hidden files should not break run and they should not be transferred. - """ - - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - strings = ['Project successfully prepared', 'Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Clean log (this will not work on windows since file is locked) - File.write(file_path=log, text="") - - # Add some hidden files - source_file = os.path.join(self.app_name, 'app', 'main-page.xml') - destination_file = os.path.join(self.app_name, 'app', '.tempfile') - File.copy(source_file, destination_file) - - # Give it 5 sec and check no messages are available in log files - time.sleep(5) - output = File.read(log) - - print "" - print "LOG AFTER HIDDEN FILE ADDED:" - print "" - print output - print "" - - assert 'Successfully' not in output, 'Sync is triggered after adding hidden file.' - assert 'synced' not in output, 'Sync is triggered after adding hidden file.' - assert 'tempfile' not in output, 'Sync is triggered after adding hidden file.' - assert EMULATOR_ID not in output, 'Sync is triggered after adding hidden file.' - - # Verify hidden file does not exists on mobile device. - path = 'app/{0}'.format('.tempfile') - app_id = Tns.get_app_id(self.app_name) - error_message = 'Hidden file {0} is transferred to {1}'.format(path, EMULATOR_ID) - assert Adb.path_does_not_exist(device_id=EMULATOR_ID, package_id=app_id, path=path), error_message - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - def test_350_tns_run_android_should_start_emulator(self): - """ - `tns run android` should start emulator if device is not connected. - """ - count = len(Adb.get_devices(include_emulators=False)) - if count == 0: - Emulator.stop() - Tns.build_android(attributes={'--path': self.app_name}) - log = Tns.run_android(attributes={'--path': self.app_name}, wait=False, assert_success=False) - strings = ['Starting Android emulator with image'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120) - Emulator.stop() - Emulator.ensure_available() - else: - raise nose.SkipTest('This test is not valid when devices are connected.') - - def test_355_tns_run_android_changes_in_app_resources_rebuild_app(self): - """ - https://github.com/NativeScript/nativescript-cli/issues/3658 - In case when some change occurs in App_Resources/iOS and tns run android command is executed, - the application is fully rebuild when it should not. - """ - - # Run app twice and check the second time it's not rebuild - log1 = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - strings = ['Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID, - 'Successfully synced application'] - Tns.wait_for_log(log_file=log1, string_list=strings, timeout=180, check_interval=10, clean_log=False) - - log2 = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - strings_skipping_prepare = ['Skipping prepare', 'Successfully synced application', 'Restarting application'] - Tns.wait_for_log(log_file=log2, string_list=strings_skipping_prepare, timeout=180, check_interval=10, - clean_log=False) - - # Make change in App_Resources/iOS folder - app_resources_file = os.path.join(self.app_name, "app", "App_Resources", "iOS", "Assets.xcassets", - "Contents.json") - file_to_change = os.path.join("data", "issues", "nativescript-cli-3658", "Contents.json") - File.copy(file_to_change, app_resources_file) - - # Run again the app and ensure it's not rebuild - log3 = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - Tns.wait_for_log(log_file=log3, string_list=strings_skipping_prepare, timeout=180, check_interval=10, - clean_log=False) - assert 'Building project' not in log3, "Project is rebuilt when it should not." def test_360_tns_run_android_with_jar_file_in_plugin(self): """ @@ -915,101 +234,3 @@ def test_370_tns_run_android_with_jar_and_aar_files_in_app_res(self): # Verify app looks correct inside emulator Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image='livesync-hello-world_home') - - def test_380_tns_run_android_livesync_aar_file_changes(self): - """ - App should not crash when reference .jar or/and .aar file in App_Resources/Android/libs - https://github.com/NativeScript/nativescript-cli/issues/3610 - """ - Tns.plugin_add("nativescript-camera", attributes={"--path": self.app_name}) - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--syncAllFiles': ''}, - wait=False, - assert_success=False) - - strings = ['Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID, - 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - copy_aar = os.path.join(TEST_RUN_HOME, 'data', 'plugins', 'TNSListView-release.aar') - paste_aar = os.path.join(self.app_name, 'node_modules', 'nativescript-camera', 'platforms', 'android') - - File.copy(src=copy_aar, dest=paste_aar) - strings = ['Project successfully built', - 'Successfully installed on device with identifier', EMULATOR_ID, - 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, - expected_image='livesync-hello-world_home') - - def test_390_tns_run_android_should_warn_if_package_ids_do_not_match(self): - """ - If bundle identifiers in package.json and app.gradle do not match CLI should warn the user. - """ - app_gradle = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'app.gradle') - File.replace(file_path=app_gradle, str1='org.nativescript.' + self.app_name, str2='org.nativescript.MyApp') - # File.replace(file_path=app_gradle, str1='__PACKAGE__', str2='org.nativescript.MyApp') - assert "org.nativescript.MyApp" in File.read(app_gradle), "Failed to replace bundle identifier." - - output = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--justlaunch': ''}) - assert "WARNING: The Application identifier is different from the one inside \"package.json\" file." in output - assert "NativeScript CLI might not work properly." in output - assert "Project successfully built" in output - - @unittest.skipIf(CURRENT_OS == OSType.LINUX, "`shell cp -r` fails for some reason on emulators on Linux.") - def test_400_tns_run_android_respect_adb_errors(self): - """ - If disk is full adb error is thrown durring deploy, CLI should respect it - """ - - # Run the app to make sure we have something at /data/data/org.nativescript.TestApp - Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--justlaunch': ''}) - - # Use all the disk space on emulator - for index in range(1, 1000): - command = "shell cp -r /data/data/org.nativescript.TestApp /data/data/org.nativescript.TestApp" + str(index) - output = Adb.run(device_id=EMULATOR_ID, command=command, log_level=CommandLogLevel.FULL) - if "No space left on device" in output: - break - - # Create new app - Tns.create_app(app_name='TestApp2', update_modules=True) - Tns.platform_add_android(attributes={'--path': 'TestApp2', '--frameworkPath': ANDROID_PACKAGE}) - - # Run the app and verify there is appropriate error - output = Tns.run_android(attributes={'--path': 'TestApp2', '--device': EMULATOR_ID, '--justlaunch': ''}, - assert_success=False) - # Test for CLI issue 2170 - assert 'No space left on device' in output or "didn't have enough storage space" in output - - @unittest.skipIf(CURRENT_OS == OSType.WINDOWS, "Delete log during livesync not possible on Windows.") - def test_401_tns_run_android_should_not_continue_on_build_failure(self): - """ - `tns run android` should start emulator if device is not connected. - """ - Tns.create_app(self.app_name, update_modules=True) - Tns.platform_add_android(attributes={'--path': self.app_name, '--frameworkPath': ANDROID_PACKAGE}) - File.replace(file_path=self.app_name + "/app/App_Resources/Android/src/main/AndroidManifest.xml", - str1="android:name=", - str2="android:name123=") - log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, - assert_success=False) - strings = ['FAILURE', 'Build failed with an exception', 'gradlew failed with exit code 1'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False) - time.sleep(10) - output = File.read(file_path=log) - assert "successfully built" not in output - assert "Installing..." not in output - assert "installed on device" not in output - assert "synced" not in output - - def test_404_run_on_invalid_device_id(self): - output = Tns.run_android(attributes={'--path': self.app_name, '--device': 'fakeId', '--justlaunch': ''}, - assert_success=False) - TnsAsserts.invalid_device(output=output) diff --git a/tests/simulator/run_ios_tests.py b/tests/simulator/run_ios_tests.py index ca39a548..a93cabaf 100644 --- a/tests/simulator/run_ios_tests.py +++ b/tests/simulator/run_ios_tests.py @@ -76,72 +76,6 @@ def tearDownClass(cls): Emulator.stop() Folder.cleanup(TEST_RUN_HOME + "/data/TestApp") - def test_001_tns_run_ios_js_css_xml(self): - """Make valid changes in JS,CSS and XML""" - - # `tns run ios` and wait until app is deployed - log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False) - strings = ['Project successfully built', 'Successfully installed on device with identifier', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10) - - # Verify app looks correct inside simulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home', timeout=60) - - # Change JS and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10) - strings = ['Successfully transferred', 'main-view-model.js', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Change XML and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3) - strings = ['Successfully transferred', 'main-page.xml', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Change CSS and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3) - strings = ['Successfully transferred', 'app.css', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify application looks correct - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_js_css_xml', timeout=60, tolerance=0.26) - - # Rollback all the changes - ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10) - strings = ['Successfully transferred', 'main-view-model.js', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3) - strings = ['Successfully transferred', 'app.css', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3) - strings = ['Successfully transferred', 'main-page.xml', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify app looks correct inside simulator - Device.screen_match(device_name=SIMULATOR_NAME, - device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home', timeout=60) - - @unittest.skip("Incorrect path") - def test_120_tns_run_ios_delete_file_check_platforms(self): - # https://github.com/NativeScript/nativescript-cli/issues/3984 - # Files are not deleted from platforms folder on `tns run` command - log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False) - strings = ['Project successfully built', 'Successfully installed on device with identifier', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home') - - file_delete = os.path.join(self.app_name + '/' + 'app', 'main-view-model.js') - File.remove(file_delete) - assert not File.exists(file_delete) - platform_file = os.path.join(self.app_name, 'platforms', 'ios', self.app_name, 'app', 'main-view-model.js') - assert not File.exists(platform_file) - def test_180_tns_run_ios_console_log(self): """ Test console info, warn, error, assert, trace, time and logging of different objects. @@ -233,361 +167,4 @@ def test_181_tns_run_ios_console_dir(self): ] Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10) - assert self.very_long_string not in log - - def test_200_tns_run_ios_break_and_fix_app(self): - """ - Make changes in xml that break the app and then changes that fix the app. - """ - - log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False) - strings = ['Project successfully prepared', 'Project successfully built', - 'Successfully installed on device with identifier', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Break the app with invalid xml changes - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML_INVALID_SYNTAX) - - # Verify console notify user for broken xml - strings = ['main-page.xml has syntax errors', 'unclosed xml attribute', - 'Successfully synced application', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - - # Revert changes - ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_XML_INVALID_SYNTAX) - strings = ['Successfully transferred', 'main-page.xml', 'Successfully synced application', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home') - - def test_210_tns_run_ios_add_remove_files_and_folders(self): - """ - New files and folders should be synced properly. - """ - - log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, - assert_success=False) - strings = ['Project successfully prepared', 'Project successfully built', - 'Successfully installed on device with identifier', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Add new files - new_file_name = 'main-page2.xml' - source_file = os.path.join(self.app_name, 'app', 'main-page.xml') - destination_file = os.path.join(self.app_name, 'app', new_file_name) - File.copy(source_file, destination_file) - strings = ['Successfully transferred', 'main-page2.xml', 'Successfully synced application', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify new file is synced and available on device. - error_message = 'Newly created file {0} not found on {1}'.format(new_file_name, self.SIMULATOR_ID) - app_id = Tns.get_app_id(app_name=self.app_name) - path = 'app/{0}'.format(new_file_name) - assert Simulator.path_exists(package_id=app_id, path=path), error_message - - # Revert changes(rename file and delete file) - File.copy(destination_file, source_file) - File.remove(destination_file) - strings = ['Successfully transferred', 'main-page.xml', 'Successfully synced application', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify new file is synced and available on device. - error_message = '{0} was deleted, but still available on {1}'.format(new_file_name, self.SIMULATOR_ID) - assert Simulator.path_does_not_exist(package_id=app_id, path=path), error_message - - # Add folder - new_folder_name = 'test2' - source_file = os.path.join(self.app_name, 'app', 'test') - destination_file = os.path.join(self.app_name, 'app', new_folder_name) - Folder.copy(source_file, destination_file) - strings = ['Successfully transferred', 'test2', 'Successfully transferred', 'test.txt', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify new folder is synced and available on device. - error_message = 'Newly created folder {0} not found on {1}'.format(new_folder_name, self.SIMULATOR_ID) - path = 'app/{0}'.format(new_folder_name) - assert Simulator.path_exists(package_id=app_id, path=path), error_message - - # Delete folder - Folder.cleanup(destination_file) - strings = ['Successfully synced application', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify new folder is sysched and available on device. - error_message = 'Deleted folder {0} is still available on {1}'.format(new_folder_name, self.SIMULATOR_ID) - assert Simulator.path_does_not_exist(package_id=app_id, path=path), error_message - - # Verify app looks correct inside emulator - Device.screen_match(device_name=SIMULATOR_NAME, - device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home') - - def test_300_tns_run_ios_just_launch_and_incremental_builds(self): - """ - This test verify following things: - 1. `--justlaunch` option release the console. - 2. Prepare is not triggered if no changed are done. - 3. Incremental prepare is triggered if js, xml and css files are changed. - """ - - # Execute `tns run android --path TNS_App --justlaunch` and verify app looks correct on emulator - Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--justlaunch': ''}, timeout=180) - Device.screen_match(device_name=SIMULATOR_NAME, - device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home') - - # Execute `tns run android --path TNS_App --justlaunch` again - # without any changes on app under test and verify incremental prepare works - output = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--justlaunch': ''}, - assert_success=False, timeout=30) - TnsAsserts.prepared(app_name=self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.SKIP) - - # Verify app looks correct inside emulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Replace JS, XML and CSS files - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS) - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS) - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML) - - # Run `tns run ios` after file changes (this should trigger incremental prepare). - output = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--justlaunch': ''}, - assert_success=False, timeout=60) - TnsAsserts.prepared(app_name=self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.INCREMENTAL) - - # Verify app looks is update after changes in js, css and xml - Device.screen_match(device_name=SIMULATOR_NAME, - device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_js_css_xml', tolerance=0.26) - - def test_315_tns_run_ios_change_appResources_check_per_platform(self): - # https://github.com/NativeScript/nativescript-cli/pull/3619 - output = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False) - strings = ['Project successfully built', 'Successfully installed on device with identifier', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=output, string_list=strings, timeout=150, check_interval=10) - - source = os.path.join('data', 'issues', 'nativescript-cli-3619', 'icon-1025.png') - target = os.path.join(self.app_name, 'app', 'App_Resources', 'iOS', 'Assets.xcassets', 'AppIcon.appiconset') - File.copy(source, target) - strings = ['Xcode build'] - Tns.wait_for_log(log_file=output, string_list=strings, clean_log=False) - assert "Gradle build" not in output - - def test_330_tns_run_ios_sync_all_files(self): - """ - Verify '--syncAllFiles' option will sync all files, including node modules. - """ - log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--syncAllFiles': ''}, - wait=False, assert_success=False) - strings = ['Successfully installed on device with identifier', - 'Successfully synced application', - self.SIMULATOR_ID, # Verify device id - 'CONSOLE LOG'] # Verify console log messages are shown. - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - - ReplaceHelper.replace(app_name=self.app_name, file_change=ReplaceHelper.CHANGE_TNS_MODULES) - - strings = ['Successfully transferred', 'application-common.js', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Verify app looks correct inside simulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home') - - def test_340_tns_run_should_not_sync_hidden_files(self): - """ - Adding hidden files should not break run and they should not be transferred. - """ - - # `tns run ios` and wait until app is deployed - log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False) - sync_message = 'Successfully synced application {0} on device {1}' \ - .format(Tns.get_app_id(self.app_name), self.SIMULATOR_ID) - strings = ['Project successfully built', 'Successfully installed on device with identifier', sync_message] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10) - - # Verify app looks correct inside simulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Add some hidden files - source_file = os.path.join(self.app_name, 'app', 'main-page.xml') - destination_file = os.path.join(self.app_name, 'app', '.tempfile') - File.copy(source_file, destination_file) - - # Give it 10 sec and check no messages are available in log files - time.sleep(10) - output = File.read(log) - assert 'Successfully' not in output, 'Sync is triggered after adding hidden file.' - assert 'synced' not in output, 'Sync is triggered after adding hidden file.' - assert 'tempfile' not in output, 'Sync is triggered after adding hidden file.' - assert self.SIMULATOR_ID not in output, 'Sync is triggered after adding hidden file.' - - # Verify hidden file does not exists on mobile device. - path = 'app/{0}'.format('.tempfile') - app_id = Tns.get_app_id(self.app_name) - error_message = 'Hidden file {0} is transferred to {1}'.format(path, self.SIMULATOR_ID) - assert Simulator.path_does_not_exist(package_id=app_id, path=path), error_message - - # Verify app looks correct inside simulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home') - - def test_350_tns_run_ios_should_start_simulator(self): - """ - `tns run ios` should start iOS Simulator if device is not connected. - """ - count = Device.get_count(platform=Platform.IOS) - if count == 0: - Simulator.stop() - Tns.run_ios(attributes={'--path': self.app_name, '--justlaunch': ''}) - assert Simulator.wait_for_simulator(timeout=10), 'iOS Simulator not started by `tns run ios`!' - else: - raise nose.SkipTest('This test is not valid when devices are connected.') - - def test_360_tns_run_ios_changes_in_app_resources_rebuild_app(self): - """ - https://github.com/NativeScript/nativescript-cli/issues/3658 - In case when some change occurs in App_Resources/Android and tns run ios command is executed, - the application is fully rebuild when it should not. - """ - - # Run app twice and check the second time it's not rebuild - log1 = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False) - strings = ['Project successfully built', 'Successfully installed on device with identifier', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log1, string_list=strings, timeout=150, check_interval=10, clean_log=False) - - log2 = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False) - strings = ['Skipping prepare', 'Successfully transferred all files', 'Successfully synced application', 'Restarting application',] - Tns.wait_for_log(log_file=log2, string_list=strings, timeout=150, check_interval=10, clean_log=False) - - # Make change in App_Resources/Android folder - app_resources_file = os.path.join(self.app_name, "app", "App_Resources", "Android", "values", - "colors.xml") - file_to_change = os.path.join("data", "issues", "nativescript-cli-3658", "colors.xml") - File.copy(file_to_change, app_resources_file) - - # Run again the app and ensure it's not rebuild - log3 = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False) - strings = ['Skipping prepare', 'Successfully synced application', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log3, string_list=strings, timeout=150, check_interval=10, clean_log=False) - assert 'Building project' not in log3, "Project is rebuilt when it should not." - - def test_370_tns_run_plugin_add(self): - """ - `tns run ios` should do full rebuild after plugin is added. - """ - # `tns run ios` and wait until app is deployed - log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False, - log_trace=True) - strings = ['Project successfully built', 'Successfully installed on device with identifier', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10) - - # Verify app looks correct inside simulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home') - - # Add plugin - Tns.plugin_add("nativescript-telerik-ui", attributes={"--path": self.app_name}) - - # Change JS and wait for full sync - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10) - strings = ['BUILD SUCCEEDED', 'Project successfully built', 'Successfully installed on device with identifier', - self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings) - - # Rollback JS changes and verify sync is incremental - ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10) - strings = ['Successfully transferred', 'main-view-model.js', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, clean_log=False) - assert 'BUILD SUCCEEDED' not in File.read(log), "Second change of JS files after plugin add is not incremental!" - File.write(file_path=log, text="") # Clean log file - - # Change XML and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3) - strings = ['Successfully transferred', 'main-page.xml', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, clean_log=False) - assert 'BUILD SUCCEEDED' not in File.read(log), "Change of XML files after plugin add is not incremental!" - File.write(file_path=log, text="") # Clean log file - - # Change CSS and wait until app is synced - ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3) - strings = ['Successfully transferred', 'app.css', 'Successfully synced application'] - Tns.wait_for_log(log_file=log, string_list=strings, clean_log=False) - assert 'BUILD SUCCEEDED' not in File.read(log), "Change of CSS files after plugin add is not incremental!" - File.write(file_path=log, text="") # Clean log file - - def test_385_tns_run_ios_source_code_in_ios_part_plugin(self): - """ - https://github.com/NativeScript/nativescript-cli/issues/3650 - """ - - # Add plugin with source code in iOS part of the plugin - Tns.plugin_add(self.plugin_path, attributes={"--path": self.app_name}) - - # Replace main-page.js to call method from the source code of the plugin - source_js = os.path.join('data', "issues", 'nativescript-cli-3650', 'main-page.js') - target_js = os.path.join(self.app_name, 'app', 'main-page.js') - File.copy(src=source_js, dest=target_js) - - log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False) - - strings = ['Project successfully built', 'Successfully installed on device with identifier', self.SIMULATOR_ID, - 'Hey!'] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10) - - # Verify app looks correct inside simulator - Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, - expected_image='livesync-hello-world_home') - - def test_390_tns_run_ios_should_warn_if_package_ids_do_not_match(self): - """ - If bundle identifiers in package.json and Info.plist do not match CLI should warn the user. - """ - str1 = "${EXECUTABLE_NAME}" - str2 = "${EXECUTABLE_NAME}" \ - "CFBundleIdentifier" \ - "org.nativescript.myapp" - info = os.path.join(self.app_name, 'app', 'App_Resources', 'iOS', 'Info.plist') - File.replace(file_path=info, str1=str1, str2=str2) - # `--emulator` added to workaround https://github.com/NativeScript/nativescript-cli/issues/3644 - output = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--justlaunch': ''}) - assert "[WARNING]: The CFBundleIdentifier key inside the 'Info.plist' will be overriden" in output - assert "Successfully synced application org.nativescript.TestApp" in output - - def test_400_tns_run_on_folder_with_spaces(self): - """ - `tns run ios` for apps with spaces - """ - destination_path = os.path.join(TEST_RUN_HOME, "folder with spaces", "Test App") - Folder.cleanup(folder=destination_path) - Folder.copy(src=self.app_name, dst=destination_path) - output = Tns.run_ios( - attributes={'--path': "\"" + destination_path + "\"", '--emulator': '', '--justlaunch': ''}) - assert "Multiple errors were thrown" not in output - - def test_404_tns_run_ios_on_not_existing_device_should_not_start_simulator(self): - Simulator.stop() - output = Tns.run_ios(attributes={'--path': self.app_name, '--device': 'fakeId', '--justlaunch': ''}, - assert_success=False) - assert not Simulator.wait_for_simulator( - timeout=10)[0], "Simulator should not be started after run `tns run ios --device `" - TnsAsserts.invalid_device(output=output) - - @unittest.skipIf(Device.get_count(platform=Platform.IOS) > 0 or Device.get_count(platform=Platform.ANDROID) > 0, - "Valid only if there are no devices.") - def test_410_run_without_platform_and_without_devices(self): - Simulator.stop() - Emulator.stop() - Tns.create_app(self.app_name, update_modules=True) - output = Tns.run(attributes={'--path': self.app_name, '--justlaunch': ''}, assert_success=False) - assert "Unable to find applicable devices to execute operation " \ - "and unable to start emulator when platform is not specified" in output + assert self.very_long_string not in log \ No newline at end of file diff --git a/tests/simulator/run_ios_tests_ng.py b/tests/simulator/run_ios_tests_ng.py deleted file mode 100644 index f127088f..00000000 --- a/tests/simulator/run_ios_tests_ng.py +++ /dev/null @@ -1,63 +0,0 @@ -""" -Test for `tns run ios` command with Angular apps (on simulator). -""" - -import os - -from core.base_class.BaseClass import BaseClass -from core.device.device import Device -from core.device.emulator import Emulator -from core.device.simulator import Simulator -from core.osutils.folder import Folder -from core.settings.settings import IOS_PACKAGE, SIMULATOR_NAME -from core.tns.tns import Tns - - -class RunIOSSimulatorTestsNG(BaseClass): - SIMULATOR_ID = '' - - @classmethod - def setUpClass(cls): - BaseClass.setUpClass(cls.__name__) - Emulator.stop() - Simulator.stop() - cls.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME) - Folder.cleanup(cls.app_name) - - # Create default NG app (to get right dependencies from package.json) - Tns.create_app_ng(cls.app_name) - Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_PACKAGE}) - - # Copy the app folder (app is modified in order to get some console logs on loaded) - source = os.path.join('data', 'apps', 'livesync-hello-world-ng', 'src') - target = os.path.join(cls.app_name, 'src') - Folder.cleanup(target) - Folder.copy(src=source, dst=target) - - def setUp(self): - BaseClass.setUp(self) - Tns.kill() - - def tearDown(self): - Tns.kill() - BaseClass.tearDown(self) - - @classmethod - def tearDownClass(cls): - BaseClass.tearDownClass() - Emulator.stop() - - def test_001_tns_run_ios(self): - # `tns run ios` and wait until app is deployed - log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, - assert_success=False) - strings = ['Project successfully built', 'Successfully installed on device with identifier', self.SIMULATOR_ID] - Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10, clean_log=False) - - # Verify initial state of the app - assert Device.wait_for_text(device_id=self.SIMULATOR_ID, text="Ter Stegen", - timeout=20), 'Hello-world NG App failed to start or it does not look correct!' - - # Verify console.log works - issue #3141 - console_log_strings = ['CONSOLE LOG', 'Home page loaded!', 'Application loaded!'] - Tns.wait_for_log(log_file=log, string_list=console_log_strings)