Skip to content

Commit f2ff107

Browse files
Mivanova/debug modified (#146)
* modified test for debug ios device * ios test debug * debug android
1 parent 5c53ebf commit f2ff107

File tree

1 file changed

+52
-17
lines changed

1 file changed

+52
-17
lines changed

tests/device/debug_device_tests.py

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
from core.tns.tns import Tns
99
from core.tns.tns_platform_type import Platform
1010
from core.osutils.command import run
11+
from time import sleep
12+
from enum import Enum
13+
from core.osutils.process import Process
14+
15+
class DebugMode(Enum):
16+
DEFAULT = 0
17+
START = 1
1118

1219
class DebugBothPlatformsTests(BaseClass):
1320
ANDROID_DEVICES = Device.get_ids(platform=Platform.ANDROID, include_emulators=True)
@@ -40,6 +47,47 @@ def tearDown(self):
4047
def tearDownClass(cls):
4148
BaseClass.tearDownClass()
4249

50+
@staticmethod
51+
def attach_chrome(log, mode=DebugMode.DEFAULT, port="41000"):
52+
"""
53+
Attach chrome dev tools and verify logs
54+
:type log: Log file of `tns debug ios` command.
55+
"""
56+
57+
# Check initial logs
58+
strings = ["Setting up debugger proxy...", "Press Ctrl + C to terminate, or disconnect.",
59+
"Opened localhost", "To start debugging, open the following URL in Chrome"]
60+
Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False)
61+
62+
# Attach Chrome DevTools
63+
url = run(command="grep chrome-devtools " + log)
64+
text_log = File.read(log)
65+
assert "chrome-devtools://devtools/remote" in text_log, "Debug url not printed in output of 'tns debug ios'."
66+
assert "localhost:" + port in text_log, "Wrong port of debug url:" + url
67+
Chrome.start(url)
68+
69+
# Verify debugger attached
70+
strings = ["Frontend client connected", "Backend socket created"]
71+
if mode != DebugMode.START:
72+
strings.extend(["Loading inspector modules",
73+
"Finished loading inspector modules",
74+
"NativeScript debugger attached"])
75+
Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False)
76+
77+
# Verify debugger not disconnected
78+
sleep(10)
79+
output = File.read(log)
80+
assert "socket closed" not in output, "Debugger disconnected."
81+
assert "detached" not in output, "Debugger disconnected."
82+
assert not Process.is_running('NativeScript Inspector'), "iOS Inspector running instead of ChromeDev Tools."
83+
84+
@staticmethod
85+
def assert_not_detached(log):
86+
output = File.read(log)
87+
assert "socket created" in output, "Debugger not attached at all.\n Log:\n" + output
88+
assert "socket closed" not in output, "Debugger disconnected.\n Log:\n" + output
89+
assert "detached" not in output, "Debugger disconnected.\n Log:\n" + output
90+
4391
def __verify_debugger_start(self, log):
4492
strings = ['NativeScript Debugger started', 'To start debugging, open the following URL in Chrome',
4593
'chrome-devtools', 'localhost:4000']
@@ -64,12 +112,6 @@ def test_001_tns_run_android(self):
64112
for android_device_id in self.ANDROID_DEVICES:
65113
strings.append(android_device_id)
66114
Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False)
67-
68-
# Verify app is deployed and running on all available android devices
69-
for device_id in self.ANDROID_DEVICES:
70-
Device.wait_until_app_is_running(app_id=Tns.get_app_id(self.app_name), device_id=device_id, timeout=30)
71-
72-
log = Tns.debug_android(attributes={'--path': self.app_name})
73115
self.__verify_debugger_start(log)
74116

75117
# Get Chrome URL and open it
@@ -78,14 +120,7 @@ def test_001_tns_run_android(self):
78120

79121
def test_002_tns_run_ios(self):
80122
log = Tns.debug_ios(attributes={'--path': self.app_name})
81-
strings = ['Successfully installed on device with identifier']
82-
for ios_device_id in self.IOS_DEVICES:
83-
strings.append(ios_device_id)
84-
Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False)
85-
86-
log = Tns.debug_ios(attributes={'--path': self.app_name})
87-
self.__verify_debugger_start(log)
88-
89-
# Get Chrome URL and open it
90-
url = run(command="grep chrome-devtools " + log)
91-
Chrome.start(url)
123+
self.attach_chrome(log)
124+
strings = ['Successfully started on device with identifier']
125+
Tns.wait_for_log(log_file=log, string_list= strings, clean_log=False)
126+
self.assert_not_detached(log)

0 commit comments

Comments
 (0)