From 272315ec4c593d6528caa423ffbea2a530caebe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=90=A6?= Date: Thu, 7 Apr 2022 15:58:41 +0800 Subject: [PATCH] =?UTF-8?q?Added=20refresh()=20interface=20to=20force=20no?= =?UTF-8?q?des=20to=20re-query,=20equivalent=20to=20invalidate()=20Fixed?= =?UTF-8?q?=20the=20issue=20that=20the=20wait=5Ffor=5Fdisappearance=20node?= =?UTF-8?q?=20was=20not=20re-queried=20=E6=96=B0=E5=A2=9Erefresh()?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=AE=A9=E8=8A=82=E7=82=B9=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E9=87=8D=E6=96=B0=E6=9F=A5=E8=AF=A2=EF=BC=8C=E7=AD=89?= =?UTF-8?q?=E5=90=8C=E4=BA=8Einvalidate()=20=E4=BF=AE=E5=A4=8D=E4=BA=86wai?= =?UTF-8?q?t=5Ffor=5Fdisappearance=E8=8A=82=E7=82=B9=E6=9C=AA=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E6=9F=A5=E8=AF=A2=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 631efd1e91226b4b4fc6bb2010372a90b1186b44) --- poco/proxy.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/poco/proxy.py b/poco/proxy.py index de8c0f1..b915ce5 100644 --- a/poco/proxy.py +++ b/poco/proxy.py @@ -696,6 +696,8 @@ def wait_for_disappearance(self, timeout=120): self.poco.sleep_for_polling_interval() if time.time() - start > timeout: raise PocoTargetTimeout('disappearance', self) + # 强制重新获取节点状态,避免节点已经存在、又消失后,这里不会刷新节点信息导致exists()永远为True的bug + self.invalidate() @refresh_when(PocoTargetRemovedException) def attr(self, name): @@ -862,11 +864,23 @@ def nodes(self): def invalidate(self): """ Clear the flag to indicate to re-query or re-select the UI element(s) from hierarchy. + + alias is refresh() + + Example: + >>> a = poco(text="settings") + >>> print(a.exists()) + >>> a.refresh() + >>> print(a.exists()) """ self._evaluated = False self._nodes = None + # refresh is alias of invalidate + # use poco(xxx).refresh() to force the UI element(s) to re-query + refresh = invalidate + def _do_query(self, multiple=True, refresh=False): if not self._evaluated or refresh: self._nodes = self.poco.agent.hierarchy.select(self.query, multiple)