behave+uiautomator2+jenkins
同理,Behave也可以和Appium/AirTest框架结合
运行环境
pip install uiautomator2 behave behave2cucumber
意事项:behave版本号建议=1.2.5,因为1.2.6和Jenkins Cucumber Report插件不兼容
生成报告
html报告
behave -f behave_html_formatter:HTMLFormatter -o report.html
allure报告
behave -f allure_behave.formatter:AllureFormatter -o allure-results
allure generate allure-results -o allure_html
Jenkins配置
安装插件:Cucumber reports&Post build task
配置步骤
定时任务
H 20 * * *
cd /Users/wan/PycharmProjects/Downloader
venv/bin/behave --lang=zh-CN -f json.pretty -o './test_report.json'
/Users/wan/PycharmProjects/Downloader/report
#!/bin/bash
FEISHU_WEBHOOK_URL="your url"
JOB_NAME="$JOB_NAME"
BUILD_NUMBER="$BUILD_NUMBER"
BUILD_URL="$BUILD_URL"
EXIT_STATUS="$?"
BUILD_RESULT=""
if [ $EXIT_STATUS -eq 0 ]; then
BUILD_RESULT="成功"
else
BUILD_RESULT="失败"
fi
BUILD_TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
PAYLOAD="{
\"msg_type\": \"interactive\",
\"card\": {
\"config\": {
\"wide_screen_mode\": true
},
\"header\": {
\"title\": {
\"content\": \"Downloader网站回归测试结果\",
\"tag\": \"plain_text\"
}
},
\"elements\": [
{
\"tag\": \"div\",
\"text\": {
\"content\": \"**项目:** $JOB_NAME\\n**构建号:**$BUILD_NUMBER\\n**构建结果:** $BUILD_RESULT\\n**构建时间:**$BUILD_TIMESTAMP\",
\"tag\": \"lark_md\"
}
},
{
\"tag\": \"action\",
\"actions\": [
{
\"tag\": \"button\",
\"text\": {
\"content\": \"查看详情\",
\"tag\": \"plain_text\"
},
\"type\": \"primary\",
\"url\": \"$BUILD_URL\"
}
]
}
]
}
}"
curl -X POST -H "Content-Type: application/json" -d "$PAYLOAD" "$FEISHU_WEBHOOK_URL"