当前位置:   article > 正文

jmeter+ant+Jenkins接口/性能自动化集成安装+配置+使用

jmeter+ant+jenkins

目录

一、安装ant

     1.下载安装ant,https://ant.apache.org/bindownload.cgi

     2.Ant配置环境变量,在我的电脑-属性-高级系统设置配置

     3. cmd命令输入ant -v 看是否安装成功

    4. ant配置

        (1)将jmeter extras目录下的ant-jmeter-1.1.1.jar文件拷贝到ant安装目录下的lib文件夹中

      (2)配置ant的编译文件build.xml,需要调整参数设置到自己的位置

      (3)配置jmeter.properties文档

    5. 验证是否配置成功,cmd进入build.xml和jmx文件夹下,输入ant

    6.优化jmeter报告格式

        (1)新增一个jmeter-results-shanhe-me.xsl  

        (2) 设置jmeter.properties

        (3) Bulid.xml文件,设置style为刚新建的xsl文件

   7. 再次执行ant

二、安装Jenkins

下载Jenkins,https://www.jenkins.io/download/

     2.打开下载的msi文件

     3.Jenkins官方安装教程

      4.设置密码可能遇到报错

                (1)Ox8007052e.- Error logging on xxx

               (2)This account either does not have the privilege to logon as a service or the account was unable to beverified.

     5.安装成功

三、Jenkins配置

     1.配置Jenkins环境

     2.新增项目 

     3. 测试构建


一、安装ant

     1.下载安装ant,https://ant.apache.org/bindownload.cgi

     2.Ant配置环境变量,在我的电脑-属性-高级系统设置配置

        ANT_HOME 为 ant解压位置

        CLASSPATH为 %ANT_HOME%\lib;

        PATH为%ANT_HOME%\bin;

     3. cmd命令输入ant -v 看是否安装成功

  1.         

    4. ant配置

        (1)将jmeter extras目录下的ant-jmeter-1.1.1.jar文件拷贝到ant安装目录下的lib文件夹中

                         

      (2)配置ant的编译文件build.xml需要调整参数设置到自己的位置

                             

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="ant-jmeter-test" default="run">
  3. <tstamp>
  4. <format property="time" pattern="yyyyMMddhhmm" />
  5. </tstamp>
  6. <property name="jmeter.home" value="D:\SoftWare\Jmeter\apache-jmeter-2.13" />
  7. <property name="report.title" value="SoaTestReport"/>
  8. <property name="jmeter.result.jtl.dir" value="D:\Jmeter\result\jtl" />
  9. <property name="jmeter.result.html.dir" value="D:\Jmeter\result\html" />
  10. <property name="ReportName" value="TestReport" />
  11. <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
  12. <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />
  13. <target name="run">
  14. <antcall target="test" />
  15. <antcall target="report" />
  16. </target>
  17. <target name="test">
  18. <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
  19. <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
  20. <testplans dir="D:\Jmeter\script" includes="*.jmx" />
  21. <property name="jmeter.save.saveservice.output_format" value="xml"/>
  22. </jmeter>
  23. </target>
  24. <path id="xslt.classpath">
  25. <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>
  26. <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>
  27. </path>
  28. <target name="report">
  29. <tstamp> <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" /></tstamp>
  30. <xslt
  31. classpathref="xslt.classpath"
  32. force="true"
  33. in="${jmeter.result.jtlName}"
  34. out="${jmeter.result.htmlName}"
  35. style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl">
  36. <param name="dateReport" expression="${report.datestamp}"/>
  37. </xslt>
  38. <copy todir="${jmeter.result.html.dir}">
  39. <fileset dir="${jmeter.home}/extras">
  40. <include name="collapse.png" />
  41. <include name="expand.png" />
  42. </fileset>
  43. </copy>
  44. </target>
  45. </project>

      (3)配置jmeter.properties文档

                jmeter/bin目录下,打开该文档并编辑,修改jmeter报告输出格式为xml

                改jmeter.save.saveservice.output_format=csv 为jmeter.save.saveservice.output_format=xml,并去掉前面的注释符号#,保存

    5. 验证是否配置成功,cmd进入build.xml和jmx文件夹下,输入ant

        

        成功后去build.xml设置的目录看是否有文件

        

    6.优化jmeter报告格式

        (1)新增一个jmeter-results-shanhe-me.xsl  

                 好处:能看到接口请求响应结果、耗时等信息

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  3. <xsl:output method="html" indent="no" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
  4. <xsl:strip-space elements="*"/>
  5. <xsl:template match="/testResults">
  6. <html lang="en">
  7. <head>
  8. <meta name="Author" content="shanhe.me"/>
  9. <title>JMeter Test Results</title>
  10. <style type="text/css"><![CDATA[
  11. * { margin: 0; padding: 0 }
  12. html, body { width: 100%; height: 100%; background: #b4b4b4; font-size: 12px }
  13. table { border: none; border-collapse: collapse; table-layout: fixed }
  14. td { vertical-align: baseline; font-size: 12px }
  15. #left-panel { position: absolute; left: 0; top: 0; bottom: 0; width: 300px; overflow: auto; background: #dee4ea }
  16. #left-panel li.navigation { font-weight: bold; cursor: default; color: #9da8b2; line-height: 18px; background-position: 12px 5px; background-repeat: no-repeat; padding: 0 0 0 25px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAICAYAAAArzdW1AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBQqGbO7BEcAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAAKRJREFUGNN1zM0KgkAYheF3RvtXSsGyWhRNaILS7bdt11W0KgJvoPwZp0UlBPUtz3nOJw7Hk7necv5dOA2Qaazo2vZP0LEt9olCVtqQROufKNmuqBuBNAYW4QzXGX6B0bDPcjGnMQYJ8Cg12U59oSzaUJQa4IUAXMclDHwAAn/MxPMw765FZd2QRgopBWmsKCrdfhXnS/4ZYElBXdyxewN008Y8AephLAkqz613AAAAAElFTkSuQmCC) }
  17. #left-panel li.success { color: #565b60 }
  18. #left-panel li.failure { color: red }
  19. #left-panel li { list-style: none; color: black; cursor: pointer }
  20. #left-panel li.selected { background-repeat: repeat-x; color: white; background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAUCAYAAABMDlehAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBQxLTs5O2gAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAAEdJREFUCNc1y7ERgEAMA0GNUhIyGqM2uqKgtyWZhE9v53A/7/A6D7BkMDNgy2AroB2wHTCZv5UMOgFLG1bvd7XBckBlwCXjA5wMOF5iOX/MAAAAAElFTkSuQmCC) }
  21. #left-panel div { line-height: 20px; background-position: 25px 3px; background-repeat: no-repeat; padding: 0 0 0 45px }
  22. #left-panel div.success { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAOCAYAAADwikbvAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBULEEc6wzcAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAAiNJREFUKM99kktIVGEYhp/jzJl08lI6logp2Y2EFkbtaqlFROsWrlq4ioJWQRs37VoUVItWkYEVRGSBlhleCpywDEWxTEuxcURTZ6YzxzP/5WshCOHUt36f93kXnyMi5Lsnb4clI4s4fhkXzp5w8mWcfHBvfEpUxVdCUUU6lUPNHuD86cYtBQX5GhPrM7hRg7GaSDRg2vuUd90WuOPVsOyqy6FFo2yOQHlU1S9z9dZT+S/8I7GCLlkAN4eyAf56mnT6Fy1HLnGuuYa++MS/4e74qMRqfXLaJ9BpfnsrLC0m2BYuoqwUbj/+274JD43OEqmexwvW8NUKXnaZtVSS1pNtAAyOvyC6v48HnUNb4Z7PH8UtTlIQWA5tb2RhYY7kz3l2FleytJYg/qWb8t2KZ/0PN+1hgI6uEUr2jpHKpGlquExVaS0VbjUZL7WxaqIXK6ADQ0n9GNfv9XCttWnD/O57t0TKFklnF3g5fJ/seoaa2D4O1x0F4PlgO9oIftbgFgYMfLgjACGqj0vlsddoUnj+Kt/mxunq72RP+UGqYjWMTA7R+b6dUCSEGEF5hoJQip6BaFs4HJtCyRrKs6wHCovDip/kys0WWpovMpOYBCtoT2N9B5uzWG0Zid8gnFrVFEQDtBaUrxEgXBimaEeER2/uIiK4roPOaMRYjBKsFly3fOO3G06dETGCWIsYjckprMphtEKMAQtgsMYi1mJMQHJ6xvkDKQoyphCzkl0AAAAASUVORK5CYII=) }
  23. #left-panel div.failure { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAOCAYAAADwikbvAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBUJOEC5CU8AAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAAeVJREFUKM+NkDtok2EUhp8vl9ZLo/EyKI6KFgqCKC4OClrBWUQEcRRx1cGpk3WyInWrgoMZKkW8thYaEYQ0i7WC2ngrNDTERHJvkv/L/3//dxwc7F8jeOAsh/c973OOEhG61aPnaen7maXYt4MLZ4+pbppQt+F06jNH3QWOb8pxUs+SmJzjv83hxY8SVy3wNdtVneiHqe54IhLoB4/TUkyMyOrKj5yXoVtPZK02kLyYK7OnlqFWzgcCGtUC/YUJ3n5a/jd28tU7ORTN0myUA6Jms8bpWIa798elqzn1fokjThrpVBC3ETzNbYAuca59j/Hp+b/N869Tsk8tgVMCXQk+RlfQuk1/tMLMwzsSMCcm5zjhvoR2AdpF0GuwO4aqttS05ZSbZHhsBoAIwI83Cdkd/460XDAOG02d24MxvlR8dsUUh3f2UHaEtgdbWCHz4oZwcVCp66PP5FLhKjEc8DXaCMsNy8DYn/SnZ+L0hhWOb/F8yLs9fDtwk8j+VpqwrlC34PrgGEu2bhlYhZ1b8dncq3AMeBaUr/k6NUyk4ChKzu+N2hc6Bqody+WDG8g2fLatD7F3axjPgmvAtYJvIbouhhIRrl0ZktnkBGIt1gqeMXQ8D2MMiCIUCqFEsFhEQMSykCuqX0MzLAUJTzRsAAAAAElFTkSuQmCC) }
  24. #left-panel div.detail { display: none }
  25. #right-panel { position: absolute; right: 0; top: 0; bottom: 0; left: 301px; overflow: auto; background: white }
  26. #right-panel .group { font-size: 12px; font-weight: bold; line-height: 16px; padding: 0 0 0 18px; counter-reset: assertion; background-repeat: repeat-x; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAQCAYAAADXnxW3AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBUkDq8pxjkAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAADdJREFUCNdVxrERwDAMAzGK0v47eS6Z927SpMFBAAbkvSvnRk5+7K5cVfLMyN39bWakJAjA5xw9R94jN3tVhVEAAAAASUVORK5CYII=) }
  27. #right-panel .zebra { background-repeat: repeat; padding: 0 0 0 18px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAmCAYAAAAFvPEHAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBYWFlNztEcAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAABdJREFUCNdjYKAtePv5338mBgYGBpoQAGy1BAJlb/y6AAAAAElFTkSuQmCC) }
  28. #right-panel .data { line-height: 19px; white-space: nowrap }
  29. #right-panel pre.data { white-space: pre }
  30. #right-panel tbody.failure { color: red }
  31. #right-panel td.key { min-width: 108px }
  32. #right-panel td.delimiter { min-width: 18px }
  33. #right-panel td.assertion:before { counter-increment: assertion; content: counter(assertion) ". " }
  34. #right-panel td.assertion { color: black }
  35. #right-panel .trail { border-top: 1px solid #b4b4b4 }
  36. ]]></style>
  37. <script type="text/javascript"><![CDATA[
  38. var onclick_li = (function() {
  39. var last_selected = null;
  40. return function(li) {
  41. if( last_selected == li )
  42. return;
  43. if( last_selected )
  44. last_selected.className = "";
  45. last_selected = li;
  46. last_selected.className = "selected";
  47. document.getElementById("right-panel").innerHTML = last_selected.firstChild.nextSibling.innerHTML;
  48. return false;
  49. };
  50. })();
  51. var patch_timestamp = function() {
  52. var spans = document.getElementsByTagName("span");
  53. var len = spans.length;
  54. for( var i = 0; i < len; ++i ) {
  55. var span = spans[i];
  56. if( "patch_timestamp" == span.className )
  57. span.innerHTML = new Date( parseInt( span.innerHTML ) );
  58. }
  59. };
  60. var patch_navigation_class = (function() {
  61. var set_class = function(el, flag) {
  62. if(el) {
  63. el.className += flag ? " success" : " failure";
  64. }
  65. };
  66. var traverse = function(el, group_el, flag) {
  67. while(1) {
  68. if(el) {
  69. if(el.className == 'navigation') {
  70. set_class(group_el, flag);
  71. group_el = el;
  72. flag = true;
  73. } else {
  74. var o = el.firstChild;
  75. o = o ? o.className : null;
  76. flag = flag ? (o == 'success') : false;
  77. }
  78. el = el.nextSibling;
  79. } else {
  80. set_class(group_el, flag);
  81. break;
  82. }
  83. }
  84. };
  85. return function() {
  86. var o = document.getElementById("result-list");
  87. o = o ? o.firstChild : null;
  88. if(o)
  89. traverse(o, null, true);
  90. };
  91. })();
  92. window.onload = function() {
  93. patch_timestamp();
  94. patch_navigation_class();
  95. var o = document.getElementById("result-list");
  96. o = o ? o.firstChild : null;
  97. o = o ? o.nextSibling : null;
  98. if(o)
  99. onclick_li(o);
  100. };
  101. ]]></script>
  102. </head>
  103. <body>
  104. <div id="left-panel">
  105. <ol id="result-list">
  106. <xsl:for-each select="*">
  107. <!-- group with the previous sibling -->
  108. <xsl:if test="position() = 1 or @tn != preceding-sibling::*[1]/@tn">
  109. <li class="navigation">Thread: <xsl:value-of select="@tn"/></li>
  110. </xsl:if>
  111. <li onclick="return onclick_li(this);">
  112. <div>
  113. <xsl:attribute name="class">
  114. <xsl:choose>
  115. <xsl:when test="@s = 'true'">success</xsl:when>
  116. <xsl:otherwise>failure</xsl:otherwise>
  117. </xsl:choose>
  118. </xsl:attribute>
  119. <xsl:value-of select="@lb"/>
  120. </div><div class="detail">
  121. <div class="group">Sampler</div>
  122. <div class="zebra">
  123. <table>
  124. <tr><td class="data key">Thread Name</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@tn"/></td></tr>
  125. <tr><td class="data key">Timestamp</td><td class="data delimiter">:</td><td class="data"><span class="patch_timestamp"><xsl:value-of select="@ts"/></span></td></tr>
  126. <tr><td class="data key">Time</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@t"/> ms</td></tr>
  127. <tr><td class="data key">Latency</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@lt"/> ms</td></tr>
  128. <tr><td class="data key">Bytes</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@by"/></td></tr>
  129. <tr><td class="data key">Sample Count</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@sc"/></td></tr>
  130. <tr><td class="data key">Error Count</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@ec"/></td></tr>
  131. <tr><td class="data key">Response Code</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@rc"/></td></tr>
  132. <tr><td class="data key">Response Message</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@rm"/></td></tr>
  133. </table>
  134. </div>
  135. <div class="trail"></div>
  136. <xsl:if test="count(assertionResult) &gt; 0">
  137. <div class="group">Assertion</div>
  138. <div class="zebra">
  139. <table>
  140. <xsl:for-each select="assertionResult">
  141. <tbody>
  142. <xsl:attribute name="class">
  143. <xsl:choose>
  144. <xsl:when test="failure = 'true'">failure</xsl:when>
  145. <xsl:when test="error = 'true'">failure</xsl:when>
  146. </xsl:choose>
  147. </xsl:attribute>
  148. <tr><td class="data assertion" colspan="3"><xsl:value-of select="name"/></td></tr>
  149. <tr><td class="data key">Failure</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="failure"/></td></tr>
  150. <tr><td class="data key">Error</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="error"/></td></tr>
  151. <tr><td class="data key">Failure Message</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="failureMessage"/></td></tr>
  152. </tbody>
  153. </xsl:for-each>
  154. </table>
  155. </div>
  156. <div class="trail"></div>
  157. </xsl:if>
  158. <div class="group">Request</div>
  159. <div class="zebra">
  160. <table>
  161. <tr><td class="data key">Method/Url</td><td class="data delimiter">:</td><td class="data"><pre class="data"><xsl:value-of select="method"/><xsl:text> </xsl:text><xsl:value-of select="java.net.URL"/></pre></td></tr>
  162. <tr><td class="data key">Query String</td><td class="data delimiter">:</td><td class="data"><pre class="data"><xsl:value-of select="queryString"/></pre></td></tr>
  163. <tr><td class="data key">Cookies</td><td class="data delimiter">:</td><td class="data"><pre class="data"><xsl:value-of select="cookies"/></pre></td></tr>
  164. <tr><td class="data key">Request Headers</td><td class="data delimiter">:</td><td class="data"><pre class="data"><xsl:value-of select="requestHeader"/></pre></td></tr>
  165. </table>
  166. </div>
  167. <div class="trail"></div>
  168. <div class="group">Response</div>
  169. <div class="zebra">
  170. <table>
  171. <tr><td class="data key">Response Headers</td><td class="data delimiter">:</td><td class="data"><pre class="data"><xsl:value-of select="responseHeader"/></pre></td></tr>
  172. <tr><td class="data key">Response Data</td><td class="data delimiter">:</td><td class="data"><pre class="data"><xsl:value-of select="responseData"/></pre></td></tr>
  173. <tr><td class="data key">Response File</td><td class="data delimiter">:</td><td class="data"><pre class="data"><xsl:value-of select="responseFile"/></pre></td></tr>
  174. </table>
  175. </div>
  176. <div class="trail"></div>
  177. </div>
  178. </li>
  179. </xsl:for-each>
  180. </ol>
  181. </div>
  182. <div id="right-panel"></div>
  183. </body>
  184. </html>
  185. </xsl:template>
  186. </xsl:stylesheet>

        (2) 设置jmeter.properties

                      jmeter的bin目录下找到jmeter.properties,全部取消注释设置为true

                

        (3) Bulid.xml文件,设置style为刚新建的xsl文件

                

   7. 再次执行ant

        

         至此,ant安装+配置完成

二、安装Jenkins

  1. 下载Jenkins,https://www.jenkins.io/download/

         

     2.打开下载的msi文件

        

     3.Jenkins官方安装教程

https://www.jenkins.io/doc/book/installing/windows/

      4.设置密码可能遇到报错

                (1)Ox8007052e.- Error logging on xxx

                        这个错误是windows用户里没有这个帐号

                        

               (2)This account either does not have the privilege to logon as a service or the account was unable to beverified.

                

          打开管理工具

                

                

                 

                 .

                

                选择要作为登录的用户名,添加,再次尝试

                

     5.安装成功

          安装好访问本地:http://localhost:8080/ 8080为安装时实际设置的端口,接着按照官方文档安装即可

         至此,Jenkins安装完成。

三、Jenkins配置

     1.配置Jenkins环境

                    

                  

                

                环境配置完成,点击保存。

     2.新增项目 ​​​​​​​

                

                 

                 

                 

     3. 测试构建

                

                构建成功

                 

                查看本地是否生成结果

                

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/416697
推荐阅读
相关标签
  

闽ICP备14008679号