通过ANT实现jmeter批量执行脚本、生成报告、发送邮件全套build.xml文件

在开始通过ANT运行build.xml之前,有一步必须要做,那就是将JMeter所在目录下extras子目录里的ant-JMeter-1.1.1.jar复制到Ant所在目录lib子目录之下,这样Ant运行时才能找到"org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"这个类,从而成功触发JMeter脚本

<?xml version="1.0"?>
<project name="autotest" default="all" basedir=".\">
 <property name="JMeter.home" value=".\..\..\..\"/>
 <property name="mail_to" value="Bodhi.Zhang@example.com,lucy.chen@example.com"/>

 <property name="ReportName" value="SnoopyAutoTestReport"/>
 <property name="ComputerName" value="szpc8888"/>
 <tstamp>
  <format property="time" pattern="yyyyMMddhhmm"/>
 </tstamp>
 <target name="all" >
  <antcall target="runBasicData"/>
  <antcall target="runDeleteBasicData"/>
  <antcall target="transfer"/>
  <antcall target="sendEmail"/>
 </target>
 <target name="runBasicData" depends="">
  <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
  <jmeter jmeterhome="${JMeter.home}" resultlog="${basedir}/Result/${ReportName}${time}.jtl">
   <testplans dir="${basedir}\Script\SmokeTest" includes="CIM_NewBasicData_SmokeTest_TP.jmx"/>
  </jmeter>
 </target>
  <target name="runDeleteBasicData" depends="">
  <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
  <jmeter jmeterhome="${JMeter.home}" resultlog="${basedir}/Result/${ReportName}${time}.jtl">
   <testplans dir="${basedir}\Script\SmokeTest" includes="CIM_DeleteBasicData_SmokeTest_TP.jmx"/>
  </jmeter>
 </target>
 <target name = "transfer" depends = "">
  <xslt in="${basedir}/Result/${ReportName}${time}.jtl"
   out="${JMeter.home}/extras/${ReportName}${time}.html"
   style="${JMeter.home}/extras/JMeter-results-detail-report_21.xsl"/>
 </target>

 <target name="sendEmail">
  <mail mailhost="internalmail.example.com" mailport="25" subject="SmokeTest Report!" messagemimetype="text/html" tolist="${mail_to}">
   <from address="jenny.zhang@example.com"/>
   <!--fileset dir="${JMeter.home}/extras/">
    <include name="${ReportName}${time}.html"/>
   </fileset-->
   <message>This email was sent automatically by ANT. &lt;br /&gt;
   Please check the automation test report by the link below.  &lt;br /&gt;
   If there are any questions, please contact with Bodhi Zhang. Thank you! &lt;br /&gt;&lt;br /&gt;
   http://${ComputerName}/${ReportName}${time}.html
   </message>
  </mail>
 </target>
</project>

posted on 2013-08-29 15:54  张缤分  阅读(1634)  评论(0编辑  收藏  举报

导航