Skip to content

Commit a3e3ddc

Browse files
committed
Add tests for livesync of NG app on iOS real devices
1 parent 3ccbf7a commit a3e3ddc

10 files changed

+146
-5
lines changed

core/device/device.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from core.device.helpers.android_uiautomator import UIAuto
1313
from core.device.helpers.libimobiledevice import IDevice
1414
from core.device.simulator import Simulator
15+
from core.osutils.command import run
16+
from core.osutils.command_log_level import CommandLogLevel
1517
from core.osutils.file import File
1618
from core.osutils.folder import Folder
1719
from core.osutils.image_utils import ImageUtils
@@ -68,6 +70,14 @@ def screen_match(device_name, device_id, expected_image, tolerance=0.05, timeout
6870
:param tolerance: Tolerance in percents.
6971
:param timeout: Timeout in seconds.
7072
"""
73+
74+
device_type = Device.__get_device_type(device_id)
75+
if device_type == DeviceType.IOS:
76+
type = run(command="ideviceinfo | grep ProductType", log_level=CommandLogLevel.SILENT)
77+
type = type.replace(',','')
78+
type = type.replace('ProductType:', '').strip(' ')
79+
device_name = type
80+
7181
print "Verify {0} looks correct...".format(expected_image)
7282
expected_image_original_path = os.path.join("data", "images", device_name, "{0}.png".format(expected_image))
7383
actual_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name, "{0}_actual.png".format(expected_image))
@@ -112,7 +122,7 @@ def screen_match(device_name, device_id, expected_image, tolerance=0.05, timeout
112122
format(device_name, expected_image, diff)
113123
else:
114124
# If expected image is not found actual will be saved as expected.
115-
print "Expected image not found. Actual image will be saved as expected."
125+
print "Expected image not found. Actual image will be saved as expected: " + expected_image_original_path
116126
time.sleep(timeout)
117127
Device.get_screen(device_id, expected_image_original_path)
118128

71.9 KB
Loading
Loading
Loading
Loading
Loading
Loading

tests/device/run_ios_tests.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"""
1717

1818
import os
19+
from time import sleep
1920

2021
from core.base_class.BaseClass import BaseClass
2122
from core.device.device import Device
2223
from core.device.emulator import Emulator
2324
from core.device.simulator import Simulator
2425
from core.osutils.file import File
2526
from core.osutils.folder import Folder
26-
from core.osutils.process import Process
2727
from core.settings.settings import IOS_RUNTIME_PATH, SIMULATOR_NAME
2828
from core.tns.replace_helper import ReplaceHelper
2929
from core.tns.tns import Tns
@@ -87,7 +87,7 @@ def test_001_tns_run_ios_js_css_xml(self):
8787
assert not Simulator.is_running()[0], 'Device is attached, but emulator is also started after `tns run ios`!'
8888

8989
# Change JS and wait until app is synced
90-
ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
90+
ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=3)
9191
strings = ['Successfully transferred', 'main-view-model.js', 'Successfully synced application', self.DEVICE_ID]
9292
Tns.wait_for_log(log_file=log, string_list=strings)
9393
assert Device.wait_for_text(device_id=self.DEVICE_ID, text="clicks"), "JS changes not synced on device!"
@@ -99,9 +99,18 @@ def test_001_tns_run_ios_js_css_xml(self):
9999
assert Device.wait_for_text(device_id=self.DEVICE_ID, text="TEST"), "XML changes not synced on device!"
100100

101101
# Change CSS and wait until app is synced
102-
ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3)
102+
css_change_1 = ['app/app.css', '42', '1']
103+
ReplaceHelper.replace(self.app_name, css_change_1, sleep=3)
103104
strings = ['Successfully transferred', 'app.css', 'Refreshing application']
104105
Tns.wait_for_log(log_file=log, string_list=strings)
106+
sleep(15)
107+
assert "TEST" not in Device.get_screen_text(device_id=self.DEVICE_ID), "Sync of CSS files failed!"
108+
109+
css_change_2 = ['app/app.css', '1', '42']
110+
ReplaceHelper.replace(self.app_name, css_change_2, sleep=3)
111+
strings = ['Successfully transferred', 'app.css', 'Refreshing application']
112+
Tns.wait_for_log(log_file=log, string_list=strings)
113+
assert Device.wait_for_text(device_id=self.DEVICE_ID, text="TEST"), "Sync of CSS files failed!"
105114

106115
# Rollback all the changes and verify files are synced
107116
ReplaceHelper.rollback(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)

tests/device/run_ios_tests_ng.py

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
"""
2+
Test for `tns run ios` command with Angular apps (on real devices).
3+
"""
4+
5+
import os
6+
from time import sleep
7+
8+
from core.base_class.BaseClass import BaseClass
9+
from core.device.device import Device
10+
from core.device.emulator import Emulator
11+
from core.device.simulator import Simulator
12+
from core.osutils.folder import Folder
13+
from core.settings.settings import IOS_RUNTIME_PATH
14+
from core.tns.replace_helper import ReplaceHelper
15+
from core.tns.tns import Tns
16+
from core.tns.tns_platform_type import Platform
17+
18+
19+
class RunIOSDeviceTestsNG(BaseClass):
20+
SIMULATOR_ID = ''
21+
DEVICES = Device.get_ids(platform=Platform.IOS)
22+
DEVICE_ID = Device.get_id(platform=Platform.IOS)
23+
24+
@classmethod
25+
def setUpClass(cls):
26+
logfile = os.path.join('out', cls.__name__ + '.txt')
27+
BaseClass.setUpClass(logfile)
28+
Emulator.stop()
29+
Simulator.stop()
30+
Device.ensure_available(platform=Platform.IOS)
31+
Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.IOS)
32+
33+
# Create default NG app (to get right dependencies from package.json)
34+
Tns.create_app_ng(cls.app_name)
35+
Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_RUNTIME_PATH})
36+
37+
# Copy the app folder (app is modified in order to get some console logs on loaded)
38+
source = os.path.join('data', 'apps', 'livesync-hello-world-ng', 'app')
39+
target = os.path.join(cls.app_name, 'app')
40+
Folder.cleanup(target)
41+
Folder.copy(src=source, dst=target)
42+
43+
def setUp(self):
44+
BaseClass.setUp(self)
45+
Tns.kill()
46+
47+
def tearDown(self):
48+
Tns.kill()
49+
BaseClass.tearDown(self)
50+
51+
@classmethod
52+
def tearDownClass(cls):
53+
BaseClass.tearDownClass()
54+
Simulator.stop()
55+
56+
def test_001_tns_run_ios_ts_css_html(self):
57+
"""Make valid changes in JS,CSS and XML"""
58+
59+
# `tns run ios` and wait until app is deployed
60+
log = Tns.run_ios(attributes={'--path': self.app_name, '--device': self.DEVICE_ID}, wait=False,
61+
assert_success=False)
62+
strings = ['Project successfully built',
63+
'Successfully installed on device with identifier', self.DEVICE_ID,
64+
'Successfully synced application',
65+
'Application loaded!',
66+
'Home page loaded!']
67+
Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)
68+
69+
# Verify initial state of the app
70+
assert Device.wait_for_text(device_id=self.DEVICE_ID, text="Ter Stegen",
71+
timeout=20), 'Hello-world NG App failed to start or it does not look correct!'
72+
73+
# Change TS and wait until app is synced
74+
ReplaceHelper.replace(self.app_name, ReplaceHelper.NG_CHANGE_TS, sleep=10)
75+
strings = ['Successfully transferred', 'item.service.js', 'Successfully synced application',
76+
'Application loaded!', # This is to verify app is restarted.
77+
'Home page loaded!']
78+
Tns.wait_for_log(log_file=log, string_list=strings)
79+
text_changed = Device.wait_for_text(device_id=self.DEVICE_ID, text="Stegen Ter", timeout=20)
80+
assert text_changed, 'Changes in TS file not applied (UI is not refreshed).'
81+
82+
# Change HTML and wait until app is synced
83+
ReplaceHelper.replace(self.app_name, ReplaceHelper.NG_CHANGE_HTML, sleep=10)
84+
strings = ['items.component.html', 'Successfully synced application', 'Home page loaded!']
85+
not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted.
86+
Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings)
87+
sleep(15)
88+
text_changed = Device.wait_for_text(device_id=self.DEVICE_ID, text="Stegen Ter", timeout=5)
89+
assert not text_changed, 'Changes in HTML file not applied (UI is not refreshed).'
90+
91+
# Change CSS and wait until app is synced
92+
ReplaceHelper.replace(self.app_name, ReplaceHelper.NG_CHANGE_CSS, sleep=10)
93+
strings = ['Successfully transferred', 'app.css', 'Successfully synced application', 'Home page loaded!']
94+
not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted.
95+
Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings)
96+
Device.screen_match(device_name="iPhone5", device_id=self.DEVICE_ID, expected_image='ng-hello-world-home-dark',
97+
tolerance=5.0)
98+
99+
# Revert HTML and wait until app is synced
100+
ReplaceHelper.rollback(self.app_name, ReplaceHelper.NG_CHANGE_HTML, sleep=10)
101+
strings = ['items.component.html', 'Successfully synced application', 'Home page loaded!']
102+
not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted.
103+
Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings)
104+
text_changed = Device.wait_for_text(device_id=self.DEVICE_ID, text="Stegen Ter", timeout=20)
105+
assert text_changed, 'Changes in HTML file not applied (UI is not refreshed).'
106+
107+
# Revert TS and wait until app is synced
108+
ReplaceHelper.rollback(self.app_name, ReplaceHelper.NG_CHANGE_TS, sleep=10)
109+
strings = ['Successfully transferred', 'item.service.js', 'Successfully synced application',
110+
'Application loaded!', # This is to verify app is restarted.
111+
'Home page loaded!']
112+
Tns.wait_for_log(log_file=log, string_list=strings)
113+
text_changed = Device.wait_for_text(device_id=self.DEVICE_ID, text="Ter Stegen", timeout=20)
114+
assert text_changed, 'Changes in TS file not applied (UI is not refreshed).'
115+
116+
# Revert CSS and wait until app is synced
117+
ReplaceHelper.rollback(self.app_name, ReplaceHelper.NG_CHANGE_CSS, sleep=10)
118+
strings = ['Successfully transferred', 'app.css', 'Successfully synced application']
119+
not_existing_strings = ['Application loaded!'] # This is to verify app is NOT restarted.
120+
Tns.wait_for_log(log_file=log, string_list=strings, not_existing_string_list=not_existing_strings)
121+
Device.screen_match(device_name="iPhone5", device_id=self.DEVICE_ID, expected_image='ng-hello-world-home-white',
122+
tolerance=5.0)

tests/emulator/run_android_ng_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from core.tns.tns import Tns
1818

1919

20-
class RunAndroidEmulatorTests(BaseClass):
20+
class RunAndroidEmulatorTestsNG(BaseClass):
2121
@classmethod
2222
def setUpClass(cls):
2323
logfile = os.path.join('out', cls.__name__ + '.txt')

0 commit comments

Comments
 (0)