Example #1
0
 def inner(self, *args, **kwargs):
     timeout = kwargs.pop('timeout', self.wait_timeout)
     if not self.wait(timeout=timeout):
         raise UiObjectNotFoundError({
             'code': -32002,
             'message': E(self.selector.__str__())
         })
     return fn(self, *args, **kwargs)
Example #2
0
    def _retry_find_element(self, **kwargs):
        from clickx3.u2.element import Element

        delay = kwargs.pop('delay', 0.5)
        timeout = kwargs.pop('timeout', 10)
        interval = kwargs.pop('interval', 0.5)

        # 计算重试次数
        retry_count = int(float(timeout) / float(interval))
        # 延迟查找元素
        if delay:
            time.sleep(delay)
        # 重试次数小于1时,不重试,找不到直接抛异常
        if retry_count < 1:
            element = self(**kwargs)
            if element.exists:
                return Element(ui_object=element)
            else:
                raise UiObjectNotFoundError(
                    {
                        'code': -32002,
                        'message': 'retry find element timeout',
                        'data': str(element.selector)
                    },
                    method='Device._retry_find_element')  # yapf: disable

        # 重试查找元素,元素存在时返回,找不到时重试直到timeout后抛出异常
        for i in range(retry_count):
            if i > 0:
                time.sleep(interval)
            element = self(**kwargs)
            if element.exists:
                return Element(ui_object=element)
        raise UiObjectNotFoundError(
            {
                'code': -32002,
                'message': 'retry find element timeout',
                'data': str(element.selector)
            },
            method='Device._retry_find_element')  # yapf: disable
Example #3
0
    def wrapper(*args, **kwargs):
        delay = kwargs.pop('delay', 0.5)
        timeout = kwargs.pop('timeout', 10)
        interval = kwargs.pop('interval', 0.5)

        # 计算重试次数
        retry_count = int(float(timeout) / float(interval))
        # 延迟查找元素
        if delay:
            sleep(delay)
        # 重试次数小于1时,不重试,找不到直接抛异常
        if retry_count < 1:
            element = func(*args, **kwargs)
            if element.exists:
                return Element(ui_object=element)
            else:
                raise UiObjectNotFoundError(
                    {
                        'code': -32002,
                        'message': 'retry find element timeout',
                        'data': str(element.selector)
                    },
                    method='@retry_find_u2element')

        # 重试查找元素,元素存在时返回,找不到时重试直到timeout后抛出异常
        for i in range(retry_count):
            if i > 0:
                sleep(interval)
            element = func(*args, **kwargs)
            if element.exists:
                return Element(ui_object=element)
        raise UiObjectNotFoundError(
            {
                'code': -32002,
                'message': 'retry find element timeout',
                'data': str(element.selector)
            },
            method='@retry_find_u2element')
Example #4
0
    def __retry_find(self, device: Device):
        # 计算重试次数
        retry_count = int(float(self._timeout) / float(self._interval))
        # 延迟查找元素
        if self._delay:
            sleep(self._delay)

        # 重试次数小于1时,不重试,找不到直接抛异常
        if retry_count < 1:
            element = device(**self._kwargs)
            if element.exists:
                self.__dict__.update(element.__dict__)
                return self
            else:
                raise UiObjectNotFoundError(
                    {
                        'code': -32002,
                        'message': 'retry find element timeout',
                        'data': str(element.selector)
                    },
                    method='Element.__retry_find')  # yapf: disable

        # 重试查找元素,元素存在时返回,找不到时重试直到timeout后抛出异常
        for i in range(retry_count):
            if i > 0:
                sleep(self._interval)
            element = device(**self._kwargs)
            if element.exists:
                self.__dict__.update(element.__dict__)
                return self
        raise UiObjectNotFoundError(
            {
                'code': -32002,
                'message': 'retry find element timeout',
                'data': str(element.selector)
            },
            method='Element.__retry_find')  # yapf: disable
Example #5
0
    def __scroll_find(self, method, **kwargs):
        scroll_find = kwargs.pop('scroll_find', True)

        if scroll_find and self.info['scrollable']:
            log.info(f'滚动至目标元素,locator:[ {kwargs} ]')
            if self.scroll.to(**kwargs):
                return method(**kwargs)
            else:
                raise UiObjectNotFoundError(
                    {
                        'code': -32002,
                        'message': 'scrool to target element failed',
                        'data': str(kwargs)
                    },
                    method='Element.__scroll_find')
        else:
            return method(**kwargs)
Example #6
0
 def must_wait(self, exists=True, timeout=None):
     """ wait and if not found raise UiObjectNotFoundError """
     if not self.wait(exists, timeout):
         raise UiObjectNotFoundError({'code': -32002, 'method': 'wait'})