Skip to content

Commit ada56bf

Browse files
committed
1 parent c49bd17 commit ada56bf

File tree

2 files changed

+120
-2
lines changed

2 files changed

+120
-2
lines changed

core/tns/tns.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from core.osutils.folder import Folder
1111
from core.osutils.os_type import OSType
1212
from core.osutils.process import Process
13-
from core.settings.settings import TNS_PATH, SUT_FOLDER, DEVELOPMENT_TEAM, BRANCH, TEST_RUN_HOME, \
13+
from core.settings.settings import TNS_PATH, SUT_FOLDER, DEVELOPMENT_TEAM, TEST_RUN_HOME, \
1414
COMMAND_TIMEOUT, CURRENT_OS, TAG
1515
from core.settings.strings import config_release, codesign, config_debug
1616
from core.tns.tns_platform_type import Platform
@@ -211,7 +211,7 @@ def create_app_ng(app_name, attributes={}, log_trace=False, assert_success=True,
211211
update_modules=update_modules)
212212
if update_modules:
213213
Tns.update_angular(path=app_name)
214-
214+
215215
if assert_success:
216216
if Npm.version() < 5:
217217
assert "nativescript-angular" in output
@@ -433,6 +433,20 @@ def deploy_ios(attributes={}, assert_success=True, log_trace=False, timeout=COMM
433433
assert "Successfully installed on device" in output
434434
return output
435435

436+
@staticmethod
437+
def run(attributes={}, assert_success=True, log_trace=False, timeout=COMMAND_TIMEOUT, tns_path=None, wait=True):
438+
if "7." in Xcode.get_version():
439+
print "Xcode 7. No need to pass --teamId param!"
440+
else:
441+
attr = {"--teamId": DEVELOPMENT_TEAM}
442+
attributes.update(attr)
443+
output = Tns.run_tns_command("run", attributes=attributes, log_trace=log_trace, timeout=timeout,
444+
tns_path=tns_path, wait=wait)
445+
if assert_success:
446+
assert "Project successfully built" in output
447+
assert "Successfully installed on device with identifier" in output
448+
return output
449+
436450
@staticmethod
437451
def run_android(attributes={}, assert_success=True, log_trace=False, timeout=COMMAND_TIMEOUT, tns_path=None,
438452
wait=True):

tests/device/run_tests.py

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
"""
2+
Test for `tns run android` command (on real devices).
3+
4+
Verify `tns run android`
5+
- Run on all available devices
6+
- Changes are synced on physical devices
7+
- Emulator is not started if physical device is attached
8+
- `tns run android --emulator` starts emulator even if device is connected
9+
- `tns run android --emulator` should deploy only on emulator
10+
- `tns run android --device` should deploy only on specified device
11+
12+
TODO: Add tests for:
13+
`tns run android --device <avd-name>` -> Should be able to start avd image
14+
`tns run android --device --emulator` -> We should throw nice error
15+
`--available-devices` and `-timeout` options
16+
"""
17+
18+
import os
19+
20+
from core.base_class.BaseClass import BaseClass
21+
from core.device.device import Device
22+
from core.device.emulator import Emulator
23+
from core.device.simulator import Simulator
24+
from core.settings.settings import ANDROID_RUNTIME_PATH, IOS_RUNTIME_PATH, SIMULATOR_NAME
25+
from core.tns.replace_helper import ReplaceHelper
26+
from core.tns.tns import Tns
27+
from core.tns.tns_platform_type import Platform
28+
29+
30+
class RunBothPlatformsTests(BaseClass):
31+
SIMULATOR_ID = ''
32+
ANDROID_DEVICES = Device.get_ids(platform=Platform.ANDROID, include_emulators=True)
33+
IOS_DEVICES = Device.get_ids(platform=Platform.IOS)
34+
DEVICE_ID = Device.get_id(platform=Platform.ANDROID)
35+
36+
@classmethod
37+
def setUpClass(cls):
38+
logfile = os.path.join('out', cls.__name__ + '.txt')
39+
BaseClass.setUpClass(logfile)
40+
Emulator.ensure_available()
41+
cls.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME)
42+
Device.ensure_available(platform=Platform.ANDROID)
43+
Device.ensure_available(platform=Platform.IOS)
44+
Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.ANDROID)
45+
Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.IOS)
46+
47+
Tns.create_app(cls.app_name,
48+
attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')},
49+
update_modules=True)
50+
Tns.platform_add_android(attributes={'--path': cls.app_name, '--frameworkPath': ANDROID_RUNTIME_PATH})
51+
Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_RUNTIME_PATH})
52+
53+
def setUp(self):
54+
BaseClass.setUp(self)
55+
Tns.kill()
56+
57+
def tearDown(self):
58+
Tns.kill()
59+
BaseClass.tearDown(self)
60+
61+
@classmethod
62+
def tearDownClass(cls):
63+
BaseClass.tearDownClass()
64+
Emulator.stop()
65+
66+
def test_001_tns_run_on_all_devices(self):
67+
68+
# Build to speed up run after that
69+
Tns.build_android(attributes={'--path': self.app_name})
70+
Tns.build_ios(attributes={'--path': self.app_name})
71+
72+
# `tns run` should deploy on all devices, emulators and simulators
73+
log = Tns.run(attributes={'--path': self.app_name}, wait=False, assert_success=False)
74+
strings = ['Successfully installed on device with identifier', self.SIMULATOR_ID]
75+
for android_device_id in self.ANDROID_DEVICES:
76+
strings.append(android_device_id)
77+
for ios_device_id in self.ANDROID_DEVICES:
78+
strings.append(ios_device_id)
79+
Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False)
80+
81+
# Verify app is deployed and running on all available android devices
82+
for device_id in self.ANDROID_DEVICES:
83+
Device.wait_until_app_is_running(app_id=Tns.get_app_id(self.app_name), device_id=device_id, timeout=30)
84+
85+
# Change JS and wait until app is synced
86+
ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
87+
strings = ['Successfully transferred main-view-model.js', 'Successfully synced application']
88+
Tns.wait_for_log(log_file=log, string_list=strings)
89+
for device_id in self.ANDROID_DEVICES:
90+
text_changed = Device.wait_for_text(device_id=device_id, text='42 clicks left', timeout=20)
91+
assert text_changed, 'Changes in JS file not applied (UI is not refreshed) on ' + device_id
92+
93+
# Change XML and wait until app is synced
94+
ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3)
95+
strings = ['Successfully transferred main-page.xml', 'Successfully synced application']
96+
Tns.wait_for_log(log_file=log, string_list=strings)
97+
for device_id in self.ANDROID_DEVICES:
98+
text_changed = Device.wait_for_text(device_id=device_id, text='TEST', timeout=20)
99+
assert text_changed, 'Changes in JS file not applied (UI is not refreshed) on ' + device_id
100+
101+
# Change CSS and wait until app is synced
102+
ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3)
103+
strings = ['Successfully transferred app.css', 'Successfully synced application']
104+
Tns.wait_for_log(log_file=log, string_list=strings)

0 commit comments

Comments
 (0)