From 9626cb208d0bb3001269728aac95d4e19cad4d5c Mon Sep 17 00:00:00 2001 From: Miroslava Ivanova Date: Mon, 11 Nov 2019 17:09:50 +0200 Subject: [PATCH 01/15] console logs --- core/utils/device/device.py | 8 ++++++-- core/utils/device/device_manager.py | 5 +++-- core/utils/device/emulator_info.py | 3 ++- products/nativescript/preview_helpers.py | 3 ++- products/nativescript/tns_logs.py | 8 ++++---- tests/cli/preview/templates/hello_word_js_tests.py | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/core/utils/device/device.py b/core/utils/device/device.py index 574d29f8..549fc611 100644 --- a/core/utils/device/device.py +++ b/core/utils/device/device.py @@ -21,18 +21,22 @@ class Device(object): # noinspection PyShadowingBuiltins - def __init__(self, id, name, type, version): + def __init__(self, id, name, type, model, version): self.id = id self.type = type self.version = version + self.model = model if type is DeviceType.IOS: type = run(cmd="ideviceinfo | grep ProductType").output type = type.replace(',', '') type = type.replace('ProductType:', '').strip(' ') self.name = type - else: + self.model = type + if type is DeviceType.ANDROID: self.name = name + model = run(cmd="adb shell getprop ro.product.model").output + self.model= model if type is DeviceType.SIM: self.device_log_file = Simctl.get_log_file(self.id) diff --git a/core/utils/device/device_manager.py b/core/utils/device/device_manager.py index 6429b0fa..f626eeb6 100644 --- a/core/utils/device/device_manager.py +++ b/core/utils/device/device_manager.py @@ -83,7 +83,8 @@ def start(emulator): booted = Adb.wait_until_boot(device_id=emulator.emu_id) if booted: Log.info('{0} is up and running!'.format(emulator.avd)) - device = Device(id=emulator.emu_id, name=emulator.avd, type=DeviceType.EMU, version=emulator.os_version) + device = Device(id=emulator.emu_id, model=emulator.model, name=emulator.avd, type=DeviceType.EMU, + version=emulator.os_version) TestContext.STARTED_DEVICES.append(device) return device else: @@ -169,7 +170,7 @@ def start(simulator_info): # Return result device = Device(id=simulator_info.id, name=simulator_info.name, type=DeviceType.SIM, - version=simulator_info.sdk) + version=simulator_info.sdk, model=simulator_info.id) TestContext.STARTED_DEVICES.append(device) return device diff --git a/core/utils/device/emulator_info.py b/core/utils/device/emulator_info.py index d996ea52..c59a09d0 100644 --- a/core/utils/device/emulator_info.py +++ b/core/utils/device/emulator_info.py @@ -1,7 +1,8 @@ # noinspection PyShadowingBuiltins class EmulatorInfo(object): - def __init__(self, avd=None, os_version=None, port=None, emu_id=None): + def __init__(self, avd=None, os_version=None, port=None, emu_id=None, model=None): self.avd = avd self.os_version = os_version self.port = port self.emu_id = emu_id + self.model = model diff --git a/products/nativescript/preview_helpers.py b/products/nativescript/preview_helpers.py index 33ba3cae..1bf5cc93 100644 --- a/products/nativescript/preview_helpers.py +++ b/products/nativescript/preview_helpers.py @@ -143,7 +143,8 @@ def run_app(app_name, platform, device, bundle=True, hmr=True, instrumented=Fals device.click("Open") # Verify logs - strings = TnsLogs.preview_initial_messages(platform=platform, hmr=hmr, bundle=bundle, instrumented=instrumented) + strings = TnsLogs.preview_initial_messages(platform=platform, device=device, hmr=hmr, bundle=bundle, + instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=200) return result diff --git a/products/nativescript/tns_logs.py b/products/nativescript/tns_logs.py index a845d545..eaf6472a 100644 --- a/products/nativescript/tns_logs.py +++ b/products/nativescript/tns_logs.py @@ -246,9 +246,9 @@ def __webpack_messages(): 'Webpack build done!'] @staticmethod - def preview_initial_messages(platform, bundle=True, hmr=False, instrumented=False): - logs = ['Start sending initial files for platform {0}'.format(str(platform)), - 'Successfully sent initial files for platform {0}'.format(str(platform))] + def preview_initial_messages(platform, device, bundle=True, hmr=False, instrumented=False): + logs = ['Start sending initial files for platform {0}'.format(str(device.model)), + 'Successfully sent initial files for platform {0}'.format(str(device.model))] if bundle or hmr: logs.extend(TnsLogs.__webpack_messages()) if instrumented: @@ -256,7 +256,7 @@ def preview_initial_messages(platform, bundle=True, hmr=False, instrumented=Fals return logs @staticmethod - def preview_file_changed_messages(platform, file_name, run_type=RunType.INCREMENTAL, + def preview_file_changed_messages(platform, device, file_name, run_type=RunType.INCREMENTAL, bundle=True, hmr=True, instrumented=False): logs = ['Start syncing changes for platform {0}'.format(str(platform))] if bundle or hmr: diff --git a/tests/cli/preview/templates/hello_word_js_tests.py b/tests/cli/preview/templates/hello_word_js_tests.py index 0c71f7db..26ce32c2 100644 --- a/tests/cli/preview/templates/hello_word_js_tests.py +++ b/tests/cli/preview/templates/hello_word_js_tests.py @@ -31,7 +31,7 @@ def setUpClass(cls): cls.emu_API24 = DeviceManager.Emulator.ensure_available(Settings.Emulators.EMU_API_24) # Download Preview and Playground packages - Preview.get_app_packages() + # Preview.get_app_packages() # Install Preview and Playground Preview.install_preview_app(cls.emu, Platform.ANDROID) From 932ed51acfd5e5cd72d5580423829d0c56076b30 Mon Sep 17 00:00:00 2001 From: Miroslava Ivanova Date: Wed, 13 Nov 2019 10:45:54 +0200 Subject: [PATCH 02/15] console logs --- core/utils/device/device.py | 12 ++++++++---- data/sync/hello_world_js.py | 6 +++--- products/nativescript/tns_logs.py | 12 ++++++------ tests/cli/preview/templates/hello_word_js_tests.py | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/core/utils/device/device.py b/core/utils/device/device.py index 549fc611..6b7b8553 100644 --- a/core/utils/device/device.py +++ b/core/utils/device/device.py @@ -26,17 +26,21 @@ def __init__(self, id, name, type, model, version): self.type = type self.version = version self.model = model + self.name = name if type is DeviceType.IOS: type = run(cmd="ideviceinfo | grep ProductType").output type = type.replace(',', '') type = type.replace('ProductType:', '').strip(' ') self.name = type - self.model = type - if type is DeviceType.ANDROID: - self.name = name - model = run(cmd="adb shell getprop ro.product.model").output + if type is DeviceType.SIM: + self.model = name + if type is DeviceType.EMU: + cmd = 'shell getprop ro.product.model' + model = Adb.run_adb_command(command=cmd, wait=True).output self.model= model + else: + self.name = name if type is DeviceType.SIM: self.device_log_file = Simctl.get_log_file(self.id) diff --git a/data/sync/hello_world_js.py b/data/sync/hello_world_js.py index 52fc4397..b18eac75 100644 --- a/data/sync/hello_world_js.py +++ b/data/sync/hello_world_js.py @@ -191,7 +191,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit CSS file and verify changes are applied Sync.replace(app_name=app_name, change_set=css_change) - strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, + strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, device=device, hmr=hmr, file_name='app.css', instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, @@ -202,7 +202,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit JS file and verify changes are applied Sync.replace(app_name=app_name, change_set=js_change) - strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, hmr=hmr, + strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, hmr=hmr, device=device, file_name=js_file, instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, @@ -213,7 +213,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit XML file and verify changes are applied Sync.replace(app_name=app_name, change_set=xml_change) - strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, + strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, device=device, hmr=hmr, file_name='main-page.xml', instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, diff --git a/products/nativescript/tns_logs.py b/products/nativescript/tns_logs.py index eaf6472a..6c8eca27 100644 --- a/products/nativescript/tns_logs.py +++ b/products/nativescript/tns_logs.py @@ -246,9 +246,9 @@ def __webpack_messages(): 'Webpack build done!'] @staticmethod - def preview_initial_messages(platform, device, bundle=True, hmr=False, instrumented=False): - logs = ['Start sending initial files for platform {0}'.format(str(device.model)), - 'Successfully sent initial files for platform {0}'.format(str(device.model))] + def preview_initial_messages(device, bundle=True, hmr=False, instrumented=False): + logs = ["Start sending initial files for device \'{0}\'".format(str(device.model)), + "Successfully sent initial files for device \'{0}\'".format(str(device.model))] if bundle or hmr: logs.extend(TnsLogs.__webpack_messages()) if instrumented: @@ -256,15 +256,15 @@ def preview_initial_messages(platform, device, bundle=True, hmr=False, instrumen return logs @staticmethod - def preview_file_changed_messages(platform, device, file_name, run_type=RunType.INCREMENTAL, + def preview_file_changed_messages(device, file_name, run_type=RunType.INCREMENTAL, bundle=True, hmr=True, instrumented=False): - logs = ['Start syncing changes for platform {0}'.format(str(platform))] + logs = ["Start syncing changes for device \'{0}\'".format(str(device.model))] if bundle or hmr: logs.extend(TnsLogs.__webpack_messages()) logs.append(file_name) else: logs.append('Successfully synced') - logs.append('{0} for platform {1}'.format(file_name.replace('.ts', '.js'), str(platform))) + logs.append('{0} for device {1}'.format(file_name.replace('.ts', '.js'), str(device.model))) if hmr: logs.append('hot-update.json') logs.append('HMR: Checking for updates to the bundle with hmr hash') diff --git a/tests/cli/preview/templates/hello_word_js_tests.py b/tests/cli/preview/templates/hello_word_js_tests.py index 26ce32c2..0c71f7db 100644 --- a/tests/cli/preview/templates/hello_word_js_tests.py +++ b/tests/cli/preview/templates/hello_word_js_tests.py @@ -31,7 +31,7 @@ def setUpClass(cls): cls.emu_API24 = DeviceManager.Emulator.ensure_available(Settings.Emulators.EMU_API_24) # Download Preview and Playground packages - # Preview.get_app_packages() + Preview.get_app_packages() # Install Preview and Playground Preview.install_preview_app(cls.emu, Platform.ANDROID) From c17a38a2592d1883461fd85f8588e3411d74db5f Mon Sep 17 00:00:00 2001 From: Miroslava Ivanova Date: Wed, 13 Nov 2019 11:19:20 +0200 Subject: [PATCH 03/15] console logs --- data/sync/hello_world_js.py | 2 +- products/nativescript/preview_helpers.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/sync/hello_world_js.py b/data/sync/hello_world_js.py index b18eac75..c660b398 100644 --- a/data/sync/hello_world_js.py +++ b/data/sync/hello_world_js.py @@ -153,7 +153,7 @@ def __sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=True, def preview_hello_world_js_ts(app_name, platform, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): - result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, platform=platform, + result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, device=device, instrumented=instrumented, click_open_alert=click_open_alert) # Verify app looks properly diff --git a/products/nativescript/preview_helpers.py b/products/nativescript/preview_helpers.py index 1bf5cc93..3a16e9fd 100644 --- a/products/nativescript/preview_helpers.py +++ b/products/nativescript/preview_helpers.py @@ -128,7 +128,7 @@ def dismiss_simulator_alert(): run(command) @staticmethod - def run_app(app_name, platform, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): + def run_app(app_name, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): result = Tns.preview(app_name=app_name, bundle=bundle, hmr=hmr) # Read the log and extract the url to load the app on emulator @@ -143,7 +143,7 @@ def run_app(app_name, platform, device, bundle=True, hmr=True, instrumented=Fals device.click("Open") # Verify logs - strings = TnsLogs.preview_initial_messages(platform=platform, device=device, hmr=hmr, bundle=bundle, + strings = TnsLogs.preview_initial_messages(device=device, hmr=hmr, bundle=bundle, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=200) return result From 3c14249698fd8e64f876f964a8f1d58e6628af8a Mon Sep 17 00:00:00 2001 From: Miroslava Ivanova Date: Mon, 18 Nov 2019 11:37:09 +0200 Subject: [PATCH 04/15] test --- data/sync/hello_world_js.py | 6 +++--- products/nativescript/tns_logs.py | 6 +++--- tests/cli/preview/templates/hello_word_js_tests.py | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/data/sync/hello_world_js.py b/data/sync/hello_world_js.py index c660b398..2484ce42 100644 --- a/data/sync/hello_world_js.py +++ b/data/sync/hello_world_js.py @@ -191,7 +191,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit CSS file and verify changes are applied Sync.replace(app_name=app_name, change_set=css_change) - strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, device=device, + strings = TnsLogs.preview_file_changed_messages(bundle=bundle, device=device, hmr=hmr, file_name='app.css', instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, @@ -202,7 +202,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit JS file and verify changes are applied Sync.replace(app_name=app_name, change_set=js_change) - strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, hmr=hmr, device=device, + strings = TnsLogs.preview_file_changed_messages(bundle=bundle, hmr=hmr, device=device, file_name=js_file, instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, @@ -213,7 +213,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit XML file and verify changes are applied Sync.replace(app_name=app_name, change_set=xml_change) - strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, device=device, + strings = TnsLogs.preview_file_changed_messages(bundle=bundle, device=device, hmr=hmr, file_name='main-page.xml', instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, diff --git a/products/nativescript/tns_logs.py b/products/nativescript/tns_logs.py index 6c8eca27..b4a69055 100644 --- a/products/nativescript/tns_logs.py +++ b/products/nativescript/tns_logs.py @@ -247,8 +247,8 @@ def __webpack_messages(): @staticmethod def preview_initial_messages(device, bundle=True, hmr=False, instrumented=False): - logs = ["Start sending initial files for device \'{0}\'".format(str(device.model)), - "Successfully sent initial files for device \'{0}\'".format(str(device.model))] + logs = ["Start sending initial files for device {0}".format(str(device.model)), + "Successfully sent initial files for device {0}".format(str(device.model))] if bundle or hmr: logs.extend(TnsLogs.__webpack_messages()) if instrumented: @@ -258,7 +258,7 @@ def preview_initial_messages(device, bundle=True, hmr=False, instrumented=False) @staticmethod def preview_file_changed_messages(device, file_name, run_type=RunType.INCREMENTAL, bundle=True, hmr=True, instrumented=False): - logs = ["Start syncing changes for device \'{0}\'".format(str(device.model))] + logs = ["Start syncing changes for device {0}".format(str(device.model))] if bundle or hmr: logs.extend(TnsLogs.__webpack_messages()) logs.append(file_name) diff --git a/tests/cli/preview/templates/hello_word_js_tests.py b/tests/cli/preview/templates/hello_word_js_tests.py index 0c71f7db..5f134ca0 100644 --- a/tests/cli/preview/templates/hello_word_js_tests.py +++ b/tests/cli/preview/templates/hello_word_js_tests.py @@ -31,7 +31,7 @@ def setUpClass(cls): cls.emu_API24 = DeviceManager.Emulator.ensure_available(Settings.Emulators.EMU_API_24) # Download Preview and Playground packages - Preview.get_app_packages() + # Preview.get_app_packages() # Install Preview and Playground Preview.install_preview_app(cls.emu, Platform.ANDROID) @@ -96,7 +96,7 @@ def test_210_tns_preview_android_livesync_on_two_emulators(self): log = File.read(result.log_file) url = Preview.get_url(log) Preview.run_url(url=url, device=self.emu) - strings = TnsLogs.preview_initial_messages(platform=Platform.ANDROID) + strings = TnsLogs.preview_initial_messages(device=self.emu) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text, timeout=90) @@ -107,7 +107,7 @@ def test_210_tns_preview_android_livesync_on_two_emulators(self): Preview.run_url(url=url, device=self.emu_API24) # Here use bundle=False because on consecutive preview build is not executed again # and no bundle messages are displayed in log - strings = TnsLogs.preview_initial_messages(platform=Platform.ANDROID, bundle=False) + strings = TnsLogs.preview_initial_messages(device=self.emu, bundle=False) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) self.emu_API24.wait_for_text(text=Changes.JSHelloWord.JS.old_text) @@ -136,7 +136,7 @@ def test_210_tns_preview_on_simulator_and_emulator_livesync(self): log = File.read(result.log_file) url = Preview.get_url(log) Preview.run_url(url=url, device=self.emu) - strings = TnsLogs.preview_initial_messages(platform=Platform.ANDROID) + strings = TnsLogs.preview_initial_messages(device=self.emu) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text) @@ -145,7 +145,7 @@ def test_210_tns_preview_on_simulator_and_emulator_livesync(self): # Preview on simulator Preview.run_url(url=url, device=self.sim) - strings = TnsLogs.preview_initial_messages(platform=Platform.IOS) + strings = TnsLogs.preview_initial_messages(device=self.sim) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text) From 0cf63c26f415e24978a3ee2f59ccbb655563218f Mon Sep 17 00:00:00 2001 From: Miroslava Ivanova Date: Thu, 21 Nov 2019 13:57:45 +0200 Subject: [PATCH 05/15] latest changes --- data/sync/hello_world_js.py | 12 +++++----- data/sync/hello_world_ng.py | 7 +++--- products/nativescript/preview_helpers.py | 4 ++-- products/nativescript/tns_assert.py | 14 ++++------- products/nativescript/tns_logs.py | 4 ++-- .../preview/templates/hello_word_js_tests.py | 24 ++++++++++--------- .../preview/templates/hello_word_ng_tests.py | 1 + 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/data/sync/hello_world_js.py b/data/sync/hello_world_js.py index 2484ce42..ac9fa977 100644 --- a/data/sync/hello_world_js.py +++ b/data/sync/hello_world_js.py @@ -153,7 +153,7 @@ def __sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=True, def preview_hello_world_js_ts(app_name, platform, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): - result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, + result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, platform=platform, device=device, instrumented=instrumented, click_open_alert=click_open_alert) # Verify app looks properly @@ -191,8 +191,8 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit CSS file and verify changes are applied Sync.replace(app_name=app_name, change_set=css_change) - strings = TnsLogs.preview_file_changed_messages(bundle=bundle, device=device, - hmr=hmr, file_name='app.css', instrumented=instrumented) + strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, device=device, hmr=hmr, + file_name='app.css', instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, not_existing_string_list=not_existing_string_list) @@ -202,8 +202,8 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit JS file and verify changes are applied Sync.replace(app_name=app_name, change_set=js_change) - strings = TnsLogs.preview_file_changed_messages(bundle=bundle, hmr=hmr, device=device, - file_name=js_file, instrumented=instrumented) + strings = TnsLogs.preview_file_changed_messages(bundle=bundle, hmr=hmr, device=device, file_name=js_file, + instrumented=instrumented, platform=platform) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, not_existing_string_list=not_existing_string_list) @@ -213,7 +213,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit XML file and verify changes are applied Sync.replace(app_name=app_name, change_set=xml_change) - strings = TnsLogs.preview_file_changed_messages(bundle=bundle, device=device, + strings = TnsLogs.preview_file_changed_messages(bundle=bundle, device=device, platform=platform, hmr=hmr, file_name='main-page.xml', instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, diff --git a/data/sync/hello_world_ng.py b/data/sync/hello_world_ng.py index 991f8e1f..840fc374 100644 --- a/data/sync/hello_world_ng.py +++ b/data/sync/hello_world_ng.py @@ -156,7 +156,8 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru # Edit TS file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS) strings = TnsLogs.preview_file_changed_messages(platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, - file_name='item.service.ts', hmr=hmr, instrumented=instrumented) + file_name='item.service.ts', hmr=hmr, instrumented=instrumented, + device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text) @@ -164,7 +165,7 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru # Edit HTML file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML) strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, file_name='items.component.html', - hmr=hmr, instrumented=instrumented) + hmr=hmr, instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) if platform == Platform.IOS: @@ -178,7 +179,7 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru # Edit CSS file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS) strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, file_name='app.css', - hmr=hmr, instrumented=instrumented) + hmr=hmr, instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) device.wait_for_main_color(color=Changes.NGHelloWorld.CSS.new_color) diff --git a/products/nativescript/preview_helpers.py b/products/nativescript/preview_helpers.py index 3a16e9fd..1bf5cc93 100644 --- a/products/nativescript/preview_helpers.py +++ b/products/nativescript/preview_helpers.py @@ -128,7 +128,7 @@ def dismiss_simulator_alert(): run(command) @staticmethod - def run_app(app_name, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): + def run_app(app_name, platform, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): result = Tns.preview(app_name=app_name, bundle=bundle, hmr=hmr) # Read the log and extract the url to load the app on emulator @@ -143,7 +143,7 @@ def run_app(app_name, device, bundle=True, hmr=True, instrumented=False, click_o device.click("Open") # Verify logs - strings = TnsLogs.preview_initial_messages(device=device, hmr=hmr, bundle=bundle, + strings = TnsLogs.preview_initial_messages(platform=platform, device=device, hmr=hmr, bundle=bundle, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=200) return result diff --git a/products/nativescript/tns_assert.py b/products/nativescript/tns_assert.py index cbd2bd75..afe42cfb 100644 --- a/products/nativescript/tns_assert.py +++ b/products/nativescript/tns_assert.py @@ -181,21 +181,17 @@ def test_initialized(app_name, framework, output): assert 'Run your tests using the' in output @staticmethod - def file_is_synced_once(log, platform, file_name): + def file_is_synced_once(log, device, file_name): """ Assert file is synced once on livesync. :param log: log or part of log you want to check :param platform: The platform you are syncing on. :param file_name: name of the file you are syncing. """ - if platform == Platform.ANDROID: - assert log.count('Start syncing changes for platform android') == 1, "File is synced more than once!" - assert log.count('hot-update.json for platform android') == 1, "File is synced more than once!" - assert file_name in log - else: - assert log.count('Start syncing changes for platform ios') == 1, "File is synced more than once!" - assert log.count('hot-update.json for platform ios') == 1, "File is synced more than once!" - assert file_name in log + assert log.count('Start syncing changes for device {0}'.format(str(device.model))) == 1, \ + "File is synced more than once!" + # assert log.count('hot-update.json for device') == 1, "File is synced more than once!" + assert file_name in log @staticmethod def snapshot_skipped(snapshot, result, release): diff --git a/products/nativescript/tns_logs.py b/products/nativescript/tns_logs.py index b4a69055..ec854a9d 100644 --- a/products/nativescript/tns_logs.py +++ b/products/nativescript/tns_logs.py @@ -246,7 +246,7 @@ def __webpack_messages(): 'Webpack build done!'] @staticmethod - def preview_initial_messages(device, bundle=True, hmr=False, instrumented=False): + def preview_initial_messages(platform, device, bundle=True, hmr=False, instrumented=False): logs = ["Start sending initial files for device {0}".format(str(device.model)), "Successfully sent initial files for device {0}".format(str(device.model))] if bundle or hmr: @@ -256,7 +256,7 @@ def preview_initial_messages(device, bundle=True, hmr=False, instrumented=False) return logs @staticmethod - def preview_file_changed_messages(device, file_name, run_type=RunType.INCREMENTAL, + def preview_file_changed_messages(device, platform, file_name, run_type=RunType.INCREMENTAL, bundle=True, hmr=True, instrumented=False): logs = ["Start syncing changes for device {0}".format(str(device.model))] if bundle or hmr: diff --git a/tests/cli/preview/templates/hello_word_js_tests.py b/tests/cli/preview/templates/hello_word_js_tests.py index 5f134ca0..d88c741d 100644 --- a/tests/cli/preview/templates/hello_word_js_tests.py +++ b/tests/cli/preview/templates/hello_word_js_tests.py @@ -1,4 +1,5 @@ import os +import time import unittest from core.base_test.tns_run_test import TnsRunTest @@ -31,7 +32,7 @@ def setUpClass(cls): cls.emu_API24 = DeviceManager.Emulator.ensure_available(Settings.Emulators.EMU_API_24) # Download Preview and Playground packages - # Preview.get_app_packages() + Preview.get_app_packages() # Install Preview and Playground Preview.install_preview_app(cls.emu, Platform.ANDROID) @@ -96,19 +97,20 @@ def test_210_tns_preview_android_livesync_on_two_emulators(self): log = File.read(result.log_file) url = Preview.get_url(log) Preview.run_url(url=url, device=self.emu) - strings = TnsLogs.preview_initial_messages(device=self.emu) + strings = TnsLogs.preview_initial_messages(device=self.emu, platform=Platform.ANDROID) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) - self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text, timeout=90) + self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text, timeout=120) # Click on TAP button on emulator Adb.click_element_by_text(self.emu.id, 'TAP', case_sensitive=True) + time.sleep(2) # Preview on second emulator Preview.run_url(url=url, device=self.emu_API24) # Here use bundle=False because on consecutive preview build is not executed again # and no bundle messages are displayed in log - strings = TnsLogs.preview_initial_messages(device=self.emu, bundle=False) - TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) + strings = TnsLogs.preview_initial_messages(device=self.emu, platform=Platform.ANDROID) + TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=120) self.emu_API24.wait_for_text(text=Changes.JSHelloWord.JS.old_text) # Verify first emulator is not refreshed, state of app is preserved @@ -136,7 +138,7 @@ def test_210_tns_preview_on_simulator_and_emulator_livesync(self): log = File.read(result.log_file) url = Preview.get_url(log) Preview.run_url(url=url, device=self.emu) - strings = TnsLogs.preview_initial_messages(device=self.emu) + strings = TnsLogs.preview_initial_messages(device=self.emu, platform=Platform.ANDROID) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text) @@ -145,7 +147,7 @@ def test_210_tns_preview_on_simulator_and_emulator_livesync(self): # Preview on simulator Preview.run_url(url=url, device=self.sim) - strings = TnsLogs.preview_initial_messages(device=self.sim) + strings = TnsLogs.preview_initial_messages(device=self.sim, platform=Platform.IOS) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text) @@ -162,8 +164,8 @@ def test_210_tns_preview_on_simulator_and_emulator_livesync(self): log = File.read(result.log_file) log = File.extract_part_of_text(log, '[VERIFIED]') # Verify files are synced once - TnsAssert.file_is_synced_once(log, Platform.ANDROID, 'main-view-model.js') - TnsAssert.file_is_synced_once(log, Platform.IOS, 'main-view-model.js') + TnsAssert.file_is_synced_once(log, device=self.emu, file_name='main-view-model.js') + TnsAssert.file_is_synced_once(log, device=self.sim, file_name='main-view-model.js') # Mark that part of the log as verified before next sync File.append(result.log_file, '[VERIFIED]') @@ -177,8 +179,8 @@ def test_210_tns_preview_on_simulator_and_emulator_livesync(self): log = File.read(result.log_file) log = File.extract_part_of_text(log, '[VERIFIED]') # Verify files are synced once - TnsAssert.file_is_synced_once(log, Platform.ANDROID, 'main-page.xml') - TnsAssert.file_is_synced_once(log, Platform.IOS, 'main-page.xml') + TnsAssert.file_is_synced_once(log, device=self.emu, file_name='main-page.xml') + TnsAssert.file_is_synced_once(log, device=self.sim, file_name='main-page.xml') def test_240_tns_preview_android_verify_plugin_warnings(self): """ diff --git a/tests/cli/preview/templates/hello_word_ng_tests.py b/tests/cli/preview/templates/hello_word_ng_tests.py index 4f1f99f8..3b03d29d 100644 --- a/tests/cli/preview/templates/hello_word_ng_tests.py +++ b/tests/cli/preview/templates/hello_word_ng_tests.py @@ -2,6 +2,7 @@ import unittest from core.base_test.tns_test import TnsTest from core.base_test.tns_run_test import TnsRunTest +from core.enums.app_type import AppType from core.enums.os_type import OSType from core.enums.platform_type import Platform from core.settings import Settings From 48f2c591328d17c617185b77b8e64c59116c6f88 Mon Sep 17 00:00:00 2001 From: Miroslava Ivanova Date: Thu, 21 Nov 2019 15:23:40 +0200 Subject: [PATCH 06/15] fix a test --- tests/cli/preview/templates/hello_word_js_tests.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/cli/preview/templates/hello_word_js_tests.py b/tests/cli/preview/templates/hello_word_js_tests.py index d88c741d..6ed47b11 100644 --- a/tests/cli/preview/templates/hello_word_js_tests.py +++ b/tests/cli/preview/templates/hello_word_js_tests.py @@ -104,12 +104,11 @@ def test_210_tns_preview_android_livesync_on_two_emulators(self): # Click on TAP button on emulator Adb.click_element_by_text(self.emu.id, 'TAP', case_sensitive=True) - time.sleep(2) # Preview on second emulator Preview.run_url(url=url, device=self.emu_API24) # Here use bundle=False because on consecutive preview build is not executed again # and no bundle messages are displayed in log - strings = TnsLogs.preview_initial_messages(device=self.emu, platform=Platform.ANDROID) + strings = TnsLogs.preview_initial_messages(device=self.emu, platform=Platform.ANDROID, bundle=False) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=120) self.emu_API24.wait_for_text(text=Changes.JSHelloWord.JS.old_text) From 4b299cb6a2e9c279ce2bc3392829fbbcd8da5191 Mon Sep 17 00:00:00 2001 From: Miroslava Ivanova Date: Thu, 21 Nov 2019 17:17:01 +0200 Subject: [PATCH 07/15] fix pylint errors --- core/utils/device/device.py | 2 +- core/utils/device/device_manager.py | 7 ++++--- products/nativescript/tns_logs.py | 2 +- tests/cli/preview/templates/hello_word_js_tests.py | 1 - tests/cli/preview/templates/hello_word_ng_tests.py | 1 - 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/utils/device/device.py b/core/utils/device/device.py index 6b7b8553..5b6579da 100644 --- a/core/utils/device/device.py +++ b/core/utils/device/device.py @@ -38,7 +38,7 @@ def __init__(self, id, name, type, model, version): if type is DeviceType.EMU: cmd = 'shell getprop ro.product.model' model = Adb.run_adb_command(command=cmd, wait=True).output - self.model= model + self.model = model else: self.name = name diff --git a/core/utils/device/device_manager.py b/core/utils/device/device_manager.py index f626eeb6..0b968db6 100644 --- a/core/utils/device/device_manager.py +++ b/core/utils/device/device_manager.py @@ -21,12 +21,12 @@ def get_devices(device_type=any): if device_type is DeviceType.ANDROID or device_type is any: for device_id in Adb.get_ids(include_emulators=False): version = Adb.get_version(device_id=device_id) - device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, version=version) + device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, version=version, model=None) devices.append(device) # Get iOS devices if device_type is DeviceType.IOS or device_type is any: for device_id in IDevice.get_devices(): - device = Device(id=device_id, name=device_id, type=DeviceType.IOS, version=None) + device = Device(id=device_id, name=device_id, type=DeviceType.IOS, version=None, model=None) devices.append(device) for device in devices: @@ -188,7 +188,8 @@ def ensure_available(simulator_info): return Device(id=simulator_info.id, name=simulator_info.name, type=DeviceType.SIM, - version=simulator_info.sdk) + version=simulator_info.sdk, + model=None) elif DeviceManager.Simulator.is_available(simulator_info=simulator_info): return DeviceManager.Simulator.start(simulator_info) else: diff --git a/products/nativescript/tns_logs.py b/products/nativescript/tns_logs.py index ec854a9d..00a63fbe 100644 --- a/products/nativescript/tns_logs.py +++ b/products/nativescript/tns_logs.py @@ -246,7 +246,7 @@ def __webpack_messages(): 'Webpack build done!'] @staticmethod - def preview_initial_messages(platform, device, bundle=True, hmr=False, instrumented=False): + def preview_initial_messages(device, platform, bundle=True, hmr=False, instrumented=False): logs = ["Start sending initial files for device {0}".format(str(device.model)), "Successfully sent initial files for device {0}".format(str(device.model))] if bundle or hmr: diff --git a/tests/cli/preview/templates/hello_word_js_tests.py b/tests/cli/preview/templates/hello_word_js_tests.py index 6ed47b11..ab7b1c11 100644 --- a/tests/cli/preview/templates/hello_word_js_tests.py +++ b/tests/cli/preview/templates/hello_word_js_tests.py @@ -1,5 +1,4 @@ import os -import time import unittest from core.base_test.tns_run_test import TnsRunTest diff --git a/tests/cli/preview/templates/hello_word_ng_tests.py b/tests/cli/preview/templates/hello_word_ng_tests.py index 3b03d29d..4f1f99f8 100644 --- a/tests/cli/preview/templates/hello_word_ng_tests.py +++ b/tests/cli/preview/templates/hello_word_ng_tests.py @@ -2,7 +2,6 @@ import unittest from core.base_test.tns_test import TnsTest from core.base_test.tns_run_test import TnsRunTest -from core.enums.app_type import AppType from core.enums.os_type import OSType from core.enums.platform_type import Platform from core.settings import Settings From f800343b2d60a836fcb6958a7102c347fe8812b7 Mon Sep 17 00:00:00 2001 From: Miroslava Ivanova Date: Thu, 21 Nov 2019 17:27:50 +0200 Subject: [PATCH 08/15] model errors --- core_tests/unit/product/tns_helpers_tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core_tests/unit/product/tns_helpers_tests.py b/core_tests/unit/product/tns_helpers_tests.py index 0dcfc432..3b9e18c7 100644 --- a/core_tests/unit/product/tns_helpers_tests.py +++ b/core_tests/unit/product/tns_helpers_tests.py @@ -29,7 +29,7 @@ def test_10_get_run_messages_first_run(self): platform=Platform.ANDROID, run_type=RunType.FIRST_TIME, file_name=None, - device=Device(id='123', name='Emu', type=DeviceType.EMU, version=6.0)) + device=Device(id='123', name='Emu', type=DeviceType.EMU, version=6.0, model=None)) assert 'Skipping prepare.' not in logs assert 'Preparing project...' in logs assert 'Project successfully prepared (android)' in logs @@ -52,7 +52,7 @@ def test_11_get_run_messages_sync_js(self): file_name='main-view-model.js', bundle=False, hmr=False, - device=Device(id='123', name='Emu', type=DeviceType.EMU, version=8.0)) + device=Device(id='123', name='Emu', type=DeviceType.EMU, version=8.0, model=None)) assert 'Successfully transferred main-view-model.js' in logs assert 'Restarting application on device' in logs assert 'Successfully synced application org.nativescript.TestApp on device' in logs @@ -84,7 +84,7 @@ def test_13_get_run_messages_sync_js_bundle_uglify(self): bundle=True, uglify=True, hmr=False, - device=Device(id='123', name='Emu', type=DeviceType.EMU, version=4.4)) + device=Device(id='123', name='Emu', type=DeviceType.EMU, version=4.4, model=None)) assert 'Skipping prepare.' not in logs assert 'File change detected.' in logs assert 'main-view-model.js' in logs From 07c07b0d84ed5b9faa9d0968ebd57fae4fa373d6 Mon Sep 17 00:00:00 2001 From: endarova Date: Tue, 26 Nov 2019 09:06:07 +0200 Subject: [PATCH 09/15] fix get model when devices are connected --- core/utils/device/device.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/device/device.py b/core/utils/device/device.py index 5b6579da..150a5fad 100644 --- a/core/utils/device/device.py +++ b/core/utils/device/device.py @@ -37,8 +37,8 @@ def __init__(self, id, name, type, model, version): self.model = name if type is DeviceType.EMU: cmd = 'shell getprop ro.product.model' - model = Adb.run_adb_command(command=cmd, wait=True).output - self.model = model + model = Adb.run_adb_command(command=cmd, wait=True, device_id=self.id).output + self.model = model.strip('\n\r') else: self.name = name From 62a44e885d3a37a054249929a84324de01ca9756 Mon Sep 17 00:00:00 2001 From: endarova Date: Tue, 26 Nov 2019 09:35:33 +0200 Subject: [PATCH 10/15] remove unused parameter --- products/nativescript/preview_helpers.py | 2 +- products/nativescript/tns_logs.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/products/nativescript/preview_helpers.py b/products/nativescript/preview_helpers.py index 1bf5cc93..9f312c6a 100644 --- a/products/nativescript/preview_helpers.py +++ b/products/nativescript/preview_helpers.py @@ -143,7 +143,7 @@ def run_app(app_name, platform, device, bundle=True, hmr=True, instrumented=Fals device.click("Open") # Verify logs - strings = TnsLogs.preview_initial_messages(platform=platform, device=device, hmr=hmr, bundle=bundle, + strings = TnsLogs.preview_initial_messages(device=device, hmr=hmr, bundle=bundle, instrumented=instrumented) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=200) return result diff --git a/products/nativescript/tns_logs.py b/products/nativescript/tns_logs.py index 00a63fbe..b4a69055 100644 --- a/products/nativescript/tns_logs.py +++ b/products/nativescript/tns_logs.py @@ -246,7 +246,7 @@ def __webpack_messages(): 'Webpack build done!'] @staticmethod - def preview_initial_messages(device, platform, bundle=True, hmr=False, instrumented=False): + def preview_initial_messages(device, bundle=True, hmr=False, instrumented=False): logs = ["Start sending initial files for device {0}".format(str(device.model)), "Successfully sent initial files for device {0}".format(str(device.model))] if bundle or hmr: @@ -256,7 +256,7 @@ def preview_initial_messages(device, platform, bundle=True, hmr=False, instrumen return logs @staticmethod - def preview_file_changed_messages(device, platform, file_name, run_type=RunType.INCREMENTAL, + def preview_file_changed_messages(device, file_name, run_type=RunType.INCREMENTAL, bundle=True, hmr=True, instrumented=False): logs = ["Start syncing changes for device {0}".format(str(device.model))] if bundle or hmr: From dc8e8aee06daf66787a3397947a1cb5463ee7c83 Mon Sep 17 00:00:00 2001 From: endarova Date: Tue, 26 Nov 2019 09:38:09 +0200 Subject: [PATCH 11/15] update device constructor --- tests/runtimes/android/abi_split_with_snapshot_arm64_tests.py | 2 +- tests/runtimes/android/abi_split_with_snapshot_arm_tests.py | 2 +- tests/runtimes/android/abi_split_with_snapshot_tests.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/runtimes/android/abi_split_with_snapshot_arm64_tests.py b/tests/runtimes/android/abi_split_with_snapshot_arm64_tests.py index dc0c050f..963ff42d 100644 --- a/tests/runtimes/android/abi_split_with_snapshot_arm64_tests.py +++ b/tests/runtimes/android/abi_split_with_snapshot_arm64_tests.py @@ -32,7 +32,7 @@ def setUpClass(cls): device_id = device if device_id is not None: cls.device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, - version=Adb.get_version(device_id)) + version=Adb.get_version(device_id), model=None) Adb.uninstall(cls.app_id, device_id, assert_success=False) def test_202_run_app_with_abi_split_and_snapshot_on_64_phone(self): diff --git a/tests/runtimes/android/abi_split_with_snapshot_arm_tests.py b/tests/runtimes/android/abi_split_with_snapshot_arm_tests.py index 5fac3fa6..c63b245a 100644 --- a/tests/runtimes/android/abi_split_with_snapshot_arm_tests.py +++ b/tests/runtimes/android/abi_split_with_snapshot_arm_tests.py @@ -32,7 +32,7 @@ def setUpClass(cls): device_id = device if device_id is not None: cls.device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, - version=Adb.get_version(device_id)) + version=Adb.get_version(device_id), model=None) Adb.uninstall(cls.app_id, device_id, assert_success=False) def test_201_run_app_with_abi_split_and_snapshot_on_32_phone(self): diff --git a/tests/runtimes/android/abi_split_with_snapshot_tests.py b/tests/runtimes/android/abi_split_with_snapshot_tests.py index 62763a01..6a6446f8 100644 --- a/tests/runtimes/android/abi_split_with_snapshot_tests.py +++ b/tests/runtimes/android/abi_split_with_snapshot_tests.py @@ -37,7 +37,7 @@ def setUpClass(cls): device_id = device if device_id is not None: cls.device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, - version=Adb.get_version(device_id)) + version=Adb.get_version(device_id), model=None) Adb.uninstall(cls.app_id, device_id, assert_success=False) Tns.platform_add_android(APP_NAME, framework_path=Android.FRAMEWORK_PATH) From 37cde3e8dfb33b29d76398706f53ac689a187b65 Mon Sep 17 00:00:00 2001 From: endarova Date: Tue, 26 Nov 2019 09:57:20 +0200 Subject: [PATCH 12/15] remove unused platform parameter --- data/sync/blank_vue.py | 6 +++--- data/sync/hello_world_js.py | 18 +++++++++--------- data/sync/hello_world_ng.py | 14 +++++++------- products/nativescript/preview_helpers.py | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/data/sync/blank_vue.py b/data/sync/blank_vue.py index 84716f03..b2f2987a 100644 --- a/data/sync/blank_vue.py +++ b/data/sync/blank_vue.py @@ -21,15 +21,15 @@ def __run_vue(app_name, platform, hmr): return Tns.run(app_name=app_name, platform=platform, emulator=True, wait=False, hmr=hmr) -def __preview_vue(app_name, platform, device, hmr): +def __preview_vue(app_name, device, hmr): # Execute `tns run` and wait until logs are OK - return Preview.run_app(app_name=app_name, hmr=hmr, platform=platform, device=device, click_open_alert=True) + return Preview.run_app(app_name=app_name, hmr=hmr, device=device, click_open_alert=True) def __workflow(preview, app_name, platform, device, hmr=True): # Execute tns command if preview: - result = __preview_vue(app_name=app_name, platform=platform, device=device, hmr=hmr) + result = __preview_vue(app_name=app_name, device=device, hmr=hmr) else: result = __run_vue(app_name=app_name, platform=platform, hmr=hmr) diff --git a/data/sync/hello_world_js.py b/data/sync/hello_world_js.py index ac9fa977..6aac7a7a 100644 --- a/data/sync/hello_world_js.py +++ b/data/sync/hello_world_js.py @@ -151,10 +151,10 @@ def __sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=True, device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30) -def preview_hello_world_js_ts(app_name, platform, device, bundle=True, hmr=True, instrumented=False, +def preview_hello_world_js_ts(app_name, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): - result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, platform=platform, - device=device, instrumented=instrumented, click_open_alert=click_open_alert) + result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, device=device, + instrumented=instrumented, click_open_alert=click_open_alert) # Verify app looks properly device.wait_for_text(text=Changes.JSHelloWord.JS.old_text, timeout=90, retry_delay=5) @@ -165,9 +165,9 @@ def preview_hello_world_js_ts(app_name, platform, device, bundle=True, hmr=True, return result -def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=True, hmr=True, instrumented=False, +def preview_sync_hello_world_js_ts(app_type, app_name, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): - result = preview_hello_world_js_ts(app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr, + result = preview_hello_world_js_ts(app_name=app_name, device=device, bundle=bundle, hmr=hmr, instrumented=instrumented, click_open_alert=click_open_alert) blue_count = device.get_pixels_by_color(color=Colors.LIGHT_BLUE) @@ -191,7 +191,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit CSS file and verify changes are applied Sync.replace(app_name=app_name, change_set=css_change) - strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, device=device, hmr=hmr, + strings = TnsLogs.preview_file_changed_messages(bundle=bundle, device=device, hmr=hmr, file_name='app.css', instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, @@ -203,7 +203,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit JS file and verify changes are applied Sync.replace(app_name=app_name, change_set=js_change) strings = TnsLogs.preview_file_changed_messages(bundle=bundle, hmr=hmr, device=device, file_name=js_file, - instrumented=instrumented, platform=platform) + instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, not_existing_string_list=not_existing_string_list) @@ -213,8 +213,8 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle= # Edit XML file and verify changes are applied Sync.replace(app_name=app_name, change_set=xml_change) - strings = TnsLogs.preview_file_changed_messages(bundle=bundle, device=device, platform=platform, - hmr=hmr, file_name='main-page.xml', instrumented=instrumented) + strings = TnsLogs.preview_file_changed_messages(bundle=bundle, device=device, hmr=hmr, + file_name='main-page.xml', instrumented=instrumented) if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, not_existing_string_list=not_existing_string_list) diff --git a/data/sync/hello_world_ng.py b/data/sync/hello_world_ng.py index 840fc374..e5e54156 100644 --- a/data/sync/hello_world_ng.py +++ b/data/sync/hello_world_ng.py @@ -129,10 +129,10 @@ def sync_hello_world_ng(app_name, platform, device, bundle=True, uglify=False, a device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30) -def preview_hello_world_ng(app_name, platform, device, bundle=False, hmr=False, instrumented=False, +def preview_hello_world_ng(app_name, device, bundle=False, hmr=False, instrumented=False, click_open_alert=False): - result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, platform=platform, - device=device, instrumented=instrumented, click_open_alert=click_open_alert) + result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, device=device, + instrumented=instrumented, click_open_alert=click_open_alert) # Verify app looks properly device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text) @@ -144,7 +144,7 @@ def preview_hello_world_ng(app_name, platform, device, bundle=False, hmr=False, def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): - result = preview_hello_world_ng(app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr, + result = preview_hello_world_ng(app_name=app_name, device=device, bundle=bundle, hmr=hmr, instrumented=instrumented, click_open_alert=click_open_alert) # Verify that application is not restarted on file changes when hmr=true @@ -155,7 +155,7 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru # Edit TS file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS) - strings = TnsLogs.preview_file_changed_messages(platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle, + strings = TnsLogs.preview_file_changed_messages(run_type=RunType.INCREMENTAL, bundle=bundle, file_name='item.service.ts', hmr=hmr, instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, @@ -164,7 +164,7 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru # Edit HTML file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML) - strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, file_name='items.component.html', + strings = TnsLogs.preview_file_changed_messages(bundle=bundle, file_name='items.component.html', hmr=hmr, instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) @@ -178,7 +178,7 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru # Edit CSS file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS) - strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, file_name='app.css', + strings = TnsLogs.preview_file_changed_messages(bundle=bundle, file_name='app.css', hmr=hmr, instrumented=instrumented, device=device) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) diff --git a/products/nativescript/preview_helpers.py b/products/nativescript/preview_helpers.py index 9f312c6a..3a16e9fd 100644 --- a/products/nativescript/preview_helpers.py +++ b/products/nativescript/preview_helpers.py @@ -128,7 +128,7 @@ def dismiss_simulator_alert(): run(command) @staticmethod - def run_app(app_name, platform, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): + def run_app(app_name, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False): result = Tns.preview(app_name=app_name, bundle=bundle, hmr=hmr) # Read the log and extract the url to load the app on emulator From 6ed9a01a95d3e3b2b57ab2d40973687a5005cce5 Mon Sep 17 00:00:00 2001 From: endarova Date: Tue, 26 Nov 2019 10:06:44 +0200 Subject: [PATCH 13/15] remove platform --- .../cli/preview/templates/hello_word_js_tests.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/cli/preview/templates/hello_word_js_tests.py b/tests/cli/preview/templates/hello_word_js_tests.py index ab7b1c11..4fa22ee2 100644 --- a/tests/cli/preview/templates/hello_word_js_tests.py +++ b/tests/cli/preview/templates/hello_word_js_tests.py @@ -64,24 +64,24 @@ class PreviewJSTests(TnsPreviewJSTests): def test_100_preview_android(self): """Preview project on emulator. Make valid changes in JS, CSS and XML""" - preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name, platform=Platform.ANDROID, + preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name, device=self.emu, instrumented=True) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.') def test_100_preview_ios(self): """Preview project on simulator. Make valid changes in JS, CSS and XML""" - preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name, platform=Platform.IOS, + preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name, device=self.sim, click_open_alert=True) def test_205_preview_android_no_hmr(self): """Preview project on emulator with --no-hmr. Make valid changes in JS, CSS and XML""" - preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name, platform=Platform.ANDROID, + preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name, device=self.emu, hmr=False) @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.') def test_205_preview_ios_no_hmr(self): """Preview project on simulator with --no-hmr. Make valid changes in JS, CSS and XML""" - preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name, platform=Platform.IOS, + preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name, device=self.sim, hmr=False) def test_210_tns_preview_android_livesync_on_two_emulators(self): @@ -96,7 +96,7 @@ def test_210_tns_preview_android_livesync_on_two_emulators(self): log = File.read(result.log_file) url = Preview.get_url(log) Preview.run_url(url=url, device=self.emu) - strings = TnsLogs.preview_initial_messages(device=self.emu, platform=Platform.ANDROID) + strings = TnsLogs.preview_initial_messages(device=self.emu) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text, timeout=120) @@ -107,7 +107,7 @@ def test_210_tns_preview_android_livesync_on_two_emulators(self): Preview.run_url(url=url, device=self.emu_API24) # Here use bundle=False because on consecutive preview build is not executed again # and no bundle messages are displayed in log - strings = TnsLogs.preview_initial_messages(device=self.emu, platform=Platform.ANDROID, bundle=False) + strings = TnsLogs.preview_initial_messages(device=self.emu, bundle=False) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=120) self.emu_API24.wait_for_text(text=Changes.JSHelloWord.JS.old_text) @@ -136,7 +136,7 @@ def test_210_tns_preview_on_simulator_and_emulator_livesync(self): log = File.read(result.log_file) url = Preview.get_url(log) Preview.run_url(url=url, device=self.emu) - strings = TnsLogs.preview_initial_messages(device=self.emu, platform=Platform.ANDROID) + strings = TnsLogs.preview_initial_messages(device=self.emu) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text) @@ -145,7 +145,7 @@ def test_210_tns_preview_on_simulator_and_emulator_livesync(self): # Preview on simulator Preview.run_url(url=url, device=self.sim) - strings = TnsLogs.preview_initial_messages(device=self.sim, platform=Platform.IOS) + strings = TnsLogs.preview_initial_messages(device=self.sim) TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings) self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text) From c71515a781eb7bea27c331b12704e05aea882a0b Mon Sep 17 00:00:00 2001 From: endarova Date: Tue, 26 Nov 2019 15:07:20 +0200 Subject: [PATCH 14/15] update preview sync workflow --- data/sync/hello_world_js.py | 9 +++++++++ data/sync/hello_world_ng.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/data/sync/hello_world_js.py b/data/sync/hello_world_js.py index 6aac7a7a..5f56ade4 100644 --- a/data/sync/hello_world_js.py +++ b/data/sync/hello_world_js.py @@ -3,6 +3,7 @@ """ import os +import time from core.enums.app_type import AppType from core.enums.os_type import OSType @@ -199,6 +200,10 @@ def preview_sync_hello_world_js_ts(app_type, app_name, device, bundle=True, hmr= else: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=90) device.wait_for_color(color=css_change.new_color, pixel_count=blue_count, delta=25) + # due to implementation when no hmr app restarts and if changes are made too quickly device is stated as + # not connected during the restart. Workaround is to wait some seconds before next change when in no hmr situation + if not hmr: + time.sleep(5) # Edit JS file and verify changes are applied Sync.replace(app_name=app_name, change_set=js_change) @@ -210,6 +215,10 @@ def preview_sync_hello_world_js_ts(app_type, app_name, device, bundle=True, hmr= else: TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=90) device.wait_for_text(text=js_change.new_text) + # due to implementation when no hmr app restarts and if changes are made too quickly device is stated as + # not connected during the restart. Workaround is to wait some seconds before next change when in no hmr situation + if not hmr: + time.sleep(5) # Edit XML file and verify changes are applied Sync.replace(app_name=app_name, change_set=xml_change) diff --git a/data/sync/hello_world_ng.py b/data/sync/hello_world_ng.py index e5e54156..7803b306 100644 --- a/data/sync/hello_world_ng.py +++ b/data/sync/hello_world_ng.py @@ -3,6 +3,7 @@ """ import os +import time from core.enums.app_type import AppType from core.enums.device_type import DeviceType @@ -161,6 +162,10 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180, not_existing_string_list=not_existing_string_list) device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text) + # due to implementation when no hmr app restarts and if changes are made too quickly device is stated as + # not connected during the restart. Workaround is to wait some seconds before next change when in no hmr situation + if not hmr: + time.sleep(5) # Edit HTML file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML) @@ -175,6 +180,10 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru for number in ["8", "9"]: device.wait_for_text(text=number) assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text) + # due to implementation when no hmr app restarts and if changes are made too quickly device is stated as + # not connected during the restart. Workaround is to wait some seconds before next change when in no hmr situation + if not hmr: + time.sleep(5) # Edit CSS file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS) From 80512136e0286c970c7fa178505826f9b4fb7167 Mon Sep 17 00:00:00 2001 From: endarova Date: Tue, 26 Nov 2019 16:46:06 +0200 Subject: [PATCH 15/15] update preview workflow --- data/sync/hello_world_js.py | 5 +++++ data/sync/hello_world_ng.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/data/sync/hello_world_js.py b/data/sync/hello_world_js.py index 5f56ade4..4a1175d6 100644 --- a/data/sync/hello_world_js.py +++ b/data/sync/hello_world_js.py @@ -172,6 +172,11 @@ def preview_sync_hello_world_js_ts(app_type, app_name, device, bundle=True, hmr= instrumented=instrumented, click_open_alert=click_open_alert) blue_count = device.get_pixels_by_color(color=Colors.LIGHT_BLUE) + + # due to implementation when app restarts and if changes are made too quickly device is stated as + # not connected during the restart. Workaround is to wait some seconds before next change + time.sleep(5) + # Set changes js_file = os.path.basename(Changes.JSHelloWord.JS.file_path) if app_type == AppType.JS: diff --git a/data/sync/hello_world_ng.py b/data/sync/hello_world_ng.py index 7803b306..b6b4e9ea 100644 --- a/data/sync/hello_world_ng.py +++ b/data/sync/hello_world_ng.py @@ -154,6 +154,10 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru else: not_existing_string_list = None + # due to implementation when app restarts and if changes are made too quickly device is stated as + # not connected during the restart. Workaround is to wait some seconds before next change + time.sleep(5) + # Edit TS file and verify changes are applied Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS) strings = TnsLogs.preview_file_changed_messages(run_type=RunType.INCREMENTAL, bundle=bundle,