Skip to content

Commit bb77d2a

Browse files
committed
Add get class name and get content description for uiobjects
- Kato: check if enanle or just raise exception if caught
1 parent 34388ba commit bb77d2a

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ def kato(func):
5252
"""
5353

5454
def wrapper(*args, **kwargs):
55+
if DEBUG:
56+
print('kato.wrapper:', args, kwargs)
5557
try:
5658
return func(*args, **kwargs)
5759
except ApiException as e:
60+
helper = args[0].uiAutomatorHelper
61+
if not helper.kato.enabled:
62+
raise e
5863
find_me_the_selectors(e, *args, **kwargs, func=func.__name__, distance_func=levenshtein_distance,
5964
distance_func_argument_mapper=str)
6065

src/com/dtmilano/android/uiautomator/uiautomatorhelper.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from __future__ import print_function
2222

23-
__version__ = '22.3.1'
23+
__version__ = '22.4.0'
2424

2525
import os
2626
import platform
@@ -36,7 +36,7 @@
3636

3737
import culebratester_client
3838
from culebratester_client import Text, ObjectRef, DefaultApi, Point, PerformTwoPointerGestureBody, \
39-
BooleanResponse, NumberResponse, StatusResponse
39+
BooleanResponse, NumberResponse, StatusResponse, StringResponse
4040

4141
from com.dtmilano.android.adb.adbclient import AdbClient
4242
from com.dtmilano.android.common import obtainAdbPath
@@ -465,7 +465,7 @@ def find_object(self, **kwargs):
465465
"""
466466
if 'body' in kwargs:
467467
return self.uiAutomatorHelper.api_instance.ui_device_find_object_post(**kwargs)
468-
if self.some(['resource_id', 'ui_selector', 'by_selector'], kwargs):
468+
if self.some(['resource_id', 'ui_selector', 'by_selector'], list(kwargs.keys())):
469469
return self.uiAutomatorHelper.api_instance.ui_device_find_object_get(**kwargs)
470470
body = culebratester_client.Selector(**kwargs)
471471
return self.uiAutomatorHelper.api_instance.ui_device_find_object_post(body=body)
@@ -664,13 +664,35 @@ def exists(self, oid: int) -> bool:
664664

665665
def get_child_count(self, oid: int) -> int:
666666
"""
667+
Counts the child views immediately under the present UiObject.
667668
:see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml
668-
:param oid:
669-
:return:
669+
:param oid: the oid
670+
:return: the child count
670671
"""
671672
response: NumberResponse = self.uiAutomatorHelper.api_instance.ui_object_oid_get_child_count_get(oid=oid)
672673
return int(response.value)
673674

675+
def get_class_name(self, oid: int) -> str:
676+
"""
677+
Retrieves the className property of the UI element.
678+
:see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml
679+
:param oid:
680+
:return: the class name
681+
"""
682+
response: StringResponse = self.uiAutomatorHelper.api_instance.ui_object_oid_get_class_name_get(oid=oid)
683+
return response.value
684+
685+
def get_content_description(self, oid: int) -> str:
686+
"""
687+
Reads the content_desc property of the UI element.
688+
:see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml
689+
:param oid: the oid
690+
:return: the content description
691+
"""
692+
response: StringResponse = self.uiAutomatorHelper.api_instance.ui_object2_oid_get_content_description_get(
693+
oid=oid)
694+
return response.value
695+
674696
def perform_two_pointer_gesture(self, oid: int, startPoint1: Tuple[int, int], startPoint2: Tuple[int, int],
675697
endPoint1: Tuple[int, int], endPoint2: Tuple[int, int], steps: int) -> None:
676698
"""

0 commit comments

Comments
 (0)