ANT调用的XML文件,包括运行脚本、生成报告、发送邮件:
<?xml version="1.0"?> <project name="morningstar" default="all" basedir="."> <property name="JMeter.home" value="......."/> <property name="mail_to" value="test.hu@qq.com,test.li@qq.com,test.bai@163.com"/> <property name="to_me_only" value="test.zhang@163.com"/> <tstamp> <format property="time" pattern="yyyyMMddhhmm"/> </tstamp> <target name="all" > <antcall target="runClient"/> <antcall target="transferAll"/> <antcall target="transferFailure"/> <antcall target="sendEmail"/> </target> <target name="runClient" depends=""> <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/> <jmeter jmeterhome="${JMeter.home}" resultlog="${basedir}/Result/CIMAutoTestReport${time}.jtl"> <testplans dir="${basedir}ScriptSmokeTest" includes="CIM_ClientProspect_SmokeTest_TP.jmx"/> </jmeter> </target> <target name = "transferAll" depends = ""> <xslt in="${basedir}/Result/CIMAutoTestReport${time}.jtl" out="${JMeter.home}/extras/CIMAutoTestReport${time}.html" style="${JMeter.home}/extras/JMeter-results-detail-report_21.xsl"/> </target> <target name = "transferFailure" depends = ""> <xslt in="${basedir}/Result/CIMAutoTestReport${time}.jtl" out="${JMeter.home}/extras/CIMAutoTestReport${time}_failure.html" style="${JMeter.home}/extras/JMeter-results-detail-report_21_failure.xsl"/> </target> <target name="sendEmail"> <mail mailhost="internalmail.test.com" mailport="25" subject="CIM SmokeTest Report!" messagefile="${JMeter.home}/extras/CIMAutoTestReport${time}_failure.html" messagemimetype="text/html" tolist="${mail_to}"> <from address="jenny.zhang@test.com"/> <fileset dir="${JMeter.home}/extras/"> <!-- <include name="CIMAutoTestReport${time}.html"/> --> <include name="expand.png"/> </fileset> <!-- <message>This email was sent automatically by ANT. <br /> Please check the automation test report by the link below. <br /> If there are any questions, please contact with Jenny Zhang. Thank you! <br /><br /> http://SZCOMPUTER/CIMAutoTestReport${time}.html </message> --> </mail> </target> </project>
其次,在D:apache-jmeter-2.7extras目录复制一份jmeter-results-detail-report_21.xsl,将其命名为jmeter-results-detail-report_21_failure.xsl,修改两个地方,一个是154行左右的地方:
<xsl:template name="summary"> <h2>Test Report Link</h2> <h2>http://SZOTWIN2K801/CIMAutoTestReport${time}.html</h2> <h2>Summary</h2>
添加了两行:
<h2>Test Report Link</h2> <h2>http://SZOTWIN2K801/CIMAutoTestReport${time}.html</h2>
另外一个地方是大概230行左右的地方,改成下面这样:
<xsl:for-each select="/testResults/*[attribute::s='false']">
原来是这样的:
<xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]">
这样运行之后,如果有失败的,发出来的邮件就会是这样的:
如果全部成功,发出来的邮件就会是这样的: