-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhello_word_js_tests.py
214 lines (176 loc) · 10.1 KB
/
hello_word_js_tests.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
206
207
208
209
210
211
212
213
214
import os
import unittest
from flaky import flaky
from core.base_test.tns_run_test import TnsRunTest
from core.base_test.tns_test import TnsTest
from core.enums.app_type import AppType
from core.enums.os_type import OSType
from core.enums.platform_type import Platform
from core.settings import Settings
from core.utils.device.adb import Adb
from core.utils.device.device_manager import DeviceManager
from core.utils.file_utils import File, Folder
from data.changes import Changes, Sync
from data.sync.hello_world_js import preview_sync_hello_world_js_ts
from data.templates import Template
from products.nativescript.preview_helpers import Preview
from products.nativescript.tns import Tns
from products.nativescript.tns_assert import TnsAssert
from products.nativescript.tns_logs import TnsLogs
class TnsPreviewJSTests(TnsRunTest):
app_name = Settings.AppName.DEFAULT
source_project_dir = os.path.join(Settings.TEST_RUN_HOME, app_name)
target_project_dir = os.path.join(Settings.TEST_RUN_HOME, 'data', 'temp', app_name)
@classmethod
def setUpClass(cls):
TnsRunTest.setUpClass()
# Start second emulator for tests
cls.emu_API24 = DeviceManager.Emulator.ensure_available(Settings.Emulators.EMU_API_24)
# Download Preview and Playground packages
Preview.get_app_packages()
# Install Preview and Playground
Preview.install_preview_app(cls.emu, Platform.ANDROID)
Preview.install_preview_app(cls.emu_API24, Platform.ANDROID)
if Settings.HOST_OS is OSType.OSX:
Preview.install_preview_app(cls.sim, Platform.IOS)
Preview.install_playground_app(cls.sim, Platform.IOS)
# Create app
Tns.create(app_name=cls.app_name, template=Template.HELLO_WORLD_JS.local_package, update=True)
src = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'logs', 'hello-world-js', 'app.js')
target = os.path.join(Settings.TEST_RUN_HOME, cls.app_name, 'app')
File.copy(source=src, target=target)
# Copy TestApp to data folder.
Folder.copy(source=cls.source_project_dir, target=cls.target_project_dir)
def setUp(self):
TnsTest.setUp(self)
# "src" folder of TestApp will be restored before each test.
# This will ensure failures in one test do not cause common failures.
source_src = os.path.join(self.target_project_dir, 'app')
target_src = os.path.join(self.source_project_dir, 'app')
Folder.clean(target_src)
Folder.copy(source=source_src, target=target_src)
class PreviewJSTests(TnsPreviewJSTests):
def test_100_preview_android(self):
"""Preview project on emulator. Make valid changes in JS, CSS and XML"""
preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name,
device=self.emu, instrumented=True)
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
def test_100_preview_ios(self):
"""Preview project on simulator. Make valid changes in JS, CSS and XML"""
preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name,
device=self.sim, click_open_alert=True)
@flaky(max_runs=3)
def test_205_preview_android_no_hmr(self):
"""Preview project on emulator with --no-hmr. Make valid changes in JS, CSS and XML"""
preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name,
device=self.emu, hmr=False)
@flaky(max_runs=3)
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
def test_205_preview_ios_no_hmr(self):
"""Preview project on simulator with --no-hmr. Make valid changes in JS, CSS and XML"""
preview_sync_hello_world_js_ts(app_type=AppType.JS, app_name=self.app_name,
device=self.sim, hmr=False)
def test_210_tns_preview_android_livesync_on_two_emulators(self):
"""
Test when preview on second emulator only the current one is refreshed.
Test changes are synced on both emulators.
"""
# Preview on emulator
result = Tns.preview(app_name=self.app_name)
# Read the log and extract the url to load the app on emulator
log = File.read(result.log_file)
url = Preview.get_url(log)
Preview.run_url(url=url, device=self.emu)
strings = TnsLogs.preview_initial_messages(device=self.emu)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
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)
# Preview on second emulator
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(device=self.emu, 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
self.emu.wait_for_text(text='41 taps left', timeout=30)
# Edit JS file and verify changes are applied on both emulators
Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
self.emu.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
self.emu_API24.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
# Edit XML file and verify changes are applied
Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.XML)
self.emu.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
self.emu_API24.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
def test_210_tns_preview_on_simulator_and_emulator_livesync(self):
"""
Preview app on simulator and emulator. Verify livesync.
"""
# Preview on emulator
result = Tns.preview(app_name=self.app_name)
# Read the log and extract the url to load the app on emulator
log = File.read(result.log_file)
url = Preview.get_url(log)
Preview.run_url(url=url, device=self.emu)
strings = TnsLogs.preview_initial_messages(device=self.emu)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
self.emu.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
# Click on TAP button on emulator
Adb.click_element_by_text(self.emu.id, 'TAP', case_sensitive=True)
# Preview on simulator
Preview.run_url(url=url, device=self.sim)
strings = TnsLogs.preview_initial_messages(device=self.sim)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
# Verify emulator is not refreshed, state of app is preserved
self.emu.wait_for_text(text='41 taps left', timeout=30)
# Edit JS file and verify changes are applied on both emulators
Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
self.emu.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
self.sim.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
# Check changes are not synced more than once per platform
# Extract the last part of the log
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, 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]')
# Edit XML file and verify changes are applied on both emulators
Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.XML)
self.emu.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
self.sim.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
# Check changes are not synced more than once per platform
# Extract the last part of the log
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, 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):
"""
Test if correct messages are shown if plugin is missing or versions differ in Preview App.
"""
# Add some plugins
Tns.plugin_add("nativescript-barcodescanner", path=self.app_name)
Tns.plugin_add("[email protected]", path=self.app_name)
result = Tns.preview(app_name=self.app_name)
# Read the log and extract the url to load the app on emulator
log = File.read(result.log_file)
url = Preview.get_url(log)
Preview.run_url(url=url, device=self.emu)
# Verify warnings for plugins
strings = [
'Plugin nativescript-barcodescanner is not included in preview app',
# 'Local plugin nativescript-geolocation differs in major version from plugin in preview app',
# 'Some features might not work as expected'
# TODO: Uncomment line above after we release preview app with version of nativescript-geolocation > 5.1.0
# Notes:
# Preview command will fail bacause CLI will detect project needs update, see:
# https://github.com/NativeScript/nativescript-cli/
# blob/b5f88a45fbde0ef5559dc02e8cee5fb95cefe882/lib/controllers/migrate-controller.ts#L58
]
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)