From bb77d2a7c15bef94db2a8a154ff4a8a8db30930e Mon Sep 17 00:00:00 2001 From: Diego Torres Milano Date: Fri, 23 Dec 2022 19:34:39 -0800 Subject: [PATCH] Add get class name and get content description for uiobjects - Kato: check if enanle or just raise exception if caught --- src/com/dtmilano/android/kato/kato.py | 5 +++ .../android/uiautomator/uiautomatorhelper.py | 32 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/com/dtmilano/android/kato/kato.py b/src/com/dtmilano/android/kato/kato.py index 7e16a472..af1548b9 100644 --- a/src/com/dtmilano/android/kato/kato.py +++ b/src/com/dtmilano/android/kato/kato.py @@ -52,9 +52,14 @@ def kato(func): """ def wrapper(*args, **kwargs): + if DEBUG: + print('kato.wrapper:', args, kwargs) try: return func(*args, **kwargs) except ApiException as e: + helper = args[0].uiAutomatorHelper + if not helper.kato.enabled: + raise e find_me_the_selectors(e, *args, **kwargs, func=func.__name__, distance_func=levenshtein_distance, distance_func_argument_mapper=str) diff --git a/src/com/dtmilano/android/uiautomator/uiautomatorhelper.py b/src/com/dtmilano/android/uiautomator/uiautomatorhelper.py index 1a41ec91..09ec288e 100644 --- a/src/com/dtmilano/android/uiautomator/uiautomatorhelper.py +++ b/src/com/dtmilano/android/uiautomator/uiautomatorhelper.py @@ -20,7 +20,7 @@ from __future__ import print_function -__version__ = '22.3.1' +__version__ = '22.4.0' import os import platform @@ -36,7 +36,7 @@ import culebratester_client from culebratester_client import Text, ObjectRef, DefaultApi, Point, PerformTwoPointerGestureBody, \ - BooleanResponse, NumberResponse, StatusResponse + BooleanResponse, NumberResponse, StatusResponse, StringResponse from com.dtmilano.android.adb.adbclient import AdbClient from com.dtmilano.android.common import obtainAdbPath @@ -465,7 +465,7 @@ def find_object(self, **kwargs): """ if 'body' in kwargs: return self.uiAutomatorHelper.api_instance.ui_device_find_object_post(**kwargs) - if self.some(['resource_id', 'ui_selector', 'by_selector'], kwargs): + if self.some(['resource_id', 'ui_selector', 'by_selector'], list(kwargs.keys())): return self.uiAutomatorHelper.api_instance.ui_device_find_object_get(**kwargs) body = culebratester_client.Selector(**kwargs) return self.uiAutomatorHelper.api_instance.ui_device_find_object_post(body=body) @@ -664,13 +664,35 @@ def exists(self, oid: int) -> bool: def get_child_count(self, oid: int) -> int: """ + Counts the child views immediately under the present UiObject. :see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml - :param oid: - :return: + :param oid: the oid + :return: the child count """ response: NumberResponse = self.uiAutomatorHelper.api_instance.ui_object_oid_get_child_count_get(oid=oid) return int(response.value) + def get_class_name(self, oid: int) -> str: + """ + Retrieves the className property of the UI element. + :see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml + :param oid: + :return: the class name + """ + response: StringResponse = self.uiAutomatorHelper.api_instance.ui_object_oid_get_class_name_get(oid=oid) + return response.value + + def get_content_description(self, oid: int) -> str: + """ + Reads the content_desc property of the UI element. + :see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml + :param oid: the oid + :return: the content description + """ + response: StringResponse = self.uiAutomatorHelper.api_instance.ui_object2_oid_get_content_description_get( + oid=oid) + return response.value + def perform_two_pointer_gesture(self, oid: int, startPoint1: Tuple[int, int], startPoint2: Tuple[int, int], endPoint1: Tuple[int, int], endPoint2: Tuple[int, int], steps: int) -> None: """