16
16
"""
17
17
18
18
import os
19
+ from datetime import datetime
19
20
from time import sleep
20
21
21
22
from flaky import flaky
26
27
from core .device .simulator import Simulator
27
28
from core .osutils .file import File
28
29
from core .osutils .folder import Folder
29
- from core .settings .settings import IOS_RUNTIME_PATH , SIMULATOR_NAME
30
+ from core .settings .settings import IOS_RUNTIME_PATH , SIMULATOR_NAME , TEST_RUN_HOME
30
31
from core .tns .replace_helper import ReplaceHelper
31
32
from core .tns .tns import Tns
32
33
from core .tns .tns_platform_type import Platform
@@ -38,6 +39,8 @@ class RunIOSDeviceTests(BaseClass):
38
39
SIMULATOR_ID = ''
39
40
DEVICES = Device .get_ids (platform = Platform .IOS )
40
41
DEVICE_ID = Device .get_id (platform = Platform .IOS )
42
+ TEMP_FOLDER = os .path .join (TEST_RUN_HOME , 'out' ,
43
+ 'livesync-hello-world_app_' + datetime .now ().strftime ('%Y_%m_%d_%H_%M_%S' ))
41
44
42
45
@classmethod
43
46
def setUpClass (cls ):
@@ -52,12 +55,18 @@ def setUpClass(cls):
52
55
Tns .create_app (cls .app_name ,
53
56
attributes = {'--template' : os .path .join ('data' , 'apps' , 'livesync-hello-world.tgz' )},
54
57
update_modules = True )
58
+ Folder .copy (src = os .path .join (cls .app_name , 'app' ), dst = cls .TEMP_FOLDER )
55
59
Tns .platform_add_ios (attributes = {'--path' : cls .app_name , '--frameworkPath' : IOS_RUNTIME_PATH })
56
60
57
61
def setUp (self ):
58
62
BaseClass .setUp (self )
59
63
Tns .kill ()
60
64
65
+ # Replace app folder between tests.
66
+ app_folder = os .path .join (self .app_name , 'app' )
67
+ Folder .cleanup (app_folder )
68
+ Folder .copy (src = self .TEMP_FOLDER , dst = app_folder )
69
+
61
70
def tearDown (self ):
62
71
Tns .kill ()
63
72
BaseClass .tearDown (self )
@@ -116,12 +125,13 @@ def test_001_tns_run_ios_js_css_xml(self):
116
125
Tns .wait_for_log (log_file = log , string_list = strings )
117
126
assert Device .wait_for_text (device_id = self .DEVICE_ID , text = "TEST" ), "Sync of CSS files failed!"
118
127
119
- # Rollback all the changes and verify files are synced
128
+ # Rollback JS changes and verify files are synced
120
129
ReplaceHelper .rollback (self .app_name , ReplaceHelper .CHANGE_JS , sleep = 10 )
121
130
strings = ['Successfully transferred' , 'main-view-model.js' , 'Refreshing application' ]
122
131
Tns .wait_for_log (log_file = log , string_list = strings )
123
132
assert Device .wait_for_text (device_id = self .DEVICE_ID , text = "taps left" ), "JS changes not synced on device!"
124
133
134
+ # Change XML again
125
135
file_change = ReplaceHelper .CHANGE_XML
126
136
File .replace (self .app_name + '/' + file_change [0 ], "TEST" , "MyTest" )
127
137
File .copy (src = self .app_name + '/' + file_change [0 ], dest = self .app_name + '/' + file_change [0 ] + ".bak" )
@@ -131,6 +141,7 @@ def test_001_tns_run_ios_js_css_xml(self):
131
141
Tns .wait_for_log (log_file = log , string_list = strings )
132
142
assert Device .wait_for_text (device_id = self .DEVICE_ID , text = "MyTest" ), "XML changes not synced on device!"
133
143
144
+ # Rollback CSS changes and verify files are synced
134
145
ReplaceHelper .rollback (self .app_name , ReplaceHelper .CHANGE_CSS , sleep = 3 )
135
146
strings = ['Successfully transferred' , 'app.css' , 'Refreshing application' ]
136
147
Tns .wait_for_log (log_file = log , string_list = strings )
@@ -186,7 +197,7 @@ def test_310_tns_run_ios_emulator_should_run_only_on_emulator(self):
186
197
self .SIMULATOR_ID = Simulator .ensure_available (simulator_name = SIMULATOR_NAME )
187
198
output = Tns .run_ios (attributes = {'--path' : self .app_name , '--emulator' : '' , '--justlaunch' : '' },
188
199
assert_success = False )
189
- TnsAsserts .prepared (app_name = self .app_name , output = output , platform = Platform .IOS , prepare = Prepare .SKIP )
200
+ TnsAsserts .prepared (app_name = self .app_name , output = output , platform = Platform .IOS , prepare = Prepare .INCREMENTAL )
190
201
assert self .SIMULATOR_ID in output
191
202
for device_id in self .DEVICES :
192
203
assert device_id not in output , 'Application is deployed on {0} device.' .format (device_id )
@@ -198,13 +209,14 @@ def test_320_tns_run_ios_specific_device(self):
198
209
self .SIMULATOR_ID = Simulator .ensure_available (simulator_name = SIMULATOR_NAME )
199
210
output = Tns .run_ios (attributes = {'--path' : self .app_name , '--device' : self .DEVICE_ID , '--justlaunch' : '' },
200
211
assert_success = False )
201
- TnsAsserts .prepared (app_name = self .app_name , output = output , platform = Platform .IOS , prepare = Prepare .SKIP )
212
+ TnsAsserts .prepared (app_name = self .app_name , output = output , platform = Platform .IOS , prepare = Prepare .INCREMENTAL )
202
213
assert self .SIMULATOR_ID not in output , 'Application is also deployed on iOS Simulator!'
203
214
for device_id in self .DEVICES :
204
215
if device_id != self .DEVICE_ID :
205
216
assert device_id not in output , \
206
217
'Application is deployed on {0} while it should be only on {1}' .format (device_id , self .DEVICES )
207
218
219
+ # Second prepare should be skipped, since there are no changes in the project.
208
220
output = Tns .run_ios (attributes = {'--path' : self .app_name , '--emulator' : '' , '--justlaunch' : '' },
209
221
assert_success = False )
210
222
TnsAsserts .prepared (app_name = self .app_name , output = output , platform = Platform .IOS , prepare = Prepare .SKIP )
@@ -257,8 +269,9 @@ def test_400_tns_run_ios_should_not_crash_when_uninstall_app(self):
257
269
"""
258
270
259
271
# `tns run ios` and wait until app is deployed
260
- log = Tns .run_ios (attributes = {'--path' : self .app_name , "--device" : self .DEVICE_ID }, log_trace = True , wait = False , assert_success = False )
261
- strings = [self .DEVICE_ID ,'Successfully synced application' ]
272
+ log = Tns .run_ios (attributes = {'--path' : self .app_name , "--device" : self .DEVICE_ID }, log_trace = True , wait = False ,
273
+ assert_success = False )
274
+ strings = [self .DEVICE_ID , 'Successfully synced application' ]
262
275
Tns .wait_for_log (log_file = log , string_list = strings , timeout = 150 , check_interval = 10 )
263
276
264
277
# Verify app is running
0 commit comments