Appium Grid
- https://github.com/SeleniumHQ/selenium/wiki/Grid2
- http://selenium-release.storage.googleapis.com/index.html
- https://www.seleniumhq.org/download/
启动hub server
java -jar selenium-server-standalone-3.141.59.jar -role hub
Appium注册
Android设备注册
{
"capabilities":
[
{
"browserName": "android",
"version": "6.0",
"maxInstances": 1,
"platformName": "android",
"abc": "1",
"platformVersion": "6.0"
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"register": true,
"registerCycle": 5000,
"hubPort": 4444,
"hubHost": "127.0.0.1",
"hubProtocol": "http"
}
}
iOS设备注册
{
"capabilities":
[
{
"browserName": "ios",
"version": "11.0.1",
"maxInstances": 1,
"deviceName":"iPhone 8",
"platform":"ios"
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"register": true,
"registerCycle": 5000,
"hubPort": 4444,
"hubHost": "127.0.0.1",
"hubProtocol": "http"
}
}
启动命令
appium --nodeconfig node_android_1208.json
appium --nodeconfig node_android_1208.json -p 5723
作业1
注册Android与iOS设备到hub并截图
Jenkins
用例执行机器
- monkey https://developer.android.com/studio/test/monkey
- 自动遍历工具做回归测试
- appium测试用例
基本的STF服务申请设备的使用流程
#申请占用设备
add_device
#连接远程的adb
remote_connect
#查看adb是否连接成功
adb devices
#安装雪球
adb install -r /Users/seveniruby/Downloads/com.xueqiu.android_11.10.2_190.apk
#启动monkey操作
adb shell monkey -p com.xueqiu.android --throttle 500 --pct-motion 100 200
#释放adb
adb disconnect
#释放设备
remove_device
改进已有的AppCrawler或者Appium的脚本支持批量设备执行
- hub地址更新
- capabilities匹配
- 测试用例的capabilities设置动态从环境变量获取
STF
#!/usr/bin/env bash
set -euxo pipefail
if [ "$DEVICE_SERIAL" == "" ]; then
echo "Please specify device serial using ENV['DEVICE_SERIAL']"
exit 1
fi
if [ "$STF_URL" == "" ]; then
echo "Please specify stf url using ENV['STF_URL']"
exit 1
fi
if [ "$STF_TOKEN" == "" ]; then
echo "Please specify stf token using using ENV['STF_TOKEN']"
exit 1
fi
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"
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"
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"
exit 1
fi
echo "Device $DEVICE_SERIAL removed successfully"
}
并行执行
- appium并行 端口问题
- jenkins设置并行
- 设备并行
Appium Grid
作业2
搭建STF平台,并使用Jenkins使用多设备的自动化调度,把调度的截图和stf的截图恢复到帖子里,比如
作业3 拔高
使用Apium + selenium Grid 搭建android与iOS的集群