我们使用mail-ext和robot框架工作来尝试以jenkins格式格式化所有测试服细节,并发送报告。
这是我们现在使用的普通电子邮件模板,它是从github https://github.com/JMcn/jenkins-email-ext-templates/blob/master/robot.groovy下载的。
但是此模板报告了以下异常情况,如下所示,我没有通过谷歌搜索得到类似的错误,我们为此模板遗漏了任何东西,感谢对此错误的任何提示。
<%
import java.text.DateFormat
import java.text.SimpleDateFormat
%>
........
<!-- System Test Result -->
<%
def robotResults = false
def actions = build.actions // List<hudson.model.Action>
def robotTestResultAction = it.getAction("hudson.plugins.robot.RobotBuildAction")
actions.each() { action ->
if( robotTestResultAction != null ) {
//if( action && (action.class.simpleName.equals("RobotBuildAction") ) ) {
robotResults = true
%>
<TABLE width="100%">
<TR><TD class="bg1" colspan="4"><B>test results</B></TD></TR>
<TR style="border:1px solid #000;height:25px">
<TD>total</TD>
<TD>passed</TD>
<TD>failure</TD>
<TD>passrate</TD></TR>
<TR style="border:1px solid #000;height:25px">
<TD>${robotTestResultAction.getTotalCount()}</TD>
<TD style="color:green"><%=robotTestResultAction.getTotalCount() - robotTestResultAction.getFailCount()%></TD>
<TD style="color:red"><a style="color:red" href="${rooturl}${build.url}/${robotTestResultAction.urlName}">${robotTestResultAction.getFailCount()}</a></TD>
<TD>${robotTestResultAction.overallPassPercentage}%</TD></TR>
</TABLE>
<TABLE cellspacing="0" cellpadding="4" border="1" align="center">
<thead>
<tr bgcolor="#F3F3F3">
<td><b>test case name </b></td>
<td><b>state</b></td>
<td><b>execute duration</b></td>
</tr>
</thead>
<tbody>
<% def suites = action.result.allSuites
suites.each() { suite ->
def currSuite = suite
def suiteName = currSuite.displayName
// ignore top 2 elements in the structure as they are placeholders
while (currSuite.parent != null && currSuite.parent.parent != null) {
currSuite = currSuite.parent
suiteName = currSuite.displayName + "." + suiteName
} %>
<tr><td colspan="3"><b><%= suiteName %></b></td></tr>
<% DateFormat format = new SimpleDateFormat("yyyyMMdd HH:mm:ss.SS")
def execDateTcPairs = []
suite.caseResults.each() { tc ->
Date execDate = format.parse(tc.starttime)
execDateTcPairs << [execDate, tc]
}
// primary sort execDate, secondary displayName
execDateTcPairs = execDateTcPairs.sort{ a,b -> a[1].displayName <=> b[1].displayName }
execDateTcPairs = execDateTcPairs.sort{ a,b -> a[0] <=> b[0] }
execDateTcPairs.each() {
def execDate = it[0]
def tc = it[1] %>
<tr>
<td><%= tc.displayName %></td>
<td style="color: <%= tc.isPassed() ? "#66CC00" : "#FF3333" %>"><%= tc.isPassed() ? "PASS" : "FAIL" %></td>
<td><%= execDate %></td>
</tr>
<% } // tests
} // suites %>
</tbody>
</TABLE>
<%
} // robot results
}
if (!robotResults) {
%>
<TABLE width="100%">
<TR><TD class="bg1" colspan="2"><B>接口测试结果</B></TD></TR>
<TR><TD colspan="2">robotTestResultAction is null</TD></TR>
</TABLE>
<%
}
%>
<BR/>
在模板呈现期间引发的异常:无此类属性:类结果:hudson.model.CauseAction groovy.lang.MissingPropertyException:无此类属性:类结果:hudson.model.CauseAction位于org.codehaus.groovy.runtime。 org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:66)上的ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)在org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGet() 296)在
使用KrzysztofBłażełek的建议调整脚本后,出现以下错误。
<!-- System Test Result -->
<%
def robotResults = false
def actions = build.actions // List<hudson.model.Action>
//def robotTestResultAction = it.getAction("hudson.plugins.robot.RobotBuildAction")
actions.each() { action ->
//if( robotTestResultAction != null ) {
if( action && (action.class.simpleName.equals("RobotBuildAction") ) ) {
robotResults = true
在模板呈现期间引发的异常:无法在空对象java.lang.NullPointerException上获取属性“ simpleName”:在org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java: 60)在org.codehaus.groovy.runtime的org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:47)的org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174) .callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)at SimpleTemplateScript211 $ _run_closure6.doCall(SimpleTemplateScript211.groovy:403)at sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)....
答案 0 :(得分:1)
您已经修改了提供的模板,这会导致问题。我相信您正在遍历所有操作(不仅是hudson.plugins.robot.RobotBuildAction
),而且这是导致异常的原因。尝试更改此部分:
<!-- System Test Result -->
<%
def robotResults = false
def actions = build.actions // List<hudson.model.Action>
def robotTestResultAction = it.getAction("hudson.plugins.robot.RobotBuildAction")
actions.each() { action ->
if( robotTestResultAction != null ) {
//if( action && (action.class.simpleName.equals("RobotBuildAction") ) ) {
robotResults = true
%>
进入
<!-- System Test Result -->
<%
def robotResults = false
def actions = build.actions // List<hudson.model.Action>
actions.each() { action ->
if( action && (action.class.simpleName.equals("RobotBuildAction") ) ) {
robotResults = true
def robotTestResultAction = action
%>
您的代码需要重构,但这是测试代码是否有效的最快方法。