Skip to content

Commit 37482ab

Browse files
miroslavaivanovaendarova
authored andcommitted
fix: device console logs (#448)
* console logs * console logs * console logs * test * latest changes * fix a test * fix pylint errors * model errors * fix get model when devices are connected * remove unused parameter * update device constructor * remove unused platform parameter * remove platform * update preview sync workflow * update preview workflow
1 parent 22252f8 commit 37482ab

14 files changed

+104
-68
lines changed

core/utils/device/device.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@
2121

2222
class Device(object):
2323
# noinspection PyShadowingBuiltins
24-
def __init__(self, id, name, type, version):
24+
def __init__(self, id, name, type, model, version):
2525
self.id = id
2626
self.type = type
2727
self.version = version
28+
self.model = model
29+
self.name = name
2830

2931
if type is DeviceType.IOS:
3032
type = run(cmd="ideviceinfo | grep ProductType").output
3133
type = type.replace(',', '')
3234
type = type.replace('ProductType:', '').strip(' ')
3335
self.name = type
36+
if type is DeviceType.SIM:
37+
self.model = name
38+
if type is DeviceType.EMU:
39+
cmd = 'shell getprop ro.product.model'
40+
model = Adb.run_adb_command(command=cmd, wait=True, device_id=self.id).output
41+
self.model = model.strip('\n\r')
3442
else:
3543
self.name = name
3644

core/utils/device/device_manager.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ def get_devices(device_type=any):
2121
if device_type is DeviceType.ANDROID or device_type is any:
2222
for device_id in Adb.get_ids(include_emulators=False):
2323
version = Adb.get_version(device_id=device_id)
24-
device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, version=version)
24+
device = Device(id=device_id, name=device_id, type=DeviceType.ANDROID, version=version, model=None)
2525
devices.append(device)
2626
# Get iOS devices
2727
if device_type is DeviceType.IOS or device_type is any:
2828
for device_id in IDevice.get_devices():
29-
device = Device(id=device_id, name=device_id, type=DeviceType.IOS, version=None)
29+
device = Device(id=device_id, name=device_id, type=DeviceType.IOS, version=None, model=None)
3030
devices.append(device)
3131

3232
for device in devices:
@@ -83,7 +83,8 @@ def start(emulator):
8383
booted = Adb.wait_until_boot(device_id=emulator.emu_id)
8484
if booted:
8585
Log.info('{0} is up and running!'.format(emulator.avd))
86-
device = Device(id=emulator.emu_id, name=emulator.avd, type=DeviceType.EMU, version=emulator.os_version)
86+
device = Device(id=emulator.emu_id, model=emulator.model, name=emulator.avd, type=DeviceType.EMU,
87+
version=emulator.os_version)
8788
TestContext.STARTED_DEVICES.append(device)
8889
return device
8990
else:
@@ -169,7 +170,7 @@ def start(simulator_info):
169170

170171
# Return result
171172
device = Device(id=simulator_info.id, name=simulator_info.name, type=DeviceType.SIM,
172-
version=simulator_info.sdk)
173+
version=simulator_info.sdk, model=simulator_info.id)
173174
TestContext.STARTED_DEVICES.append(device)
174175
return device
175176

@@ -187,7 +188,8 @@ def ensure_available(simulator_info):
187188
return Device(id=simulator_info.id,
188189
name=simulator_info.name,
189190
type=DeviceType.SIM,
190-
version=simulator_info.sdk)
191+
version=simulator_info.sdk,
192+
model=None)
191193
elif DeviceManager.Simulator.is_available(simulator_info=simulator_info):
192194
return DeviceManager.Simulator.start(simulator_info)
193195
else:

core/utils/device/emulator_info.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# noinspection PyShadowingBuiltins
22
class EmulatorInfo(object):
3-
def __init__(self, avd=None, os_version=None, port=None, emu_id=None):
3+
def __init__(self, avd=None, os_version=None, port=None, emu_id=None, model=None):
44
self.avd = avd
55
self.os_version = os_version
66
self.port = port
77
self.emu_id = emu_id
8+
self.model = model

core_tests/unit/product/tns_helpers_tests.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_10_get_run_messages_first_run(self):
2929
platform=Platform.ANDROID,
3030
run_type=RunType.FIRST_TIME,
3131
file_name=None,
32-
device=Device(id='123', name='Emu', type=DeviceType.EMU, version=6.0))
32+
device=Device(id='123', name='Emu', type=DeviceType.EMU, version=6.0, model=None))
3333
assert 'Skipping prepare.' not in logs
3434
assert 'Preparing project...' in logs
3535
assert 'Project successfully prepared (android)' in logs
@@ -52,7 +52,7 @@ def test_11_get_run_messages_sync_js(self):
5252
file_name='main-view-model.js',
5353
bundle=False,
5454
hmr=False,
55-
device=Device(id='123', name='Emu', type=DeviceType.EMU, version=8.0))
55+
device=Device(id='123', name='Emu', type=DeviceType.EMU, version=8.0, model=None))
5656
assert 'Successfully transferred main-view-model.js' in logs
5757
assert 'Restarting application on device' in logs
5858
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):
8484
bundle=True,
8585
uglify=True,
8686
hmr=False,
87-
device=Device(id='123', name='Emu', type=DeviceType.EMU, version=4.4))
87+
device=Device(id='123', name='Emu', type=DeviceType.EMU, version=4.4, model=None))
8888
assert 'Skipping prepare.' not in logs
8989
assert 'File change detected.' in logs
9090
assert 'main-view-model.js' in logs

data/sync/blank_vue.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def __run_vue(app_name, platform, hmr):
2121
return Tns.run(app_name=app_name, platform=platform, emulator=True, wait=False, hmr=hmr)
2222

2323

24-
def __preview_vue(app_name, platform, device, hmr):
24+
def __preview_vue(app_name, device, hmr):
2525
# Execute `tns run` and wait until logs are OK
26-
return Preview.run_app(app_name=app_name, hmr=hmr, platform=platform, device=device, click_open_alert=True)
26+
return Preview.run_app(app_name=app_name, hmr=hmr, device=device, click_open_alert=True)
2727

2828

2929
def __workflow(preview, app_name, platform, device, hmr=True):
3030
# Execute tns command
3131
if preview:
32-
result = __preview_vue(app_name=app_name, platform=platform, device=device, hmr=hmr)
32+
result = __preview_vue(app_name=app_name, device=device, hmr=hmr)
3333
else:
3434
result = __run_vue(app_name=app_name, platform=platform, hmr=hmr)
3535

data/sync/hello_world_js.py

+25-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import os
6+
import time
67

78
from core.enums.app_type import AppType
89
from core.enums.os_type import OSType
@@ -151,10 +152,10 @@ def __sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=True,
151152
device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
152153

153154

154-
def preview_hello_world_js_ts(app_name, platform, device, bundle=True, hmr=True, instrumented=False,
155+
def preview_hello_world_js_ts(app_name, device, bundle=True, hmr=True, instrumented=False,
155156
click_open_alert=False):
156-
result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, platform=platform,
157-
device=device, instrumented=instrumented, click_open_alert=click_open_alert)
157+
result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, device=device,
158+
instrumented=instrumented, click_open_alert=click_open_alert)
158159

159160
# Verify app looks properly
160161
device.wait_for_text(text=Changes.JSHelloWord.JS.old_text, timeout=90, retry_delay=5)
@@ -165,12 +166,17 @@ def preview_hello_world_js_ts(app_name, platform, device, bundle=True, hmr=True,
165166
return result
166167

167168

168-
def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=True, hmr=True, instrumented=False,
169+
def preview_sync_hello_world_js_ts(app_type, app_name, device, bundle=True, hmr=True, instrumented=False,
169170
click_open_alert=False):
170-
result = preview_hello_world_js_ts(app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr,
171+
result = preview_hello_world_js_ts(app_name=app_name, device=device, bundle=bundle, hmr=hmr,
171172
instrumented=instrumented, click_open_alert=click_open_alert)
172173

173174
blue_count = device.get_pixels_by_color(color=Colors.LIGHT_BLUE)
175+
176+
# due to implementation when app restarts and if changes are made too quickly device is stated as
177+
# not connected during the restart. Workaround is to wait some seconds before next change
178+
time.sleep(5)
179+
174180
# Set changes
175181
js_file = os.path.basename(Changes.JSHelloWord.JS.file_path)
176182
if app_type == AppType.JS:
@@ -191,30 +197,38 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=
191197

192198
# Edit CSS file and verify changes are applied
193199
Sync.replace(app_name=app_name, change_set=css_change)
194-
strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle,
195-
hmr=hmr, file_name='app.css', instrumented=instrumented)
200+
strings = TnsLogs.preview_file_changed_messages(bundle=bundle, device=device, hmr=hmr,
201+
file_name='app.css', instrumented=instrumented)
196202
if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS:
197203
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
198204
not_existing_string_list=not_existing_string_list)
199205
else:
200206
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=90)
201207
device.wait_for_color(color=css_change.new_color, pixel_count=blue_count, delta=25)
208+
# due to implementation when no hmr app restarts and if changes are made too quickly device is stated as
209+
# not connected during the restart. Workaround is to wait some seconds before next change when in no hmr situation
210+
if not hmr:
211+
time.sleep(5)
202212

203213
# Edit JS file and verify changes are applied
204214
Sync.replace(app_name=app_name, change_set=js_change)
205-
strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, hmr=hmr,
206-
file_name=js_file, instrumented=instrumented)
215+
strings = TnsLogs.preview_file_changed_messages(bundle=bundle, hmr=hmr, device=device, file_name=js_file,
216+
instrumented=instrumented)
207217
if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS:
208218
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
209219
not_existing_string_list=not_existing_string_list)
210220
else:
211221
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=90)
212222
device.wait_for_text(text=js_change.new_text)
223+
# due to implementation when no hmr app restarts and if changes are made too quickly device is stated as
224+
# not connected during the restart. Workaround is to wait some seconds before next change when in no hmr situation
225+
if not hmr:
226+
time.sleep(5)
213227

214228
# Edit XML file and verify changes are applied
215229
Sync.replace(app_name=app_name, change_set=xml_change)
216-
strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle,
217-
hmr=hmr, file_name='main-page.xml', instrumented=instrumented)
230+
strings = TnsLogs.preview_file_changed_messages(bundle=bundle, device=device, hmr=hmr,
231+
file_name='main-page.xml', instrumented=instrumented)
218232
if hmr and instrumented and Settings.HOST_OS != OSType.WINDOWS:
219233
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings,
220234
not_existing_string_list=not_existing_string_list)

data/sync/hello_world_ng.py

+24-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import os
6+
import time
67

78
from core.enums.app_type import AppType
89
from core.enums.device_type import DeviceType
@@ -129,10 +130,10 @@ def sync_hello_world_ng(app_name, platform, device, bundle=True, uglify=False, a
129130
device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
130131

131132

132-
def preview_hello_world_ng(app_name, platform, device, bundle=False, hmr=False, instrumented=False,
133+
def preview_hello_world_ng(app_name, device, bundle=False, hmr=False, instrumented=False,
133134
click_open_alert=False):
134-
result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, platform=platform,
135-
device=device, instrumented=instrumented, click_open_alert=click_open_alert)
135+
result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, device=device,
136+
instrumented=instrumented, click_open_alert=click_open_alert)
136137

137138
# Verify app looks properly
138139
device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text)
@@ -144,7 +145,7 @@ def preview_hello_world_ng(app_name, platform, device, bundle=False, hmr=False,
144145

145146
def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=True, instrumented=False,
146147
click_open_alert=False):
147-
result = preview_hello_world_ng(app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr,
148+
result = preview_hello_world_ng(app_name=app_name, device=device, bundle=bundle, hmr=hmr,
148149
instrumented=instrumented, click_open_alert=click_open_alert)
149150

150151
# Verify that application is not restarted on file changes when hmr=true
@@ -153,18 +154,27 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru
153154
else:
154155
not_existing_string_list = None
155156

157+
# due to implementation when app restarts and if changes are made too quickly device is stated as
158+
# not connected during the restart. Workaround is to wait some seconds before next change
159+
time.sleep(5)
160+
156161
# Edit TS file and verify changes are applied
157162
Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS)
158-
strings = TnsLogs.preview_file_changed_messages(platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
159-
file_name='item.service.ts', hmr=hmr, instrumented=instrumented)
163+
strings = TnsLogs.preview_file_changed_messages(run_type=RunType.INCREMENTAL, bundle=bundle,
164+
file_name='item.service.ts', hmr=hmr, instrumented=instrumented,
165+
device=device)
160166
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
161167
not_existing_string_list=not_existing_string_list)
162168
device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text)
169+
# due to implementation when no hmr app restarts and if changes are made too quickly device is stated as
170+
# not connected during the restart. Workaround is to wait some seconds before next change when in no hmr situation
171+
if not hmr:
172+
time.sleep(5)
163173

164174
# Edit HTML file and verify changes are applied
165175
Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML)
166-
strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, file_name='items.component.html',
167-
hmr=hmr, instrumented=instrumented)
176+
strings = TnsLogs.preview_file_changed_messages(bundle=bundle, file_name='items.component.html',
177+
hmr=hmr, instrumented=instrumented, device=device)
168178
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
169179
not_existing_string_list=not_existing_string_list)
170180
if platform == Platform.IOS:
@@ -174,11 +184,15 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru
174184
for number in ["8", "9"]:
175185
device.wait_for_text(text=number)
176186
assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text)
187+
# due to implementation when no hmr app restarts and if changes are made too quickly device is stated as
188+
# not connected during the restart. Workaround is to wait some seconds before next change when in no hmr situation
189+
if not hmr:
190+
time.sleep(5)
177191

178192
# Edit CSS file and verify changes are applied
179193
Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS)
180-
strings = TnsLogs.preview_file_changed_messages(platform=platform, bundle=bundle, file_name='app.css',
181-
hmr=hmr, instrumented=instrumented)
194+
strings = TnsLogs.preview_file_changed_messages(bundle=bundle, file_name='app.css',
195+
hmr=hmr, instrumented=instrumented, device=device)
182196
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
183197
not_existing_string_list=not_existing_string_list)
184198
device.wait_for_main_color(color=Changes.NGHelloWorld.CSS.new_color)

products/nativescript/preview_helpers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def dismiss_simulator_alert():
128128
run(command)
129129

130130
@staticmethod
131-
def run_app(app_name, platform, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False):
131+
def run_app(app_name, device, bundle=True, hmr=True, instrumented=False, click_open_alert=False):
132132
result = Tns.preview(app_name=app_name, bundle=bundle, hmr=hmr)
133133

134134
# Read the log and extract the url to load the app on emulator
@@ -143,7 +143,8 @@ def run_app(app_name, platform, device, bundle=True, hmr=True, instrumented=Fals
143143
device.click("Open")
144144

145145
# Verify logs
146-
strings = TnsLogs.preview_initial_messages(platform=platform, hmr=hmr, bundle=bundle, instrumented=instrumented)
146+
strings = TnsLogs.preview_initial_messages(device=device, hmr=hmr, bundle=bundle,
147+
instrumented=instrumented)
147148
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=200)
148149
return result
149150

products/nativescript/tns_assert.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,17 @@ def test_initialized(app_name, framework, output):
181181
assert 'Run your tests using the' in output
182182

183183
@staticmethod
184-
def file_is_synced_once(log, platform, file_name):
184+
def file_is_synced_once(log, device, file_name):
185185
"""
186186
Assert file is synced once on livesync.
187187
:param log: log or part of log you want to check
188188
:param platform: The platform you are syncing on.
189189
:param file_name: name of the file you are syncing.
190190
"""
191-
if platform == Platform.ANDROID:
192-
assert log.count('Start syncing changes for platform android') == 1, "File is synced more than once!"
193-
assert log.count('hot-update.json for platform android') == 1, "File is synced more than once!"
194-
assert file_name in log
195-
else:
196-
assert log.count('Start syncing changes for platform ios') == 1, "File is synced more than once!"
197-
assert log.count('hot-update.json for platform ios') == 1, "File is synced more than once!"
198-
assert file_name in log
191+
assert log.count('Start syncing changes for device {0}'.format(str(device.model))) == 1, \
192+
"File is synced more than once!"
193+
# assert log.count('hot-update.json for device') == 1, "File is synced more than once!"
194+
assert file_name in log
199195

200196
@staticmethod
201197
def snapshot_skipped(snapshot, result, release):

0 commit comments

Comments
 (0)