8
8
from core .tns .tns import Tns
9
9
from core .tns .tns_platform_type import Platform
10
10
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
11
18
12
19
class DebugBothPlatformsTests (BaseClass ):
13
20
ANDROID_DEVICES = Device .get_ids (platform = Platform .ANDROID , include_emulators = True )
@@ -40,6 +47,47 @@ def tearDown(self):
40
47
def tearDownClass (cls ):
41
48
BaseClass .tearDownClass ()
42
49
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
+
43
91
def __verify_debugger_start (self , log ):
44
92
strings = ['NativeScript Debugger started' , 'To start debugging, open the following URL in Chrome' ,
45
93
'chrome-devtools' , 'localhost:4000' ]
@@ -64,12 +112,6 @@ def test_001_tns_run_android(self):
64
112
for android_device_id in self .ANDROID_DEVICES :
65
113
strings .append (android_device_id )
66
114
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 })
73
115
self .__verify_debugger_start (log )
74
116
75
117
# Get Chrome URL and open it
@@ -78,14 +120,7 @@ def test_001_tns_run_android(self):
78
120
79
121
def test_002_tns_run_ios (self ):
80
122
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