|
1 | 1 | import os
|
2 | 2 |
|
3 | 3 | from core.base_class.BaseClass import BaseClass
|
4 |
| -from core.device.device import Device |
5 | 4 | from core.chrome.chrome import Chrome
|
6 |
| -from core.osutils.file import File |
| 5 | +from core.device.device import Device |
| 6 | +from core.osutils.command import run |
7 | 7 | from core.settings.settings import ANDROID_PACKAGE, IOS_PACKAGE
|
8 | 8 | from core.tns.tns import Tns
|
9 | 9 | from core.tns.tns_platform_type import Platform
|
10 |
| -from core.osutils.command import run |
11 |
| -from time import sleep |
12 |
| -from enum import Enum |
13 |
| -from core.osutils.process import Process |
| 10 | +from tests.helpers.debug_chrome import DebugChromeHelpers |
14 | 11 |
|
15 |
| -class DebugMode(Enum): |
16 |
| - DEFAULT = 0 |
17 |
| - START = 1 |
18 | 12 |
|
19 |
| -class DebugBothPlatformsTests(BaseClass): |
20 |
| - ANDROID_DEVICES = Device.get_ids(platform=Platform.ANDROID, include_emulators=True) |
21 |
| - IOS_DEVICES = Device.get_ids(platform=Platform.IOS) |
22 |
| - DEVICE_ID = Device.get_id(platform=Platform.ANDROID) |
| 13 | +class DebugOnDevice(BaseClass): |
| 14 | + ANDROID_DEVICE_ID = Device.get_id(platform=Platform.ANDROID) |
| 15 | + IOS_DEVICE_ID = Device.get_id(platform=Platform.IOS) |
23 | 16 |
|
24 | 17 | @classmethod
|
25 | 18 | def setUpClass(cls):
|
@@ -47,80 +40,19 @@ def tearDown(self):
|
47 | 40 | def tearDownClass(cls):
|
48 | 41 | BaseClass.tearDownClass()
|
49 | 42 |
|
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 |
| - |
91 |
| - def __verify_debugger_start(self, log): |
92 |
| - strings = ['NativeScript Debugger started', 'To start debugging, open the following URL in Chrome', |
93 |
| - 'chrome-devtools', 'localhost:4000'] |
94 |
| - Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10, clean_log=False) |
95 |
| - output = File.read(file_path=log, print_content=True) |
96 |
| - assert "closed" not in output |
97 |
| - assert "detached" not in output |
98 |
| - assert "did not start in time" not in output |
99 |
| - |
100 |
| - def __verify_debugger_attach(self, log): |
101 |
| - strings = ['To start debugging', 'Chrome', 'chrome-devtools', 'localhost:4000'] |
102 |
| - Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10, clean_log=False) |
103 |
| - output = File.read(file_path=log, print_content=True) |
104 |
| - assert "closed" not in output |
105 |
| - assert "detached" not in output |
106 |
| - assert "did not start in time" not in output |
107 |
| - assert "NativeScript Debugger started" not in output |
108 |
| - |
109 |
| - def test_001_tns_run_android(self): |
110 |
| - log = Tns.debug_android(attributes={'--path': self.app_name}) |
111 |
| - strings = ['Successfully installed on device with identifier'] |
112 |
| - for android_device_id in self.ANDROID_DEVICES: |
113 |
| - strings.append(android_device_id) |
114 |
| - Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10, clean_log=False) |
115 |
| - self.__verify_debugger_start(log) |
| 43 | + def test_001_debug_android(self): |
| 44 | + log = Tns.debug_android(attributes={'--path': self.app_name, '--device': self.ANDROID_DEVICE_ID}) |
| 45 | + strings = [self.ANDROID_DEVICE_ID, 'Successfully installed on device with identifier'] |
| 46 | + Tns.wait_for_log(log_file=log, string_list=strings, timeout=240, check_interval=10, clean_log=False) |
| 47 | + DebugChromeHelpers.verify_debugger_started(log) |
116 | 48 |
|
117 | 49 | # Get Chrome URL and open it
|
118 | 50 | url = run(command="grep chrome-devtools " + log)
|
119 | 51 | Chrome.start(url)
|
120 | 52 |
|
121 |
| - def test_002_tns_run_ios(self): |
122 |
| - log = Tns.debug_ios(attributes={'--path': self.app_name}) |
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) |
| 53 | + def test_002_debug_ios(self): |
| 54 | + log = Tns.debug_ios(attributes={'--path': self.app_name, '--device': self.IOS_DEVICE_ID}) |
| 55 | + DebugChromeHelpers.attach_chrome(log) |
| 56 | + strings = [self.IOS_DEVICE_ID, 'Successfully started on device with identifier'] |
| 57 | + Tns.wait_for_log(log_file=log, string_list=strings, clean_log=False) |
| 58 | + DebugChromeHelpers.assert_not_detached(log) |
0 commit comments