-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdd.js
155 lines (127 loc) · 4.68 KB
/
dd.js
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
auto.waitFor(); // home(); click('钉钉');
console.show();
waitForPackage("com.alibaba.android.rimet");
sleep(1000);
let loopCount = 0;
let checkWarningNumberCount = 0;
(function main() {
console.log("程序运行次数:", loopCount++, "loopCount:", new Date().toLocaleString());
checkWarningNumberCount = 0;
// loop
setTimeout(() => {
checkFunc().then(() => main()).catch((e) => main());
}, 1000 * 1);
})();
function checkFunc() {
return new Promise((resolve, reject) => {
checkWarningRoboot().then(() => {
sleep(2000);
checkWarningNumber().then((result) => {
handlerSearchResult(result).then(() => {
sleep(2000);
sendText("正常");
sleep(2000);
back();
resolve();
}).catch((e) => {
console.log(e);
handlerError(reject);
})
}).catch((e) => {
console.log(e);
handlerError(reject);
})
}).catch((e) => {
console.log("未检测到机器人", e);
})
})
}
function checkWarningRoboot() {
return new Promise((resolve, reject) => {
try {
const name = descContains("告警机器人").depth(12);
name.waitFor();
const name_w = name.findOne();
click(name_w.bounds().left, name_w.bounds().top, name_w.bounds().right, name_w.bounds().bottom);
resolve();
} catch (e) {
reject(e);
}
})
}
function callPhone() {
return new Promise((resolve, reject) => {
try {
// 点击指定用户
const callPhoneName = descContains("拨出联系人123").depth(12);
callPhoneName.waitFor();
const callPhoneName_w = callPhoneName.findOne();
click(callPhoneName_w.bounds().left, callPhoneName_w.bounds().top, callPhoneName_w.bounds().right, callPhoneName_w.bounds().bottom);
sleep(1000);
sendText("异常");
sleep(1000);
// 点击右上角语音电话 icon
const callPhonteIcon = descContains("发起钉钉电话").depth(15);
callPhonteIcon.waitFor();
const callPhonteIcon_w = callPhonteIcon.findOne();
click(callPhonteIcon_w.bounds().left, callPhonteIcon_w.bounds().top, callPhonteIcon_w.bounds().right, callPhonteIcon_w.bounds().bottom);
sleep(1000);
// 点击语音通话
const textCall = textContains("语音通话").depth(10);
textCall.waitFor();
const textCall_w = textCall.findOne();
click(textCall_w.bounds().left, textCall_w.bounds().top, textCall_w.bounds().right, textCall_w.bounds().bottom);
console.log('拨出电话');
resolve();
} catch (e) {
console.log('callPhone', e)
reject(e);
}
})
}
function checkWarningNumber() {
let searchText = "活跃用户";
return new Promise((resolve, reject) => {
const searchResult = descContains(searchText).depth(15).find();
if (searchResult.length > 0) {
console.log("检测到告警机器人发送当前:", searchResult.map((item) => item.contentDescription).join(','));
return resolve(searchResult);
}
if (checkWarningNumberCount >= 5){
console.log("未检测到告警机器人发送当前:", searchText, 'count:', checkWarningNumberCount, '超过5次');
return reject('未检测到告警机器人发送');
}
if (checkWarningNumberCount < 5) {
checkWarningNumberCount++;
console.log("未检测到告警机器人发送当前:", searchText, 'count:', checkWarningNumberCount);
setTimeout(() => {
checkWarningNumber().then((result) => resolve(result)).catch((e) => reject(e));
}, 1000);
}
})
}
function handlerSearchResult(searchResult){
const text = searchResult.map((item) => item.contentDescription).join(',');
console.log('handlerSearchResult', text);
return new Promise((resolve, reject) => {
if (/(-)?(30(\.0{1,2})?|[3-9]\d|\d{3,})(\.)(\d{1,})?%/.test(text)) {
return reject('检测到百分比超过30%');
} else {
resolve();
}
})
}
function handlerError(reject) {
// 遇到异常
back();
sleep(2000);
callPhone().then(() => {}).catch((e) => {
return reject(e);
})
reject();
}
function sendText(text) {
className("EditText").setText(text);
sleep(2000);
textContains("发送").depth(14).click();
}