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, device_id=self.id).output
self.model = model.strip('\n\r')
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
6 changes: 3 additions & 3 deletions data/sync/blank_vue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
36 changes: 25 additions & 11 deletions data/sync/hello_world_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
import time

from core.enums.app_type import AppType
from core.enums.os_type import OSType
Expand Down Expand Up @@ -151,10 +152,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)
Expand All @@ -165,12 +166,17 @@ 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)

# 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:
Expand All @@ -191,30 +197,38 @@ 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(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)
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)
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)
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)
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)
strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle,
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)
Expand Down
34 changes: 24 additions & 10 deletions data/sync/hello_world_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
import time

from core.enums.app_type import AppType
from core.enums.device_type import DeviceType
Expand Down Expand Up @@ -129,10 +130,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)
Expand All @@ -144,7 +145,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
Expand All @@ -153,18 +154,27 @@ 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(platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='item.service.ts', hmr=hmr, instrumented=instrumented)
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,
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)
strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, file_name='items.component.html',
hmr=hmr, instrumented=instrumented)
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)
if platform == Platform.IOS:
Expand All @@ -174,11 +184,15 @@ 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)
strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, file_name='app.css',
hmr=hmr, instrumented=instrumented)
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)
device.wait_for_main_color(color=Changes.NGHelloWorld.CSS.new_color)
Expand Down
5 changes: 3 additions & 2 deletions products/nativescript/preview_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(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
Loading