前面的博文中有对 JMeter 中的 响应断言 进行了讲解并实例演示,详情敬请参阅博文:JMeter学习-007-JMeter 断言实例之一 - 响应断言。
在 JMeter 中总计提供了如下几种 BeanShell 组件:
Beanshell Sampler:单独的采样器。
Beanshell PreProcessor:针对其他采样器的前置处理器。可以在采样器执行之前进行预处理操作,生成相关测试数据供采样器使用,相当于 TestNG 中的 before annotation。
Beanshell PostProcessor:针对其他采样器的后置处理器。可以在采样器执行之后进行测试环境恢复或数据清理等操作,相当于 TestNG 中的 after annotation。
Beanshell Assertion:JMeter 中的高级断言,可直接调用 JMeter API 进行相关的脚本操作,同时可进行断言结果的设定,实现对脚本测试结果报告的定制输出等。
_Beanshell function:JMeter 中的调用函数,允许在采样器等的执行过程中调用已存在的扩展脚本中的函数方法。
此文主要讲述 JMeter 断言中的 Bean Shell Asserttion。其对应的路径为:【 添加 / 断言 / Bean Shell Assertion】,其配置页面如下所示:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA9oAAAJNCAIAAABBYZpfAAAgAElEQVR4nO3dzYrrWpsf8L6kBl2MBudGxB4c3kFI4FyA4czOKIPQU0P3MO88NM6gyeSFN5CGhhAnIYEeZLAz8NeS1ockW/ZjV/1+POxdJetjaUlV9feqVfbf/Pjtd6WUUkoppVRI/c2P337/23/zt0oppZRSSqlX1o/ffj8ej+K4UkoppZRSAfXjt99//vwpjiullFJKKRVQx+NxGsePAADAM12zd2F0PLptAADwxYnjAAAQRhwHAIAw4jgAAIQRxwEAIIw4DgAAYcRxAAAII44DAEAYcRwAAMKI4wAAEEYcX6Hruq7rXrMVAADfgTi+TjFYzwZuiRwAgKL74vh+6MqG/UtaPTp+eszzA6ubcdj11+3Sj5MkXfz36rqnSsdUPdYRAAB8to3j+AsS+Tktl4/53Dg+ydDCNAAAD3oojo9T7yUnPzePn4/S7w5pSyafPiOOH7M5J+I4AAAP2jCOT5PycTySnSxOdjF97LrnZNPRltODjJty++y2//GBy02ai+O5YzOO17aa7AEAgG9u+9Hx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t="" width="750" height="448" />
配置参数列表说明如下:
配置项属性 | 详细描述 | 是否必填 |
名称 | 脚本目录树显示当前 Bean Shell Assertion 的概要描述性名称。该名称存储在脚本变量标签中。 | 否 |
注释 | 对当前项更加详细的描述。例如相关业务描述等等。 | 否 |
Reset bsh.Interpreter before each calll | 若选择此项,则将为每个样本创建对应的解释器。一般用不到。 | 是 |
参数 |
传递到脚本的参数,有如下两种参数传递方式:
|
否 |
Script file | 包含 BeanShell 脚本的运行文件。将重写当前脚本 Script,其文件名存储在脚本变量名中。 | 否 |
Script | BeanShell 脚本。当包含了 BeanShell 脚本文件时,Script 可为空。 | 是 |
BeanShell 获取变量的两种方法如下所示(假定需获取的变量分别为 exp_sysNo、sysNo):
// get compare data
exp = vars.get("exp_sysNo").toString();
act = String.valueOf( ${sysNo});
修改 exp_sysNo 的方法如下所示(修改 exp_sysNo 数据后,原来获取的 exp 需要重新获取):
vars.put("exp_sysNo", "exp_sysNo");
下面为 BeanShell Assert 的简单应用实例,敬请参阅!
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.8" jmeter="2.13 r1665067">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="接口自动化测试实例 - BeanShell Assertion 简单实例演示" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="008-搜索商品" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器" 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">0</stringProp>
<longProp name="ThreadGroup.start_time">1419232321000</longProp>
<longProp name="ThreadGroup.end_time">1419232321000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量 - 商品编号 101-006-78945" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="goodsNo" elementType="Argument">
<stringProp name="Argument.name">goodsNo</stringProp>
<stringProp name="Argument.value">101-006-78945</stringProp>
<stringProp name="Argument.desc">商品编号</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="districtId" elementType="Argument">
<stringProp name="Argument.name">districtId</stringProp>
<stringProp name="Argument.value">29313</stringProp>
<stringProp name="Argument.desc">配送区域</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="areacode" elementType="Argument">
<stringProp name="Argument.name">areacode</stringProp>
<stringProp name="Argument.value">1</stringProp>
<stringProp name="Argument.desc">仓库大区</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="exp_sysNo" elementType="Argument">
<stringProp name="Argument.name">exp_sysNo</stringProp>
<stringProp name="Argument.value">2169256</stringProp>
<stringProp name="Argument.desc">商品系统编号,用于校验搜索结果</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="skuid" elementType="Argument">
<stringProp name="Argument.name">skuid</stringProp>
<stringProp name="Argument.value">489349159815</stringProp>
<stringProp name="Argument.desc">单品SKU,用户校验搜索结果</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="appSource" elementType="Argument">
<stringProp name="Argument.name">appSource</stringProp>
<stringProp name="Argument.value">android</stringProp>
<stringProp name="Argument.desc">平台</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="appVersion" elementType="Argument">
<stringProp name="Argument.name">appVersion</stringProp>
<stringProp name="Argument.value">45</stringProp>
<stringProp name="Argument.desc">版本</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
<stringProp name="TestPlan.comments">,,,,,,</stringProp>
</Arguments>
<hashTree/>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="008-01-搜索商品 【${goodsNo} | ${districtId}】" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="q" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">${goodsNo}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">q</stringProp>
</elementProp>
<elementProp name="districtId" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">${districtId}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">districtId</stringProp>
</elementProp>
<elementProp name="areacode" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">${areacode}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">areacode</stringProp>
</elementProp>
<elementProp name="dtype" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">list|page|classes</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">dtype</stringProp>
</elementProp>
<elementProp name="districtId" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.name">districtId</stringProp>
<stringProp name="Argument.value">${districtId}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
</elementProp>
<elementProp name="exAppTag" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.name">exAppTag</stringProp>
<stringProp name="Argument.value">2045191607</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
</elementProp>
<elementProp name="appSource" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">${appSource}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">appSource</stringProp>
</elementProp>
<elementProp name="appVersion" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">${appVersion}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">appVersion</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="HTTPSampler.domain">mb.51buy.com</stringProp>
<stringProp name="HTTPSampler.port"></stringProp>
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
<stringProp name="HTTPSampler.protocol">http</stringProp>
<stringProp name="HTTPSampler.contentEncoding">GB2312</stringProp>
<stringProp name="HTTPSampler.path">/json.php?mod=Search&act=page&p=1&pp=20</stringProp>
<stringProp name="HTTPSampler.method">POST</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<boolProp name="HTTPSampler.monitor">false</boolProp>
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
</HTTPSamplerProxy>
<hashTree>
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP信息头管理器" enabled="true">
<collectionProp name="HeaderManager.headers">
<elementProp name="Charset" elementType="Header">
<stringProp name="Header.name">Charset</stringProp>
<stringProp name="Header.value">UTF-8</stringProp>
</elementProp>
<elementProp name="Content-Type" elementType="Header">
<stringProp name="Header.name">Content-Type</stringProp>
<stringProp name="Header.value">application/x-www-form-urlencoded</stringProp>
</elementProp>
<elementProp name="Accept-Encoding" elementType="Header">
<stringProp name="Header.name">Accept-Encoding</stringProp>
<stringProp name="Header.value">gzip</stringProp>
</elementProp>
<elementProp name="User-Agent" elementType="Header">
<stringProp name="Header.name">User-Agent</stringProp>
<stringProp name="Header.value">Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9502 Build/KOT49H)</stringProp>
</elementProp>
</collectionProp>
</HeaderManager>
<hashTree/>
<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="获取商品的系统编号" enabled="true">
<stringProp name="RegexExtractor.useHeaders">false</stringProp>
<stringProp name="RegexExtractor.refname">sysNo</stringProp>
<stringProp name="RegexExtractor.regex">"sysNo":"(.+?)","</stringProp>
<stringProp name="RegexExtractor.template">$1$</stringProp>
<stringProp name="RegexExtractor.default">ERROR</stringProp>
<stringProp name="RegexExtractor.match_number">1</stringProp>
</RegexExtractor>
<hashTree/>
</hashTree>
<BeanShellAssertion guiclass="BeanShellAssertionGui" testclass="BeanShellAssertion" testname="BeanShell Assertion - 简单示例" enabled="true">
<stringProp name="BeanShellAssertion.query">import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.assertions.AssertionResult; String exp = vars.get("exp_sysNo");
String act = vars.get("sysNo"); if (exp.equals(act)) {
log.info(exp);
log.info(act);
log.info("Test passed.");
} else {
log.info(exp);
log.info(act);
log.info("Test failed to assert : Expected <" + exp + ">, but <" + act + ">.");
} ac = "a"; if (exp.equals(ac)) {
log.info(exp);
log.info(ac);
log.info("Test passed.");
} else {
log.info(exp);
log.info(ac);
log.info("Test failed to assert : Expected <" + exp + ">, but <" + ac + ">.");
} </stringProp>
<stringProp name="BeanShellAssertion.filename"></stringProp>
<stringProp name="BeanShellAssertion.parameters"></stringProp>
<boolProp name="BeanShellAssertion.resetInterpreter">true</boolProp>
</BeanShellAssertion>
<hashTree/>
<BeanShellAssertion guiclass="BeanShellAssertionGui" testclass="BeanShellAssertion" testname="BeanShell Assertion - 常用方法" enabled="true">
<stringProp name="BeanShellAssertion.query">
log.info("\n01.获取请求响应数据:SampleResult.getResponseData()" + SampleResult.getResponseData() + "\n\n");
log.info("\n02.获取请求响应返回码:SampleResult.getResponseCode()\n" + SampleResult.getResponseCode() + "\n\n");
log.info("\n03.获取请求响应信息:SampleResult.getResponseMessage()\n" + SampleResult.getResponseMessage() + "\n\n");
log.info("\n04.获取请求响应头信息:SampleResult.getResponseHeaders()\n" + SampleResult.getResponseHeaders() + "\n\n"); log.info("\n05.获取请求的头信息:SampleResult.getRequestHeaders()\n" + SampleResult.getRequestHeaders() + "\n\n");
log.info("\n06.获取请求的标签:SampleResult.getSampleLabel()\n" + SampleResult.getSampleLabel() + "\n\n"); log.info("\n07.获取请求执行结果:SampleResult.isSuccessful()\n" + SampleResult.isSuccessful() + "\n\n");
log.info("\n08.设置请求响应的返回码:SampleResult.setResponseCode(\"502\")\n" + SampleResult.setResponseCode("502") + "\n\n");
log.info("\n09.设置请求响应的信息:SampleResult.setResponseMessage(\"SampleResult.setResponseMessage\")\n" + SampleResult.setResponseMessage("设置响应信息:SampleResult.setResponseMessage") + "\n\n");
log.info("\n10.获取请求的返回码:SampleResult.getResponseCode()\n" + SampleResult.getResponseCode() + "\n\n");
log.info("\n11.获取请求的响应信息:SampleResult.getResponseMessage()\n" + SampleResult.getResponseMessage() + "\n\n"); log.info("\n12.获取请求的头信息:vars.toString()\n" + vars.toString() + "\n\n"); log.info("\n13.获取请求的头信息:props.toString()\n" + props.toString() + "\n\n");
log.info("\n14.获取请求的头信息:ctx.toString()\n" + ctx.toString() + "\n\n"); </stringProp>
<stringProp name="BeanShellAssertion.filename"></stringProp>
<stringProp name="BeanShellAssertion.parameters"></stringProp>
<boolProp name="BeanShellAssertion.resetInterpreter">false</boolProp>
</BeanShellAssertion>
<hashTree/>
</hashTree>
<ResultCollector guiclass="AssertionVisualizer" testclass="ResultCollector" testname="断言结果" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<threadCounts>true</threadCounts>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="察看结果树" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<threadCounts>true</threadCounts>
</value>
</objProp>
<stringProp name="filename">${__property(JmeterAuto_LogFile)}</stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</jmeterTestPlan>
BeanShell Assertion 简单实例源码
执行结果如下所示:
2015/09/02 17:22:35 INFO - jmeter.engine.StandardJMeterEngine: Running the test!
2015/09/02 17:22:35 INFO - jmeter.samplers.SampleEvent: List of sample_variables: []
2015/09/02 17:22:35 INFO - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*)
2015/09/02 17:22:35 INFO - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : 008-搜索商品
2015/09/02 17:22:35 INFO - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group 008-搜索商品.
2015/09/02 17:22:35 INFO - jmeter.engine.StandardJMeterEngine: Thread will continue on error
2015/09/02 17:22:35 INFO - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 0 perThread 0.0 delayedStart=false
2015/09/02 17:22:35 INFO - jmeter.threads.ThreadGroup: Started thread group number 1
2015/09/02 17:22:35 INFO - jmeter.engine.StandardJMeterEngine: All thread groups have been started
2015/09/02 17:22:35 INFO - jmeter.threads.JMeterThread: Thread started: 008-搜索商品 1-1
2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement: 2169256
2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement: 2169256
2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement: Test passed.
2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement: 2169256
2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement: a
2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement: Test failed to assert : Expected <2169256>, but <a>.
2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
01.获取请求响应数据:SampleResult.getResponseData()[B@652fd11d 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
02.获取请求响应返回码:SampleResult.getResponseCode()
200 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
03.获取请求响应信息:SampleResult.getResponseMessage()
OK 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
04.获取请求响应头信息:SampleResult.getResponseHeaders()
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 02 Sep 2015 09:19:43 GMT
Content-Type: text/html; charset=GB2312
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Vary: Accept-Encoding
Cache-Control: max-age=0
Pragma: no-cache
Expires: Wed, 02 Sep 2015 09:19:43 GMT
X-Cache: HIT-LT
Content-Encoding: gzip 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
05.获取请求的头信息:SampleResult.getRequestHeaders()
Connection: keep-alive
Charset: UTF-8
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9502 Build/KOT49H)
Content-Length: 140
Host: mb.51buy.com 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
06.获取请求的标签:SampleResult.getSampleLabel()
008-01-搜索商品 【101-006-78945 | 29313】 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
07.获取请求执行结果:SampleResult.isSuccessful()
true 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
08.设置请求响应的返回码:SampleResult.setResponseCode("502")
void 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
09.设置请求响应的信息:SampleResult.setResponseMessage("SampleResult.setResponseMessage")
void 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
10.获取请求的返回码:SampleResult.getResponseCode()
502 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
11.获取请求的响应信息:SampleResult.getResponseMessage()
设置响应信息:SampleResult.setResponseMessage 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
12.获取请求的头信息:vars.toString()
org.apache.jmeter.threads.JMeterVariables@6e6e7861 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
13.获取请求的头信息:props.toString()
{not_in_menu=org.apache.jmeter.protocol.http.modifier.gui.ParamModifierGui, HTTP User Parameter Modifier, org.apache.jmeter.protocol.http.control.gui.WebServiceSamplerGui, xml.parser=org.apache.xerces.parsers.SAXParser, cookies=cookies, wmlParser.className=org.apache.jmeter.protocol.http.parser.RegexpHTMLParser, START.YMD=20150902, HTTPResponse.parsers=htmlParser wmlParser, view.results.tree.renderers_order=.RenderAsText,.RenderAsRegexp,.RenderAsCssJQuery,.RenderAsXPath,.RenderAsHTML,.RenderAsHTMLWithEmbedded,.RenderAsDocument,.RenderAsJSON,.RenderAsXML, remote_hosts=127.0.0.1, system.properties=system.properties, beanshell.server.file=../extras/startup.bsh, jmeter.version=2.13 r1665067, log_level.jmeter.junit=DEBUG, sampleresult.timestamp.start=true, START.HMS=170201, jmeter.laf.mac=System, log_level.jorphan=INFO, classfinder.functions.contain=.functions., user.properties=user.properties, wmlParser.types=text/vnd.wap.wml , log_level.jmeter=INFO, TESTSTART.MS=1441185755385, START.MS=1441184521097, classfinder.functions.notContain=.gui., htmlParser.types=text/html application/xhtml+xml application/xml text/xml, upgrade_properties=/bin/upgrade.properties} 2015/09/02 17:22:35 INFO - jmeter.util.BeanShellTestElement:
14.获取请求的头信息:ctx.toString()
org.apache.jmeter.threads.JMeterContext@349e3c2b 2015/09/02 17:22:35 INFO - jmeter.threads.JMeterThread: Thread is done: 008-搜索商品 1-1
2015/09/02 17:22:35 INFO - jmeter.threads.JMeterThread: Thread finished: 008-搜索商品 1-1
2015/09/02 17:22:35 INFO - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test
2015/09/02 17:22:35 INFO - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*)
PS:BeanShell 是一个 Java 轻量化脚本语言,详细信息请参阅: BeanShell官方网址。
至此, JMeter学习-015-JMeter 断言之-Bean Shell Assertion 顺利完结,希望此文能够给初学 JMeter 的您一份参考。
最后,非常感谢亲的驻足,希望此文能对亲有所帮助。热烈欢迎亲一起探讨,共同进步。非常感谢! ^_^