• jmeter接口自动化部署jenkins教程详解


    首先,保证本地安装并部署了jenkins,jmeter,xslproc

    我搭建的自动化测试框架是jmeter+jenkins+xslproc

    注意:原理是,jmeter自生成的报告jtl文件,通过xslproc工具,再结合jmeter自带的模板修改,自带模板目录如下,最终将测试结果报告转化为html格式

    在这我也准备了一份软件测试视频教程(含接口、自动化、性能等),需要的可以直接在下方观看,或者直接关注VX公众号:互联网杂货铺,免费领取

    软件测试视频教程观看处:

    京东内部员工自动化测试培训课程!盲目自学真的会毁终生,27天学完,能救一个是一个...

    1.jenkins新建一个任务,选择“构建一个自由风格的软件项目”,点击OK

    2.选择构建触发器,根据时间点,每天到点进行自动触发构建

    3.输入构建命令

    (1)D:/soft/apache-jmeter-3.2/bin/jmeter -n -t D:/soft/apache-jmeter-3.2/jmx/接口测试.jmx 

    这一句是通过cmd命令调用jmeter程序,执行jmeter的jmx自动化脚本;

    (2)D:/soft/xsltproc/bin/xsltproc D:/soft/apache-jmeter-3.2/xsl/jmeter-results-detail-report_new.xsl %WORKSPACE%/test.jtl>%WORKSPACE%/test.html

    这一句是调用xslproc程序,通过jmeter-results-detail-report_new.xsl模板,将jtl文件转换为html报告文件;

    4.

    邮件的格式代码如下:

    大家好,本次接口测试构建结果如下:

    1. <hr/>
    2. <!DOCTYPE html >
    3. <html>
    4. <head>
    5. <meta name="referrer" content="never">
    6. <title>${ENV, var="JOB_NAME"}-第${BUILD_NUMBER}次构建日志</title>
    7. </head>
    8. <body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4" offset="0">
    9. <table width="95%" cellpadding="0" cellspacing="0"
    10. style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
    11. <tr>
    12. <td>(本邮件是程序自动下发的,请勿回复!)</td>
    13. </tr>
    14. <tr>
    15. <td><h2>
    16. <font color="#0000FF">构建结果 - ${BUILD_STATUS}</font>
    17. </h2></td>
    18. </tr>
    19. <tr>
    20. <td><br />
    21. <b><font color="#0B610B">构建信息</font></b>
    22. <hr size="2" width="100%" align="center" /></td>
    23. </tr>
    24. <tr>
    25. <td>
    26. <ul>
    27. <li>项目名称&nbsp;:&nbsp;${PROJECT_NAME}</li>
    28. <li>构建编号&nbsp;:&nbsp;第${BUILD_NUMBER}次构建</li>
    29. <li>触发原因:&nbsp;${CAUSE}</li>
    30. <li>构建日志:&nbsp;<a href="${BUILD_URL}console">${BUILD_URL}console</a></li>
    31. <li>构建&nbsp;&nbsp;Url&nbsp;:&nbsp;<a href="${BUILD_URL}">${BUILD_URL}</a></li>
    32. <li>工作目录&nbsp;:&nbsp;<a href="${PROJECT_URL}ws">${PROJECT_URL}ws</a></li>
    33. <li>项目&nbsp;&nbsp;Url&nbsp;:&nbsp;<a href="${PROJECT_URL}">${PROJECT_URL}</a></li>
    34. </ul>
    35. </td>
    36. </tr>
    37. <tr>
    38. <td><b><font color="#0B610B">Changes Since Last
    39. Successful Build:</font></b>
    40. <hr size="2" width="100%" align="center" /></td>
    41. </tr>
    42. <tr>
    43. <td>
    44. <ul>
    45. <li>历史变更记录 : <a href="${PROJECT_URL}changes">${PROJECT_URL}changes</a></li>
    46. </ul> ${CHANGES_SINCE_LAST_SUCCESS,reverse=true, format="Changes for Build #%n:
      %c
      "
      ,showPaths=true,changesFormat="
      [%a]
      %m
      "
      ,pathFormat="    %p"}
    47. </td>
    48. </tr>
    49. <tr>
    50. <td><b>Failed Test Results</b>
    51. <hr size="2" width="100%" align="center" /></td>
    52. </tr>
    53. <tr>
    54. <td><pre
    55. style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">$FAILED_TESTS</pre>
    56. <br /></td>
    57. </tr>
    58. </table>
    59. </body>
    60. </html>
    61. <b>${FILE,path="D:/jenkins/workspace/test/test.html"}</b>

    以上是jenkins的所有设置

    5.jenkins的版本太低的话,可能存在需要手动下载jenkins插件

    最后,附上模板代码给各位:

    1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    2. <!--
    3. Licensed to the Apache Software Foundation (ASF) under one or more
    4. contributor license agreements. See the NOTICE file distributed with
    5. this work for additional information regarding copyright ownership.
    6. The ASF licenses this file to You under the Apache License, Version 2.0
    7. (the "License"); you may not use this file except in compliance with
    8. the License. You may obtain a copy of the License at
    9. http://www.apache.org/licenses/LICENSE-2.0
    10. Unless required by applicable law or agreed to in writing, software
    11. distributed under the License is distributed on an "AS IS" BASIS,
    12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13. See the License for the specific language governing permissions and
    14. limitations under the License.
    15. -->
    16. <!--
    17. Stylesheet for processing 2.1 output format test result files
    18. To uses this directly in a browser, add the following to the JTL file as line 2:
    19. <?xml-stylesheet type="text/xsl" href="../extras/jmeter-results-detail-report_21.xsl"?>
    20. and you can then view the JTL in a browser
    21. -->
    22. <xsl:output method="html" indent="yes" encoding="GB18030" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
    23. <!-- Defined parameters (overrideable) <td bgcolor="#ff00ff"> -->
    24. <xsl:param name="showData" select="'y'"/>
    25. <xsl:param name="titleReport" select="'接口测试'"/>
    26. <xsl:template match="testResults">
    27. <html >
    28. <head>
    29. <title><xsl:value-of select="$titleReport" /></title>
    30. <style type="text/css">
    31. body {
    32. font:normal 95% verdana,arial,helvetica;
    33. color:#000000;
    34. }
    35. table tr td, table tr th {
    36. font-size: 95%;
    37. }
    38. table.details tr th{
    39. word-wrap:break-word;
    40. color: #ffffff;
    41. font-weight: bold;
    42. text-align:center;
    43. background:#2674a6;
    44. }
    45. table.details tr td{
    46. width: 400px;
    47. word-wrap:break-word;
    48. background:#eeeee0;
    49. }
    50. table{
    51. table-layout:fixed ;
    52. }
    53. h1 {
    54. margin: 0px 0px 5px; font: 165% verdana,arial,helvetica
    55. }
    56. h2 {
    57. margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica
    58. }
    59. h3 {
    60. margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica
    61. }
    62. .Failure {
    63. font-weight:bold; color:red;
    64. }
    65. img
    66. {
    67. border-width: 0px;
    68. }
    69. .expand_link
    70. {
    71. position:absolute;
    72. right: 0px;
    73. width: 27px;
    74. top: 1px;
    75. height: 27px;
    76. }
    77. .page_details
    78. {
    79. display: none;
    80. }
    81. /* .page_details_expanded
    82. {
    83. display: block;
    84. displayhide this definition from IE5/6: table-row;
    85. } */
    86. </style>
    87. <script language="JavaScript"><![CDATA[
    88. function expand(details_id)
    89. {
    90. document.getElementById(details_id).className = "page_details_expanded";
    91. }
    92. function collapse(details_id)
    93. {
    94. document.getElementById(details_id).className = "page_details";
    95. }
    96. function change(details_id)
    97. {
    98. if(document.getElementById(details_id+"_image").src.match("expand"))
    99. {
    100. document.getElementById(details_id+"_image").src = "collapse.png";
    101. expand(details_id);
    102. }
    103. else
    104. {
    105. document.getElementById(details_id+"_image").src = "expand.png";
    106. collapse(details_id);
    107. }
    108. }
    109. ]]></script>
    110. </head>
    111. <body >
    112. <xsl:call-template name="pageHeader" />
    113. <xsl:call-template name="myresult" />
    114. <xsl:call-template name="summary" />
    115. <hr size="1" width="75%" align="center" />
    116. <xsl:call-template name="pagelist" />
    117. <hr size="1" width="75%" align="center" />
    118. <xsl:call-template name="detail" />
    119. </body>
    120. </html>
    121. </xsl:template>
    122. <xsl:template name="pageHeader">
    123. <h1><xsl:value-of select="$titleReport" /></h1>
    124. <table width="100%">
    125. <tr>
    126. <td align="left">Date report:</td>
    127. <td align="right">from 一卡通</td>
    128. </tr>
    129. </table>
    130. <hr size="1" />
    131. </xsl:template>
    132. <xsl:template name="myresult">
    133. <xsl:variable name="allFailCount" select="count(/testResults/*[attribute::s='false'])" />
    134. <xsl:if test="$allFailCount = '0'">
    135. <h2>测试结果:成功</h2>
    136. </xsl:if>
    137. <xsl:if test="$allFailCount > '0'">
    138. <h2 bgcolor="#ff00ff">测试结果:失败</h2>
    139. <h2 bgcolor="#ff00ff">失败个数:<xsl:value-of select="count(/testResults/*[attribute::s='false'])"/></h2>
    140. </xsl:if>
    141. </xsl:template>
    142. <xsl:template name="summary">
    143. <h2>报告概况</h2>
    144. <table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
    145. <tr valign="top">
    146. <th>用例总数</th>
    147. <th>失败数</th>
    148. <th>成功率</th>
    149. <th>平均响应时间</th>
    150. </tr>
    151. <tr valign="top">
    152. <xsl:variable name="allCount" select="count(/testResults/*)" />
    153. <xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::s='false'])" />
    154. <xsl:variable name="allSuccessCount" select="count(/testResults/*[attribute::s='true'])" />
    155. <xsl:variable name="allSuccessPercent" select="$allSuccessCount div $allCount" />
    156. <xsl:variable name="allTotalTime" select="sum(/testResults/*/@t)" />
    157. <xsl:variable name="allAverageTime" select="$allTotalTime div $allCount" />
    158. <xsl:variable name="allMinTime">
    159. <xsl:call-template name="min">
    160. <xsl:with-param name="nodes" select="/testResults/*/@t" />
    161. </xsl:call-template>
    162. </xsl:variable>
    163. <xsl:variable name="allMaxTime">
    164. <xsl:call-template name="max">
    165. <xsl:with-param name="nodes" select="/testResults/*/@t" />
    166. </xsl:call-template>
    167. </xsl:variable>
    168. <xsl:attribute name="class">
    169. <xsl:choose>
    170. <xsl:when test="$allFailureCount > 0">Failure</xsl:when>
    171. </xsl:choose>
    172. </xsl:attribute>
    173. <td align="center">
    174. <xsl:value-of select="$allCount" />
    175. </td>
    176. <td align="center">
    177. <xsl:value-of select="$allFailureCount" />
    178. </td>
    179. <td align="center">
    180. <xsl:call-template name="display-percent">
    181. <xsl:with-param name="value" select="$allSuccessPercent" />
    182. </xsl:call-template>
    183. </td>
    184. <td align="center">
    185. <xsl:call-template name="display-time">
    186. <xsl:with-param name="value" select="$allAverageTime" />
    187. </xsl:call-template>
    188. </td>
    189. </tr>
    190. </table>
    191. </xsl:template>
    192. <xsl:template name="pagelist">
    193. <h2>详细情况</h2>
    194. <table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
    195. <tr valign="top">
    196. <th width="50%">功能模块</th>
    197. <th>检查次数</th>
    198. <th>失败数</th>
    199. <th>成功率</th>
    200. <th>平均响应时间</th>
    201. </tr>
    202. <xsl:for-each select="/testResults/*[not(@tn = preceding::*/@tn)]">
    203. <xsl:variable name="label" select="@tn" />
    204. <xsl:variable name="count" select="count(../*[@tn = current()/@tn])" />
    205. <xsl:variable name="failureCount" select="count(../*[@tn = current()/@tn][attribute::s='false'])" />
    206. <xsl:variable name="successCount" select="count(../*[@tn = current()/@tn][attribute::s='true'])" />
    207. <xsl:variable name="successPercent" select="$successCount div $count" />
    208. <xsl:variable name="totalTime" select="sum(../*[@tn = current()/@tn]/@t)" />
    209. <xsl:variable name="averageTime" select="$totalTime div $count" />
    210. <xsl:variable name="minTime">
    211. <xsl:call-template name="min">
    212. <xsl:with-param name="nodes" select="../*[@tn = current()/@tn]/@t" />
    213. </xsl:call-template>
    214. </xsl:variable>
    215. <xsl:variable name="maxTime">
    216. <xsl:call-template name="max">
    217. <xsl:with-param name="nodes" select="../*[@tn = current()/@tn]/@t" />
    218. </xsl:call-template>
    219. </xsl:variable>
    220. <tr valign="top">
    221. <xsl:attribute name="class">
    222. <xsl:choose>
    223. <xsl:when test="$failureCount > 0">Failure</xsl:when>
    224. </xsl:choose>
    225. </xsl:attribute>
    226. <td>
    227. <xsl:if test="$failureCount > 0">
    228. <a><xsl:attribute name="href">#<xsl:value-of select="$label" /></xsl:attribute>
    229. <xsl:value-of select="$label" />
    230. </a>
    231. </xsl:if>
    232. <xsl:if test="0 >= $failureCount">
    233. <xsl:value-of select="$label" />
    234. </xsl:if>
    235. </td>
    236. <td align="center">
    237. <xsl:value-of select="$count" />
    238. </td>
    239. <td align="center">
    240. <xsl:value-of select="$failureCount" />
    241. </td>
    242. <td align="center">
    243. <xsl:call-template name="display-percent">
    244. <xsl:with-param name="value" select="$successPercent" />
    245. </xsl:call-template>
    246. </td>
    247. <td align="center">
    248. <xsl:call-template name="display-time">
    249. <xsl:with-param name="value" select="$averageTime" />
    250. </xsl:call-template>
    251. </td>
    252. </tr>
    253. </xsl:for-each>
    254. </table>
    255. </xsl:template>
    256. <xsl:template name="detail">
    257. <xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::s='false'])" />
    258. <xsl:if test="$allFailureCount > 0">
    259. <h2>Failure Detail</h2>
    260. <xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]">
    261. <xsl:variable name="failureCount" select="count(../*[@lb = current()/@lb][attribute::s='false'])" />
    262. <xsl:if test="$failureCount > 0">
    263. <xsl:for-each select="/testResults/*[@lb = current()/@lb][attribute::s='false']">
    264. <h3><xsl:value-of select="@tn" />---<xsl:value-of select="@lb" /><a><xsl:attribute name="name"><xsl:value-of select="@tn" /></xsl:attribute></a></h3>
    265. <table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
    266. <tr valign="top">
    267. <th>http请求</th>
    268. <th>失败详细信息</th>
    269. <xsl:if test="$showData = 'y'">
    270. <th>响应数据</th>
    271. </xsl:if>
    272. </tr>
    273. <tr>
    274. <td><xsl:value-of select="java.net.URL" /> </td>
    275. <td><xsl:value-of select="assertionResult/failureMessage" /></td>
    276. <xsl:if test="$showData = 'y'">
    277. <td><xsl:value-of select="responseData" /></td>
    278. </xsl:if>
    279. </tr>
    280. </table>
    281. </xsl:for-each>
    282. </xsl:if>
    283. </xsl:for-each>
    284. </xsl:if>
    285. </xsl:template>
    286. <xsl:template name="min">
    287. <xsl:param name="nodes" select="/.." />
    288. <xsl:choose>
    289. <xsl:when test="not($nodes)">NaN</xsl:when>
    290. <xsl:otherwise>
    291. <xsl:for-each select="$nodes">
    292. <xsl:sort data-type="number" />
    293. <xsl:if test="position() = 1">
    294. <xsl:value-of select="number(.)" />
    295. </xsl:if>
    296. </xsl:for-each>
    297. </xsl:otherwise>
    298. </xsl:choose>
    299. </xsl:template>
    300. <xsl:template name="max">
    301. <xsl:param name="nodes" select="/.." />
    302. <xsl:choose>
    303. <xsl:when test="not($nodes)">NaN</xsl:when>
    304. <xsl:otherwise>
    305. <xsl:for-each select="$nodes">
    306. <xsl:sort data-type="number" order="descending" />
    307. <xsl:if test="position() = 1">
    308. <xsl:value-of select="number(.)" />
    309. </xsl:if>
    310. </xsl:for-each>
    311. </xsl:otherwise>
    312. </xsl:choose>
    313. </xsl:template>
    314. <xsl:template name="display-percent">
    315. <xsl:param name="value" />
    316. <xsl:value-of select="format-number($value,'0.00%')" />
    317. </xsl:template>
    318. <xsl:template name="display-time">
    319. <xsl:param name="value" />
    320. <xsl:value-of select="format-number($value,'0 ms')" />
    321. </xsl:template>
    322. </xsl:stylesheet>

    模板的截图如下:

    写在最后

    PS:这套软件测试的自学教程合集,对于在测试行业发展的小伙伴们来说应该会很有帮助。全套内容已经打包到网盘,内容总量接近500个G。如需要软件测试学习资料,关注公众号(互联网杂货铺),后台回复1,整理不易,给个关注点个赞吧,谢谢各位大佬!

    这些资料,对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。

     

  • 相关阅读:
    深入了解网络流量清洗--使用免费的雷池社区版进行防护
    能自动更新的万能周报模板,有手就会用!
    蓝桥杯DP算法——背包问题(C++)
    思腾云计算
    C++中STL库
    小红书KOC获得“官方认可”丨价值评估模型
    图解LeetCode——1302. 层数最深叶子节点的和(难度:中等)
    【算法与数据结构】106、LeetCode从中序与后序遍历序列构造二叉树
    arduino 复习题
    为什么在桌面右键word、excel和ppt会出现“在笔记本中编辑”的字样?
  • 原文地址:https://blog.csdn.net/HUA6911/article/details/134532281