Jmeter+ant+jekens接口自动化环境搭建演示

                                                                                                                 Jmeter+ant+jekens接口自动化环境搭建演示

 

一、首先安装JDK

 

 

 

 

配置环境变量

JAVA_HOME   C:\Program Files (x86)\Java\jdk1.8.0_11

PATH         %JAVA_HOME%/bin;%JAVA_HOME%\jre\bin;

验证:分别输入 java javac,出现以下截图说明配置成功

 

 

 

 

 

二、接口自动化框架搭建

1.下载jemer 

https://jmeter.apache.org/download_jmeter.cgi

 

 

 

 

 

 

 

 

2.下载ant软件包

 

 

 

2.配置环境变量,把jemterAnt放入环境变量里,方便启动

 

E:\jmeter\apache-jmeter-5.4.1\bin;E:\jmeter\apache-ant-1.10.10-bin\apache-ant-1.10.10\bin;

验证: cmd的命令提示符输入ant or ant -v 

 

 

 

 

 

 

 

 jmeter.save.saveservice.output_format=csv

   修改为jmeter.save.saveservice.output_format=xml

 

 

 

 

 

3.框架目录设计

主目录:I-framework

  Data :存放测试数据文件夹

  Script:测试脚本

  Report:存放测试报告

    Html:html格式

         Jtl:jtl格式

 

 

 

 

 4.编写build.xml文件

 

  

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

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

<property name="jmeterPath" value="E:\apache-jmeter-5.4.1"/>
<property name="mailhost" value="smtp.sina.cn"/>
<property name="username" value="allen8354@sina.cn"/>
<property name="password" value=""/>
<property name="mailfrom" value="allen8354@sina.com"/>
<property name="mail_to" value="835422241@qq.com,"/>
<property name="mailsubject" value="XX系统接口自动化测试报告"/>
<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="${jmeterPath}\I-framework\report\jtl" />
     <property name="jmeter.result.html.dir" value="${jmeterPath}\I-framework\report\html" />
     <property name="htmlReportNameSummary" value="接口测试报告" />
     <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}\I-framework\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-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>

测试ant-build

 

 

 

 

 

 

 

5.配置邮件

需要三个jar,分别是:activation.jar,

commons-email-1.2.jar,mail.jar,这三个文件放在antlib目录下

 

 

 

 

 

 

 

6.安装配置jekens

1.下载war包放到tomcatwebapp下,然后启动服务

 

 

 

 

 初始化设置 ,安装插件,设置密码

http://localhost:8080/jenkins  找到原始密码输入

 

 

 

 

 

 

必须安装的插件
Ant
Checkstyle
Cobertura
Email Extension
Git
HTML Publisher
Violations plugin
xUnit plugin
svn

 

 

 

 

 

 

 

 

 

  

 

posted on 2021-04-24 19:41  jiapengchu  阅读(485)  评论(0编辑  收藏  举报

导航