-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdebug_ios_chrome_tests.py
148 lines (122 loc) · 6.19 KB
/
debug_ios_chrome_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
"""
Tests for `tns debug ios` executed on iOS Simulator.
"""
import os
import time
from core.base_class.BaseClass import BaseClass
from core.chrome.chrome import Chrome
from core.device.device import Device
from core.device.emulator import Emulator
from core.device.simulator import Simulator
from core.osutils.command import run
from core.osutils.file import File
from core.osutils.folder import Folder
from core.osutils.process import Process
from core.settings.settings import IOS_RUNTIME_PATH, SIMULATOR_NAME
from core.tns.replace_helper import ReplaceHelper
from core.tns.tns import Tns
from core.tns.tns_platform_type import Platform
from core.tns.tns_prepare_type import Prepare
from core.tns.tns_verifications import TnsAsserts
class DebugiOSChromeSimulatorTests(BaseClass):
SIMULATOR_ID = ''
@classmethod
def setUpClass(cls):
BaseClass.setUpClass(cls.__name__)
Chrome.stop()
Process.kill('Safari')
Process.kill('NativeScript Inspector')
Emulator.stop()
Simulator.stop()
cls.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME)
Tns.create_app(cls.app_name,
attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')},
update_modules=True)
Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_RUNTIME_PATH})
def setUp(self):
BaseClass.setUp(self)
Chrome.stop()
Tns.kill()
def tearDown(self):
assert not Process.is_running('NativeScript Inspector')
BaseClass.tearDown(self)
Chrome.stop()
Tns.kill()
@classmethod
def tearDownClass(cls):
BaseClass.tearDownClass()
Folder.cleanup(cls.app_name)
def __verify_debugger_start(self, log):
strings = ["Setting up debugger proxy...", "Press Ctrl + C to terminate, or disconnect.",
"Opened localhost", "To start debugging, open the following URL in Chrome"]
Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False)
time.sleep(10)
output = File.read(log)
assert "socket closed" not in output
assert "detached" not in output
assert not Process.is_running('NativeScript Inspector')
def test_001_debug_ios_simulator(self):
"""
Default `tns debug ios` starts debugger (do not stop at the first code statement)
"""
log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': ''})
self.__verify_debugger_start(log)
# Verify app starts and do not stop on first line of code
Device.screen_match(device_name=SIMULATOR_NAME,
device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home')
def test_002_debug_ios_simulator_debug_brk(self):
"""
Starts debugger and stop at the first code statement.
"""
log = Tns.debug_ios(
attributes={'--path': self.app_name, '--emulator': '', '--debug-brk': ''})
self.__verify_debugger_start(log)
# Get Chrome URL and open it
url = run(command="grep chrome-devtools " + log)
Chrome.start(url)
# Verify app starts and stops on the first line of code
Device.screen_match(device_name=SIMULATOR_NAME, tolerance=3.0, device_id=self.SIMULATOR_ID,
expected_image='livesync-hello-world_debug_brk')
def test_003_debug_ios_simulator_start(self):
"""
Attach the debug tools to a running app in the iOS Simulator
"""
# Run the app and ensure it works
log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--justlaunch': ''},
assert_success=False, timeout=30)
TnsAsserts.prepared(app_name=self.app_name, platform=Platform.IOS, output=log, prepare=Prepare.SKIP)
Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID,
expected_image='livesync-hello-world_home')
# Attach debugger
log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': '', '--start': ''})
self.__verify_debugger_start(log=log)
def test_100_debug_ios_simulator_with_livesync(self):
"""
`tns debug ios` should be able to run with livesync
"""
log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': ''})
self.__verify_debugger_start(log)
# Get Chrome URL
url_1 = run(command="grep chrome-devtools " + log)
# Verify app starts and do not stop on first line of code
Device.screen_match(device_name=SIMULATOR_NAME,
device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home')
# Change JS and wait until app is synced
ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10)
strings = ['Successfully transferred', 'main-view-model.js', 'open the following URL in Chrome', 'CONSOLE LOG']
Tns.wait_for_log(log_file=log, string_list=strings)
# Change XML and wait until app is synced
ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3)
strings = ['Successfully transferred', 'main-page.xml', 'open the following URL in Chrome', 'CONSOLE LOG']
Tns.wait_for_log(log_file=log, string_list=strings)
# Change CSS and wait until app is synced
ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3)
strings = ['Successfully transferred', 'app.css', 'open the following URL in Chrome', 'CONSOLE LOG']
Tns.wait_for_log(log_file=log, string_list=strings, clean_log=False)
# Verify application looks correct
Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID,
expected_image='livesync-hello-world_js_css_xml')
# Get Chrome URL and check it is not changed - https://github.com/NativeScript/nativescript-cli/issues/3183
url_2 = run(command="grep -a chrome-devtools " + log)
assert url_1 == url_2, "Chrome DevTools URLs are different! \n First URL: {0}, \n Second URL: {1}"\
.format(url_1, url_2)