整体架构
STF
在独立的机器上部署STF与设备集群
STF的远程连接脚本
localhost:0622_9 seveniruby$ cat stf.sh
#!/usr/bin/env bash
#STF_TOKEN=9d06d1b4dae94c88863138bac8bf50369be151b812a44215b19e0b4f137b13fb
STF_TOKEN=fa46cb5aff944731a5cf88491b5b02a54125c9711d3741c2b160e3ceaea3928d
#STF_URL=http://localhost:7100
STF_URL=http://192.168.1.50: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 '"')
#增加一个拉取的设备名字的变量,方便后面并行执行
remote_device=$(echo "$response" | jq .remoteConnectUrl | 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
}
Jenkins
搭建jenkins,(Jenkins课程会独立教)
docker run -d --name jenkins_9 -p 8080:8080 -p 50000:50000 -v /Users/seveniruby/jenkins/9:/var/jenkins_home jenkins/jenkins
- 添加某个pc为jenkins的节点
创建多配置任务
cd /Users/seveniruby/temp/appcrawler/0622_9
ls
. stf.sh
DEVICE_SERIAL=$device
add_device
remote_connect
sleep 2
adb devices
echo remote_device=$remote_device
adb -s $remote_device install -r ~/Downloads/xueqiu_wxdialog.apk
java -jar appcrawler-2.4.0-jar-with-dependencies.jar -c demo_1.yml --capability "udid=$remote_device,systemPort=1${remote_device#*:}"
adb disconnect $remote_device
remove_device
并行运行appium
-
appium支持多连接
-
自动遍历要指定设备