赞
踩
1.jemter写好脚本
2.下载并配置ant环境变量:加上activation.jar、commons-lang3-3.8.1.jar、mail.jar 这3个包
mail.jar需要引用到jmeter
3.下载安装Jenkins 并进行构建
Ant的意义是:配置Jmeter:用ant构建命令来调动执行jmeter接口测试,并生成测试报告
2.下载完成并放在jmeter的lib中
- <?xml version="1.0" encoding="UTF-8"?>
-
- <project name="ant-jmeter" default="run" basedir=".">
-
- <property name="jmeterPath" value="C:\Users\86150\Downloads\apache-jmeter-5.4.3\apache-jmeter-5.4.3" />
-
- <!-- 邮箱相关 -->
-
- <property name="mailhost" value="smtp.qq.com" />
-
- <property name="mailsubject" value="接口自动化测试报告" />
-
- <property name="mail_port" value="465" />
-
- <property name="username" value="xx@qq.com" />
-
- <property name="password" value="qq邮箱密钥" />
-
- <property name="mailfrom" value="xx@qq.com" />
-
- <property name="mail_to" value="xx@meprestamo.mx"/>
-
- <property name="message" value="HI!,详情请看附件(建议用UC/Edge浏览器打开),请查收~~" />
-
- <tstamp>
-
- <format property="time" pattern="_yyyy_MMdd_HHmmss" />
-
- </tstamp>
-
- <property name="basedirectory" value="C:\Users\86150\Downloads\apache-jmeter-5.4.3\apache-jmeter-5.4.3" />
-
- <!-- 需要改成自己本地的jmeter目录 -->
-
- <property name="jmeter.home" value="${jmeterPath}" />
-
- <!-- 报告标题名称 -->
-
- <property name="report.title" value="接口报告" />
-
- <!-- jmeter生成jtl格式的结果报告的路径-->
-
- <property name="jmeter.result.jtl.dir" value="${basedirectory}\report" />
-
- <!-- jmeter生成html格式的结果报告的路径-->
-
- <property name="jmeter.result.html.dir" value="${basedirectory}\report" />
-
- <!-- 生成的报告的前缀-->
-
- <property name="ReportName" value="APIreport" />
-
- <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
-
- <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />
-
-
-
- <!-- jmeter生成jtl/html格式的结果报告的路径
-
- <property name="jmeter.result.dir" value="C:\Users\86150\Downloads\apache-jmeter-5.4.3\apache-jmeter-5.4.3\result" /> -->
-
- <!-- 生成的报告的前缀
-
- <property name="ReportName" value="完件接口" />
-
- <property name="jmeter.result.jtlName" value="${jmeter.result.dir}/${ReportName}.jtl"/>
-
- <property name="jmeter.result.htmlName" value="${jmeter.result.dir}/${ReportName}.html" />-->
-
-
-
- <target name="run">
-
- <antcall target="test"/>
-
- <antcall target="report"/>
-
- <antcall target="sendEmail"/>
-
- </target>
-
-
-
- <target name="test">
-
- <echo>API_TEST</echo>
-
- <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
-
- <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
-
- <!-- 要执行的测试脚本,"*.jmx"指包含此目录下的所有jmeter脚本-->
-
- <testplans dir="C:\Users\86150\Downloads\apache-jmeter-5.4.3\apache-jmeter-5.4.3\bin" includes="*.jmx"/>
-
- <property name="jmeter.save.saveservice.output_format" value="xml"/>
-
- </jmeter>
-
- </target>
-
- <!--html报告中时间显示为NAN,原因是ant中确实了两个lib库,xalan-2.7.2.jar和serializer-2.7.2.jar,将这两个库拷贝到ant的lib目录下-->
-
- <path id="xslt.classpath">
-
- <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>
-
- <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>
-
- </path>
-
- <!--生成HTML测试报告-->
-
- <target name="report">
-
- <echo>API_TEST</echo>
-
- <tstamp>
-
- <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/>
-
- </tstamp>
-
- <xslt
-
- classpathref="xslt.classpath"
-
- force="true"
-
- in="${jmeter.result.jtlName}"
-
- out="${jmeter.result.htmlName}"
-
- style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl"> <!-- 报告模板路径 -->
-
- <param name="dateReport" expression="${report.datestamp}"/>
-
- <param name="titleReport" expression="${report.title}:${report.datestamp}"/>
-
- </xslt>
-
- <!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 -->
-
- <copy todir="${jmeter.result.html.dir}">
-
- <fileset dir="${jmeter.home}/extras">
-
- <include name="collapse.png" />
-
- <include name="expand.png" />
-
- </fileset>
-
- </copy>
-
- </target>
-
- <path id="lib_classpath">
-
- <fileset dir="${basedir}/">
-
- <include name="mail*.jar" />
-
- <include name="activation*.jar" />
-
- <include name="commons-email*.jar" />
-
- <include name="ant-contrib*.jar" />
-
- </fileset>
-
- </path>
-
- <!--自动发送邮件-->
-
- <target name="sendEmail">
-
- <echo>发送自动化测试报告</echo>
-
- <mail
-
- mailhost="${mailhost}"
-
- mailport="${mail_port}"
-
- charset="UTF-8"
-
- ssl="true"
-
- subject="${mailsubject}"
-
- messagemimetype="text/html"
-
- user="${username}"
-
- password="${password}"
-
- tolist="${mail_to}">
-
- <from address="${mailfrom}" />
-
- <attachments>
-
- <fileset dir="${jmeter.result.html.dir}">
-
- <include name="${ReportName}${time}.html" />
-
- <include name="collapse.png" />
-
- <include name="expand.png" />
-
- <!-- -->
-
- </fileset>
-
- </attachments>
-
- <message>${message}</message>
-
- </mail>
-
- </target>
-
- </project>
修改完成后,进入C:\Users\86150\Downloads\apache-jmeter-5.4.3\apache-jmeter-5.4.3\extras
输入命令 ant run
1、进入jenkins设置jdk / ant的全局变量;兄弟们一定要设置啊,不然完犊子了
新建一个项目--构建设置如下
就跑起来了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。