def _moveToElement(self, action): ''' :param action: :return: ''' element = self._getElement(action) DriverBaseWeb.move_to_element(element)
def _addCookie(self, action): ''' :param action: :return: ''' key = self._getParms(action, 0) DriverBaseWeb.add_cookie(key)
def _clear(self, action): ''' :param action: :return: ''' element = self._getElement(action) DriverBaseWeb.clear(element)
def _contextClick(self, action): ''' :param action: :return: ''' element = self._getElement(action) DriverBaseWeb.context_click(element)
def _switchToFrame(self, action): ''' :param action: :return: ''' frame_reference = self._getParms(action) DriverBaseWeb.switch_to_frame(frame_reference)
def _openUrl(self, action): ''' :param action: :return: ''' url = self._getParms(action, 0) DriverBaseWeb.open_url(url)
def _submit(self, action): ''' :param action: :return: ''' element = self._getElement(action) DriverBaseWeb.submit(element)
def _switchToWindow(self, action): ''' :param action: :return: ''' handle = self._getParms(action) DriverBaseWeb.switch_to_window(handle)
def _holdClick(self, action): ''' :param action: :return: ''' element = self._getElement(action) DriverBaseWeb.click_and_hold(element)
def _doubleClick(self, action): ''' :param action: :return: ''' element = self._getElement(action) DriverBaseWeb.double_click(element)
def _deleteCookie(self, action): ''' :param action: :return: ''' key = self._getParms(action, 0) DriverBaseWeb.delete_cookie(key)
def _moveByOffset(self, action): ''' :param action: :return: ''' xoffset = self._getParms(action, 0) yoffset = self._getParms(action, 1) DriverBaseWeb.move_by_offset(float(xoffset), float(yoffset))
def _dragDrop(self, action): ''' :param action: :return: ''' element = self._getElement(action, 0) target = self._getElement(action, 1) DriverBaseWeb.drag_and_drop(element, target)
def _setWindowPosition(self, action): ''' :param action: :return: ''' x = self._getParms(action, 0) y = self._getParms(action, 1) DriverBaseWeb.set_window_position(float(x), float(y))
def setUp(self): if self.skip: self.skipTest('skip') if Var.re_start: if Var.driver != 'selenium': DriverBaseApp.launch_app(None) else: DriverBaseWeb.createSession()
def _setWindowSize(self, action): ''' :param action: :return: ''' width = self._getParms(action, 0) height = self._getParms(action, 0) DriverBaseWeb.set_window_size(float(width), float(height))
def tearDown(self): if Var.re_start: try: if Var.driver != 'selenium': DriverBaseApp.close_app(None) else: DriverBaseWeb.quit() except: pass
def _moveToElementWithOffset(self, action): ''' :param action: :return: ''' element = self._getElement(action) xoffset = self._getParms(action, 1) yoffset = self._getParms(action, 2) DriverBaseWeb.move_to_element_with_offset(element, float(xoffset), float(yoffset))
def _dragDropByOffset(self, action): ''' :param action: :return: ''' element = self._getElement(action) xoffset = self._getParms(action, 1) yoffset = self._getParms(action, 2) DriverBaseWeb.drag_and_drop_by_offse(element, float(xoffset), float(yoffset))
def _sendKeys(self, action): ''' :param action: :return: ''' element = self._getElement(action) text_list = [] if len(action.parms) == 2: text_list.append(self._getParms(action, 1)) elif len(action.parms) == 3: text_list.append(self._getParms(action, 1)) text_list.append(self._getParms(action, 2)) else: raise TypeError('missing 1 required positional argument') DriverBaseWeb.send_keys(element, text_list)
def start(self): if not self._suite: return None # 组装启动参数 log_info( '******************* analytical desired capabilities *******************' ) Var.desired_capabilities = Dict({ 'driver': Var.driver.lower(), 'timeOut': Var.time_out, 'desired': Var.desired_caps, 'index': self._index, 'root': self._root }) # 启动服务 if Var.driver != 'selenium': server = ServerUtilsApp(Var.desired_capabilities) Var.instance = server.start_server() elif not Var.re_start: server = ServerUtilsWeb(Var.desired_capabilities) Var.instance = server.start_server() DriverBaseWeb.init() else: server = None # 用例运行 suite = unittest.TestSuite(tuple(self._suite)) runner = TestRunner() runner.run(suite) # 结束服务 if Var.driver != 'selenium': server.stop_server() elif not Var.re_start: server.stop_server(Var.instance) # 打印失败结果 if Var.all_result: if Var.all_result.errorsList: log_info(' Error case:') for error in Var.all_result.errorsList: log_error(error, False) if Var.all_result.failuresList: log_info(' Failed case:') for failure in Var.all_result.failuresList: log_error(failure, False) return Var.all_result
def _getText(self, action): ''' :param action: :return: ''' element = self._getElement(action) return DriverBaseWeb.get_text(element)
def _getElement(self, action, index=0): ''' :param action: :return: ''' parms = action.parms if len(parms) <= index or not len(parms): raise TypeError( 'missing {} required positional argument'.format(index + 1)) if isinstance(parms[index], WebElement): element = parms[index] elif isinstance(parms[index], str): if not re.match( r'^(id|name|class|tag_name|link_text|partial_link_text|xpath|css_selector)\s*=.+', parms[index].strip(), re.I): raise TypeError('input parameter format error:{}'.format( parms[index])) key = parms[index].split('=', 1)[0].strip() value = parms[index].split('=', 1)[-1].strip() element = DriverBaseWeb.get_element(key, value, Var.time_out) else: raise TypeError('the parms type must be: WebElement or str') if not element: raise Exception("Can't find element: {}".format(parms[index])) return element
def _getTagName(self, action): ''' :param action: :return: ''' element = self._getElement(action) return DriverBaseWeb.get_tag_name(element)
def _getCookie(self, action): ''' :param action: :return: ''' key = self._getParms(action) return DriverBaseWeb.get_cookie(key)
def _getLocation(self, action): ''' :param action: :return: ''' element = self._getElement(action) return DriverBaseWeb.get_location(element)
def _getSize(self, action): ''' :param action: :return: ''' element = self._getElement(action) return DriverBaseWeb.get_size(element)
def _isEnabled(self, action): ''' :param action: :return: ''' element = self._getElement(action) return DriverBaseWeb.is_enabled(element)
def _isDisplayed(self, action): ''' :param action: :return: ''' element = self._getElement(action) return DriverBaseWeb.is_displayed(element)
def _getCssProperty(self, action): ''' :param action: :return: ''' element = self._getElement(action) css_value = self._getParms(action, 1) return DriverBaseWeb.get_css_property(element, css_value)