一. jenkins + ant + jmeter发送邮件失败

  解决方法:https://www.javazxz.com/thread-8722-1-1.html中下载jar包复制到ant-lib中jmeter+ant+Jenkins实现接口持续集成_自动化测试



<?xml version="1.0" encoding="UTF8"?>

<project name="ant-jmeter-test" default="run" basedir=".">

<!-- 需要改成自己本地的 Jmeter 目录-->
<property name="jmeterPath" value="C:\instll file\apache-jmeter-5.3\apache-jmeter-5.3"/>
<!-- 邮箱的配置-->
<property name="mailhost" value="smtp.163.com"/>
<property name="username" value="mrbaigeng@163.com"/>
<property name="password" value="TNGHYQPRFLJWKPIK"/>
<!-- 此处为邮件授权码-->

<property name="mailfrom" value="mrbaigeng@163.com"/>
<!-- 需要发送的邮箱地址,多个邮箱的话用,隔开-->
<property name="mail_to" value="821601472@qq.com"/>
<!--发送邮件的主题-->
<property name="mailsubject" value="云学习接口自动化测试报告"/>
<property name="mail_port" value="25"/>
<!-- 邮件正文-->
<property name="message" value="Hi!请查收下,这是XX接口自动化测试报告,如有任何疑问,请联系我,谢谢!"/>


<tstamp>
<format property="time" pattern="yyyyMMddhhmm" />
</tstamp>

<property name="jmeter.home" value="${jmeterPath}" />
<!-- 脚本生成报告的路径,需要自己创建成已经存在的路径-->
<property name="jmeter.result.jtl.dir" value="C:\instll file\apache-jmeter-5.3\apache-jmeter-5.3\TestSuite\report\jtl" />
<property name="jmeter.result.html.dir" value="C:\instll file\apache-jmeter-5.3\apache-jmeter-5.3\TestSuite\report\html" />
<property name="htmlReportNameSummary" value="TestReport" />
<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${htmlReportNameSummary}${time}.jtl" />
<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${htmlReportNameSummary}${time}.html" />

<!-- 测试的步骤-->
<target name="run">
<antcall target="test" />
<antcall target="report" />
<antcall target="sendEmail" />
</target>

<!--执行接口测试-->
<target name="test">
<echo>执行接口自动化测试</echo>
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
<jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
<!--要执行的测试脚本-->
<testplans dir="${jmeterPath}\TestSuite\script" includes="*.jmx" />
<property name="jmeter.save.saveservice.output_format" value="xml"/>
</jmeter>
</target>

<!--解决报告中NAN字段显示问题-->
<path id="xslt.classpath">
<fileset dir="${jmeter.home}/lib" includes="xalan-2.7.2.jar"/>
<fileset dir="${jmeter.home}/lib" includes="serializer-2.7.2.jar"/>
</path>

<!--生成HTML测试报告-->
<target name="report">
<echo>生成接口自动测试报告</echo>
<xslt
classpathref="xslt.classpath"
force="true"
in="${jmeter.result.jtlName}" out="${jmeter.result.htmlName}"
style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl"/>
<!--style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" /-->

<!--复制图片-->
<copy todir="${jmeter.result.html.dir}">
<fileset dir="${jmeter.home}/extras">
<include name="collapse.png" />
<include name="expand.png" />
</fileset>
</copy>
</target>
<!--自动发送邮件-->
<target name="sendEmail">
<echo>发送自动化测试报告</echo>
<mail mailhost="${mailhost}"
ssl="ture"
user="${username}"
password="${password}"
mailport="${mail_port}"
subject="${mailsubject}"
messagemimetype="text/html"
tolist="${mail_to}">
<from address="${mailfrom}" />
<attachments>
<fileset dir="${jmeter.result.html.dir}">
<include name="${htmlReportNameSummary}${time}.html"/>
<include name="collapse.png" />
<include name="expand.png" />
</fileset>
</attachments>
<message>
${message}
</message>
</mail>
</target>
</project>