最近再玩一个动物餐厅小游戏时,需要频繁点击手机,点击电台宣传来获得客户,后来想到是不是可以用脚本实现,自动点击呢,就想到了用adb 的input 命令,然后写成bat批处理执行。首先看下input有哪些用法,如下图:
text:输入字符串
例如: adb shell input text "123" 当前的焦点空间输入123
keyevent:输入键盘事件
例如:adb shell input keyevent "KEYCODE_POWER" 模拟点击电源按钮
tap: 点击指定位置,指定x,y坐标
例如:adb shell input tap 100 100 点击屏幕(100,100)的位置
屏幕的位置坐标可以在开发者选项中打开查看轨迹功能查看
swipe:滑动位置,模拟滑动手机,输入起点坐标(x,y),终点坐标(X1,Y1),以及滑动时间
例如:adb shell input swipe 100 100 200 200 300,从(100,100)滑动到(200,200),执行时间300毫秒
adb shell input swipe 100 100 100 100 300 长按300毫秒
rem 动物餐厅小程序点击宣传单代码
:abc
for /l %%i in (1,1,20) do (
rem 点击电台宣传
adb shell input tap 1000 1750
)
rem 点击第一桌的点菜
adb shell input tap 406 708
rem 点击第二桌的点菜
adb shell input tap 652 720
rem 点击第三桌的点菜
adb shell input tap 888 721
rem 点击第四桌的点菜
adb shell input tap 419 1028
rem 点击第五桌的点菜
adb shell input tap 658 1040
rem 点击第六桌的点菜
adb shell input tap 900 1050
goto abc
更多软件测试相关知识关注公众号:软件测试道与术