常见的测试工具与平台
- Android测试设备管理:STF
- Android与iOS任务调度:Selenium Grid
- 持续集成平台:Jenkins
- 测试报告框架:Allure2
STF
-
面向自动化测试:远程调试功能是常用的功能
-
手工测试:交互调试
STF API
#!/usr/bin/env bash
# set -euxo pipefail
DEVICE_SERIAL=emulator-5554
STF_URL=http://localhost:7100
STF_TOKEN=34982fcd4c0c4f6cb2f5bb82222655a98ec3c690e7854d4ebcd00eb88125d795
if [ "$DEVICE_SERIAL" == "" ]; then
echo "Please specify device serial using ENV['DEVICE_SERIAL']"
return 1
fi
if [ "$STF_URL" == "" ]; then
echo "Please specify stf url using ENV['STF_URL']"
return 1
fi
if [ "$STF_TOKEN" == "" ]; then
echo "Please specify stf token using using ENV['STF_TOKEN']"
return 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"
return 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"
return 1
fi
remote_connect_url=$(echo "$response" | jq .remoteConnectUrl | tr -d '"')
adb connect $remote_connect_url
echo "Device $DEVICE_SERIAL remote connected successfully"
}
function remote_disconnect() {
local remote_device=$(curl -H "Authorization: Bearer $STF_TOKEN" \
$STF_URL/api/v1/user/devices |
jq -c '.devices[]|[.remoteConnectUrl,.serial]' |
awk -F\" -v serial=$DEVICE_SERIAL '$4==serial{print $2}')
[ -n "$remote_device" ] && adb disconnect $remote_device
}
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"
return 1
fi
echo "Device $DEVICE_SERIAL removed successfully"
}
function udid() {
DEVICE_SERIAL=$1
}
for p in "$@"; do
$p
done
测试流程
- 申请设备
- 申请远程连接
- udid=xxx pytest xxxx
- 释放远程连接
- 释放设备
Selenium Grid
- grid下载地址 https://www.selenium.dev/downloads/
用途:
- Central entry point for all tests
- Management and control of the nodes / environment where the browsers run
- Scaling
- Running tests in parallel
- Cross platform testing
- Load balancing
node的匹配规则
grid如何找node, 首先node先找hub注册。注册的时候表示了自己的capability。
client运行脚本的时候,也会发送一个脚本里的capability。
node的capability与client的capability必须对应。如果client里声明了一个capability在node中没有,那么就不会选择任何node
client的设备选择
- 如果没有udid,那么默认选择adb devices列表的第一个
- 如果有,那么就执行特定的udid,找不到就报错。udid可以通过环境变量传递到脚本中
udid=os.getenv("udid", None)
if udid is not None:
caps["udid"] = os.getenv("udid", "")
测试流程
- 为每台设备注册一个节点
- 节点注册到hub
- udid=xxx pytest xxxx
grid与stf的特点对比
用例执行 | 设备 | 自动化引擎 | 方案 | 特点 |
---|---|---|---|---|
远程上传 | 远程 | 远程 | 国内云测试方案 | 分析使用不方便 |
本地运行 | 远程 | 远程 | Selenium Grid方案,国外云测试服务的主要方式 | 只适合自动化 |
本地运行 | 远程 | 本地运行 | STF方案 | 手工测试也可以执行 |
jenkins
- jenkins STF插件 简单的并行串行,不支持用例的分布式运行
- 使用jenkins slave来代表node,可以很好的支持分布式运行
课后作业
用stf
1、至少2台模拟器,并行运行自动遍历
2、至少2太模拟器,并行运行po的用例
todo:分布式执行在后面再给大家演示
课程连接
Python 测试开发从入门到高级实战系统进阶课程_霍格沃兹测试学院
第11期——移动⾃动化测试平台价值
Python 测试开发从入门到高级实战系统进阶课程_霍格沃兹测试学院
第11期——技术架构与智能设备选型
Python 测试开发从入门到高级实战系统进阶课程_霍格沃兹测试学院
第11期——多设备管理平台STF
Python 测试开发从入门到高级实战系统进阶课程_霍格沃兹测试学院
第11期——Selenium Grid⽅案