-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest.js
More file actions
1561 lines (1446 loc) · 62.5 KB
/
test.js
File metadata and controls
1561 lines (1446 loc) · 62.5 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ({
/***/ "./src/common/api.js":
/*!***************************!*\
!*** ./src/common/api.js ***!
\***************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileOverview API接口文件
* @description 本脚本在Auto.Js 4.0.1版本中,自动化控制Android微博版本号:9.6.3版测试通过!
* @author <a href=”tuple@youshui.ren”>Tuple</a>
* @version 0.1
*/
var Env = __webpack_require__(/*! ../env */ "./src/env.js")
var Sms = __webpack_require__(/*! ./sms */ "./src/common/sms.js")
var api={
/**
* 获取一个全局的配置文件
*/
getConfig:function() {
try {
// toast('开始获取配置');
let c = Env.curName;
let r = http.get("https://kapi.i-tax.ren/api/aichat/config?f="+Env.CLIENT+"&n=" + encodeURIComponent(c) + "&t=" + new Date().getTime() + "&d=" + device.getIMEI() + "&v=" + Env.VERSION);
let body = r.body.string();
// toast('get config ok');
if (!!body) {
let conf = JSON.parse(body);
if (conf) {
if (!conf.disabled) {
Env.config = conf;
}
Env.token = !!Env.config.token ? Env.config.token : Env.token;
Env.itemJihuo = !!Env.config.itemJihuo ? Env.config.itemJihuo : Env.itemJihuo;
Env.itemLogin = !!Env.config.itemLogin ? Env.config.itemLogin : Env.itemLogin;
Env.itemRegister = !!Env.config.itemRegister ? Env.config.itemRegister : Env.itemRegister;
Env.exceptPhone = !!Env.config.exceptPhone ? Env.config.exceptPhone : Env.exceptPhone;
Env.canReply = Env.config.canReplyDisabled ? Env.canReply : Env.config.canReply;
Env.config.debug ? console.show() : console.hide();
}
}
return body;
} catch (e) {
// console.log(JSON.stringify(e));
}
},
/**
* 获取关键字
*/
getKeyword:function () {
// console.log('get reply msg');
try {
let r = http.get("https://kapi.i-tax.ren/api/aichat/keyword?f="+Env.CLIENT+"&n=" + encodeURIComponent(Env.curName) + "&t=" + new Date().getTime() + "&d=" + device.getIMEI() + "&v=" + Env.VERSION);
let body = r.body.string();
// console.log('reply msg:' + body);
if (!!body) {
// let conf = JSON.parse(body);
// if (conf) {
// Env.curKeywords = conf;
// }
Env.curKeyword = body;
}
return body;
} catch (e) {
Env.curKeyword = null;
}
},
/**
* 获取评论内容
* @param {*} msg
*/
getReplyMsg:function(msg) {
// console.log('get reply msg');
try {
let c = !!msg ? msg : Env.curTitleContent.substr(0, 255);
let r = http.get("https://kapi.i-tax.ren/api/aichat/reply?f="+Env.CLIENT+"&c=" + encodeURIComponent(c) + "&t=" + new Date().getTime() + "&d=" + device.getIMEI() + "&v=" + Env.VERSION);
let body = r.body.string();
// console.log('reply msg:' + body);
Env.curComment = body;
return body;
} catch (e) {
Env.curComment = null;
}
},
getComment:function(){
return this.postReplyMsg();
},
getLoginPhone:function(){
return Sms.getPhone(Env.itemLogin);
},
getActivePhone:function(){
return Sms.getPhone(Env.itemJihuo);
},
getLoginCode:function(){
return Sms.getSMS(Env.curPhone,Env.itemLogin);
},
getHotTextItem:function(){
let groupItems = ['推荐', '榜单', '社会', '搞笑', '情感', '时尚', '校园', '摄影', '艺术', '明星', '美女', 'NBA'];
if (Env.config && Env.config.groupItems && Env.config.groupItems.length > 0) {
groupItems = Env.config.groupItems;
// toast('use Env.config group items');
}
Env.curGroupId = 0;
let subGroup = random(0, groupItems.length - 1);
if (Env.config && Env.config.subGroupId > -1) {
subGroup = Env.config.subGroupId;
}
Env.curHotTextItem = groupItems[subGroup];
// console.log('get hot text item api:',Env.curHotTextItem);
return groupItems[subGroup];
// return "国学";
},
getGivenWeiboTitle:function(){
// return "35岁检察官带人上门打70岁空巢老人 相关部门否认寻衅滋事? 官官相护";
return "青凌巴山越岭";
},
/**
* 获取评论内容
* @param {*} msg
*/
postReplyMsg:function(msg) {
let url = "https://kapi.i-tax.ren/api/aichat/reply";
r = http.postJson(url, {
n: Env.curName,
c: !!msg ? msg : Env.curTitleContent,
d: device.getIMEI(),
t: new Date().getTime(),
v: Env.VERSION,
f: Env.CLIENT,
});
let body = r.body.string();
// toast(body);
Env.curComment = body;
return body;
},
/**
* 获取评论内容
* @param {*} msg
*/
postUpdateStatus:function(status) {
let url = "https://kapi.i-tax.ren/api/aichat/status";
r = http.postJson(url, {
n: Env.curName,
s: status,
d: device.getIMEI(),
t: new Date().getTime(),
v: Env.VERSION,
f: Env.CLIENT,
});
let body = r.body.string();
// toast(body);
Env.curComment = body;
return body;
},
getTuling:function(msg) {
let url = "http://www.tuling123.com/openapi/api";
r = http.postJson(url, {
key: "65458a5df537443b89b31f1c03202a80",
info: "你好啊",
userid: "1",
});
let body = r.body.string();
toast(body);
Env.curComment = body;
return body;
},
loginOk:function(phone, name, type,msg) {
try {
let c = name;
let r = http.get("https://kapi.i-tax.ren/api/aichat/loginok?f="+Env.CLIENT+"&n=" + encodeURIComponent(c) +"&msg=" + encodeURIComponent(msg)
+ "&t=" + new Date().getTime() + "&d=" + device.getIMEI() + "&p=" + phone + "&tp=" + type);
let body = r.body.string();
// toast(body);
// config = body;
// console.log('login ok back:' + body);
return body;
} catch (e) {
}
},
/**
* 获取手机号的激活码
*/
getCode:function(phone){
try {
phone = !!phone ? phone : Env.curPhone
let c = name;
let r = http.get("https://kapi.i-tax.ren/api/aichat/phone/code?f="+Env.CLIENT+"&n=" + encodeURIComponent(c) + "&t=" + new Date().getTime() + "&d=" + device.getIMEI() + "&p=" + phone );
let body = r.body.string();
return body;
} catch (e) {
}
},
getRegisterPhone: function () {
return Sms.getPhone(Env.itemRegister);
},
getRegisterCode: function () {
return Sms.getSMS(Env.curPhone, Env.itemRegister);
},
getRegisterSendCode: function () {
return Sms.sendSMS(Env.curPhone, Env.itemRegister, '注册验证');
},
getRegisterName: function () {
let names = [
"Aaron", "Abbott", "Abel", "Abner", "Abraham", "Adair", "Adam", "Adolph", "Adonis", "Alan", "Albert", "Aldrich", "Alexander", "Alfred", "Alger", "Allen", "Alston", "Alva", "Alvin", "Alvis", "Amos", "Andre", "Andrew", "Andy", "Angelo", "Augus", "Ansel", "Antony", "Antonio", "Archer", "Archibald", "Aries", "Arlen", "Armand", "Armstrong", "Arno", "Arthur", "Arvin", "Asa", "Atwood", "Aubrey", "August", "Augustine", "Avery",
];
let rs = names[random(0, names.length - 1)] + random(10000, 99999);
rs = rs.toLowerCase();
toast("username:" + rs);
console.log("username:" + rs);
return rs;
},
getRegisterPassword: function () {
return "16181814";
},
getRegisterOk: function (){
let msg = {name:Env.curName,phone:Env.curPhone,item:Env.itemRegister,client:Env.CLIENT};
console.log('register ok:',msg)
return this.loginOk(Env.curPhone,Env.curName,'register',JSON.stringify(msg));
},
finish: function (){
let msg = {username:Env.curUsername,name:Env.curName,phone:Env.curPhone,item:Env.itemRegister,client:Env.CLIENT};
console.log('register ok:',msg)
return this.loginOk(Env.curPhone,Env.curName,'register',JSON.stringify(msg));
},
}
module.exports=api
/***/ }),
/***/ "./src/common/operate.js":
/*!*******************************!*\
!*** ./src/common/operate.js ***!
\*******************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileOverview 定义可以的操作
* @description 本脚本在Auto.Js 4.0.1版本中,自动化控制Android微博版本号:9.6.3版测试通过!
* @author <a href=”tuple@youshui.ren”>Tuple</a>
* @version 0.1
*
*/
/**
* get 获取本地或者远程文本并写到全局变量,
* set_text 设置控件的text属性,
* click 点击这个按钮,
* input OneByOne向控件输入文字,
* swipe 滑动页面,
* sleep 暂停,
* refresh 下拉刷新页面,
* back 点击Android的返回键,
* text 获取控件的text属性值,
* desc 获取控件的desc描述值,
* tap 点击控件位置的屏幕,
* enter 触发回车,
* 函数可以扩展
*/
var Utils = __webpack_require__(/*! ./utils */ "./src/common/utils.js");
var Api = __webpack_require__(/*! ./api */ "./src/common/api.js");
var Env = __webpack_require__(/*! ../env */ "./src/env.js");
var operate = {
/**
* 获取当前页面,OK
* @param {*} pages
*/
curPage: function (pages) {
// var result = [];
let result = { name: '', pageid: 0 };
// pages.forEach((item, index, arr) => {
// if (this.doExists(item.mark)) {
// result = item;
// }
// })
// console.log(JSON.stringify(pages));
for (let k in pages) {
if (this.doExists(pages[k].mark)) {
result = pages[k];
}
}
return result;
},
/**
* 获取下一个步骤
* @param {*} pages
*/
nextStep: function (pageid, pages) {
// var result = [];
// console.log('nextStep:',pageid,JSON.stringify(pages));
let result = { next: 0, pageid: 0, jobs: [] };
for (let k in pages) {
let item = pages[k];
if (item.pageid === pageid) {
result = item;
}
}
return result.next;
},
/**
* 判断是否为指定页面,OK
* @param {*} mark
*/
isPage: function (mark) {
return this.doExists(mark);
},
/**
*
* 根据传入的属性,构建查找到对应节点的对象,OK
*
* @param {*} item
*/
build: function (item) {
// let funNames = ['id','text','desc','className','depth','textStartsWith','textEndsWith'];
let target = null;
if (Utils.isNull(item.name)) {
for (let k in item) {
let v = item[k];
if (v != "" && v != null && v != undefined) {
if (!!target) {
target = eval('target.' + k + '(v)');
} else {
target = eval(k + '(v)');
}
// console.log('build target:'+JSON.stringify(target));
}
}
}
return target;
},
/**
* 支持更复杂的或者表达式,目前不启用
* @param {*} item
*/
parseItem: function (item) {
let obj = JSON.parse(JSON.stringify(item));
let t = 1;
for (let k in item) {
let v = item[k];
if (v != "" && v != null && v != undefined) {
obj[k] = v.split('||');
// t *= Math.pow(2,obj[k].length-1);
t *= obj[k].length;
}
}
// console.log(t);
// console.log(JSON.stringify(obj));
let ls = Utils.fill(t, item);
for (let k in obj) {
let v = obj[k];
// console.log(k);
// console.log(JSON.stringify(v));
if (Array.isArray(v)) {
// let n = t / v.length;
// let m = v.length;
for (let m = 0; m < v.length; m += 1) {
// console.log("m:"+m);
for (let n = 0; n < t / v.length; n += 1) {
// console.log("n:"+n);
// console.log("v[m]:"+v[m]);
let i = m * (t / v.length) + n;
ls[i][k] = v[m];
// console.log("ls["+i+"]["+k+"]:"+ls[i][k]);
}
}
} else {
for (let m = 0; m < t; m += 1) {
ls[m][k] = v;
}
}
// console.log(JSON.stringify(ls));
}
return ls;
},
/**
* 根据传入的属性,查找对应的节点并返回,OK
* @param {*} mark
* @param {*} param
*/
findNode: function (mark, param) {
let target = null;
// 有多个同样的,或者只有一个但是需要向上一级获取子节点
if (!!param && !Utils.isNull(param.indexOf)) {
//需要向上一级获取子节点
if (!Utils.isNull(param.parent) && param.parent > 0) {
target = this.build(mark).findOne();
let pLen = param.parent;
while (pLen > 0) {
target = target.parent;
pLen--;
}
target = target.children();
} else {
target = this.build(mark).find();
}
//有多个同样的,根据param.indexOf过滤节点,选择一个
// {name:"click", mark:{id:"tv_userinfo"}, param:{indexOf:{tag:"text",try:10,get:{name:"given_weibo_title",uri:"api"}}}},
// {name:"click", mark:{id:"tv_userinfo"}, param:{indexOf:{tag:"text",try:10,default:"测试位置"}}},
target = this.indexOfNode(target, param);
} else {
//只会有一个的情况
target = this.build(mark).findOnce();
}
if (!target) {
console.log('can not find ctrl', JSON.stringify(mark), JSON.stringify(param));
}
return target;
},
indexOfNode: function (target, param) {
//没有找到尝试向上滚动一下找找
let maxTry = 1;
if (!Utils.isNull(param.indexOf.try) && param.indexOf.try > -1) {
maxTry = param.indexOf.try;
}
let tryt = maxTry;
while (tryt > 0 && target.length <= 0) {
// console.log('find node try down',tryt,target.length);
this.doSwipe({}, { count: 1 });
target = this.build(mark).find();
tryt--;
}
// 找到了处理一下
if (target.length > 0) {
if (typeof param.indexOf === 'number') {
//取多个里的指定个
if (param.indexOf == -1 || param.indexOf >= target.length) {
target = target[target.length - 1];
} else {
target = target[param.indexOf];
}
} else if (typeof param.indexOf === 'object'
&& typeof param.indexOf.get === 'object'
) {
if (!Utils.isNull(param.indexOf.tag)) {
let str = this.doGet(param.indexOf.get);
// console.log('find node str:',str);
target = eval('target.findOne(' + param.indexOf.tag + "(str))");
} else if (!Utils.isNull(param.indexOf.default)) {
let str = param.indexOf.default;
target = eval('target.findOne(' + param.indexOf.tag + "(str))");
} else {
target = target[0];
}
} else {
target = target[0];
}
} else {
target = null;
}
//移动一段距离
while (maxTry - tryt > 0) {
// console.log('find node try up',tryt);
this.doSwipe({}, { count: 1, isUp: true });
tryt++;
}
return target;
},
/**
* 调用click执行点击操作,OK
* @param {*} mark
* @param {*} param
*/
doClick: function (mark, param) {
console.log('do click');
let target = this.findNode(mark, param);
if (!!target) {
if (target.clickable()) {
return target.click();
} else {
if (!!param && param.clickChild) {
return this.clickChild(target);
} else {
return this.clickParent(target);
}
}
} else {
console.log('not do click');
}
return false;
},
/**
* 调用tap点击界面,OK
* @param {*} mark
* @param {*} param
*/
doTap: function (mark, param) {
console.log('do tap');
let target = this.findNode(mark, param);
if (!!target) {
Tap(target.bounds().centerX(), target.bounds().centerY());
sleep(500);
Tap(target.bounds().centerX() + 1, target.bounds().centerY()) + 1;
Tap(target.bounds().centerX() - 1, target.bounds().centerY()) - 1;
Tap(target.bounds().centerX() + 2, target.bounds().centerY()) + 2;
Tap(target.bounds().centerX() - 2, target.bounds().centerY()) - 2;
return true;
} else {
console.log('not do tap');
}
return false;
},
/**
* 一个一个输入到控件,OK
* @param {*} mark
* @param {*} param
*/
doInput: function (mark, param) {
console.log('do input');
let target = this.findNode(mark, param);
if (!!target) {
Tap(target.bounds().centerX(), target.bounds().centerY());
sleep(1000);
// let tp = 'code';
// let str = '';
// if(!!param && !Utils.isNull(param.type)){
// tp = param.type;
// }
// if( tp == 'reply'){
// str = Api.postReplyMsg();
// }else{
// str = Api.getCode();
// }
let name = "login_code";
if (!!param && !Utils.isNull(param.get)) {
name = param.get;
}
// let str = Api.postReplyMsg();
let str = this.doGet(name);
if (!!str) {
let strArray = str.split("")
if (strArray.length > 0) {
setText(strArray[0]);
}
for (let i = 1; i < strArray.length; i++) {
let char = strArray[i];
input(char);
sleep(random(1000, 1500));
}
return true;
}
} else {
console.log('not do input');
}
return false;
},
/**
* 设置控件内容,OK
* @param {*} mark
* @param {*} param
*/
doSetText: function (mark, param) {
console.log('do set text');
let target = this.findNode(mark, param);
if (!!target) {
let name = { name: 'comment' };
if (!!param && !Utils.isNull(param.get)) {
name = param.get;
}
// let str = Api.postReplyMsg();
let str = this.doGet(name);
if (!!str) {
return target.setText(str);
}
} else {
console.log('not do set text');
}
return false;
},
/**
* 获取控件text内容,OK
* @param {*} mark
* @param {*} param
*/
doText: function (mark, param) {
console.log('do text');
let target = this.findNode(mark, param);
if (!!target) {
let name = { name: "title_content" };
if (!!param && !Utils.isNull(param.set)) {
name = param.set;
}
let str = target.text();
this.doSet(name, { default: str });
console.log(str.substr(0, 100));
return str;
} else {
console.log('not do text');
}
return null;
},
/**
* 获取控件desc内容,OK
* @param {*} mark
* @param {*} param
*/
doDesc: function (mark, param) {
console.log('do desc');
let target = this.findNode(mark, param);
if (!!target) {
Env.curTitleContent = target.desc();
console.log(Env.curTitleContent.substr(0, 100));
return target.desc();
} else {
console.log('not do desc');
}
return null;
},
/**
* 向下滚动,OK
* @param {*} mark
* @param {*} param
*/
doSwipe: function (mark, param) {
//滚动
console.log('do swipe');
let rx = random(200, 400);
let rm = -1;
if (!!param && !Utils.isNull(param.count) && param.count > -1) {
rm = parseInt(param.count);
}
if (rm == -1 || rm == undefined || rm == null || rm == "") {
rm = random(1, 3);
}
let isUp = false;
if (!!param && !Utils.isNull(param.isUp)) {
isUp = param.isUp;
}
while (rm > 0) {
console.log('swipe:' + rm, isUp);
if (isUp) {
Swipe(rx + random(0, 25), 180 + random(0, 100), rx + random(0, 29), 580 + random(0, 158), 200 + random(0, 200));
} else {
Swipe(rx + random(0, 29), 580 + random(0, 158), rx + random(0, 25), 180 + random(0, 100), 200 + random(0, 200));
}
sleep(random(500, 1000));
rm -= 1;
}
return true;
},
/**
* 刷新页面,Ok
*/
doRefresh: function (mark, param) {
console.log('do refresh');
//下拉刷新
Swipe(310, 250, 310, 600);
// Swipe(310 + random(0, 5), 400 + random(0, 15), 310 + random(0, 25), 700 + random(0, 10));
sleep(1000 + random(0, 2000));
return true;
},
/**
* 执行回退操作,Ok
* @param {*} mark
* @param {*} param
*/
doBack: function (mark, param) {
console.log('do back');
back();
return true;
},
/**
* 执行sleep,OK
* @param {*} mark
* @param {*} param
*/
doSleep: function (mark, param) {
let rm = -1;
if (!!param && !Utils.isNull(param.delay) && param.delay > -1) {
rm = parseInt(param.delay);
}
if (rm == -1 || rm == undefined || rm == null || rm == "") {
rm = random(1000, 2000);
}
console.log('do sleep', rm);
sleep(rm);
return true;
},
doEnter: function () {
console.log('do enter');
KeyCode("KEYCODE_ENTER");
},
/**
* 等待控件出现
* @param {*} mark
* @param {*} param
*/
doWait: function (mark, param) {
console.log('do wait for');
let target = this.build(mark);
let msg = 'Wait For';
if (!Utils.isNull(mark.text)) {
msg += ':Text:' + mark.text;
}
if (!Utils.isNull(mark.desc)) {
msg += ':Desc:' + mark.desc;
}
if (!Utils.isNull(mark.id)) {
msg += ':Id:' + mark.id;
}
console.log(msg);
toast(msg);
return target.waitFor();
},
/**
* 执行shell命令
* @param {*} mark
* @param {*} param
*/
doShell: function (mark, param) {
console.log('do shell');
let rs = { code: -1 };
// console.log(JSON.stringify(param));
if (!!param && !Utils.isNull(param.cmd)) {
let root = false;
if (!Utils.isNull(param.root) && param.root === true) {
root = true;
}
rs = shell(param.cmd, root);
if (rs.code == 0) {
console.log("run shell success", JSON.stringify(rs));
} else {
console.log("run shell failed", JSON.stringify(rs));
}
}
return rs.code == 0;
},
/**
* 点击指定图片
* @param {*} mark
* @param {*} param
*/
doImage: function (mark, param) {
console.log('do image');
let img = null;
try {
if (!Utils.isNull(mark.path)) {
console.log('image read from path');
if (files.isFile(mark.path))
img = images.read(mark.path)
}
if (!Utils.isNull(mark.base64)) {
console.log('image from base64');
img = images.fromBase64(mark.base64);
}
if (!Utils.isNull(mark.url)) {
console.log('image load from url');
img = images.load(mark.url);
}
if (img != null) {
let p = findImage(captureScreen(), img);
if (p) {
let x = p.x + img.getWidth() / 2;
let y = p.y + img.getHeight() / 2;
console.log("find image: ", p, img.getWidth(), img.getHeight(), x, y);
if(!!param && !Utils.isNull(param.action) && Utils.titleCase(param.action) == 'Tap'){
Tap(x, y);
sleep(1000);
}
return true;
} else {
console.log("not find image");
return false;
}
}
console.log("not find image");
return false;
} catch (error) {
console.log("do image in catch", error);
return false;
}
},
/**
*
* 根据传入的属性,判断对应的节点是否存在,OK
*
* @param {*} mark
*/
doExists: function (mark, param) {
// console.log('do exists');
if (!Utils.isNull(mark.name)) {
return this.doFun(mark);
// return eval('this.do'+Utils.titleCase(mark.name)+'(mark.mark, param)');
} else {
let target = this.build(mark);
// console.log(this.build(mark).exists());
return !!target ? target.exists() : false;
}
},
/**
* 点击父控件,OK
* @param {*} target
*/
clickParent: function (target) {
if (!!target) {
let count = target.depth();
// console.log('depth:'+count);
while (count > 0 && target != null) {
if (target.clickable()) {
target.click();
count = -1;
break;
} else {
if (!!target.parent()) {
target = target.parent();
count -= 1;
} else {
count = -1;
break;
}
}
}
if (count == -1) {
return true;
}
} else {
console.log('not click parent');
}
return false;
},
/**
*
* 点击子控件
*
* @param {*} target
*/
clickChild: function (target) {
if (!!target) {
if (target.clickable()) {
return target.click();
} else {
target.children().forEach(child => {
if (child.clickable()) {
return child.click();
}
});
}
} else {
console.log('not click child');
}
return false;
},
/**
* 设置全局变量
* @param {*} mark
* @param {*} param
*/
doSet: function (mark, param) {
console.log('do set');
if (!!mark && !Utils.isNull(mark.name)) {
let valName = "cur" + Utils.titleCase(mark.name);
let value = '';
if (!!param && !Utils.isNull(param.default)) {
value = param.default;
}
return eval("Env." + valName + "=value;");
}
return null;
},
/**
* 获取全局变量的内容或者调用指定API获取内容并设置全局变量
* @param {*} mark
* @param {*} param
*/
doGet: function (mark, param) {
console.log('do get');
if (!!mark && !Utils.isNull(mark.name)) {
let valName = "Env.cur" + Utils.titleCase(mark.name);