我是用python+pytest+allure+Jenkins跑的UI自动化用例,Jenkins是用的本地结果就是生成的allure测试报告通过Jenkins邮件发送后别人不能访问,现在想法是生成一个HTML的测试报告通过Jenkins邮件发送出去别人就可以在浏览器访问HTML的测试报告了,在Jenkins里用的是groovy的邮件模板,希望有人能帮助我这个newcomer指导一下Jenkins要怎么设置,代码怎么写尽量详细。
这是jenkins上cmd命令:
d:
cd D:\pythondir\pomoa\test_cases
call python -m pytest test_oacase.py --alluredir=C:\Users\58305\.jenkins\workspace\OA门户自动化拨测\allure-result --clean-alluredir
exit 0
这是我使用的groovy模板:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<style type="text/css">
/*base css*/
body
{
margin: 0px;
padding: 15px;
}
body, td, th
{
font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Tahoma, sans-serif;
font-size: 10pt;
}
th
{
text-align: left;
}
h1
{
margin-top: 0px;
}
a
{
color:#4a72af
}
/*div styles*/
.status{background-color:<%=
build.result.toString() == "SUCCESS" ? 'green' : 'red' %>;font-size:28px;font-weight:bold;color:white;width:720px;height:52px;margin-bottom:18px;text-align:center;vertical-align:middle;border-collapse:collapse;background-repeat:no-repeat}
.status .info{color:white!important;text-shadow:0 -1px 0 rgba(0,0,0,0.3);font-size:32px;line-height:36px;padding:8px 0}
</style>
<body>
<div class="content round_border">
<div class="status">
<p class="info">The build <%= build.result.toString().toLowerCase() %></p>
</div>
<table>
<tbody>
<tr>
<th>项目名称:</th>
<td>${project.name}</td>
</tr>
<tr>
<th>触发原因:</th>
<%
cause = build.getCause(hudson.model.Cause.UserIdCause.class)
if (cause != null) {
user_name = cause.getUserName()
} else {
user_name = 'fuhao'
}
%>
<td>Started by ${user_name} </td>
</tr>
<tr>
<th>构建编号 ${build.displayName}:</th>
<td><a
href="${rooturl}${build.url}">${rooturl}${build.url}</a></td>
</tr>
<tr>
<th>构建时间:</th>
<td>${it.timestampString}</td>
</tr>
<tr>
<th>构建耗时:</th>
<td>${build.durationString}</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</tbody>
</table>
<% def artifacts = build.artifacts
if(artifacts != null && artifacts.size() > 0) { %>
<b>离线报告:</b>
<ul>
<% artifacts.each() { f -> %>
<li><a href="${rooturl}${build.url}artifact/${f}">${f}</a></li>
<% } %>
</ul>
<% } %>
<%
lastAllureReportBuildAction = build.getAction(ru.yandex.qatools.allure.jenkins.AllureReportBuildAction.class)
lastAllureBuildAction = build.getAction(ru.yandex.qatools.allure.jenkins.AllureBuildAction.class)
if (lastAllureReportBuildAction) {
allureResultsUrl = "${rooturl}${build.url}allure"
allureLastBuildSuccessRate = String.format("%.2f", lastAllureReportBuildAction.getPassedCount() * 100f / lastAllureReportBuildAction.getTotalCount())
}
%>
<% if (lastAllureReportBuildAction) { %>
<h2>测试结果</h2>
<table>
<tbody>
<tr>
<th>执行用例数:</th>
<td><a href="${allureResultsUrl}">${lastAllureReportBuildAction.getTotalCount()}</a></td>
</tr>
<tr>
<th>失败:</th>
<td>${lastAllureReportBuildAction.getFailedCount()} </td>
</tr>
<tr>
<th>成功:</th>
<td>${lastAllureReportBuildAction.getPassedCount()} </td>
</tr>
<tr>
<th>跳过:</th>
<td>${lastAllureReportBuildAction.getSkipCount()} </td>
</tr>
<tr>
<th>故障:</th>
<td>${lastAllureReportBuildAction.getBrokenCount()} </td>
</tr>
<tr>
<th>通过率: </th>
<td>${allureLastBuildSuccessRate}% </td>
</tr>
</tbody>
</table>
<%
String auth = "jeevan" + ":" + "Fuhaoking7"; byte[] encodedAuth = auth.bytes.encodeBase64().toString(); String authHeaderValue = "Basic " + new String(encodedAuth);
content=new URL("${allureResultsUrl}/graph").getBytes( useCaches: true, allowUserInteraction: false, requestProperties: ["User-Agent": "Groovy Sample Script","Authorization": authHeaderValue])
%>
<img src="data:image/png;base64, ${content.encodeBase64().toString()}"/>
<% } %>
</body>