def test_port_manager(self): port_type = "agent" udid1 = "aaaaaaaaaaaa" udid2 = "bbbbbbbbbbbb" PortManager.set_port(port_type, udid1) port1 = PortManager.get_port(port_type, udid1) port2 = PortManager.get_port(port_type, udid2) self.assertEqual(port1, 8100, 'PortManager分配端口错误') self.assertNotEqual(port1, port2, 'PortManager分配端口重复') PortManager.del_port(port_type, udid1) self.assertTrue(udid1 not in PortManager.ports(port_type), 'PortManager清理端口失败')
def _modify_wi_port(self, udid): port = PortManager.get_port('web', udid) if self.xcode_version.startswith('9'): wi_plist_path = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/LaunchDaemons/com.apple.webinspectord.plist' else: wi_plist_path = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/LaunchDaemons/com.apple.webinspectord.plist' cmd = ['/usr/libexec/PlistBuddy', '-c', 'Set :Sockets:com.apple.webinspectord.socket:SockServiceName %s' % port, wi_plist_path] subprocess.call(cmd)
def _get_webinspector_socket_below_xcode93(self, udid): sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) wi_port = PortManager.get_port('web', udid) if wi_port is None: wi_port = 27753 self.logger.info('webport: %s' % wi_port) sock.connect(('::1', wi_port)) return sock
def start_agent(self, device_id, server_ip=DEFAULT_IP, server_port=DEFAULT_PORT, keep_alive=False, retry=3, timeout=60): '''启动Agent并返回 :param device_id: 设备ID :type device_id: str :param server_ip: 设备IP地址 :type server_ip: str :param server_port: 设备端口号 :type server_port: int :param keep_alive: HTTP远程连接是否使用keep-alive,默认为False :type keep_alive: boolean :param retry: 启动尝试次数,默认3次 :type retry: int :param timeout: 单次启动超时 (秒) :type timeout: int :returns: XCUITestAgent ''' self.log = logger.get_logger("xctest_%s" % device_id) if device_id not in self._agents: try: PortManager.set_port('agent', device_id, server_port) server_port = PortManager.get_port('agent', device_id) self.log.info('start_agent, port: %d' % server_port) with self._lock: self._agents[device_id] = XCUITestAgent( device_id, server_ip, server_port, keep_alive, retry, timeout) except: self.log.exception('start_agent') PortManager.del_port('agent', device_id) raise return self._agents[device_id]