Skip to content

Commit

Permalink
Added refresh() interface to force nodes to re-query, equivalent to i…
Browse files Browse the repository at this point in the history
…nvalidate()

Fixed the issue that the wait_for_disappearance node was not re-queried
新增refresh()接口,让节点强制重新查询,等同于invalidate()
修复了wait_for_disappearance节点未重新查询导致的问题

(cherry picked from commit 631efd1e91226b4b4fc6bb2010372a90b1186b44)
  • Loading branch information
yimelia committed Apr 14, 2022
1 parent a50cb93 commit 272315e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions poco/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 272315e

Please sign in to comment.