-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathblank_vue.py
123 lines (102 loc) · 5.61 KB
/
blank_vue.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
"""
Sync changes on JS/TS project helper.
"""
import os
from core.enums.app_type import AppType
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.run_type import RunType
from products.nativescript.tns import Tns
from products.nativescript.tns_logs import TnsLogs
def __run_vue(app_name, platform, bundle, hmr):
# Execute `tns run` and wait until logs are OK
return Tns.run(app_name=app_name, platform=platform, emulator=True, wait=False, bundle=bundle, hmr=hmr)
def __preview_vue(app_name, bundle, hmr):
# Execute `tns run` and wait until logs are OK
return Tns.preview(app_name=app_name, bundle=bundle, hmr=hmr)
def __workflow(preview, app_name, platform, device, bundle=False, hmr=False):
# Execute tns command
if preview:
result = __preview_vue(app_name=app_name, bundle=bundle, hmr=hmr)
else:
result = __run_vue(app_name=app_name, platform=platform, bundle=bundle, hmr=hmr)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.FULL, bundle=bundle,
hmr=hmr, app_type=AppType.VUE)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=240)
# Verify it looks properly
device.wait_for_text(text=Changes.BlankVue.VUE_SCRIPT.old_text)
device.wait_for_text(text=Changes.BlankVue.VUE_TEMPLATE.old_text)
initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png')
device.get_screen(path=initial_state)
# Edit script in .vue file
Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_SCRIPT)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
device.wait_for_text(text=Changes.BlankVue.VUE_SCRIPT.new_text)
# Edit template in .vue file
Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_TEMPLATE)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
device.wait_for_text(text=Changes.BlankVue.VUE_TEMPLATE.new_text)
# Edit styling in .vue file
Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_STYLE)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
style_applied = Wait.until(lambda: device.get_pixels_by_color(Colors.RED) > 100)
assert style_applied, 'Failed to sync changes in style.'
# Revert script in .vue file
Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_SCRIPT)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
device.wait_for_text(text=Changes.BlankVue.VUE_SCRIPT.old_text)
# Revert template in .vue file
Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_TEMPLATE)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
device.wait_for_text(text=Changes.BlankVue.VUE_TEMPLATE.old_text)
# Revert styling in .vue file
Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_STYLE)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle,
hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
if hmr:
Log.info('Skip next steps because of https://github.com/nativescript-vue/nativescript-vue/issues/425')
else:
style_applied = Wait.until(lambda: device.get_pixels_by_color(Colors.RED) == 0)
assert style_applied, 'Failed to sync changes in style.'
# Assert final and initial states are same
device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)
def sync_blank_vue(app_name, platform, device, bundle=False, hmr=False):
__workflow(preview=False, app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr)
def preview_blank_vue(app_name, platform, device, bundle=False, hmr=False):
__workflow(preview=True, app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr)