Skip to content

fix: device console logs #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Nov 28, 2019
10 changes: 9 additions & 1 deletion core/utils/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@

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
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
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

Expand Down
12 changes: 7 additions & 5 deletions core/utils/device/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -187,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:
Expand Down
3 changes: 2 additions & 1 deletion core/utils/device/emulator_info.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions core_tests/unit/product/tns_helpers_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions data/sync/hello_world_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(platform=platform, bundle=bundle,
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)
Expand All @@ -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(platform=platform, bundle=bundle, hmr=hmr,
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)
Expand All @@ -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(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,
Expand Down
7 changes: 4 additions & 3 deletions data/sync/hello_world_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ 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)

# 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:
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion products/nativescript/preview_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 5 additions & 9 deletions products/nativescript/tns_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions products/nativescript/tns_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,25 +246,25 @@ 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(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:
logs.extend(TnsLogs.__webpack_messages())
if instrumented:
logs.append('QA: Application started')
return logs

@staticmethod
def preview_file_changed_messages(platform, 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 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')
Expand Down
20 changes: 10 additions & 10 deletions tests/cli/preview/templates/hello_word_js_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ 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, 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)
Expand All @@ -107,8 +107,8 @@ 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)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
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)

# Verify first emulator is not refreshed, state of app is preserved
Expand Down Expand Up @@ -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, 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)

Expand All @@ -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, 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)

Expand All @@ -162,8 +162,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]')

Expand All @@ -177,8 +177,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):
"""
Expand Down