From 00f3bf749542c6db1aee77d2cc08081e1c3f5189 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 15 Jul 2024 22:09:21 +0800 Subject: [PATCH] Add: [ALAS] Add interval on dump_hierarchy() --- module/device/app_control.py | 20 ++++++++++++++++++++ module/device/device.py | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/module/device/app_control.py b/module/device/app_control.py index cf6c3a529..3d3791b22 100644 --- a/module/device/app_control.py +++ b/module/device/app_control.py @@ -1,9 +1,11 @@ from lxml import etree +from module.base.timer import Timer from module.device.method.adb import Adb from module.device.method.uiautomator_2 import Uiautomator2 from module.device.method.utils import HierarchyButton from module.device.method.wsa import WSA +from module.exception import ScriptError from module.logger import logger @@ -12,6 +14,7 @@ class AppControl(Adb, WSA, Uiautomator2): # Use ADB for all # See https://github.com/openatx/uiautomator2/issues/565 _app_u2_family = [] + _hierarchy_interval = Timer(0.1) def app_is_running(self) -> bool: method = self.config.Emulator_ControlMethod @@ -44,11 +47,28 @@ class AppControl(Adb, WSA, Uiautomator2): else: self.app_stop_adb() + def hierarchy_timer_set(self, interval=None): + if interval is None: + interval = 0.1 + elif isinstance(interval, (int, float)): + # No limitation for manual set in code + pass + else: + logger.warning(f'Unknown hierarchy interval: {interval}') + raise ScriptError(f'Unknown hierarchy interval: {interval}') + + if interval != self._hierarchy_interval.limit: + logger.info(f'Hierarchy interval set to {interval}s') + self._hierarchy_interval.limit = interval + def dump_hierarchy(self) -> etree._Element: """ Returns: etree._Element: Select elements with `self.hierarchy.xpath('//*[@text="Hermit"]')` for example. """ + self._hierarchy_interval.wait() + self._hierarchy_interval.reset() + # method = self.config.Emulator_ControlMethod # if method in AppControl._app_u2_family: # self.hierarchy = self.dump_hierarchy_uiautomator2() diff --git a/module/device/device.py b/module/device/device.py index 494914176..9847232f7 100644 --- a/module/device/device.py +++ b/module/device/device.py @@ -1,6 +1,8 @@ import collections import itertools +from lxml import etree + # Patch pkg_resources before importing adbutils and uiautomator2 from module.device.pkg_resources import get_distribution @@ -157,6 +159,10 @@ class Device(Screenshot, Control, AppControl): return self.image + def dump_hierarchy(self) -> etree._Element: + self.stuck_record_check() + return super().dump_hierarchy() + def release_during_wait(self): # Scrcpy server is still sending video stream, # stop it during wait