Skip to content

Commit b6beef6

Browse files
committed
Fix device tests
1 parent ada56bf commit b6beef6

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed
File renamed without changes.

tests/device/run_ios_tests.py renamed to tests/device/run_ios_device_tests.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717

1818
import os
19+
from datetime import datetime
1920
from time import sleep
2021

2122
from flaky import flaky
@@ -26,7 +27,7 @@
2627
from core.device.simulator import Simulator
2728
from core.osutils.file import File
2829
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
3031
from core.tns.replace_helper import ReplaceHelper
3132
from core.tns.tns import Tns
3233
from core.tns.tns_platform_type import Platform
@@ -38,6 +39,8 @@ class RunIOSDeviceTests(BaseClass):
3839
SIMULATOR_ID = ''
3940
DEVICES = Device.get_ids(platform=Platform.IOS)
4041
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'))
4144

4245
@classmethod
4346
def setUpClass(cls):
@@ -52,12 +55,18 @@ def setUpClass(cls):
5255
Tns.create_app(cls.app_name,
5356
attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')},
5457
update_modules=True)
58+
Folder.copy(src=os.path.join(cls.app_name, 'app'), dst=cls.TEMP_FOLDER)
5559
Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_RUNTIME_PATH})
5660

5761
def setUp(self):
5862
BaseClass.setUp(self)
5963
Tns.kill()
6064

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+
6170
def tearDown(self):
6271
Tns.kill()
6372
BaseClass.tearDown(self)
@@ -116,12 +125,13 @@ def test_001_tns_run_ios_js_css_xml(self):
116125
Tns.wait_for_log(log_file=log, string_list=strings)
117126
assert Device.wait_for_text(device_id=self.DEVICE_ID, text="TEST"), "Sync of CSS files failed!"
118127

119-
# Rollback all the changes and verify files are synced
128+
# Rollback JS changes and verify files are synced
120129
ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
121130
strings = ['Successfully transferred', 'main-view-model.js', 'Refreshing application']
122131
Tns.wait_for_log(log_file=log, string_list=strings)
123132
assert Device.wait_for_text(device_id=self.DEVICE_ID, text="taps left"), "JS changes not synced on device!"
124133

134+
# Change XML again
125135
file_change = ReplaceHelper.CHANGE_XML
126136
File.replace(self.app_name + '/' + file_change[0], "TEST", "MyTest")
127137
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):
131141
Tns.wait_for_log(log_file=log, string_list=strings)
132142
assert Device.wait_for_text(device_id=self.DEVICE_ID, text="MyTest"), "XML changes not synced on device!"
133143

144+
# Rollback CSS changes and verify files are synced
134145
ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3)
135146
strings = ['Successfully transferred', 'app.css', 'Refreshing application']
136147
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):
186197
self.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME)
187198
output = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--justlaunch': ''},
188199
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)
190201
assert self.SIMULATOR_ID in output
191202
for device_id in self.DEVICES:
192203
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):
198209
self.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME)
199210
output = Tns.run_ios(attributes={'--path': self.app_name, '--device': self.DEVICE_ID, '--justlaunch': ''},
200211
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)
202213
assert self.SIMULATOR_ID not in output, 'Application is also deployed on iOS Simulator!'
203214
for device_id in self.DEVICES:
204215
if device_id != self.DEVICE_ID:
205216
assert device_id not in output, \
206217
'Application is deployed on {0} while it should be only on {1}'.format(device_id, self.DEVICES)
207218

219+
# Second prepare should be skipped, since there are no changes in the project.
208220
output = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--justlaunch': ''},
209221
assert_success=False)
210222
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):
257269
"""
258270

259271
# `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']
262275
Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10)
263276

264277
# Verify app is running

0 commit comments

Comments
 (0)