-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_common.js
More file actions
138 lines (123 loc) · 3.81 KB
/
_common.js
File metadata and controls
138 lines (123 loc) · 3.81 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// auto.js参考文档:https://hyb1996.github.io/AutoJs-Docs/
module.exports = {
// 所有辅助脚本初始化的操作
init: function (operationName) {
// 当前所有脚本中的坐标都是基于小米 MIX 2(2160 X 1080)的屏幕适配,通过调用该函数,可实现在其他分辨率的设备上自动进行坐标缩放
setScreenMetrics(1080, 2160)
this.log("准备解锁屏幕~")
// 确保无障碍服务已启用
auto.waitFor()
// 若处于锁屏状态,则解锁
if (!device.isScreenOn()) {
device.wakeUp()
sleep(1000)
this.swipe("下拉状态栏", 180, 75, 180, 1200, 300)
this.click("点击时间", 150, 170)
}
this.sleep_default_with_msg("即将开始运行 " + operationName)
},
// 双击退出当前应用
exit_current_app: function (msg) {
this.log(msg)
// 双击back,退出当前应用
back()
back()
},
// -- 对常用函数的一些封装 --
launchPackage: function (msg, packageName) {
this.log(msg)
launchPackage(packageName)
this.sleep_long()
this.sleep("额外等待一会", 12)
},
reLaunchPackage: function (msg, packageName) {
// 先尝试关闭应用
this.shutdownPackage(packageName)
// 然后重新打开
this.launchPackage(msg, packageName)
},
shutdownPackage: function (packageName) {
appName = app.getAppName(packageName)
app.openAppSetting(packageName)
this.sleep_default_with_msg("打开" + appName + "的设置界面")
text(appName).waitFor()
shuwdownBtn = text("结束运行").findOne()
if (shuwdownBtn.enabled()) {
this.click_text("点击 [结束运行] 按钮", "结束运行")
this.click_text("点击 [确定] 按钮", "确定")
} else {
this.sleep_default_with_msg(appName + "目前未在运行,不需要关闭")
}
this.back()
},
click: function (msg, x, y) {
this.log(msg)
click(x, y)
this.sleep_default()
},
click_sleep_long: function (msg, x, y) {
this.log(msg)
click(x, y)
this.sleep_long()
},
double_click: function (msg, x, y) {
this.log(msg)
click(x, y)
click(x, y)
this.sleep_default()
},
click_text: function (msg, textToClick) {
this.log(msg)
click(textToClick, 0)
this.sleep_default()
},
swipe: function (msg, x1, y1, x2, y2, duration) {
this.log(msg)
swipe(x1, y1, x2, y2, duration)
this.sleep_default()
},
// 退出到最顶层
back_to_top: function (msg, maxLevel, waitMillSeconds) {
this.log(msg)
for (let i = 0; i < maxLevel; i++) {
back()
sleep(waitMillSeconds)
}
},
back: function () {
this.log("回到上一层")
back()
this.sleep_default()
},
// -- 一些辅助函数 --
headline: function (msg) {
sideMsg = "--"
this.log(sideMsg + " " + msg + " " + sideMsg)
sleep(1000)
},
foot: function () {
this.log("操作完成,请看看是否ok")
this.sleep_default_with_msg("三秒后将锁屏~")
KeyCode("KEYCODE_POWER");
},
// 在命令行和toast输出日志
log: function log(msg) {
console.info(msg)
toast(msg)
},
// 通用等待逻辑
sleep: function (msg, seconds) {
this.log(msg + "(等待" + seconds + "秒)")
sleep(seconds * 1000)
},
sleep_default: function () {
sleep(5000)
},
sleep_default_with_msg: function (msg) {
this.log(msg)
this.sleep_default()
},
sleep_long: function () {
sleep(8000)
},
}