https://testerhome.com/topics/19410
Android 设备组合:
2.3 x
4.4 + 6.0 + 7.0 + 8.0 + 9.0
定制的ROM
iPad iPhone 只能穿戴
7.x 8.x 基本不用考虑
note:safari上打开一个网页时,打开开发者工具,切换设备型号可以大概看看webview兼容性问题
安装stf
#安装stf需要的环境。node版本不要太高,推荐node8
brew install rethinkdb graphicsmagick zeromq protobuf yasm pkg-config #安装stf
npm install -g stf
搭建一个localhost的
#放在后台
rethinkdb & #开启一个简单的本地开发环境
stf local --public-ip=0.0.0.0
浏览器里打开localhost:7100
输入LvT16/849286651@qq.com
在命令行输入 adb connect 0.0.0.0:7401,在stf控制台点击add key。adb connect可以获取更多的权限。
问题:adb connect一直失败,去settings里把key删除,再adb connect就成功了
然后用adb devices查看,就可以发现该设备已经连接。此时该设备无法Stop Using,如果要关闭,先adb disconnect,然后在stf控制台点击Stop Using。
stf的api
通过以下命令访问stf的api,参考: https://vbanthia.github.io/angular-swagger-ui/
https://github.com/openstf/stf/blob/master/doc/API.md
#stf上获取token:Settings->Keys
token: 77e827b526d84693938abd59dad7953aa15e650a4a6c44a58ded9c78528beb0f
# 访问stf的api
curl -H "Authorization: Bearer c56ba52bfbc34cd7952c5be3dfea5f5eb5951c7a85da4a1189e691901921f5d1" http://0.0.0.0:7100/api/v1/user
#jq是显示json的工具
curl -H "Authorization: Bearer c56ba52bfbc34cd7952c5be3dfea5f5eb5951c7a85da4a1189e691901921f5d1" https://localhost:7100/api/v1/devices | jq
demo脚本
vim stf.sh
neros-MacBook-Pro-2:stf nero$ cat stf.sh #!/usr/bin/env bash STF_TOKEN=c56ba52bfbc34cd7952c5be3dfea5f5eb5951c7a85da4a1189e691901921f5d1 STF_URL=http://0.0.0.0:7100 DEVICE_SERIAL="demo" function add_device { response=$(curl -X POST -H "Content-Type: application/json" \ -H "Authorization: Bearer $STF_TOKEN" \ --data "{\"serial\": \"$DEVICE_SERIAL\"}" $STF_URL/api/v1/user/devices) success=$(echo "$response" | jq .success | tr -d '"') description=$(echo "$response" | jq .description | tr -d '"') if [ "$success" != "true" ]; then echo "Failed because $description" echo exit 1 fi echo "Device $DEVICE_SERIAL added successfully" } function remote_connect { response=$(curl -X POST \ -H "Authorization: Bearer $STF_TOKEN" \ $STF_URL/api/v1/user/devices/$DEVICE_SERIAL/remoteConnect) success=$(echo "$response" | jq .success | tr -d '"') description=$(echo "$response" | jq .description | tr -d '"') if [ "$success" != "true" ]; then echo "Failed because $description" echo exit 1 fi remote_connect_url=$(echo "$response" | jq .remoteConnectUrl | tr -d '"') adb connect $remote_connect_url echo "Device $DEVICE_SERIAL remote connected successfully" } function remove_device { response=$(curl -X DELETE \ -H "Authorization: Bearer $STF_TOKEN" \ $STF_URL/api/v1/user/devices/$DEVICE_SERIAL) success=$(echo "$response" | jq .success | tr -d '"') description=$(echo "$response" | jq .description | tr -d '"') if [ "$success" != "true" ]; then echo "Failed because $description" echo exit 1 fi echo "Device $DEVICE_SERIAL removed successfully" } every_device(){ #获得可用设备列表 devices=$(curl -H "Authorization: Bearer $STF_TOKEN" $STF_URL/api/v1/devices | jq -r '.devices[] | select(.present==true)|.serial ') for DEVICE_SERIAL in $devices do add_device remote_connect sleep 2 device=$(adb devices | grep : | awk '{print $1}' | head -1) adb devices eval $1 adb disconnect $device sleep 2 adb devices remove_device done }
#创建完stf.sh后,分别输入以下命令
. stf.sh DEVICE_SERIAL=emulator-5554 add_device
此时设备在stf控制台上的状态是“Stop Automation”,继续永兴以下代码
remote_connect
此时用adb devices可以发现远程的设备已经连接到本地
想要断开设备,输入以下命令
528 adb disconnect 0.0.0.0:7409 529 remove_device 530 adb devices
Monkey
adb -s emulator-5554 shell monkey -p com.google.android.dialer 1000
#把可用的设备轮流使用一遍
every_device "echo device=\$device"
#在所有可用设备上轮流跑一遍Monkey,1000次事件。包名不一定在所有设备上都通用
every_device "adb -s \$device shell monkey -p com.google.android.dialer 1000"
#在所有设备上轮流安装app
every_device "adb -s \$device install -r ~/Documents/lv/xueqiu_wxdialog.apk"
#在所有设备上轮流给app跑Monkey
every_device "adb -s \$device shell monkey -p com.xueqiu.android 1000"
学习自赫格沃滋-思寒