def getIFrameElementCoordinateByXpath(self, elementXpath, iFrameXpath, contextId): ''' 获得IFrame中元素的坐标 :param elementXpath:待获取坐标的元素的xpath :param iFrameXpath: 外层iFrame的xpath :param contextId: iFrame的ContextId :return:element相对于整个屏幕的x、y坐标,单位为px ''' self.logger.info('elementXpathXpath ---> ' + elementXpath + ' iFrameXpath ---> ' + iFrameXpath + ' contextId ---> ' + str(contextId)) # 防止websocket未失效但页面已经开始跳转 self.wait(WAIT_REFLESH_05_SECOND) if self.isElementExist(iFrameXpath): sendStr = self._pageOperator.getElementRect(iFrameXpath) self._networkHandler.send(sendStr) iframeLeft = self._getRelativeDirectionValue("left") iframeTop = self._getRelativeDirectionValue("topp") if self.isElementExist(elementXpath, contextId): sendStr = self._pageOperator.getElementRect( elementXpath, contextId) self._networkHandler.send(sendStr) x = self._getRelativeDirectionValue("x", contextId) y = self._getRelativeDirectionValue("y", contextId) x = iframeLeft + x y = iframeTop + y x, y = self.changeDp2Px(x, y) return x, y errorMessage = ErrorMsgManager().errorCodeToString( ERROR_CODE_GETCOORDINATE) raise RuntimeError(errorMessage)
def _checkReturnOrThrow(self, netWorkRequest): needThrown = (netWorkRequest.getResponse() is None and netWorkRequest.getException() is None) if needThrown: errorMsg = ErrorMsgManager().errorCodeToString( ERROR_CODE_BAD_REQUEST) raise RuntimeError("%s, request data {%s}" % (errorMsg, netWorkRequest.getRequestData()))
def _selectDevice(self): devicesList = AdbHelper.listDevices(ignoreUnconnectedDevices=True) # 假如没有指定设备,那么判断当前机器是否连接1个设备 if self._device is None: devicesCount = len(devicesList) errorMsg = None if devicesCount <= 0: errorMsg = ErrorMsgManager().errorCodeToString(ERROR_CODE_DEVICE_NOT_CONNECT) elif devicesCount == 1: self._device = devicesList[0] else: errorMsg = ErrorMsgManager().errorCodeToString(ERROR_CODE_MULTIPLE_DEVICE) if errorMsg is not None: raise RuntimeError(errorMsg)
def _waitForConnectOrThrow(self): if self._webSocketDataTransfer.isConnected(): return self._connectSyncEvent.wait(WAIT_REFLESH_60_SECOND) if not self._webSocketDataTransfer.isConnected(): errorMsg = ErrorMsgManager().errorCodeToString( ERROR_CODE_CONNECT_CLOSED) raise RuntimeError( "connect %s timeout, %s" % (self._webSocketDataTransfer.getUrl(), errorMsg))
def getAllIFrameNode(self): ''' 获得body标签中所有的IFrameNode :return: ''' try: iFrameNodeList = [] nodesList = self.getBodyNode()['params']['nodes'] for node in nodesList: if node['nodeName'] == 'IFRAME': iFrameNodeList.append(node) frameIdList = [] for iFrameNode in iFrameNodeList: frameIdList.append(iFrameNode['frameId']) return frameIdList except: errorMessage = ErrorMsgManager().errorCodeToString(ERROR_CODE_SETUP_FRAME_PAGE) raise RuntimeError(errorMessage)
def getElementCoordinateByXpath(self, elementXpath): ''' 获得Element的坐标 :param elementXpath:待获取坐标的元素的xpath :return:element相对于整个屏幕的x、y坐标,单位为px ''' self.logger.info('elementXpathXpath ---> ' + elementXpath) # 防止websocket未失效但页面已经开始跳转 self.wait(WAIT_REFLESH_05_SECOND) if self.isElementExist(elementXpath): sendStr = self._pageOperator.getElementRect(elementXpath) self._networkHandler.send(sendStr) x = self._getRelativeDirectionValue("x") y = self._getRelativeDirectionValue("y") x, y = self.changeDp2Px(x, y) return x, y errorMessage = ErrorMsgManager().errorCodeToString( ERROR_CODE_GETCOORDINATE) raise RuntimeError(errorMessage)