通过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脚本

<?xmlversion="1.0"?>

<projectname="autotest" default="all" basedir=".\">

 <propertyname="JMeter.home" value=".\..\..\..\"/>

 <propertyname="mail_to" value="Bodhi.Zhang@example.com,lucy.chen@example.com"/>

 <propertyname="ReportName" value="SnoopyAutoTestReport"/>

 <propertyname="ComputerName" value="szpc8888"/>

 <tstamp>

  <formatproperty="time" pattern="yyyyMMddhhmm"/>

 </tstamp>

 <targetname="all" >

  <antcalltarget="runBasicData"/>

  <antcalltarget="runDeleteBasicData"/>

  <antcalltarget="transfer"/>

  <antcalltarget="sendEmail"/>

 </target>

 <targetname="runBasicData" depends="">

  <taskdefname="jmeter"classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>

  <jmeterjmeterhome="${JMeter.home}"resultlog="${basedir}/Result/${ReportName}${time}.jtl">

   <testplansdir="${basedir}\Script\SmokeTest"includes="CIM_NewBasicData_SmokeTest_TP.jmx"/>

  </jmeter>

 </target>

  <targetname="runDeleteBasicData" depends="">

  <taskdefname="jmeter"classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>

  <jmeterjmeterhome="${JMeter.home}"resultlog="${basedir}/Result/${ReportName}${time}.jtl">

   <testplansdir="${basedir}\Script\SmokeTest"includes="CIM_DeleteBasicData_SmokeTest_TP.jmx"/>

  </jmeter>

 </target>

 <targetname = "transfer" depends = "">

  <xsltin="${basedir}/Result/${ReportName}${time}.jtl"

   out="${JMeter.home}/extras/${ReportName}${time}.html"

   style="${JMeter.home}/extras/JMeter-results-detail-report_21.xsl"/>

 </target>

 <targetname="sendEmail">

  <mailmailhost="internalmail.example.com" mailport="25"subject="SmokeTest Report!" messagemimetype="text/html"tolist="${mail_to}">

   <fromaddress="jenny.zhang@example.com"/>

   <!--filesetdir="${JMeter.home}/extras/">

    <includename="${ReportName}${time}.html"/>

   </fileset-->

   <message>Thisemail was sent automatically by ANT. &lt;br /&gt;

   Pleasecheck the automation test report by the link below.  &lt;br /&gt;

   Ifthere 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>

 

源文档 <http://www.cnblogs.com/MasterMonkInTemple/archive/2013/08/29/3289321.html>

posted @ 2017-05-01 16:47  李清欣  阅读(1258)  评论(0编辑  收藏  举报