🤡 :默认自带节点
🥶 :可选节点
💩 :变量必填
👺 :变量非必填
文件整体结构
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.3">
<hashTree>
<!--压测计划-->
<TestPlan></TestPlan>
<hashTree>
<!--前置操作-->
<SetupThreadGroup></SetupThreadGroup>
<!--线程组1-->
<ThreadGroup></ThreadGroup>
<hashTree>
<!--请求头-->
<HeaderManager></HeaderManager>
<hashTree/>
<!--http请求-->
<HTTPSamplerProxy></HTTPSamplerProxy>
<hashTree/>
<!--http请求-->
<HTTPSamplerProxy></HTTPSamplerProxy>
<hashTree/>
<!--压测数据文件-->
<CSVDataSet></CSVDataSet>
<hashTree/>
<!--用户自定义变量-->
<Arguments></Arguments>
<hashTree/>
</hashTree>
<!--线程组2-->
<ThreadGroup></ThreadGroup>
<hashTree>
<!--http请求-->
<HTTPSamplerProxy></HTTPSamplerProxy>
<hashTree/>
<!--压测数据文件-->
<CSVDataSet></CSVDataSet>
<hashTree/>
</hashTree>
<!--influxdb监听-->
<BackendListener></BackendListener>
<hashTree/>
<!--后置操作-->
<PostThreadGroup></PostThreadGroup>
<hashTree/>
</hashTree>
</jmeterTestPlan>
测试计划
<!-- 🤡 -->
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="👺 plan name " enabled="true">
<!--🤡 描述,默认没有值-->
<stringProp name="TestPlan.comments">👺 plan description </stringProp>
<!--🤡 true 表示多个线程组顺序执行,false表示多个线程组并行执行,默认是fasle -->
<boolProp name="TestPlan.functional_mode">💩 false</boolProp>
<!--🤡 true 表示执行TearDown线程组,false表示不执行TearDown线程组,默认是true -->
<boolProp name="TestPlan.tearDown_on_shutdown">💩 true</boolProp>
<!--🤡 true 表示记录每个请求从服务器取得的数据到文件,默认是false -->
<boolProp name="TestPlan.serialize_threadgroups">💩 false</boolProp>
<!--🤡 用户自定义变量-->
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<!-- 🤡 -->
<collectionProp name="Arguments.arguments">
<!-- 🥶 可选-->
<elementProp name="👺 args-name" elementType="Argument">
<stringProp name="Argument.name">👺 args-name</stringProp>
<stringProp name="Argument.value">👺 args-value</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<!-- 🥶 可选 -->
<elementProp name="👺 args-name2" elementType="Argument">
<stringProp name="Argument.name">👺 args-name2</stringProp>
<stringProp name="Argument.value">👺 args-value2</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<!--🤡 引用外部jar包,一般不使用这种方法,默认没有值 -->
<stringProp name="TestPlan.user_define_classpath">👺 /Users/bjhl/Documents/apache-maven-3.6.3/lib/commons-cli-1.4.jar,/Users/bjhl/Documents/apache-maven-3.6.3/lib/guava-25.1-android.jar</stringProp>
</TestPlan>
线程组
<!--🤡 enabled="false" 表示不执行此线程组,默认是true -->
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="👺 Group name" enabled="true">
<!--🥶 描述 -->
<stringProp name="TestPlan.comments">👺 Group comments</stringProp>
<!--🤡 请求失败时策略,continue:继续执行,start next thread loop:请求失败则启动第二轮请求,stop thread:运行完第一轮的所有请求然后停止测试,
stop test:停止测试, stop test now:立即停止测试 ;
默认是continue-->
<stringProp name="ThreadGroup.on_sample_error">💩 continue</stringProp>
<!--🤡 线程数,默认是1 -->
<stringProp name="ThreadGroup.num_threads">💩 1</stringProp>
<!--🤡 多长时间内启动所有线程,默认是1 -->
<stringProp name="ThreadGroup.ramp_time">💩 1</stringProp>
<!--🤡 循环控制器 enabled="true"-->
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<!--🤡 true:表示一直运行,默认是false -->
<boolProp name="LoopController.continue_forever">💩 false</boolProp>
<!--🤡 指定循环次数,负数表示一直运行,默认是1 -->
<stringProp name="LoopController.loops">👺 1</stringProp>
</elementProp>
<!--🤡 使用cookies时选择false, 默认是true -->
<boolProp name="ThreadGroup.same_user_on_next_iteration">💩 true</boolProp>
<!--🤡 直到需要时创建线程 可以延迟线程的创建 减少不必要的资源损失。默认false,测试开始的时候,所有线程就被创建完了。-->
<boolProp name="ThreadGroup.delayedStart">💩 true</boolProp>
<!--🤡 调度器控制每个线程组运行的持续时间以及它在多少秒后再启动。
true:使用调度器,显示ThreadGroup.duration和ThreadGroup.delay选项;
false:不显示ThreadGroup.duration和ThreadGroup.delay选项
默认false
-->
<boolProp name="ThreadGroup.scheduler">💩 true</boolProp>
<!--🤡 线程组运行的持续时间。ramp_time=true时可填,默认没有值 -->
<stringProp name="ThreadGroup.duration">👺 12</stringProp>
<!--🤡 启动延迟;测试计划开始后,线程组的线程将在多少秒后再启动运行。ramp_time=true时可填,默认没有值 -->
<stringProp name="ThreadGroup.delay">👺 32</stringProp>
</ThreadGroup>
前置线程组
<SetupThreadGroup guiclass="🤢 SetupThreadGroupGui" testclass="🤢 SetupThreadGroup" testname="setUp Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
</SetupThreadGroup>
后置线程组
<PostThreadGroup guiclass="🤢 PostThreadGroupGui" testclass="🤢 PostThreadGroup" testname="tearDown Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
</PostThreadGroup>
<🤢 hashTree/>
GET-http请求配置
<!--🤡 enabled="false" 表示不执行此请求,默认是true -->
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="👺 HTTP Request" enabled="true">
<!--🤡 用户自定义变量 -->
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<!-- 🤡 -->
<collectionProp name="Arguments.arguments">
<!-- 🥶 可选-->
<elementProp name="👺 get_key" elementType="HTTPArgument">
<!-- 编码 ,默认是false-->
<boolProp name="HTTPArgument.always_encode">💩 true</boolProp>
<!-- 变量值 -->
<stringProp name="Argument.value">👺 get_value</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<!-- 变量名 -->
<stringProp name="Argument.name">👺 get_key</stringProp>
<!-- 参数类型 ,默认是text/plain-->
<stringProp name="HTTPArgument.content_type">?? text/plain</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<!--🥶 描述,可选,默认没有值。无值时不显示节点-->
<stringProp name="TestPlan.comments">👺 </stringProp>
<!--🤡 服务器IP,默认没有值 -->
<stringProp name="HTTPSampler.domain">💩 </stringProp>
<!--🤡 port端口,默认没有值 -->
<stringProp name="HTTPSampler.port">👺 </stringProp>
<!--🤡 协议类型,默认没有值,内部默认是http -->
<stringProp name="HTTPSampler.protocol">👺 </stringProp>
<!--🤡 编码,默认没有值 -->
<stringProp name="HTTPSampler.contentEncoding">?? </stringProp>
<!--🤡 路径,默认没有值 -->
<stringProp name="HTTPSampler.path">💩 /index.html</stringProp>
<!--🤡 请求方法 ,可选项:GET POST HEAD PUT OPTIONS TRACE DELETE PATCH,默认是GET-->
<stringProp name="HTTPSampler.method">💩 GET</stringProp>
<!--🤡 Http Request取样器的默认选项,当响应code是3xx时,自动跳转到目标地址.Jmeter会记录重定向过程中的所有请求响应 ,默认是true-->
<boolProp name="HTTPSampler.follow_redirects">💩 true</boolProp>
<!--🤡 只针对Get和Head请求,自动重定向可以自动转向到最终目标页面.但是Jmeter是不记录重定向的过程内容;默认是false-->
<boolProp name="HTTPSampler.auto_redirects">💩 false</boolProp>
<!--🤡 jmeter与目标服务器使用Keep-Alive 方式进行HTTP通信,默认true -->
<boolProp name="HTTPSampler.use_keepalive">💩 true</boolProp>
<!--🤡 上传文件时勾选 默认是false-->
<boolProp name="HTTPSampler.DO_MULTIPART_POST">💩 false</boolProp>
<!-- 当勾选了Use multipart/form-data for HTTP POST后,可以选择这个,可以保证不受HTTP信息头管理器设置的Content-Type 和Content-Transfer-Encoding 影响 -->
<boolProp name="HTTPSampler.BROWSER_COMPATIBLE_MULTIPART">true</boolProp>
<!--🤡 默认没有值 -->
<stringProp name="HTTPSampler.embedded_url_re">👺 </stringProp>
<!--🤡 等待服务器连接1000ms,不管此时是否已连接上服务器,硬等待,默认没有值 -->
<stringProp name="HTTPSampler.connect_timeout">👺 </stringProp>
<!--🤡 等待返回消息时间1000ms,不管此时是否早已返回消息,硬等待,默认没有值 -->
<stringProp name="HTTPSampler.response_timeout">👺 </stringProp>
</HTTPSamplerProxy>
<hashTree/>
post-http请求配置
<!--🤡 enabled="false" 表示不执行此请求,默认是true -->
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="👺 HTTP Request" enabled="true">
<!--🥶 post请求使用,true表示设置body data类型。body Data和parameters只能选择一个.默认是true -->
<boolProp name="HTTPSampler.postBodyRaw">?? true</boolProp>
<!--🥶 post请求body data参数 -->
<elementProp name="HTTPsampler.Arguments" elementType="Arguments">
<collectionProp name="Arguments.arguments">
<elementProp name="?? " elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">💩 false</boolProp>
<stringProp name="Argument.value">👺 {"aa":"bb"}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<!--🥶 描述,可选,默认没有值。无值时不显示节点-->
<stringProp name="TestPlan.comments">👺 </stringProp>
<!--🤡 服务器IP,默认没有值 -->
<stringProp name="HTTPSampler.domain">💩 www.baidu.com</stringProp>
<!--🤡 port端口,默认没有值 -->
<stringProp name="HTTPSampler.port">👺 443</stringProp>
<!--🤡 协议类型,默认没有值,内部默认是http -->
<stringProp name="HTTPSampler.protocol">👺 https</stringProp>
<!--🤡 编码,默认没有值 -->
<stringProp name="HTTPSampler.contentEncoding">👺 </stringProp>
<!--🤡 路径,默认没有值 -->
<stringProp name="HTTPSampler.path">💩 /index.html</stringProp>
<!--🤡 请求方法 ,可选项:GET POST HEAD PUT OPTIONS TRACE DELETE PATCH,默认是GET-->
<stringProp name="HTTPSampler.method">💩 POST</stringProp>
<!--🤡 Http Request取样器的默认选项,当响应code是3xx时,自动跳转到目标地址.Jmeter会记录重定向过程中的所有请求响应 ,默认是true-->
<boolProp name="HTTPSampler.follow_redirects">💩 true</boolProp>
<!--🤡 只针对Get和Head请求,自动重定向可以自动转向到最终目标页面.但是Jmeter是不记录重定向的过程内容;默认是false-->
<boolProp name="HTTPSampler.auto_redirects">💩 false</boolProp>
<!--🤡 jmeter与目标服务器使用Keep-Alive 方式进行HTTP通信,默认true -->
<boolProp name="HTTPSampler.use_keepalive">💩 true</boolProp>
<!--🤡 上传文件时勾选,默认是false -->
<boolProp name="HTTPSampler.DO_MULTIPART_POST">💩 false</boolProp>
<!--🤡 默认没有值 -->
<stringProp name="HTTPSampler.embedded_url_re">👺 </stringProp>
<!--🤡 等待服务器连接1000ms,不管此时是否已连接上服务器,硬等待,默认没有值 -->
<stringProp name="HTTPSampler.connect_timeout">👺 </stringProp>
<!--🤡 等待返回消息时间1000ms,不管此时是否早已返回消息,硬等待,默认没有值 -->
<stringProp name="HTTPSampler.response_timeout">👺 </stringProp>
</HTTPSamplerProxy>
<hashTree/>
----------------
<!--🤡 -->
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<!--🤡 -->
<collectionProp name="Arguments.arguments"/>
<!--?? -->
<elementProp name="sd" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">sd</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">sd</stringProp>
</elementProp>
</collectionProp>
</elementProp>
HTTP信息头管理器
可以放在线程组下,也可放到计划下
<!--🤡 enabled="false" 表示不生效,默认是true -->
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="👺 HTTP Header Manager" enabled="true">
<!--🤡 -->
<collectionProp name="HeaderManager.headers">
<!--🥶 描述,可选,默认没有值。无值时不显示节点-->
<stringProp name="TestPlan.comments">👺 sda</stringProp>
<!--🥶 请求头变量-->
<elementProp name="👺 User-Agent" elementType="Header">
<stringProp name="Header.name">👺 User-Agent</stringProp>
<stringProp name="Header.value">👺 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:48.0) Gecko/20100101 Firefox/48.0</stringProp>
</elementProp>
<elementProp name=" 👺 Accept" elementType="Header">
<stringProp name="Header.name">👺 Accept</stringProp>
<stringProp name="Header.value">👺 text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</stringProp>
</elementProp>
</collectionProp>
</HeaderManager>
<hashTree/>
CSV文件
可以放在线程组下,也可放到计划下
<!--🤡 enabled="false" 表示不生效,默认是true -->
<CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="👺 CSV Data Set Config" enabled="true">
<!--🥶 描述,可选,默认没有值。无值时不显示节点-->
<stringProp name="TestPlan.comments">👺 sds</stringProp>
<!--🤡 数字分隔符,默认是逗号 -->
<stringProp name="delimiter">💩 ,</stringProp>
<!--🤡 编码格式 ,默认没有值,测试需要填写utf-8-->
<stringProp name="fileEncoding">?? utf-8</stringProp>
<!--🤡 文件路径,默认没有值 -->
<stringProp name="filename">💩 /Users/bjhl/jmeter/jmeter5.2.1/data/token.txt</stringProp>
<!--🤡 true:忽视第一行 ,false相反,默认false-->
<boolProp name="ignoreFirstLine">💩 false</boolProp>
<!--🤡 数据是否允许带引号 ,默认false-->
<boolProp name="quotedData">💩 false</boolProp>
<!--🤡 true:循环使用,默认true -->
<boolProp name="recycle">💩 true</boolProp>
<!--🤡 默认shareMode.all ,可选shareMode.all,shareMode.group,shareMode.thread-->
<stringProp name="shareMode">💩 shareMode.all</stringProp>
<!--🤡 当Recycle on EOF为False时,当读取文件到结尾时,停止进程,当Recycle on EOF为True时,此项无意义.默认false -->
<boolProp name="stopThread">💩 false</boolProp>
<!--🤡 变量名,默认没有值 -->
<stringProp name="variableNames">💩 变量名</stringProp>
</CSVDataSet>
<hashTree/>
用户自定义变量
两种,一种是ArgumentsPanel,一种是HTTPArgumentsPanel。
可以放在线程组下,也可放到计划下
One
<!--🤡 -->
<Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="👺 User Defined Variables" enabled="true">
<!--🤡 -->
<collectionProp name="Arguments.arguments">
<!--🥶 描述,可选,默认没有值。无值时不显示节点-->
<stringProp name="TestPlan.comments">👺 sdsd</stringProp>
<!-- 🥶 -->
<elementProp name="👺 user_key" elementType="Argument">
<stringProp name="Argument.name">👺 user_key</stringProp>
<stringProp name="Argument.value">👺 user_value</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="👺 user_key1" elementType="Argument">
<stringProp name="Argument.name">👺 user_key1</stringProp>
<stringProp name="Argument.value">👺 value1</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</Arguments>
<hashTree/>
Two
<!--🤡 -->
<Arguments guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="👺 User Defined Variables" enabled="true">
<!--🤡 -->
<collectionProp name="Arguments.arguments">
<!-- 🥶 -->
<elementProp name="👺 sds" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">true</boolProp>
<stringProp name="Argument.value">👺 sdsd</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">👺 sds</stringProp>
</elementProp>
</collectionProp>
</Arguments>
<hashTree/>
cookie管理
可以放在线程组下,也可放到计划下
<!--🤡 enabled="false" 表示不生效,默认是true -->
<CookieManager guiclass="CookiePanel" testclass="CookieManager" testname="👺 HTTP Cookie Manager" enabled="true">
<!--🤡 -->
<collectionProp name="CookieManager.cookies">
<!--🥶 描述,可选,默认没有值。无值时不显示节点-->
<stringProp name="TestPlan.comments">👺 s</stringProp>
<!--🥶 -->
<elementProp name="👺 a1" elementType="Cookie" testname="👺 a1">
<stringProp name="Cookie.value">👺 a1</stringProp>
<stringProp name="Cookie.domain">👺 a1</stringProp>
<stringProp name="Cookie.path">👺 a1</stringProp>
<!--默认false-->
<boolProp name="Cookie.secure">?? true</boolProp>
<longProp name="Cookie.expires">0</longProp>
<boolProp name="Cookie.path_specified">true</boolProp>
<boolProp name="Cookie.domain_specified">true</boolProp>
</elementProp>
</collectionProp>
<!--🤡 true:每次线程执行完就会清除cookies,默认false -->
<boolProp name="CookieManager.clearEachIteration">💩 false</boolProp>
<!--🤡 使用线程组的设置来控制清除cookie,建议与线程组设置中的不勾选Same user on each iteration一起使用来模拟每次迭代登录使用不同session登录的情况。默认false-->
<boolProp name="CookieManager.controlledByThreadGroup">💩 false</boolProp>
</CookieManager>
<hashTree/>
正则表达式提取器
Mysql压测
<!--🤡 需要现在testplan中引入jar -->
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
// 添加JDBC驱动
<stringProp name="TestPlan.user_define_classpath">/Users/bjhl/Downloads/apache-jmeter-5.3/bin/mysql-connector-java-8.0.11.jar</stringProp>
</TestPlan>
...
<!--🤡 添加在ThreadGroup下面 -->
<JDBCSampler guiclass="TestBeanGUI" testclass="JDBCSampler" testname="JDBC Request" enabled="true">
<stringProp name="dataSource">stress_testing</stringProp>
<stringProp name="query">select * from st_data limit 1</stringProp>
<stringProp name="queryArguments"></stringProp>
<stringProp name="queryArgumentsTypes"></stringProp>
<stringProp name="queryTimeout"></stringProp>
<stringProp name="queryType">Select Statement</stringProp>
<stringProp name="resultSetHandler">Store as String</stringProp>
<stringProp name="resultSetMaxRows"></stringProp>
<stringProp name="resultVariable"></stringProp>
<stringProp name="variableNames"></stringProp>
</JDBCSampler>
<hashTree/>
// 配置JDBC连接池
<JDBCDataSource guiclass="TestBeanGUI" testclass="JDBCDataSource" testname="JDBC Connection Configuration" enabled="true">
<boolProp name="autocommit">true</boolProp>
<stringProp name="checkQuery"></stringProp>
<stringProp name="connectionAge">5000</stringProp>
<stringProp name="connectionProperties"></stringProp>
<stringProp name="dataSource">stress_testing</stringProp>
<stringProp name="dbUrl">jdbc:mysql://172.16.34.15:3307/stress_testing?serverTimezone=UTC&characterEncoding=utf-8</stringProp>
<stringProp name="driver">com.mysql.jdbc.Driver</stringProp>
<stringProp name="initQuery"></stringProp>
<boolProp name="keepAlive">true</boolProp>
<stringProp name="password">DSIcGCGOfDnSBHQB</stringProp>
<stringProp name="poolMax">10</stringProp>
<boolProp name="preinit">false</boolProp>
<stringProp name="timeout">10000</stringProp>
<stringProp name="transactionIsolation">DEFAULT</stringProp>
<stringProp name="trimInterval">60000</stringProp>
<stringProp name="username">stress_rw</stringProp>
</JDBCDataSource>
<hashTree/>