ビルドにジェンキンス+ ANT + JMeterの自動化環境

JMeterの:インタフェーステストツール、サポートJava言語。

アリ:Apache Antがそのタスク相互依存的な目標と拡張ポイントとして文書に記載されたプロセスを構築することであるJavaライブラリとコマンドラインツールです。長いLinuxシステムを使用するように、読者は、このコマンドを作ることを知っている必要があります。Linuxカーネルといくつかのソフトウェアのソースコードをコンパイルする場合、多くの場合、このコマンドを使用します。makeコマンドは、実際にプロジェクト管理ツールで、メイクのように、これと同様のAntの機能を達成し、gnumakeとNMAKEこれらのコンパイルツールはいくつかの欠点を持っていますが、Antはこれらのツールの欠点を克服しました。
ジェンキンス:継続的インテグレーションツール
 
I.はじめに
1.JDK:JDK-8u121-Windowsのx64の
2.jmeterツール:apacheの-JMeterの-3.1
3.ANTツール:apacheの-ANT-1.9.10-ビン
4.jenkinsツール:jenkins.warのjenkins2.109
5.jmeter插件:JMeterPlugins-エクストラ-1.4.0、JMeterPluginsスタンダード-1.4.0
その他のツールおよびインストールパッケージ版ダウンロード: https://pan.baidu.com/s/4kWiEEXL
第二に、ソフトウェアのインストール
1.JDKインストール
> JDKのインストールパッケージをダブルクリックして、インストールパスを選択する(JDKのインストールパスを参照します。cmd、Javaの-verbose、私はCにインストール:\プログラムファイル\のJava \ jdk1.8.0_121)。
1)→新システム変数のJAVA_HOME変数。
変数JDKのインストールディレクトリの値でフィル(IはC:\ Program Files \ Javaの\ jdk1.8.0_121)。
2)システム環境変数Path変数→編集→ルッキング
変数%JAVA_HOME%\ binにの最後の入力値には、%JAVA_HOME%\ JRE \ binに。
(注が可変経路端の元の値すなわち、数、そうでない場合、第一の入力と、数は上記のコードを入力)
3)システム変数→新しいCLASSPATH変数
変数の値を記入;%JAVA_HOME%\ LIB;%JAVA_HOME%\ LIB \ tools.jarを(注:前のビットこと)
システム変数の設定は完了です
4))正常に実行cmdがJavaと-version間のjava -version(スペースを入力する設定を確認
図に示すように、バージョン情報が表示されている場合は正常にインストールして設定します。
2.jmeterソフトウェアのインストール
>解凍apache-jmeter-3.1.zipをC:\ apacheの-のJMeter-3.1 \ apacheの-のJMeter-3.1ディレクトリの下。

> JMeterのプラグインをインストールしてください。\ \のapache-のJMeter-3.1のapache-のJMeter-3.1 \ libに\ extディレクトリ:CにコピーされたディレクトリEXT内のファイルに対応する解凍JMeterPlugins-Extras-1.3.0.zip、JMeterPlugins-Standard-1.3.0.zip、 ;

>設定JMeterの環境変数:
1)環境変数、変数名の新しいシステム変数、入力設定:JMETER_HOMEを、変数の値は、次のコマンドを入力します。C:\ apacheの-のJMeter-3.1 \ apacheの-のJMeter-3.1、および[OK]をクリックします。
%JMETER_HOME%\ libに\ jorphan.jar;%JMETER_HOME%\ libに\ logkit-1.2.jar 2)CLASSPATH環境変数%JMETER_HOME%\ libに\ extに\ ApacheJMeter_core.jarを追加します。
環境変数PATHに%JMETER_HOME%\ binを追加します
3) 检验是否配置成功 运行cmd 输入 jmeter -v (jmeter和 -v 之间有空格)
若如图所示 显示版本信息 则说明安装和配置成功。
三、安装ANT
>解压apache-ant-1.9.10-bin.zip到C:\Program Files (x86)\Java\apache-ant-1.9.10目录下;
>配置ANT环境变量
1)新建以下环境变量:
ANT_HOME:C:\Program Files (x86)\Java\apache-ant-1.9.10,此为你的ANT安装路径;
设置完成后,点击"确认"来保存。
2)在环境变量PATH的最后面添加一下内容:
;%ANT_HOME%\bin 注意前面的分号,如果PATH中最后没有分号";"的话要加上,有的话就可去除。
进入cmd命令窗口,在CMD窗口中输入ant -version,敲击回城键,会显示出你安装的ANT版本,如果成功显示,说明你的配置应该是成功了.
四、ANT+Jmeter整合
1、将Jmeter所在目录下extras子目录里的ant-jmeter-1.1.1.jar复制到ant所在目录lib子目录之下,ant运行时才能找到
"org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"这个类,之后可以触发Jmeter脚本
2、修改Jmeter的bin目录下jmeter.properties文件的配置:jmeter.save.saveservice.output_format=xml
3、建了一个目录C:\apache-jmeter-3.1\apache-jmeter-3.1\demo\resultLog,目录中分别建立了html和jtl两个文件夹,之后Ant运行之后将jtl中的文件转换成html中
(为什么要创建jtl和html,可以直接通过jenkins查看生成的折线图以及html报表,这两个文件夹存放相应格式的报告)
html:存放生成的html报告
jtl:存放生成的jtl报告
4、在C:\apache-jmeter-3.1\apache-jmeter-3.1\scripts文件中建立一个build.xml文件,build.xml内容如下(注意:jmeter下也有一个build.xml文件,这个新建的文件跟jmeter下的不一样,这个build.xml要在网上找,具体如下配置):

 


build.xml代码,注意要修改红色框框的内容

5.将build.xml中的第42行
style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl">
拷贝以下内容将这个路径下的jmeter-results-detail-report_21.xsl文件覆盖,这个文件说明了xsl文件装换为html文件的一些规则:
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"; version="1.0">
 
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
 
<!--
Stylesheet for processing 2.1 output format test result files
To uses this directly in a browser, add the following to the JTL file as line 2:
<?xml-stylesheet type="text/xsl" href="../extras/jmeter-results-detail-report_21.xsl"?>
and you can then view the JTL in a browser
-->
 
<xsl:output method="html" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
 
<!-- Defined parameters (overrideable) --><xsl:param name="showData" select="'n'"/><xsl:param name="titleReport" select="'Load Test Results'"/><xsl:param name="dateReport" select="'date not defined'"/>
 
<xsl:template match="testResults">
<html>
<head>
<title><xsl:value-of select="$titleReport" /></title>
<style type="text/css">
body {
font:normal 68% verdana,arial,helvetica;
color:#000000;
}
table tr td, table tr th {
font-size: 68%;
}
table.details tr th{
color: #ffffff;
font-weight: bold;
text-align:center;
background:#2674a6;
white-space: nowrap;
}
table.details tr td{
background:#eeeee0;
white-space: nowrap;
}
h1 {
margin: 0px 0px 5px; font: 165% verdana,arial,helvetica
}
h2 {
margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica
}
h3 {
margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica
}
.Failure {
font-weight:bold; color:red;
}
img
{
border-width: 0px;
}
.expand_link
{
position=absolute;
right: 0px;
width: 27px;
top: 1px;
height: 27px;
}
.page_details
{
display: none;
}
.page_details_expanded
{
display: block;
display/* hide this definition from IE5/6 */: table-row;
}
 
 
</style>
<script language="JavaScript"><![CDATA[
function expand(details_id)
{
document.getElementById(details_id).className = "page_details_expanded";
}
function collapse(details_id)
{
document.getElementById(details_id).className = "page_details";
}
function change(details_id)
{
if(document.getElementById(details_id+"_image").src.match("expand"))
{
document.getElementById(details_id+"_image").src = "collapse.png";
expand(details_id);
}
else
{
document.getElementById(details_id+"_image").src = "expand.png";
collapse(details_id);
}
}
]]></script>
</head>
<body>
<xsl:call-template name="pageHeader" />
<xsl:call-template name="summary" />
<hr size="1" width="95%" align="center" />
<xsl:call-template name="pagelist" />
<hr size="1" width="95%" align="center" />
<xsl:call-template name="detail" />
 
</body>
</html></xsl:template>
 
<xsl:template name="pageHeader">
<h1><xsl:value-of select="$titleReport" /></h1>
<table width="100%">
<tr>
<td align="left">Date report: <xsl:value-of select="$dateReport" /></td>
<td align="right">Designed for use with <a href=" http://jmeter.apache.org/";>JMeter</a> and <a href=" http://ant.apache.org";>Ant</a>.</td>
</tr>
</table>
<hr size="1" /></xsl:template>
 
<xsl:template name="summary">
<h2>Summary</h2>
<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th># Samples</th>
<th>Failures</th>
<th>Success Rate</th>
<th>Average Time</th>
<th>Min Time</th>
<th>Max Time</th>
</tr>
<tr valign="top">
<xsl:variable name="allCount" select="count(/testResults/*)" />
<xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::s='false'])" />
<xsl:variable name="allSuccessCount" select="count(/testResults/*[attribute::s='true'])" />
<xsl:variable name="allSuccessPercent" select="$allSuccessCount div $allCount" />
<xsl:variable name="allTotalTime" select="sum(/testResults/*/@t)" />
<xsl:variable name="allAverageTime" select="$allTotalTime div $allCount" />
<xsl:variable name="allMinTime">
<xsl:call-template name="min">
<xsl:with-param name="nodes" select="/testResults/*/@t" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="allMaxTime">
<xsl:call-template name="max">
<xsl:with-param name="nodes" select="/testResults/*/@t" />
</xsl:call-template>
</xsl:variable>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="$allFailureCount &gt; 0">Failure</xsl:when>
</xsl:choose>
</xsl:attribute>
<td align="center">
<xsl:value-of select="$allCount" />
</td>
<td align="center">
<xsl:value-of select="$allFailureCount" />
</td>
<td align="center">
<xsl:call-template name="display-percent">
<xsl:with-param name="value" select="$allSuccessPercent" />
</xsl:call-template>
</td>
<td align="center">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$allAverageTime" />
</xsl:call-template>
</td>
<td align="center">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$allMinTime" />
</xsl:call-template>
</td>
<td align="center">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$allMaxTime" />
</xsl:call-template>
</td>
</tr>
</table></xsl:template>
 
<xsl:template name="pagelist">
<h2>Pages</h2>
<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th>URL</th>
<th># Samples</th>
<th>Failures</th>
<th>Success Rate</th>
<th>Average Time</th>
<th>Min Time</th>
<th>Max Time</th>
<th></th>
</tr>
<xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]">
<xsl:variable name="label" select="@lb" />
<xsl:variable name="count" select="count(../*[@lb = current()/@lb])" />
<xsl:variable name="failureCount" select="count(../*[@lb = current()/@lb][attribute::s='false'])" />
<xsl:variable name="successCount" select="count(../*[@lb = current()/@lb][attribute::s='true'])" />
<xsl:variable name="successPercent" select="$successCount div $count" />
<xsl:variable name="totalTime" select="sum(../*[@lb = current()/@lb]/@t)" />
<xsl:variable name="averageTime" select="$totalTime div $count" />
<xsl:variable name="minTime">
<xsl:call-template name="min">
<xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="maxTime">
<xsl:call-template name="max">
<xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
</xsl:call-template>
</xsl:variable>
<tr valign="top">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
</xsl:choose>
</xsl:attribute>
<td>
<xsl:if test="$failureCount > 0">
<a><xsl:attribute name="href">#<xsl:value-of select="$label" /></xsl:attribute>
<xsl:value-of select="$label" />
</a>
</xsl:if>
<xsl:if test="0 >= $failureCount">
<xsl:value-of select="$label" />
</xsl:if>
</td>
<td align="center">
<xsl:value-of select="$count" />
</td>
<td align="center">
<xsl:value-of select="$failureCount" />
</td>
<td align="right">
<xsl:call-template name="display-percent">
<xsl:with-param name="value" select="$successPercent" />
</xsl:call-template>
</td>
<td align="right">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$averageTime" />
</xsl:call-template>
</td>
<td align="right">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$minTime" />
</xsl:call-template>
</td>
<td align="right">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$maxTime" />
</xsl:call-template>
</td>
<td align="center">
<a href="">
<xsl:attribute name="href"><xsl:text/>javascript:change('page_details_<xsl:value-of select="position()" />')</xsl:attribute>
<img src="expand.png" alt="expand/collapse"><xsl:attribute name="id"><xsl:text/>page_details_<xsl:value-of select="position()" />_image</xsl:attribute></img>
</a>
</td>
</tr>
<tr class="page_details">
<xsl:attribute name="id"><xsl:text/>page_details_<xsl:value-of select="position()" /></xsl:attribute>
<td colspan="8" bgcolor="#FF0000">
<div align="center">
<b>Details for Page "<xsl:value-of select="$label" />"</b>
<table bordercolor="#000000" bgcolor="#2674A6" border="0" cellpadding="1" cellspacing="1" width="95%">
<tr>
<th>Thread</th>
<th>Iteration</th>
<th>Time (milliseconds)</th>
<th>Bytes</th>
<th>Success</th>
</tr>
<xsl:for-each select="../*[@lb = $label and @tn != $label]">
<tr>
<td><xsl:value-of select="@tn" /></td>
<td align="center"><xsl:value-of select="position()" /></td>
<td align="right"><xsl:value-of select="@t" /></td>
<!-- TODO allow for missing bytes field -->
<td align="right"><xsl:value-of select="@by" /></td>
<td align="center"><xsl:value-of select="@s" /></td>
</tr>
</xsl:for-each>
</table>
</div>
</td>
</tr>
</xsl:for-each>
</table></xsl:template>
 
<xsl:template name="detail">
<xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::s='false'])" />
 
<xsl:if test="$allFailureCount > 0">
<h2>Failure Detail</h2>
 
<xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]">
 
<xsl:variable name="failureCount" select="count(../*[@lb = current()/@lb][attribute::s='false'])" />
 
<xsl:if test="$failureCount > 0">
<h3><xsl:value-of select="@lb" /><a><xsl:attribute name="name"><xsl:value-of select="@lb" /></xsl:attribute></a></h3>
 
<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th>Response</th>
<th>Failure Message</th>
<xsl:if test="$showData = 'y'">
<th>Response Data</th>
</xsl:if>
</tr>
<xsl:for-each select="/testResults/*[@lb = current()/@lb][attribute::s='false']">
<tr>
<td><xsl:value-of select="@rc | @rs" /> - <xsl:value-of select="@rm" /></td>
<td><xsl:value-of select="assertionResult/failureMessage" /></td>
<xsl:if test="$showData = 'y'">
<td><xsl:value-of select="./binary" /></td>
</xsl:if>
</tr>
</xsl:for-each>
</table>
</xsl:if>
 
</xsl:for-each>
</xsl:if></xsl:template>
 
<xsl:template name="min">
<xsl:param name="nodes" select="/.." />
<xsl:choose>
<xsl:when test="not($nodes)">NaN</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$nodes">
<xsl:sort data-type="number" />
<xsl:if test="position() = 1">
<xsl:value-of select="number(.)" />
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose></xsl:template>
 
<xsl:template name="max">
<xsl:param name="nodes" select="/.." />
<xsl:choose>
<xsl:when test="not($nodes)">NaN</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$nodes">
<xsl:sort data-type="number" order="descending" />
<xsl:if test="position() = 1">
<xsl:value-of select="number(.)" />
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose></xsl:template>
 
<xsl:template name="display-percent">
<xsl:param name="value" />
<xsl:value-of select="format-number($value,'0.00%')" /></xsl:template>
 
<xsl:template name="display-time">
<xsl:param name="value" />
<xsl:value-of select="for
mat-number($value,'0 ms')" /></xsl:template>
</xsl:stylesheet>
6、进入Dos窗口,切换到build.xml路径(我的是C:\apache-jmeter-3.1\apache-jmeter-3.1\extras),输入命令ant敲回车,运行结束会有success信息提示
7、查看报告:
1.在\demo\resultLog\html路径下查看html报告如下
五、Jenkins的安装
1,接下来安装jenkins,下载war包
放到tomcat下的webapps下:
2,查看端口命令:
(1)netstat -ano:显示机器的端口占用情况
(2)netstat -ano|findstr “提示的端口”:显示某个端口的占用情况
(3)tasklist|findstr “pid”:根据pid找到进程名称
疑惑:查找到的端口具体每列代表什么意思?后面linux学习总结
3,修改tomcat默认的端口号port(tomcat下的conf中的server.xml):
4,重启tomcat,打开地址: http://localhost:8081/jenkins
5,打开的页面要求粘贴密码,具体路径在:C:\Users\dell\.jenkins\secrets\initialAdminPassword
6,进入jenkins后选择推荐的插件安装。
7,创建管理员用户:
用户名:root
密码:C:\Users\dell\.jenkins\secrets\initialAdminPassword中复制的内容
全名:默认跟用户名同名
电子邮件: [email protected]
保存并完成,显示:
六、配置
1、jenkins系统设置->管理插件->可选插件,搜索Performance plugin(Jmeter报告需要),安装此插件
2、因为需要用到ANT和JDK,所以需要在jenkins中添加插件,选择点击“系统管理”,之后在全局工具配置的界面看到ant和jdk选项,然后将自己本地的ANT和JDK地址填写上

2、因为需要用到ANT和JDK,所以需要在jenkins中添加插件,选择点击“系统管理”,之后在全局工具配置的界面看到ant和jdk选项,然后将自己本地的ANT和JDK地址填写上

 

 

3、配置、测试邮件1
>在系统设置中找到Jenkins Locaction项填入Jenkins URL和系统管理员邮件地址,系统管理员邮件地址一定要配置,否则发不了邮件通知。因为邮件通知都是由系统管理员的邮箱发出来的

>按照如图所示设置即可,本处设置的是QQ企业邮箱的服务,其他邮箱按照类似设置即可

>>首先在度娘中找到SMTP服务器地址和端口号及设置QQ邮箱的POP3/SMTP服务

测试邮件发送成功之后,Extended E-mail Notification参照上面的设置即可。(注意:必须配置,否则后期项目构建发送邮件将失败)
4、创建job:

构建步骤:

 

点击保存,立即构建,成功:

具体成功或者失败原因可看控制台输出:

 

html报告:

疑问:
1,配置的发送邮件这次没有用到,不知道什么时候开启,发送,具体后面琢磨。
2,html报告里面pages中有三个请求:Sample1,Sample2,HTTP请求,其实HTTP请求才是我要测试的脚本,但是显示3个,上面Sample1,Sample2显示的什么意思?相关的配置在哪里?
3,如果只对于jmeter+ant集成的话,怎么看html的报告,在这个文章中jmeter+ant集成和jmeter+ant+jenkins集成的html报告成一样的了。
 
 
 
              PS:比我优秀的人不可怕,可怕的是比我优秀的人比我还努力,只要思想不滑坡,办法总比困难多!

おすすめ

転載: www.cnblogs.com/jiachangwei/p/12142631.html
おすすめ