一.制作一个能双击执行的mac command指令

  1. Mac快捷键comand+空格,输入terminals打开terminals
  2. 输入touch 文件名.command
touch test.command
  1. 用文本编辑器打开刚刚生成的shell文件,输入想要执行的操作,比如
adb uninstall 应用包名
  1. 让文件有执行权限
chmod +x  test.command的文件路径

二.优雅地使用adb模拟点击来实现应用半自动登录

  1. 常用几种adb模拟命令
adb shell input tap 200 300  //点击(200,300)坐标点(假设该点就是跳转按钮所在位置)
adb shell input text "hello,world" 模拟输入文本(text)
adb shell input keyevent 4  触发enter键
  1. 打开手机设置-其他设置-开发者选项-打开指针位置,获取对应点击位置的坐标
  2. 将所有路径点击和输入写到文件
#点击app的我的
adb shell input tap 936 2321
#点击头像
adb shell input tap 144 258

sleep 1s 
#点击账号密码
adb shell input tap 659 2149
#点击用户名
adb shell input tap 168 732

adb shell input text "159****8917"
#点击密码
adb shell input tap 168 950

adb shell input text "你的密码"
#点击同意
adb shell input tap 114 1292
#点击登录
adb shell input tap 568 1123
  1. 按照上面的制作一个双击指令

三.设置mac电脑和手机的代理

1.手机端

开启Wi-Fi代理设置,有时候需要重新打开应用才能使用新代理;下面的8899是whistle的默认端口,可以更改
#!/bin/sh
ipconfig=`ifconfig | grep "inet " | grep -v 127.0.0.1`
temp=${ipconfig%%netmask*}
adb shell settings put global http_proxy ${ipconfig: 5:(${#temp}-6)}:8899

⚠️以上方式打开网络代理,并不会出现在网络里面的高级设置里面,所以这只能配合下面的重置网络代理使用

#关闭代理网络
adb shell settings put global http_proxy :0

2.mac端

#开启whistle,并打开代理
w2 start
networksetup -setsecurewebproxy 'Wi-Fi' 127.0.0.1 8899
networksetup -setwebproxy 'Wi-Fi' 127.0.0.1 8899
#当然也可以使用下面的,但是没有设置端口和ip
#networksetup -setsecurewebproxystate 'Wi-Fi' on
#networksetup -setwebproxystate 'Wi-Fi' on
#关闭网络
networksetup -setwebproxy "Wi-fi" off
networksetup -setwebproxystate 'Wi-Fi' off

四.安装指定路径最新下载的apk文件

#指定/Users/lihongyi16/Downloads/路径下筛选出apk后缀名的最新文件
filename=`ls -t /Users/lihongyi16/Downloads/ |grep ".apk" |head -n1|awk '{print $0}'`
#echo $filename
adb install "/Users/lihongyi16/Downloads/$filename"

⚠️需要配合插件Downloads Overwrite Already Existing Files使用,不然重复下载的文件后面的“ (1)”无法处理会抛出No #such file or directory问题

五.截取当前屏幕并推到电脑指定文件夹

#截取当前屏幕并推到电脑指定文件夹
currentTimeStamp=$(date +%s)
echo $currentTimeStamp
#截图保存到sd卡指定路径
adb shell screencap "/sdcard/screen-${currentTimeStamp}.png"
#将文件推到电脑指定文件
adb pull screencap "/sdcard/screen-${currentTimeStamp}.png" /Users/lihongyi16/体验问题截图/

六.其他一些常用命令

#数据清理
adb shell pm clear 包名
#卸载应用
adb uninstall 包名
#获取当前栈定activity
adb shell dumpsys activity top | grep ACTIVITY

遇到的问题

  1. oppo手机使用adb来设置网络代理的时候,会报权限问题如下
Exception occurred while executing 'put':
java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
	at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:2374)
	at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1413)
	at com.android.providers.settings.SettingsProvider.insertGlobalSetting(SettingsProvider.java:1367)
	at 
	。。。

#解决办法:
设置-其他设置-开发者选项-打开禁止权限监控