|
|
@@ -1,6 +1,4 @@
|
|
|
import json
|
|
|
-import this
|
|
|
-import time
|
|
|
|
|
|
import uiautomator2 as u2
|
|
|
|
|
|
@@ -68,6 +66,13 @@ class UiElement(object):
|
|
|
|
|
|
|
|
|
class UiFactory(object):
|
|
|
+ """
|
|
|
+ 这个类对 u2.connect 的几个方法做了封装,主要解决耗时问题。
|
|
|
+ 并且做缓存。不重复定位。
|
|
|
+
|
|
|
+ 可以使用 load_point 方法 加载 xxx_point.json中,已经配置好的坐标。
|
|
|
+ """
|
|
|
+
|
|
|
_cache = {}
|
|
|
|
|
|
def __init__(self, serial: str):
|
|
|
@@ -80,8 +85,9 @@ class UiFactory(object):
|
|
|
|
|
|
def xpath(self, alisa: str, xpath: str = None):
|
|
|
"""
|
|
|
- 通过 xpath获取坐标
|
|
|
+ 通过 xpath获取元素
|
|
|
alisa 别名
|
|
|
+ xpath 如果别名没有获取缓存, 会通过xpath 重新定位,并且缓存
|
|
|
"""
|
|
|
if alisa in self._cache:
|
|
|
return self._cache[alisa]
|
|
|
@@ -93,6 +99,11 @@ class UiFactory(object):
|
|
|
return el
|
|
|
|
|
|
def desc(self, alisa: str, desc: str = None):
|
|
|
+ """
|
|
|
+ 通过文本获取元素
|
|
|
+ alisa 别名
|
|
|
+ desc 如果别名没有获取缓存, 会通过description 重新定位,并且缓存
|
|
|
+ """
|
|
|
if alisa in self._cache:
|
|
|
return self._cache[alisa]
|
|
|
|
|
|
@@ -102,9 +113,9 @@ class UiFactory(object):
|
|
|
|
|
|
return el
|
|
|
|
|
|
- def load_point(self):
|
|
|
+ def load_point(self, point_json: str):
|
|
|
__tmp__ = {}
|
|
|
- with open("deepcion_point.json", "r", encoding="utf-8") as f:
|
|
|
+ with open(point_json, "r", encoding="utf-8") as f:
|
|
|
__tmp__ = json.load(f)
|
|
|
|
|
|
for k, v in __tmp__.items():
|
|
|
@@ -113,7 +124,7 @@ class UiFactory(object):
|
|
|
elif 'description' in v:
|
|
|
self._cache[k] = UiElement(self.d, description=v['description'], point=v['point'])
|
|
|
|
|
|
- def save_point(self):
|
|
|
+ def save_point(self, point_json: str):
|
|
|
"""
|
|
|
保存坐标
|
|
|
"""
|
|
|
@@ -121,7 +132,7 @@ class UiFactory(object):
|
|
|
for k, v in self._cache.items():
|
|
|
__tmp__[k] = v.info
|
|
|
|
|
|
- with open("deepcion_point.json", "w", encoding="utf-8") as f:
|
|
|
+ with open(point_json, "w", encoding="utf-8") as f:
|
|
|
json.dump(__tmp__, f, ensure_ascii=False, indent=4)
|
|
|
|
|
|
def check_app_running(self, appid: str):
|