Exemplo n.º 1
0
 def _moveToElement(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     DriverBaseWeb.move_to_element(element)
Exemplo n.º 2
0
 def _addCookie(self, action):
     '''
     :param action:
     :return:
     '''
     key = self._getParms(action, 0)
     DriverBaseWeb.add_cookie(key)
Exemplo n.º 3
0
 def _clear(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     DriverBaseWeb.clear(element)
Exemplo n.º 4
0
 def _contextClick(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     DriverBaseWeb.context_click(element)
Exemplo n.º 5
0
 def _switchToFrame(self, action):
     '''
     :param action:
     :return:
     '''
     frame_reference = self._getParms(action)
     DriverBaseWeb.switch_to_frame(frame_reference)
Exemplo n.º 6
0
 def _openUrl(self, action):
     '''
     :param action:
     :return:
     '''
     url = self._getParms(action, 0)
     DriverBaseWeb.open_url(url)
Exemplo n.º 7
0
 def _submit(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     DriverBaseWeb.submit(element)
Exemplo n.º 8
0
 def _switchToWindow(self, action):
     '''
     :param action:
     :return:
     '''
     handle = self._getParms(action)
     DriverBaseWeb.switch_to_window(handle)
Exemplo n.º 9
0
 def _holdClick(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     DriverBaseWeb.click_and_hold(element)
Exemplo n.º 10
0
 def _doubleClick(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     DriverBaseWeb.double_click(element)
Exemplo n.º 11
0
 def _deleteCookie(self, action):
     '''
     :param action:
     :return:
     '''
     key = self._getParms(action, 0)
     DriverBaseWeb.delete_cookie(key)
Exemplo n.º 12
0
 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))
Exemplo n.º 13
0
 def _dragDrop(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action, 0)
     target = self._getElement(action, 1)
     DriverBaseWeb.drag_and_drop(element, target)
Exemplo n.º 14
0
 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))
Exemplo n.º 15
0
 def setUp(self):
     if self.skip:
         self.skipTest('skip')
     if Var.re_start:
         if Var.driver != 'selenium':
             DriverBaseApp.launch_app(None)
         else:
             DriverBaseWeb.createSession()
Exemplo n.º 16
0
 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))
Exemplo n.º 17
0
 def tearDown(self):
     if Var.re_start:
         try:
             if Var.driver != 'selenium':
                 DriverBaseApp.close_app(None)
             else:
                 DriverBaseWeb.quit()
         except:
             pass
Exemplo n.º 18
0
 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))
Exemplo n.º 19
0
 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))
Exemplo n.º 20
0
 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)
Exemplo n.º 21
0
    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
Exemplo n.º 22
0
 def _getText(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     return DriverBaseWeb.get_text(element)
Exemplo n.º 23
0
    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
Exemplo n.º 24
0
 def _getTagName(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     return DriverBaseWeb.get_tag_name(element)
Exemplo n.º 25
0
 def _getCookie(self, action):
     '''
     :param action:
     :return:
     '''
     key = self._getParms(action)
     return DriverBaseWeb.get_cookie(key)
Exemplo n.º 26
0
 def _getLocation(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     return DriverBaseWeb.get_location(element)
Exemplo n.º 27
0
 def _getSize(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     return DriverBaseWeb.get_size(element)
Exemplo n.º 28
0
 def _isEnabled(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     return DriverBaseWeb.is_enabled(element)
Exemplo n.º 29
0
 def _isDisplayed(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     return DriverBaseWeb.is_displayed(element)
Exemplo n.º 30
0
 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)