-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBase.py
91 lines (79 loc) · 2.93 KB
/
Base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# encoding=utf-8
import abc
import platform
import openpyxl
from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
def gen_py():
"""
根据excel表格生成python对象,写脚本的时候可以运行该方法,把表格内容转为python类对象
:return:
"""
# prefix这个变量是你当前应用的包名
APP_PREFIX = "com.charme.starnote:id/"
PERMISSION_PREFIX = "com.android.permissioncontroller:id/"
# 这个文件只做参照
filepath = "ResourceConfig.xlsx"
workbook = openpyxl.load_workbook(filepath)
sheet_names = workbook.sheetnames
for sheet_name in sheet_names:
sheet = workbook[sheet_name]
max_row = sheet.max_row + 1
print(sheet_name)
with open(file=f"gen/{sheet_name}.py", mode="w+", encoding="UTF-8-sig") as f:
f.write(f"class {sheet_name}:\r\n")
for i in range(1, max_row):
if sheet_name == "Sheet":
continue
if sheet_name == "Permission":
f.write(f" {sheet[f'A{i}'].value} = \""
f"{PERMISSION_PREFIX}{sheet[f'B{i}'].value}\"\r\n")
elif sheet_name == "Component":
f.write(f" {sheet[f'A{i}'].value} = \"{sheet[f'B{i}'].value}\"\r\n")
else:
f.write(f" {sheet[f'A{i}'].value} = \""
f"{APP_PREFIX}{sheet[f'B{i}'].value}\"\r\n")
class Base(metaclass=abc.ABCMeta):
def __init__(self, deviceid, log_dir=None):
ST.LOG_FILE = f"{deviceid}.txt"
ST.OPDELAY = 1
if log_dir is None:
system = platform.system()
if system == 'Windows':
log_dir = ".\\report\\"
elif system in ['Darwin', 'Linux']:
log_dir = "./report/"
auto_setup(devices=[
f"Android://127.0.0.1:5037/{deviceid}?cap_method=JAVACAP"
f"&&ori_method=MINICAPORI"
f"&&touch_method=MAXTOUCH"
], logdir=log_dir)
self.poco = AndroidUiautomationPoco()
self.device = self.poco.device
self.width = self.device.display_info["width"]
self.height = self.device.display_info["height"]
# 点亮屏幕
if not self.device.is_screenon():
self.poco.device.keyevent(keyname="26")
@abc.abstractmethod
def click(self, name):
pass
@abc.abstractmethod
def double_click(self, name):
pass
def key_event(self, keycode):
"""
调用KeyEvent事件
:param keycode:
:return:
"""
self.device.keyevent(str(keycode))
@abc.abstractmethod
def set_text(self, name, content):
pass
@abc.abstractmethod
def find_on_vertical(self, obj, length, top_target=None, end_target=None):
pass
@abc.abstractmethod
def find_on_horizontal(self, obj, target, length):
pass