Skip to content

Commit

Permalink
Add ui object get child and get from parent
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmilano committed Oct 13, 2024
1 parent 29befc6 commit 5edf403
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
29 changes: 29 additions & 0 deletions examples/helper/get-wifi-dns
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /usr/bin/env python3
#
# Gets the DNS names when connected via WiFi
#

import subprocess

from com.dtmilano.android.viewclient import ViewClient

WIFI = "MY-SSID" # Use your WiFi SSID here
subprocess.run(["adb", "shell", "am", "start", "-a", "android.settings.WIFI_SETTINGS"])
helper = ViewClient.view_client_helper()
obj_ref = helper.until.find_object(body={'desc': f"{WIFI},Connected,Wifi signal full.,Secure network"})
helper.ui_object2.click(oid=helper.ui_device.wait(oid=obj_ref.oid)["oid"])
helper.ui_device.wait_for_window_update()
try:
obj_ref = helper.until.find_object(body={'text': "Advanced"})
helper.ui_object2.click(oid=helper.ui_device.wait(oid=obj_ref.oid)["oid"])
except:
pass
helper.ui_device.swipe(segments=[(300, 1500), (300, 300)], segment_steps=50)
helper.ui_device.wait_for_window_update()
obj_ref = helper.ui_device.find_object(ui_selector="text@DNS")
obj_ref = helper.ui_object.get_from_parent(obj_ref.oid, ui_selector="res@android:id/summary")
obj = helper.ui_object.dump(obj_ref.oid)
print("DNS")
print(obj.text)
helper.ui_device.press_back()
helper.ui_device.press_back()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
classifiers=['Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License'],
install_requires=['setuptools', 'requests', 'numpy', 'matplotlib', 'culebratester-client >= 2.0.70'],
install_requires=['setuptools', 'requests', 'numpy', 'matplotlib', 'culebratester-client >= 2.0.73'],
)
44 changes: 37 additions & 7 deletions src/com/dtmilano/android/uiautomator/uiautomatorhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import warnings
from abc import ABC
from datetime import datetime
from typing import Optional, List, Tuple
from typing import Optional, List, Tuple, Union

import culebratester_client
from culebratester_client import Text, ObjectRef, DefaultApi, Point, PerformTwoPointerGestureBody, \
Expand Down Expand Up @@ -259,9 +259,9 @@ def __init__(self, uiAutomatorHelper) -> None:
self.uiAutomatorHelper = uiAutomatorHelper

@staticmethod
def intersection(l1: list, l2: list) -> list:
def intersection(l1: Union[list, tuple], l2: Union[list, tuple]) -> list:
"""
Obtains the intersection between the two lists.
Obtains the intersection between the two lists or tuples.
:param l1: list 1
:type l1: list
Expand All @@ -272,7 +272,7 @@ def intersection(l1: list, l2: list) -> list:
"""
return list(set(l1) & set(l2))

def some(self, l1: list, l2: list) -> bool:
def some(self, l1: Union[list, tuple], l2: Union[list, tuple]) -> bool:
"""
Some elements are in both lists.
Expand All @@ -285,7 +285,7 @@ def some(self, l1: list, l2: list) -> bool:
"""
return len(self.intersection(l1, l2)) > 0

def all(self, l1: list, l2: list) -> bool:
def all(self, l1: Union[list, tuple], l2: Union[list, tuple]) -> bool:
"""
All the elements are in both lists.
Expand Down Expand Up @@ -550,7 +550,7 @@ def has_object(self, **kwargs) -> bool:
"""
if 'body' in kwargs:
return self.uiAutomatorHelper.api_instance.ui_device_has_object_post(**kwargs).value
if self.some(['resource_id', 'ui_selector', 'by_selector'], kwargs):
if self.some(('resource_id', 'ui_selector', 'by_selector'), tuple(kwargs.keys())):
return self.uiAutomatorHelper.api_instance.ui_device_has_object_get(**kwargs).value
body = culebratester_client.Selector(**kwargs)
return self.uiAutomatorHelper.api_instance.ui_device_has_object_post(body=body).value
Expand Down Expand Up @@ -611,7 +611,7 @@ def swipe(self, **kwargs) -> None:
:param kwargs:
:return:
"""
if self.all(['start_x', 'start_y', 'end_x', 'end_y', 'steps'], kwargs):
if self.all(('start_x', 'start_y', 'end_x', 'end_y', 'steps'), tuple(kwargs.keys())):
check_response(self.uiAutomatorHelper.api_instance.ui_device_swipe_get(**kwargs))
return
if 'segments' in kwargs:
Expand Down Expand Up @@ -757,11 +757,41 @@ def get_bounds(self, oid: int) -> Tuple[int, int, int, int]:
rect: Rect = self.uiAutomatorHelper.api_instance.ui_object_oid_get_bounds_get(oid=oid)
return rect.left, rect.top, rect.right, rect.bottom

def get_child(self, oid: int, ui_selector: str) -> ObjectRef:
"""
Creates a new UiObject for a child view that is under the present UiObject.
:see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml
:param oid: The oid
:type oid: int
:param ui_selector:
:type ui_selector:
:return:
:rtype: ObjectRef
"""
return self.uiAutomatorHelper.api_instance.ui_object_oid_get_child(oid, ui_selector=ui_selector)

def get_from_parent(self, oid: int, ui_selector: str) -> ObjectRef:
"""
Creates a new UiObject for a sibling view or a child of the sibling view, relative to the present UiObject.
:see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml
:param oid: The oid
:type oid: int
:param ui_selector:
:type ui_selector:
:return:
:rtype: ObjectRef
"""
return self.uiAutomatorHelper.api_instance.ui_object_oid_get_from_parent_get(oid,
ui_selector=ui_selector)

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:
"""
Generates a two-pointer gesture with arbitrary starting and ending points.
:see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml
:param oid: the oid
:param startPoint1:
:param startPoint2:
Expand Down

0 comments on commit 5edf403

Please sign in to comment.