예제 #1
0
 def wait_for_disappearance(timeout):
     start = time.time()
     while self.exists():
         self.poco.sleep_for_polling_interval()
         self.get_ui()
         if time.time() - start > timeout:
             raise PocoTargetTimeout('disappearance', self)
예제 #2
0
    def dismiss(self,
                targets,
                exit_when=None,
                sleep_interval=0.5,
                appearance_timeout=20,
                timeout=120):
        """
        Automatically dismiss the target objects

        Args:
            targets (:obj:`list`): list of poco objects to be dropped
            exit_when: termination condition, default is None which means to automatically exit when list of
             ``targets`` is empty
            sleep_interval: time interval between each actions for the given targets, default is 0.5s
            appearance_timeout: time interval to wait for given target to appear on the screen, automatically exit when
             timeout, default is 20s
            timeout: dismiss function timeout, default is 120s

        Raises:
            PocoTargetTimeout: when dismiss time interval timeout, under normal circumstances, this should not happen
             and if happens, it will be reported
        """

        try:
            self.wait_for_any(targets, timeout=appearance_timeout)
        except PocoTargetTimeout:
            # here returns only when timeout
            # 仅当超时时自动退出
            warnings.warn(
                'Waiting timeout when trying to dismiss something before them appear. Targets are {}'
                .encode('utf-8').format(targets))
            return

        start_time = time.time()
        while True:
            no_target = True
            for t in targets:
                if t.exists():
                    try:
                        for n in t:
                            try:
                                n.click(sleep_interval=sleep_interval)
                                no_target = False
                            except:
                                pass
                    except:
                        # Catch the NodeHasBeenRemoved exception if some node was removed over the above iteration
                        # and just ignore as this will not affect the result.
                        # 遍历(__iter__: for n in t)过程中如果节点正好被移除了,可能会报远程节点被移除的异常
                        # 这个报错忽略就行
                        pass
            time.sleep(sleep_interval)
            should_exit = exit_when() if exit_when else False
            if no_target or should_exit:
                return

            if time.time() - start_time > timeout:
                raise PocoTargetTimeout('dismiss', targets)
예제 #3
0
    def wait_for_disappearance(self, timeout=120):
        """
        Block and wait until the UI element **disappears** within the given timeout.

        Args:
            timeout: maximum waiting time in seconds

        Raises:
            PocoTargetTimeout: when timeout
        """

        start = time.time()
        while self.exists():
            self.poco.sleep_for_polling_interval()
            if time.time() - start > timeout:
                raise PocoTargetTimeout('disappearance', self)
예제 #4
0
    def wait_for_appearance(self, timeout=120):
        """
        Block and wait until the UI element **appears** within the given timeout. When timeout, the
        :py:class:`PocoTargetTimeout <poco.exceptions.PocoTargetTimeout>` is raised.

        Args:
            timeout: maximum waiting time in seconds

        Raises:
            PocoTargetTimeout: when timeout
        """

        start = time.time()
        while not self.exists():
            self.poco.sleep_for_polling_interval()
            if time.time() - start > timeout:
                raise PocoTargetTimeout('appearance', self)
예제 #5
0
파일: proxy.py 프로젝트: fakegit/Poco
    def wait_for_disappearance(self, timeout=120):
        """
        Block and wait until the UI element **disappears** within the given timeout.

        Args:
            timeout: maximum waiting time in seconds

        Raises:
            PocoTargetTimeout: when timeout
        """

        start = time.time()
        while self.exists():
            self.poco.sleep_for_polling_interval()
            if time.time() - start > timeout:
                raise PocoTargetTimeout('disappearance', self)
            # 强制重新获取节点状态,避免节点已经存在、又消失后,这里不会刷新节点信息导致exists()永远为True的bug
            self.invalidate()