def __console_log(self, platform, device): # Run `tns debug` wait until debug url is in the console and app is loaded result = Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open Chrome Dev Tools -> Console self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.CONSOLE) # TAP the button to trigger console log and ensure it is in device logs device.click(text='TAP', case_sensitive=True) assert device.wait_for_log( text='Test Debug!', timeout=90), 'Console logs not available in device logs.' # Ensure logs are available in tns logs tns_logs = File.read(result.log_file) assert "Test Debug!" in tns_logs, 'Console log messages not available in CLI output.' + os.linesep + tns_logs message = 'Console log messages(Arabic and Kurdish characters) not available in CLI output.' # add test for issue https://github.com/NativeScript/android-runtime/issues/1302 assert 'العربییە' in tns_logs, message + os.linesep + tns_logs # Verify console logs are available in Chrome dev tools log = self.dev_tools.wait_element_by_text(text='Test Debug!') assert log is not None, 'Console logs not displayed in Chrome Dev Tools.' if Settings.PYTHON_VERSION < 3: text = 'العربییە'.decode('utf-8') else: text = 'العربییە' log = self.dev_tools.wait_element_by_text(text=text) # add test for issue https://github.com/NativeScript/android-runtime/issues/1302 assert log is not None, 'Console logs(Arabic and Kurdish characters) not displayed in Chrome Dev Tools.'
def __debug_watch_expression(self, platform, device): # Start debug and wait until app is deployed Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open sources tab and place breakpoint on line 18 of main-view-model.js self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) self.dev_tools.load_source_file("main-view-model.js") self.dev_tools.breakpoint(18) # Tap on TAP button in emulator and check it is hit device.click(text="TAP", case_sensitive=True) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=60) assert pause_element is not None, 'Failed to pause on breakpoint.' # Add watch expression if platform == Platform.ANDROID: self.dev_tools.add_watch_expression( expression='console', expected_result='console: Object') elif platform == Platform.IOS: self.dev_tools.add_watch_expression( expression='console', expected_result='console: Console') self.dev_tools.add_watch_expression( expression='viewModel', expected_result='viewModel: Observable')
def __debug_elements(self, platform, device): # Run `tns debug` wait until app is visible on device Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Start debug session and verify elements tab self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.ELEMENTS) assert self.dev_tools.wait_element_by_text( text=self.xml_change.old_text ) is not None, 'Elements tab is empty.' # Sync changes and verify elements tab is updated Sync.replace(app_name=self.app_name, change_set=self.xml_change) device.wait_for_text(text=self.xml_change.new_text) assert self.dev_tools.wait_element_by_text( text=self.xml_change.new_text ) is not None, 'Elements tab not updated.' # Update label in CDT and verify it is updated on device self.dev_tools.edit_text(old_text=self.xml_change.new_text, new_text=self.xml_change.old_text) element = self.dev_tools.wait_element_by_text( text=self.xml_change.old_text, timeout=90) assert element is not None, 'Failed to change text in elements tab.' device.wait_for_text(text=self.xml_change.old_text)
def __debug_sync_changes(self, platform, device): # Start debug and wait until app is deployed result = Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open sources tab and verify content is loaded self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) # Open JS file and place breakpoint on line 18 self.dev_tools.load_source_file("main-view-model.js") self.dev_tools.breakpoint(18) # Sync JS changes works fine until breakpoint is hit Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS) js_file_name = os.path.basename(Changes.JSHelloWord.JS.file_path) logs = [ js_file_name, 'Webpack build done!', 'Refreshing application', 'Successfully synced application' ] TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs) device.wait_for_text(text=Changes.JSHelloWord.JS.new_text, timeout=30) # Revert changes Sync.revert(app_name=self.app_name, change_set=Changes.JSHelloWord.JS) TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs) device.wait_for_text(text=Changes.JSHelloWord.JS.old_text, timeout=30) # Tap on TAP button in emulator and check it is hit device.click(text="TAP", case_sensitive=True) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=90) assert pause_element is not None, 'Failed to pause on breakpoint.' # Test for https://github.com/NativeScript/nativescript-cli/issues/4227 Sync.replace(app_name=self.app_name, change_set=self.xml_change) xml_file_name = os.path.basename(self.xml_change.file_path) logs = [ xml_file_name, 'Webpack build done!', 'Refreshing application', 'Successfully synced application' ] TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs) sleep(10) # Give it some more time to crash logs = File.read(result.log_file) assert 'Unable to apply changes' not in logs assert 'Stopping webpack watch' not in logs assert 'closed' not in logs assert 'detached' not in logs assert "did not start in time" not in logs # Resume execution self.dev_tools.continue_debug() device.wait_for_text( text='42 taps left', timeout=30) # We tapped but changes synced so number is restarted device.wait_for_text(text=self.xml_change.new_text, timeout=10) # Verify change applied during debug
def __debug_elements(self, platform, device): # Start debug and open elements tab Tns.debug(app_name=self.app_name, platform=platform, emulator=True) self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.ELEMENTS) self.dev_tools.wait_element_by_text(text=ACTION_BAR_TITLE) # Add child and verify it is visible in CDT device.click(text=HOME_ADD_CHILD_BUTTON) self.dev_tools.doubleclick_line(text='StackLayout') self.dev_tools.doubleclick_line(text='ScrollView') time.sleep(4) self.dev_tools.doubleclick_line(text='FlexboxLayout') if platform == Platform.ANDROID: assert self.dev_tools.wait_element_by_text( text='StackLayout id=') is not None else: assert self.dev_tools.wait_element_by_text( text='StackLayout iosOverflowSafeArea="true" id=') is not None # Remove child and verify it is NOT visible in CDT device.click(text=HOME_REMOVE_CHILD_BUTTON) text = 'StackLayout id=' if platform == Platform.IOS: text = 'StackLayout iosOverflowSafeArea="true" id=' found = Wait.until( lambda: self.dev_tools.find_element_by_text(text=text) is None, timeout=10) assert found is True, 'Item not removed from elements tab after removed from app.'
def __debug_brk(self, platform, device): # Hack to workaround https://github.com/NativeScript/nativescript-cli/issues/4567 Tns.run(app_name=self.app_name, platform=platform, emulator=True, source_map=True, just_launch=True) device.wait_for_text(text='TAP') Tns.debug(app_name=self.app_name, platform=platform, emulator=True, debug_brk=True) self.dev_tools = ChromeDevTools(self.chrome, platform=platform) self.dev_tools.open_tab(tab=ChromeDevToolsTabs.SOURCES, verify=False) pause_element = self.dev_tools.wait_element_by_text( text="Debugger paused", timeout=30) assert pause_element is not None, 'Failed to stop on first line of code.' assert self.dev_tools.find_element_by_text( text="function" ) is not None, 'Failed to stop on first line of code.' assert 'NativeScript' in device.get_text( ), 'Failed to stop on first line of code.' # Resume execution self.dev_tools.continue_debug() device.wait_for_text(text='TAP')
def __debug_sources(self, platform, device): # Run debug, to network page and open network tab in CDT result = Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.click(text=HOME_NETWORK_BUTTON) self.dev_tools = ChromeDevTools(self.chrome, platform=platform) self.dev_tools.open_tab(tab=ChromeDevToolsTabs.SOURCES, verify=False) # Place breakpoint and verify it is hit self.dev_tools.load_source_file('network-page.ts') self.dev_tools.breakpoint(line=12) device.click(text=NET_GET_WITHOUT_BODY) self.dev_tools.wait_element_by_text(text='Paused on breakpoint', timeout=10) assert 'httpbin.org' not in File.read(result.log_file) self.dev_tools.continue_debug() TnsLogs.wait_for_log(log_file=result.log_file, string_list=['httpbin.org']) # Add one more breakpoint and hit it self.dev_tools.load_source_file('network-page.ts') self.dev_tools.breakpoint(line=30) device.click(text=NET_GET_WITH_BODY) self.dev_tools.wait_element_by_text(text='Paused on breakpoint', timeout=60) assert 'My custom Arbitrary Header value' not in File.read( result.log_file) self.dev_tools.continue_debug() TnsLogs.wait_for_log(log_file=result.log_file, string_list=['My custom Arbitrary Header value'])
def __debug_console(self, platform, device): Tns.debug(app_name=self.app_name, platform=platform, emulator=True) self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.CONSOLE) device.click(text=HOME_CONSOLE_BUTTON) if platform == Platform.ANDROID: self.dev_tools.wait_element_by_text(text='main-view-model.ts:34') else: self.dev_tools.wait_element_by_text(text='main-view-model.ts:35')
def __console_eval(self, platform, device): # Run `tns debug` wait until debug url is in the console and app is loaded Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open Chrome Dev Tools -> Console self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.CONSOLE) # Evaluate on console self.dev_tools.type_on_console("1024+1024") self.dev_tools.wait_element_by_text(text='2048', timeout=10)
def __debug_elements(self, platform, device): # Run `tns debug` wait until app is visible on device Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text=self.ts_change.old_text, timeout=240) # Start debug session and verify elements tab self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.ELEMENTS) assert self.dev_tools.wait_element_by_text( text=self.xml_change.old_text ) is not None, 'Elements tab is empty.' # Sync changes and verify elements tab is updated Sync.replace(app_name=self.app_name, change_set=self.xml_change) device.wait_for_text(text=self.xml_change.new_text) # Elements tab do not auto-update for NG apps and need to be refreshed manually self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.ELEMENTS) assert self.dev_tools.wait_element_by_text( text=self.xml_change.new_text ) is not None, 'Elements tab not updated.' # Update label in CDT and verify it is updated on device self.dev_tools.edit_text(old_text=self.xml_change.new_text, new_text=self.xml_change.old_text) element = self.dev_tools.wait_element_by_text( text=self.xml_change.old_text) assert element is not None, 'Failed to change text in elements tab.' device.wait_for_text(text=self.xml_change.old_text) # Expand items self.dev_tools.doubleclick_line(text='ProxyViewContainer') self.dev_tools.doubleclick_line(text='GridLayout') time.sleep(3) self.dev_tools.doubleclick_line(text='ListView') if platform == Platform.ANDROID: self.dev_tools.doubleclick_line(text='StackLayout') self.dev_tools.wait_element_by_text(text='Label', timeout=10) if platform == Platform.IOS: self.dev_tools.wait_element_by_text(text='StackLayout', timeout=10)
def __debug_network(self, platform, device): Tns.debug(app_name=self.app_name, platform=platform, emulator=True) self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.NETWORK) device.click(text=HOME_NETWORK_BUTTON) # Request without body device.click(text=NET_GET_WITHOUT_BODY) assert self.dev_tools.wait_element_by_text(text='get') is not None assert self.dev_tools.wait_element_by_text(text='200') is not None assert self.dev_tools.wait_element_by_text(text='0 B') is not None self.dev_tools.clean_network_tab() # Request with body device.click(text=NET_GET_WITH_BODY) assert self.dev_tools.wait_element_by_text(text='get') is not None assert self.dev_tools.wait_element_by_text(text='200') is not None assert self.dev_tools.wait_element_by_text(text=' B') is not None self.dev_tools.clean_network_tab()
def __debug_sources(self, platform, device): # Start debug and wait until app is deployed Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text=self.ts_change.old_text) # Open sources tab and verify content is loaded self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) # Open TS file and place breakpoint on line 21 self.dev_tools.load_source_file('item-detail.component.ts') self.dev_tools.breakpoint(21) # Navigate to details page and check breakpoint is hit device.click(text=self.ts_change.old_text) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=10) assert pause_element is not None, 'Failed to pause on breakpoint.' # Resume execution self.dev_tools.continue_debug() device.wait_for_text(text='Goalkeeper', timeout=30) # Sync changes and verify sources tab is updated Sync.replace(app_name=self.app_name, change_set=self.ts_change) device.wait_for_text(text=self.ts_change.new_text) self.dev_tools.load_source_file('item.service.ts') self.dev_tools.wait_element_by_text(text=self.ts_change.new_text, timeout=10) # Navigate to details page and check breakpoint is hit device.click(text=self.ts_change.new_text) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=10) assert pause_element is not None, 'Failed to pause on breakpoint.' # Resume execution self.dev_tools.continue_debug() device.wait_for_text(text='Goalkeeper', timeout=30)
def __debug_start(self, platform, device): # Run the app and verify it is deployed Tns.run(app_name=self.app_name, platform=platform, emulator=True, source_map=True, just_launch=True) device.wait_for_text(text='TAP') # Attach debug session result = Tns.debug(app_name=self.app_name, platform=platform, emulator=True, start=True) # Verify sources tab is loaded self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) device.wait_for_text(text='TAP') # Verify console log is working (covers https://github.com/NativeScript/nativescript-cli/issues/3629) self.dev_tools.open_tab(ChromeDevToolsTabs.CONSOLE) device.click(text='TAP', case_sensitive=True) assert self.dev_tools.wait_element_by_text( text='Test Debug!' ) is not None, 'Console logs not displayed in CDT.' tns_logs = File.read(result.log_file) assert "Test Debug!" in tns_logs, 'Console log messages not available in CLI output.' + os.linesep + tns_logs # Verify debug is working (covers https://github.com/NativeScript/nativescript-cli/issues/2831) self.dev_tools.open_tab(ChromeDevToolsTabs.SOURCES) self.dev_tools.load_source_file("main-view-model.js") self.dev_tools.breakpoint(18) device.click(text="TAP", case_sensitive=True) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=10) assert pause_element is not None, 'Failed to pause on breakpoint.'
def __debug_sources(self, platform, device): # Start debug and wait until app is deployed Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open sources tab and verify content is loaded self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) # Open JS file and place breakpoint on line 18 self.dev_tools.load_source_file("main-view-model.js") self.dev_tools.breakpoint(18) # Tap on TAP button in emulator and check it is hit device.click(text="TAP", case_sensitive=True) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=40) assert pause_element is not None, 'Failed to pause on breakpoint.' # Resume execution self.dev_tools.continue_debug() device.wait_for_text(text='41 taps left', timeout=30)
def __console_log(self, platform, device): # Run `tns debug` wait until debug url is in the console and app is loaded result = Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open Chrome Dev Tools -> Console self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.CONSOLE) # TAP the button to trigger console log and ensure it is in device logs device.click(text='TAP', case_sensitive=True) assert device.wait_for_log( text='Test Debug!'), 'Console logs not available in device logs.' # Ensure logs are available in tns logs tns_logs = File.read(result.log_file) assert "Test Debug!" in tns_logs, 'Console log messages not available in CLI output.' + os.linesep + tns_logs # Verify console logs are available in Chrome dev tools log = self.dev_tools.wait_element_by_text(text='Test Debug!') assert log is not None, 'Console logs not displayed in Chrome Dev Tools.'
def __reload_page(self, platform, device): # Start debug and wait until app is deployed Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open CDT with debug url twice self.dev_tools = ChromeDevTools(self.chrome, platform=platform) sleep(1) self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) device.wait_for_text(text='TAP') # Open another site and then back to CDT self.chrome.open(url='https://www.nativescript.org') self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) device.wait_for_text(text='TAP')
class DebugJSTests(TnsRunTest): app_name = Settings.AppName.DEFAULT xml_change = Changes.JSHelloWord.XML_ACTION_BAR js_change = Changes.JSHelloWord.JS chrome = None dev_tools = None @classmethod def setUpClass(cls): TnsRunTest.setUpClass() Tns.create(app_name=cls.app_name, template=Template.HELLO_WORLD_JS.local_package, update=True) # Instrument the app so it console log events. source_js = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'runtime', 'debug', 'files', "console_log", 'main-view-model.js') target_js = os.path.join(Settings.TEST_RUN_HOME, cls.app_name, 'app', 'main-view-model.js') File.copy(source=source_js, target=target_js) Tns.platform_add_android( app_name=cls.app_name, framework_path=Settings.Android.FRAMEWORK_PATH) if Settings.HOST_OS == OSType.OSX: Tns.platform_add_ios(app_name=cls.app_name, framework_path=Settings.IOS.FRAMEWORK_PATH) def setUp(self): TnsRunTest.setUp(self) Sync.revert(app_name=self.app_name, change_set=self.js_change, fail_safe=True) Sync.revert(app_name=self.app_name, change_set=self.xml_change, fail_safe=True) self.chrome = Chrome() def tearDown(self): self.chrome.kill() TnsRunTest.tearDown(self) def test_001_debug_android_elements(self): self.__debug_elements(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_001_debug_ios_elements(self): self.__debug_elements(platform=Platform.IOS, device=self.sim) def test_010_debug_android_console_log(self): self.__console_log(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_010_debug_ios_console_log(self): self.__console_log(platform=Platform.IOS, device=self.sim) def test_011_debug_android_console_eval(self): self.__console_eval(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_011_debug_ios_console_eval(self): self.__console_eval(platform=Platform.IOS, device=self.sim) def test_020_debug_android_sources(self): self.__debug_sources(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_020_debug_ios_sources(self): self.__debug_sources(platform=Platform.IOS, device=self.sim) def test_021_debug_android_synch_changes(self): self.__debug_sync_changes(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_021_debug_ios_synch_changes(self): self.__debug_sync_changes(platform=Platform.IOS, device=self.sim) def test_022_debug_android_watch_expression(self): self.__debug_watch_expression(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_022_debug_ios_watch_expression(self): self.__debug_watch_expression(platform=Platform.IOS, device=self.sim) def test_030_debug_android_brk(self): self.__debug_brk(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_030_debug_ios_brk(self): self.__debug_brk(platform=Platform.IOS, device=self.sim) def test_040_debug_android_start(self): self.__debug_start(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_040_debug_ios_start(self): self.__debug_start(platform=Platform.IOS, device=self.sim) def test_100_reload_chrome_page_android(self): self.__reload_page(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_100_reload_chrome_page_ios(self): self.__reload_page(platform=Platform.IOS, device=self.sim) def __debug_elements(self, platform, device): # Run `tns debug` wait until app is visible on device Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Start debug session and verify elements tab self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.ELEMENTS) assert self.dev_tools.wait_element_by_text( text=self.xml_change.old_text ) is not None, 'Elements tab is empty.' # Sync changes and verify elements tab is updated Sync.replace(app_name=self.app_name, change_set=self.xml_change) device.wait_for_text(text=self.xml_change.new_text) assert self.dev_tools.wait_element_by_text( text=self.xml_change.new_text ) is not None, 'Elements tab not updated.' # Update label in CDT and verify it is updated on device self.dev_tools.edit_text(old_text=self.xml_change.new_text, new_text=self.xml_change.old_text) element = self.dev_tools.wait_element_by_text( text=self.xml_change.old_text, timeout=90) assert element is not None, 'Failed to change text in elements tab.' device.wait_for_text(text=self.xml_change.old_text) def __console_log(self, platform, device): # Run `tns debug` wait until debug url is in the console and app is loaded result = Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open Chrome Dev Tools -> Console self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.CONSOLE) # TAP the button to trigger console log and ensure it is in device logs device.click(text='TAP', case_sensitive=True) assert device.wait_for_log( text='Test Debug!', timeout=90), 'Console logs not available in device logs.' # Ensure logs are available in tns logs tns_logs = File.read(result.log_file) assert "Test Debug!" in tns_logs, 'Console log messages not available in CLI output.' + os.linesep + tns_logs message = 'Console log messages(Arabic and Kurdish characters) not available in CLI output.' # add test for issue https://github.com/NativeScript/android-runtime/issues/1302 assert 'العربییە' in tns_logs, message + os.linesep + tns_logs # Verify console logs are available in Chrome dev tools log = self.dev_tools.wait_element_by_text(text='Test Debug!') assert log is not None, 'Console logs not displayed in Chrome Dev Tools.' if Settings.PYTHON_VERSION < 3: text = 'العربییە'.decode('utf-8') else: text = 'العربییە' log = self.dev_tools.wait_element_by_text(text=text) # add test for issue https://github.com/NativeScript/android-runtime/issues/1302 assert log is not None, 'Console logs(Arabic and Kurdish characters) not displayed in Chrome Dev Tools.' def __console_eval(self, platform, device): # Run `tns debug` wait until debug url is in the console and app is loaded Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open Chrome Dev Tools -> Console self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.CONSOLE) # Evaluate on console self.dev_tools.type_on_console("1024+1024") self.dev_tools.wait_element_by_text(text='2048', timeout=10) # TODO: Add tests for eval something {N} specific def __debug_sources(self, platform, device): # Start debug and wait until app is deployed Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open sources tab and verify content is loaded self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) # Open JS file and place breakpoint on line 18 self.dev_tools.load_source_file("main-view-model.js") self.dev_tools.breakpoint(18) # Tap on TAP button in emulator and check it is hit device.click(text="TAP", case_sensitive=True) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=40) assert pause_element is not None, 'Failed to pause on breakpoint.' # Resume execution self.dev_tools.continue_debug() device.wait_for_text(text='41 taps left', timeout=30) def __debug_sync_changes(self, platform, device): # Start debug and wait until app is deployed result = Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open sources tab and verify content is loaded self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) # Open JS file and place breakpoint on line 18 self.dev_tools.load_source_file("main-view-model.js") self.dev_tools.breakpoint(18) # Sync JS changes works fine until breakpoint is hit Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS) js_file_name = os.path.basename(Changes.JSHelloWord.JS.file_path) logs = [ js_file_name, 'Webpack build done!', 'Refreshing application', 'Successfully synced application' ] TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs) device.wait_for_text(text=Changes.JSHelloWord.JS.new_text, timeout=30) # Revert changes Sync.revert(app_name=self.app_name, change_set=Changes.JSHelloWord.JS) TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs) device.wait_for_text(text=Changes.JSHelloWord.JS.old_text, timeout=30) # Tap on TAP button in emulator and check it is hit device.click(text="TAP", case_sensitive=True) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=90) assert pause_element is not None, 'Failed to pause on breakpoint.' # Test for https://github.com/NativeScript/nativescript-cli/issues/4227 Sync.replace(app_name=self.app_name, change_set=self.xml_change) xml_file_name = os.path.basename(self.xml_change.file_path) logs = [ xml_file_name, 'Webpack build done!', 'Refreshing application', 'Successfully synced application' ] TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs) sleep(10) # Give it some more time to crash logs = File.read(result.log_file) assert 'Unable to apply changes' not in logs assert 'Stopping webpack watch' not in logs assert 'closed' not in logs assert 'detached' not in logs assert "did not start in time" not in logs # Resume execution self.dev_tools.continue_debug() device.wait_for_text( text='42 taps left', timeout=30) # We tapped but changes synced so number is restarted device.wait_for_text(text=self.xml_change.new_text, timeout=10) # Verify change applied during debug def __debug_watch_expression(self, platform, device): # Start debug and wait until app is deployed Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open sources tab and place breakpoint on line 18 of main-view-model.js self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) self.dev_tools.load_source_file("main-view-model.js") self.dev_tools.breakpoint(18) # Tap on TAP button in emulator and check it is hit device.click(text="TAP", case_sensitive=True) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=60) assert pause_element is not None, 'Failed to pause on breakpoint.' # Add watch expression if platform == Platform.ANDROID: self.dev_tools.add_watch_expression( expression='console', expected_result='console: Object') elif platform == Platform.IOS: self.dev_tools.add_watch_expression( expression='console', expected_result='console: Console') self.dev_tools.add_watch_expression( expression='viewModel', expected_result='viewModel: Observable') def __debug_brk(self, platform, device): # Hack to workaround https://github.com/NativeScript/nativescript-cli/issues/4567 Tns.run(app_name=self.app_name, platform=platform, emulator=True, source_map=True, just_launch=True) device.wait_for_text(text='TAP') Tns.debug(app_name=self.app_name, platform=platform, emulator=True, debug_brk=True) self.dev_tools = ChromeDevTools(self.chrome, platform=platform) self.dev_tools.open_tab(tab=ChromeDevToolsTabs.SOURCES, verify=False) pause_element = self.dev_tools.wait_element_by_text( text="Debugger paused", timeout=30) assert pause_element is not None, 'Failed to stop on first line of code.' assert self.dev_tools.find_element_by_text( text="function" ) is not None, 'Failed to stop on first line of code.' assert 'NativeScript' in device.get_text( ), 'Failed to stop on first line of code.' # Resume execution self.dev_tools.continue_debug() device.wait_for_text(text='TAP') def __debug_start(self, platform, device): # Run the app and verify it is deployed Tns.run(app_name=self.app_name, platform=platform, emulator=True, source_map=True, just_launch=True) device.wait_for_text(text='TAP') # Attach debug session result = Tns.debug(app_name=self.app_name, platform=platform, emulator=True, start=True) # Verify sources tab is loaded self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) device.wait_for_text(text='TAP') # Verify console log is working (covers https://github.com/NativeScript/nativescript-cli/issues/3629) self.dev_tools.open_tab(ChromeDevToolsTabs.CONSOLE) device.click(text='TAP', case_sensitive=True) assert self.dev_tools.wait_element_by_text( text='Test Debug!' ) is not None, 'Console logs not displayed in CDT.' tns_logs = File.read(result.log_file) assert "Test Debug!" in tns_logs, 'Console log messages not available in CLI output.' + os.linesep + tns_logs # Verify debug is working (covers https://github.com/NativeScript/nativescript-cli/issues/2831) self.dev_tools.open_tab(ChromeDevToolsTabs.SOURCES) self.dev_tools.load_source_file("main-view-model.js") self.dev_tools.breakpoint(18) device.click(text="TAP", case_sensitive=True) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=10) assert pause_element is not None, 'Failed to pause on breakpoint.' def __reload_page(self, platform, device): # Start debug and wait until app is deployed Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text='TAP') # Open CDT with debug url twice self.dev_tools = ChromeDevTools(self.chrome, platform=platform) sleep(1) self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) device.wait_for_text(text='TAP') # Open another site and then back to CDT self.chrome.open(url='https://www.nativescript.org') self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) device.wait_for_text(text='TAP')
class DebugNGTests(TnsRunTest): ts_change = Changes.NGHelloWorld.TS xml_change = Changes.NGHelloWorld.XML_ACTION_BAR app_name = Settings.AppName.DEFAULT chrome = None dev_tools = None @classmethod def setUpClass(cls): TnsRunTest.setUpClass() Tns.create(app_name=cls.app_name, template=Template.HELLO_WORLD_NG.local_package, update=True) Tns.platform_add_android( app_name=cls.app_name, framework_path=Settings.Android.FRAMEWORK_PATH) if Settings.HOST_OS == OSType.OSX: Tns.platform_add_ios(app_name=cls.app_name, framework_path=Settings.IOS.FRAMEWORK_PATH) def setUp(self): TnsRunTest.setUp(self) Sync.revert(app_name=self.app_name, change_set=self.ts_change, fail_safe=True) Sync.revert(app_name=self.app_name, change_set=self.xml_change, fail_safe=True) self.chrome = Chrome() def tearDown(self): self.chrome.kill() TnsRunTest.tearDown(self) def test_001_debug_android_elements(self): self.__debug_elements(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_001_debug_ios_elements(self): self.__debug_elements(platform=Platform.IOS, device=self.sim) def test_020_debug_android_sources(self): self.__debug_sources(platform=Platform.ANDROID, device=self.emu) @unittest.skip( 'Do not work because we fail to click on "Ter Stegen". Wait until click is implemented via Appium.' ) def test_020_debug_ios_sources(self): self.__debug_sources(platform=Platform.IOS, device=self.sim) def __debug_elements(self, platform, device): # Run `tns debug` wait until app is visible on device Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text=self.ts_change.old_text, timeout=240) # Start debug session and verify elements tab self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.ELEMENTS) assert self.dev_tools.wait_element_by_text( text=self.xml_change.old_text ) is not None, 'Elements tab is empty.' # Sync changes and verify elements tab is updated Sync.replace(app_name=self.app_name, change_set=self.xml_change) device.wait_for_text(text=self.xml_change.new_text) # Elements tab do not auto-update for NG apps and need to be refreshed manually self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.ELEMENTS) assert self.dev_tools.wait_element_by_text( text=self.xml_change.new_text ) is not None, 'Elements tab not updated.' # Update label in CDT and verify it is updated on device self.dev_tools.edit_text(old_text=self.xml_change.new_text, new_text=self.xml_change.old_text) element = self.dev_tools.wait_element_by_text( text=self.xml_change.old_text) assert element is not None, 'Failed to change text in elements tab.' device.wait_for_text(text=self.xml_change.old_text) # Expand items self.dev_tools.doubleclick_line(text='ProxyViewContainer') self.dev_tools.doubleclick_line(text='GridLayout') time.sleep(3) self.dev_tools.doubleclick_line(text='ListView') if platform == Platform.ANDROID: self.dev_tools.doubleclick_line(text='StackLayout') self.dev_tools.wait_element_by_text(text='Label', timeout=10) if platform == Platform.IOS: self.dev_tools.wait_element_by_text(text='StackLayout', timeout=10) def __debug_sources(self, platform, device): # Start debug and wait until app is deployed Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.wait_for_text(text=self.ts_change.old_text) # Open sources tab and verify content is loaded self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.SOURCES) # Open TS file and place breakpoint on line 21 self.dev_tools.load_source_file('item-detail.component.ts') self.dev_tools.breakpoint(21) # Navigate to details page and check breakpoint is hit device.click(text=self.ts_change.old_text) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=10) assert pause_element is not None, 'Failed to pause on breakpoint.' # Resume execution self.dev_tools.continue_debug() device.wait_for_text(text='Goalkeeper', timeout=30) # Sync changes and verify sources tab is updated Sync.replace(app_name=self.app_name, change_set=self.ts_change) device.wait_for_text(text=self.ts_change.new_text) self.dev_tools.load_source_file('item.service.ts') self.dev_tools.wait_element_by_text(text=self.ts_change.new_text, timeout=10) # Navigate to details page and check breakpoint is hit device.click(text=self.ts_change.new_text) pause_element = self.dev_tools.wait_element_by_text( text="Paused on breakpoint", timeout=10) assert pause_element is not None, 'Failed to pause on breakpoint.' # Resume execution self.dev_tools.continue_debug() device.wait_for_text(text='Goalkeeper', timeout=30)
class DebugNetworkTests(TnsRunTest): app_name = Settings.AppName.DEFAULT chrome = None dev_tools = None @classmethod def setUpClass(cls): TnsRunTest.setUpClass() app_folder = os.path.join(Settings.TEST_RUN_HOME, cls.app_name) Folder.clean(app_folder) Git.clone( repo_url='https://github.com/NativeScript/chrome-devtools-test-app', local_folder=app_folder) Tns.platform_add_android( app_name=cls.app_name, framework_path=Settings.Android.FRAMEWORK_PATH) if Settings.HOST_OS == OSType.OSX: Tns.platform_add_ios(app_name=cls.app_name, framework_path=Settings.IOS.FRAMEWORK_PATH) App.update(app_name=cls.app_name) def setUp(self): TnsRunTest.setUp(self) self.chrome = Chrome() def tearDown(self): self.chrome.kill() TnsRunTest.tearDown(self) def test_010_debug_android_elements(self): self.__debug_elements(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_010_debug_ios_elements(self): self.__debug_elements(platform=Platform.IOS, device=self.sim) def test_020_debug_android_console(self): self.__debug_console(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_020_debug_ios_console(self): self.__debug_console(platform=Platform.IOS, device=self.sim) def test_030_debug_android_sources(self): self.__debug_sources(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_030_debug_ios_sources(self): self.__debug_sources(platform=Platform.IOS, device=self.sim) def test_040_debug_android_network(self): self.__debug_network(platform=Platform.ANDROID, device=self.emu) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Can not debug iOS on non macOS hosts.') def test_040_debug_ios_network(self): self.__debug_network(platform=Platform.IOS, device=self.sim) def __debug_elements(self, platform, device): # Start debug and open elements tab Tns.debug(app_name=self.app_name, platform=platform, emulator=True) self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.ELEMENTS) self.dev_tools.wait_element_by_text(text=ACTION_BAR_TITLE) # Add child and verify it is visible in CDT device.click(text=HOME_ADD_CHILD_BUTTON) self.dev_tools.doubleclick_line(text='StackLayout') self.dev_tools.doubleclick_line(text='ScrollView') time.sleep(4) self.dev_tools.doubleclick_line(text='FlexboxLayout') if platform == Platform.ANDROID: assert self.dev_tools.wait_element_by_text( text='StackLayout id=') is not None else: assert self.dev_tools.wait_element_by_text( text='StackLayout iosOverflowSafeArea="true" id=') is not None # Remove child and verify it is NOT visible in CDT device.click(text=HOME_REMOVE_CHILD_BUTTON) text = 'StackLayout id=' if platform == Platform.IOS: text = 'StackLayout iosOverflowSafeArea="true" id=' found = Wait.until( lambda: self.dev_tools.find_element_by_text(text=text) is None, timeout=10) assert found is True, 'Item not removed from elements tab after removed from app.' def __debug_console(self, platform, device): Tns.debug(app_name=self.app_name, platform=platform, emulator=True) self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.CONSOLE) device.click(text=HOME_CONSOLE_BUTTON) if platform == Platform.ANDROID: self.dev_tools.wait_element_by_text(text='main-view-model.ts:34') else: self.dev_tools.wait_element_by_text(text='main-view-model.ts:35') def __debug_sources(self, platform, device): # Run debug, to network page and open network tab in CDT result = Tns.debug(app_name=self.app_name, platform=platform, emulator=True) device.click(text=HOME_NETWORK_BUTTON) self.dev_tools = ChromeDevTools(self.chrome, platform=platform) self.dev_tools.open_tab(tab=ChromeDevToolsTabs.SOURCES, verify=False) # Place breakpoint and verify it is hit self.dev_tools.load_source_file('network-page.ts') self.dev_tools.breakpoint(line=12) device.click(text=NET_GET_WITHOUT_BODY) self.dev_tools.wait_element_by_text(text='Paused on breakpoint', timeout=10) assert 'httpbin.org' not in File.read(result.log_file) self.dev_tools.continue_debug() TnsLogs.wait_for_log(log_file=result.log_file, string_list=['httpbin.org']) # Add one more breakpoint and hit it self.dev_tools.load_source_file('network-page.ts') self.dev_tools.breakpoint(line=30) device.click(text=NET_GET_WITH_BODY) self.dev_tools.wait_element_by_text(text='Paused on breakpoint', timeout=60) assert 'My custom Arbitrary Header value' not in File.read( result.log_file) self.dev_tools.continue_debug() TnsLogs.wait_for_log(log_file=result.log_file, string_list=['My custom Arbitrary Header value']) def __debug_network(self, platform, device): Tns.debug(app_name=self.app_name, platform=platform, emulator=True) self.dev_tools = ChromeDevTools(self.chrome, platform=platform, tab=ChromeDevToolsTabs.NETWORK) device.click(text=HOME_NETWORK_BUTTON) # Request without body device.click(text=NET_GET_WITHOUT_BODY) assert self.dev_tools.wait_element_by_text(text='get') is not None assert self.dev_tools.wait_element_by_text(text='200') is not None assert self.dev_tools.wait_element_by_text(text='0 B') is not None self.dev_tools.clean_network_tab() # Request with body device.click(text=NET_GET_WITH_BODY) assert self.dev_tools.wait_element_by_text(text='get', timeout=60) is not None assert self.dev_tools.wait_element_by_text(text='200', timeout=50) is not None assert self.dev_tools.wait_element_by_text(text=' B', timeout=50) is not None self.dev_tools.clean_network_tab()
def test_01_smoke(self): # Open chrome dev tools dev_tools = ChromeDevTools(self.chrome, platform=None) # Verify all tabs dev_tools.open_tab(ChromeDevToolsTabs.SOURCES, verify=False) assert dev_tools.wait_element_by_text(text="Drop in a folder to add to workspace", timeout=10) is not None dev_tools.open_tab(ChromeDevToolsTabs.CONSOLE, verify=False) assert dev_tools.wait_element_by_text(text="Default levels", timeout=10) is not None dev_tools.open_tab(ChromeDevToolsTabs.ELEMENTS, verify=False) assert dev_tools.wait_element_by_text(text="Styles", timeout=10) is not None
def test_02_type_in_console(self): dev_tools = ChromeDevTools(self.chrome, platform=None) dev_tools.open_tab(ChromeDevToolsTabs.CONSOLE) dev_tools.type_on_console("1+1")