Yug*_*hou 7 junit android gradle android-gradle-plugin
我正在为Android应用程序开发验收测试.android gradle插件为测试生成了漂亮的html报告.现在我想自定义报告,将屏幕截图链接嵌入到失败测试用例中,如下所示:

这是我目前的解决方案:
在生成报告后,按adb拉取屏幕截图并装饰html报告
task fetchScreenshots(type: Exec) {
executable "adb"
args "pull",
"/sdcard/Robotium-Screenshots/",
"${buildDir}/outputs/reports/androidTests/connected/Robotium-Screenshots/"
}
task decoratingAndroidTestsHtmlReport << {
def screenshots = fileTree("${buildDir}/outputs/reports/androidTests/connected/Robotium-Screenshots")
screenshots.each { screenshot ->
def testName = screenshot.name.substring(0, screenshot.name.lastIndexOf("."))
def testClassName = testClassName(testName)
def testMethodName = testMethodName(testName)
def html = file("${buildDir}/outputs/reports/androidTests/connected/${testClassName}.html")
def patternToFind = "<h3 class=\"failures\">${testMethodName}</h3>"
def patternToReplace = "${patternToFind}<a href=\"Robotium-Screenshots/${screenshot.name}\">Screenshot</a>"
replacePatternInFile(html){
it.replaceAll(patternToFind, patternToReplace)
}
}
}
gradle.projectsEvaluated {
decoratingAndroidTestsHtmlReport.dependsOn(fetchScreenshots)
connectedAndroidTest {
finalizedBy decoratingAndroidTestsHtmlReport
}
}
Run Code Online (Sandbox Code Playgroud)
这种方法有效,但我认为这不是正确的方法.我认为修改html模板而不是黑客攻击html内容会更加清晰.但我没有找到开始的线索.
| 归档时间: |
|
| 查看次数: |
739 次 |
| 最近记录: |