Skip to content

Commit f65c330

Browse files
committed
Add comply with pkg to kato
1 parent a93e453 commit f65c330

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

.idea/runConfigurations/screenshot_box_100_300_300_600__tmp_box_png.xml

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/helper/find-object

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ body = {'checkable': False, 'checked': False, 'clazz': 'android.widget.ImageButt
1414
'desc': 'add', 'index': None, 'instance': None, 'pkg': 'com.google.android.calculator',
1515
'res': 'com.google.android.calculator:id/op_add', 'scrollable': False, 'text': None}
1616

17+
# This will restrict the search for candidates to the same pkg: 'com.google.android.calculator'
18+
helper.kato.comply_with_pkg = True
19+
1720
try:
1821
obj_ref = helper.ui_device.find_object(body=body)
1922
print(helper.ui_object2.dump(oid=obj_ref.oid).desc)
2023
except Exception as e:
2124
print(f"I couldn't find any view matching selector={body}")
22-
print(f'But found other {len(helper.kato.selectors)} potential ones.')
23-
print('Choosing a closest selector from such potential list:')
24-
body = next(iter(helper.kato.distances.values()))
25-
obj_ref = helper.ui_device.find_object(body=body)
26-
print(helper.ui_object2.dump(oid=obj_ref.oid))
25+
n = len(helper.kato.selectors)
26+
if n:
27+
print(f'But found other {n} potential ones.')
28+
print('Choosing a closest selector from such potential list:')
29+
body = next(iter(helper.kato.distances.values()))
30+
obj_ref = helper.ui_device.find_object(body=body)
31+
print(helper.ui_object2.dump(oid=obj_ref.oid))
32+
else:
33+
print('There are no potential ones either.')

src/com/dtmilano/android/kato/kato.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def __init__(self):
3939
self.enabled = False
4040
self.selectors = []
4141
self.distances = OrderedDict()
42+
# If pkg has been specified in the selector, only finds other selectors with the same pkg when True
43+
self.comply_with_pkg = False
4244

4345

4446
def kato(func):
@@ -90,6 +92,8 @@ def find_me_the_selectors(e: ApiException, *args, **kwargs):
9092
selector = Selector(**kwargs['body'])
9193
helper.kato.selectors = window_hierarchy_to_selector_list(
9294
helper.ui_device.dump_window_hierarchy(_format='JSON'))
95+
if selector.pkg and helper.kato.comply_with_pkg:
96+
helper.kato.selectors = list(filter(lambda _s: _s.pkg == selector.pkg, helper.kato.selectors))
9397
_d = dict()
9498
for n, s in enumerate(helper.kato.selectors):
9599
if n == 0:

0 commit comments

Comments
 (0)