Skip to content

Commit

Permalink
Add get class name and get content description for uiobjects
Browse files Browse the repository at this point in the history
- Kato: check if enanle or just raise exception if caught
  • Loading branch information
dtmilano committed Dec 24, 2022
1 parent 34388ba commit bb77d2a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/com/dtmilano/android/kato/kato.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
32 changes: 27 additions & 5 deletions src/com/dtmilano/android/uiautomator/uiautomatorhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from __future__ import print_function

__version__ = '22.3.1'
__version__ = '22.4.0'

import os
import platform
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
"""
Expand Down

0 comments on commit bb77d2a

Please sign in to comment.