-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhello_world_ng.py
205 lines (178 loc) · 11 KB
/
hello_world_ng.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
"""
Sync changes on NG project helper.
"""
import os
import time
from core.enums.app_type import AppType
from core.enums.device_type import DeviceType
from core.enums.platform_type import Platform
from core.enums.os_type import OSType
from core.log.log import Log
from core.settings import Settings
from core.utils.wait import Wait
from data.changes import Changes, Sync
from data.const import Colors
from products.nativescript.preview_helpers import Preview
from products.nativescript.run_type import RunType
from products.nativescript.tns import Tns
from products.nativescript.tns_logs import TnsLogs
def run_hello_world_ng(app_name, platform, device, bundle=True, uglify=False, aot=False, hmr=True,
instrumented=True, release=False, snapshot=False):
# Define if it should be executed on device or emulator
emulator = True
device_id = None
if device.type == DeviceType.ANDROID or device.type == DeviceType.IOS:
emulator = False
device_id = device.id
# Execute tns run command
result = Tns.run(app_name=app_name, platform=platform, emulator=emulator, bundle=bundle, aot=aot,
uglify=uglify, hmr=hmr, release=release, snapshot=snapshot, device=device_id)
# Check logs
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.UNKNOWN, bundle=bundle,
release=release, hmr=hmr, instrumented=instrumented, app_type=AppType.NG,
device=device, snapshot=snapshot)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
# Verify it looks properly
device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text, timeout=180)
device.wait_for_main_color(color=Colors.WHITE)
initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png')
device.get_screen(path=initial_state)
return result
def sync_hello_world_ng(app_name, platform, device, bundle=True, uglify=False, aot=False, hmr=True,
instrumented=True):
result = run_hello_world_ng(app_name=app_name, platform=platform, device=device, uglify=uglify, aot=aot, hmr=hmr)
# Verify that application is not restarted on file changes when hmr=true
if hmr and Settings.HOST_OS != OSType.WINDOWS:
not_existing_string_list = ['Restarting application']
else:
not_existing_string_list = None
# Apply changes
Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS)
device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG,
device=device)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
not_existing_string_list=not_existing_string_list)
Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML)
if platform == Platform.IOS:
for number in ["10", "11"]:
device.wait_for_text(text=number)
else:
for number in ["8", "9"]:
device.wait_for_text(text=number)
assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='items.component.html', hmr=hmr, instrumented=instrumented,
app_type=AppType.NG, aot=aot, device=device)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
not_existing_string_list=not_existing_string_list)
Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS)
if platform == Platform.IOS:
for number in ["10", "1"]:
device.wait_for_text(text=number)
else:
for number in ["8", "9"]:
device.wait_for_text(text=number)
assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG,
device=device)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
not_existing_string_list=not_existing_string_list)
assert Wait.until(lambda: device.get_pixels_by_color(color=Changes.NGHelloWorld.CSS.new_color) > 100), \
'CSS on root level not applied!'
Log.info('CSS on root level applied successfully!')
# Revert changes
Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.HTML)
device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='items.component.html', hmr=hmr, instrumented=instrumented,
app_type=AppType.NG, aot=aot, device=device)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
not_existing_string_list=not_existing_string_list)
Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.TS)
device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG,
device=device)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
not_existing_string_list=not_existing_string_list)
Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.CSS)
device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG,
device=device)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
not_existing_string_list=not_existing_string_list)
assert Wait.until(lambda: device.get_pixels_by_color(color=Changes.NGHelloWorld.CSS.new_color) < 100), \
'CSS on root level not applied!'
Log.info('CSS on root level applied successfully!')
# Assert final and initial states are same
initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png')
device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
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, device=device,
instrumented=instrumented, click_open_alert=click_open_alert)
# Verify app looks properly
device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text)
device.wait_for_main_color(color=Colors.WHITE)
initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png')
device.get_screen(path=initial_state)
return result
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, 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
if hmr and Settings.HOST_OS != OSType.WINDOWS:
not_existing_string_list = ['Restarting application']
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,
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(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:
for number in ["10", "1"]:
device.wait_for_text(text=number)
else:
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(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)
if platform == Platform.IOS:
for number in ["10", "1"]:
device.wait_for_text(text=number)
else:
for number in ["8", "9"]:
device.wait_for_text(text=number)
assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text)