def test_003_android_run_hmr_wrong_xml(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) # Verify app looks correct inside emulator Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image=HelpersHMR.image_original) # 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 = ['for activity org.nativescript.TestApp / com.tns.ErrorReportActivity'] strings = ['com.tns.NativeScriptException', 'Parsing XML at', '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 = ['JS: HMR: Hot Module Replacement Enabled. Waiting for signal.', '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=HelpersHMR.image_original)
def test_360_tns_run_android_with_jar_file_in_plugin(self): """ App should not crash when reference .jar file in some plugin https://github.com/NativeScript/android-runtime/pull/905 """ # Add .jar file in plugin and modify the app to reference it custom_jar_file = os.path.join('data', 'issues', 'android-runtime-pr-905', 'customLib.jar') modules_widgets = os.path.join(self.app_name, 'node_modules', 'tns-core-modules-widgets', 'platforms', 'android') File.copy(src=custom_jar_file, dest=modules_widgets) source = os.path.join('data', 'issues', 'android-runtime-pr-905', 'app.js') target = os.path.join(self.app_name, 'app', 'app.js') File.copy(src=source, dest=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'] 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_100_debug_ios_simulator_with_livesync(self): """ `tns debug ios` should be able to run with livesync """ log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': '', '--inspector': ''}) DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log) # Verify app starts and do not stop on first line of code Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_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', 'CONSOLE LOG', 'Backend socket closed', 'Frontend socket closed', 'Frontend client connected', 'Backend socket created', 'NativeScript debugger attached'] Tns.wait_for_log(log_file=log, string_list=strings) # Change XML and wait until app is synced. App doesn't restart from 5.1.0 version ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3) strings = ['Successfully transferred', 'main-page.xml', 'CONSOLE LOG'] Tns.wait_for_log(log_file=log, string_list=strings) # Change CSS and wait until app is synced. App doesn't restart from 5.1.0 version ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3) strings = ['Successfully transferred', 'app.css', 'CONSOLE LOG'] 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', tolerance=0.26) assert Process.is_running('NativeScript Inspector')
def test_003_debug_ios_simulator_start(self): """ Attach the debug tools to a running app in the iOS Simulator """ # Run the app and ensure it works log = 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=log, prepare=Prepare.SKIP) Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home') # Attach debugger log = Tns.debug_ios( attributes={ '--path': self.app_name, '--emulator': '', '--start': '', '--inspector': '' }) DebugiOSInspectorSimulatorTests.__verify_debugger_attach( log, app_started=False)
def test_370_tns_run_android_with_jar_and_aar_files_in_app_res(self): """ App should not crash when reference .jar or/and .aar file in App_Resources/Android/libs https://github.com/NativeScript/android-runtime/issues/899 """ # Create libs/ in app/App_resources/, add .jar and .aar files in it and modify the app to reference them curr_folder = os.getcwd() Folder.navigate_to(os.path.join(self.app_name, 'app', 'App_Resources', 'Android')) Folder.create("libs") app_res_libs = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'libs') Folder.navigate_to(curr_folder) custom_jar_file = os.path.join('data', 'issues', 'android-runtime-pr-905', 'customLib.jar') custom_aar_file = os.path.join('data', 'issues', 'android-runtime-899', 'mylibrary.aar') File.copy(src=custom_jar_file, dest=app_res_libs) File.copy(src=custom_aar_file, dest=app_res_libs) source = os.path.join('data', 'issues', 'android-runtime-899', 'app.js') target = os.path.join(self.app_name, 'app', 'app.js') File.copy(src=source, dest=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'] 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_280_tns_run_android_console_time(self): # 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) # Replace app.component.ts to use console.time() and console.timeEnd() source = os.path.join('data', 'issues', 'ios-runtime-843', 'app.component.ts') target = os.path.join(self.app_name, 'src', 'app', 'app.component.ts') File.copy(src=source, dest=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) # Verify the app is running strings = ['Successfully synced application', 'Application loaded!', 'Home page loaded!'] Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10, clean_log=False) # Verify initial state of the app Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image='ng-hello-world-home-white', tolerance=5.0) # Verify console.time() works console_time = ['JS: startup:'] Tns.wait_for_log(log_file=log, string_list=console_time)
def test_001_debug_ios_simulator(self): """ Default `tns debug ios` starts debugger (do not stop at the first code statement) """ log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': '', '--inspector': ''}) DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log) # Verify app starts and do not stop on first line of code Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home')
def test_003_android_run_hmr_wrong_xml(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) # Verify app looks correct inside emulator Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image=HelpersHMR.image_original) # 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 = ['for activity org.nativescript.TestApp / com.tns.ErrorReportActivity'] strings = [ 'com.tns.NativeScriptException', 'Parsing XML at', '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 = [ 'JS: HMR: Hot Module Replacement Enabled. Waiting for signal.', '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=HelpersHMR.image_original)
def test_002_debug_ios_simulator_debug_brk(self): """ Starts debugger and stop at the first code statement. """ log = Tns.debug_ios( attributes={'--path': self.app_name, '--emulator': '', '--debug-brk': '', '--inspector': ''}) DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log, app_started=False) # In this case `app_started` is False because app is not loaded when using '--debug-brk'. # '--debug-brk' stops before app loaded. # Verify app starts and do not stop on first line of code Device.screen_match(device_name=SIMULATOR_NAME, tolerance=3.0, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_debug_brk')
def test_008_android_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_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False, assert_success=False) strings = ['LOG Hello'] 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=HelpersHMR.image_original)
def test_370_tns_run_android_with_jar_and_aar_files_in_app_res(self): """ App should not crash when reference .jar or/and .aar file in App_Resources/Android/libs https://github.com/NativeScript/android-runtime/issues/899 """ # Create libs/ in app/App_resources/, add .jar and .aar files in it and modify the app to reference them curr_folder = os.getcwd() Folder.navigate_to( os.path.join(self.app_name, 'app', 'App_Resources', 'Android')) Folder.create("libs") app_res_libs = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'libs') Folder.navigate_to(curr_folder) custom_jar_file = os.path.join('data', 'issues', 'android-runtime-pr-905', 'customLib.jar') custom_aar_file = os.path.join('data', 'issues', 'android-runtime-899', 'mylibrary.aar') File.copy(src=custom_jar_file, dest=app_res_libs) File.copy(src=custom_aar_file, dest=app_res_libs) source = os.path.join('data', 'issues', 'android-runtime-899', 'app.js') target = os.path.join(self.app_name, 'app', 'app.js') File.copy(src=source, dest=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' ] 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_003_debug_ios_simulator_start(self): """ Attach the debug tools to a running app in the iOS Simulator """ # Run the app and ensure it works log = 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=log, prepare=Prepare.SKIP) Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home') # Attach debugger log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': '', '--start': '', '--inspector': ''}) DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log, app_started=False)
def test_001_debug_ios_simulator(self): """ Default `tns debug ios` starts debugger (do not stop at the first code statement) """ log = Tns.debug_ios(attributes={ '--path': self.app_name, '--emulator': '', '--inspector': '' }) DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log) # Verify app starts and do not stop on first line of code Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home')
def test_100_debug_ios_simulator_with_livesync(self): """ `tns debug ios` should be able to run with livesync """ log = Tns.debug_ios(attributes={ '--path': self.app_name, '--emulator': '', '--inspector': '' }) DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log) # Verify app starts and do not stop on first line of code Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_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', 'CONSOLE LOG', 'Backend socket closed', 'Frontend socket closed', 'Frontend client connected', 'Backend socket created', 'NativeScript debugger attached' ] Tns.wait_for_log(log_file=log, string_list=strings) # Change XML and wait until app is synced. App doesn't restart from 5.1.0 version ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3) strings = ['Successfully transferred', 'main-page.xml', 'CONSOLE LOG'] Tns.wait_for_log(log_file=log, string_list=strings) # Change CSS and wait until app is synced. App doesn't restart from 5.1.0 version ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3) strings = ['Successfully transferred', 'app.css', 'CONSOLE LOG'] 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', tolerance=0.26) assert Process.is_running('NativeScript Inspector')
def test_360_tns_run_android_with_jar_file_in_plugin(self): """ App should not crash when reference .jar file in some plugin https://github.com/NativeScript/android-runtime/pull/905 """ # Add .jar file in plugin and modify the app to reference it custom_jar_file = os.path.join('data', 'issues', 'android-runtime-pr-905', 'customLib.jar') modules_widgets = os.path.join(self.app_name, 'node_modules', 'tns-core-modules-widgets', 'platforms', 'android') File.copy(src=custom_jar_file, dest=modules_widgets) source = os.path.join('data', 'issues', 'android-runtime-pr-905', 'app.js') target = os.path.join(self.app_name, 'app', 'app.js') File.copy(src=source, dest=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' ] 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_002_debug_ios_simulator_debug_brk(self): """ Starts debugger and stop at the first code statement. """ log = Tns.debug_ios( attributes={ '--path': self.app_name, '--emulator': '', '--debug-brk': '', '--inspector': '' }) DebugiOSInspectorSimulatorTests.__verify_debugger_attach( log, app_started=False) # In this case `app_started` is False because app is not loaded when using '--debug-brk'. # '--debug-brk' stops before app loaded. # Verify app starts and do not stop on first line of code Device.screen_match(device_name=SIMULATOR_NAME, tolerance=3.0, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_debug_brk')
def test_008_android_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_android(attributes={ '--path': self.app_name, '--device': EMULATOR_ID, '--hmr': '' }, wait=False, assert_success=False) strings = ['LOG Hello'] 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=HelpersHMR.image_original)