Skip to content

Commit 7ce0b2e

Browse files
committed
support parent node selection
1 parent 9e904c2 commit 7ce0b2e

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

poco/proxy.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,25 @@ def sibling(self, name=None, **attrs):
189189
obj.query = query
190190
return obj
191191

192+
def parent(self):
193+
"""
194+
Select the direct child(ren) from the UI element(s) given by the query expression, see ``QueryCondition`` for
195+
more details about the selectors.
196+
197+
Warnings:
198+
Experimental method, may not be available for all drivers.
199+
200+
Returns:
201+
:py:class:`UIObjectProxy <poco.proxy.UIObjectProxy>`: a new UI proxy object representing the direct parent
202+
of the first UI element.
203+
"""
204+
205+
sub_query = build_query(None) # as placeholder
206+
query = ('^', (self.query, sub_query))
207+
obj = UIObjectProxy(self.poco)
208+
obj.query = query
209+
return obj
210+
192211
def __getitem__(self, item):
193212
"""
194213
Select the specific UI element by index. If this UI proxy represents a set of UI elements, then use this method

poco/proxy.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class UIObjectProxy(object):
3030
def sibling(self, name: Text=None, **attrs) -> UIObjectProxy:
3131
...
3232

33+
def parent(self) -> UIObjectProxy:
34+
...
35+
3336
def __getitem__(self, item: int) -> UIObjectProxy:
3437
...
3538

poco/sdk/Selector.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class Selector(ISelector):
4444
'>': offsprings, select all offsprings matched expr1 from all roots matched expr0.
4545
'/': children, select all children matched expr1 from all roots matched expr0.
4646
'-': siblings, select all siblings matched expr1 from all roots matched expr0.
47-
47+
'^': parent, select the parent of 1st UI element matched expr0. expr1 is always None.
48+
4849
- ``'index'``: select specific n-th UI element from the previous results
4950
5051
- ``others``: passes the expression to matcher
@@ -137,6 +138,15 @@ def selectImpl(self, cond, multiple, root, maxDepth, onlyVisibleNode, includeRoo
137138
except IndexError:
138139
raise NoSuchTargetException(
139140
u'Query results index out of range. Index={} condition "{}" from root "{}".'.format(i, cond, root))
141+
elif op == '^':
142+
# parent
143+
# only select parent of the first matched UI element
144+
query1, _ = args
145+
result1 = self.selectImpl(query1, False, root, maxDepth, onlyVisibleNode, includeRoot)
146+
if result1:
147+
parent_node = result1[0].getParent()
148+
if parent_node is not None:
149+
result = [parent_node]
140150
else:
141151
self._selectTraverse(cond, root, result, multiple, maxDepth, onlyVisibleNode, includeRoot)
142152

poco/utils/query_util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'/': '/',
2020
'>': '>',
2121
'-': '-',
22+
'^': '\'s parent',
2223
}
2324

2425

@@ -27,7 +28,7 @@
2728

2829
def query_expr(query):
2930
op = query[0]
30-
if op in ('/', '>', '-'):
31+
if op in ('/', '>', '-', '^'):
3132
return TranslateOp[op].join([query_expr(q) for q in query[1]])
3233
elif op == 'index':
3334
return '{}[{}]'.format(query_expr(query[1][0]), query[1][1])

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def parse_requirements(filename='requirements.txt'):
1010

1111
setup(
1212
name='pocoui',
13-
version='1.0.72',
13+
version='1.0.73',
1414
keywords="poco, automation test, ui automation",
1515
description='Poco cross-engine UI automated test framework.',
1616
long_description='Poco cross-engine UI automated test framework. 2018 present by NetEase Games',

0 commit comments

Comments
 (0)