Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ecnusse/Kea
Browse files Browse the repository at this point in the history
  • Loading branch information
XixianLiang committed Jan 3, 2025
2 parents 6693764 + 88aabe0 commit df133cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions kea/adapter/uiautomator2_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class Uiautomator2_Helper:
def __init__(self, device=None):
def __init__(self, device=None, package_name = None):
if device is None:
from kea.device import Device

Expand All @@ -20,6 +20,8 @@ def __init__(self, device=None):
self.__first_cap_re = re.compile("(.)([A-Z][a-z]+)")
self.__all_cap_re = re.compile("([a-z0-9])([A-Z])")

self.package_name: str = package_name

def __id_convert(self, name):
name = name.replace(".", "_").replace(":", "_").replace("/", "_")
s1 = self.__first_cap_re.sub(r"\1_\2", name)
Expand Down Expand Up @@ -117,14 +119,17 @@ def select_target_root_node(self, xml):
:return: the selected root node
"""
# exclude some package
exlude_package = ["com.android.systemui","com.github.uiautomator","android"]
exlude_package = ["com.android.systemui","com.github.uiautomator"]
# iterate all the root nodes from the xml node, and select the one we want
root = ET.fromstring(xml)
for child in root:
if child.tag == "node" and child.get("package") in exlude_package:
continue
return child

packages = {child.get("package") : child for child in root if child.tag == "node"}
if self.package_name in packages:
return packages[self.package_name]
else:
for package in packages:
if package in exlude_package:
continue
return packages[package]
return None

def dump_view(self) -> Dict:
Expand Down
2 changes: 1 addition & 1 deletion kea/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __init__(
# ProcessMonitor is a class used to monitor and manage processes on the device.
self.process_monitor = ProcessMonitor(device=self)
# Uiautomator2_Helper is a class used to handle the logic for interacting with UIAutomator2.
self.uiautomator_helper = Uiautomator2_Helper(device=self)
self.uiautomator_helper = Uiautomator2_Helper(device=self, package_name=self.app_package_name)

# self.droidbot_ime = DroidBotIme(device=self)

Expand Down

0 comments on commit df133cc

Please sign in to comment.