• JMeter学习-015-JMeter 断言之-Bean Shell Assertion


    前面的博文中有对 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】,其配置页面如下所示:

    配置参数列表说明如下:

    配置项属性 详细描述 是否必填
    名称 脚本目录树显示当前 Bean Shell Assertion 的概要描述性名称。该名称存储在脚本变量标签中。
    注释 对当前项更加详细的描述。例如相关业务描述等等。
    Reset bsh.Interpreter before each calll 若选择此项,则将为每个样本创建对应的解释器。一般用不到。
    参数

    传递到脚本的参数,有如下两种参数传递方式:

    1. String Parameters:作为单一的变量参数传递
    2. String[] bash.args:作为数组的字符串数组参数,参数之间通过空格进行分割
    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 的简单应用实例,敬请参阅!

      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <jmeterTestPlan version="1.2" properties="2.8" jmeter="2.13 r1665067">
      3   <hashTree>
      4     <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="接口自动化测试实例 - BeanShell Assertion 简单实例演示" enabled="true">
      5       <stringProp name="TestPlan.comments"></stringProp>
      6       <boolProp name="TestPlan.functional_mode">false</boolProp>
      7       <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      8       <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
      9         <collectionProp name="Arguments.arguments"/>
     10       </elementProp>
     11       <stringProp name="TestPlan.user_define_classpath"></stringProp>
     12     </TestPlan>
     13     <hashTree>
     14       <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="008-搜索商品" enabled="true">
     15         <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
     16         <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器" enabled="true">
     17           <boolProp name="LoopController.continue_forever">false</boolProp>
     18           <stringProp name="LoopController.loops">1</stringProp>
     19         </elementProp>
     20         <stringProp name="ThreadGroup.num_threads">1</stringProp>
     21         <stringProp name="ThreadGroup.ramp_time">0</stringProp>
     22         <longProp name="ThreadGroup.start_time">1419232321000</longProp>
     23         <longProp name="ThreadGroup.end_time">1419232321000</longProp>
     24         <boolProp name="ThreadGroup.scheduler">false</boolProp>
     25         <stringProp name="ThreadGroup.duration"></stringProp>
     26         <stringProp name="ThreadGroup.delay"></stringProp>
     27       </ThreadGroup>
     28       <hashTree>
     29         <Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量 - 商品编号 101-006-78945" enabled="true">
     30           <collectionProp name="Arguments.arguments">
     31             <elementProp name="goodsNo" elementType="Argument">
     32               <stringProp name="Argument.name">goodsNo</stringProp>
     33               <stringProp name="Argument.value">101-006-78945</stringProp>
     34               <stringProp name="Argument.desc">商品编号</stringProp>
     35               <stringProp name="Argument.metadata">=</stringProp>
     36             </elementProp>
     37             <elementProp name="districtId" elementType="Argument">
     38               <stringProp name="Argument.name">districtId</stringProp>
     39               <stringProp name="Argument.value">29313</stringProp>
     40               <stringProp name="Argument.desc">配送区域</stringProp>
     41               <stringProp name="Argument.metadata">=</stringProp>
     42             </elementProp>
     43             <elementProp name="areacode" elementType="Argument">
     44               <stringProp name="Argument.name">areacode</stringProp>
     45               <stringProp name="Argument.value">1</stringProp>
     46               <stringProp name="Argument.desc">仓库大区</stringProp>
     47               <stringProp name="Argument.metadata">=</stringProp>
     48             </elementProp>
     49             <elementProp name="exp_sysNo" elementType="Argument">
     50               <stringProp name="Argument.name">exp_sysNo</stringProp>
     51               <stringProp name="Argument.value">2169256</stringProp>
     52               <stringProp name="Argument.desc">商品系统编号,用于校验搜索结果</stringProp>
     53               <stringProp name="Argument.metadata">=</stringProp>
     54             </elementProp>
     55             <elementProp name="skuid" elementType="Argument">
     56               <stringProp name="Argument.name">skuid</stringProp>
     57               <stringProp name="Argument.value">489349159815</stringProp>
     58               <stringProp name="Argument.desc">单品SKU,用户校验搜索结果</stringProp>
     59               <stringProp name="Argument.metadata">=</stringProp>
     60             </elementProp>
     61             <elementProp name="appSource" elementType="Argument">
     62               <stringProp name="Argument.name">appSource</stringProp>
     63               <stringProp name="Argument.value">android</stringProp>
     64               <stringProp name="Argument.desc">平台</stringProp>
     65               <stringProp name="Argument.metadata">=</stringProp>
     66             </elementProp>
     67             <elementProp name="appVersion" elementType="Argument">
     68               <stringProp name="Argument.name">appVersion</stringProp>
     69               <stringProp name="Argument.value">45</stringProp>
     70               <stringProp name="Argument.desc">版本</stringProp>
     71               <stringProp name="Argument.metadata">=</stringProp>
     72             </elementProp>
     73           </collectionProp>
     74           <stringProp name="TestPlan.comments">,,,,,,</stringProp>
     75         </Arguments>
     76         <hashTree/>
     77         <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="008-01-搜索商品 【${goodsNo} | ${districtId}】" enabled="true">
     78           <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
     79             <collectionProp name="Arguments.arguments">
     80               <elementProp name="q" elementType="HTTPArgument">
     81                 <boolProp name="HTTPArgument.always_encode">false</boolProp>
     82                 <stringProp name="Argument.value">${goodsNo}</stringProp>
     83                 <stringProp name="Argument.metadata">=</stringProp>
     84                 <boolProp name="HTTPArgument.use_equals">true</boolProp>
     85                 <stringProp name="Argument.name">q</stringProp>
     86               </elementProp>
     87               <elementProp name="districtId" elementType="HTTPArgument">
     88                 <boolProp name="HTTPArgument.always_encode">false</boolProp>
     89                 <stringProp name="Argument.value">${districtId}</stringProp>
     90                 <stringProp name="Argument.metadata">=</stringProp>
     91                 <boolProp name="HTTPArgument.use_equals">true</boolProp>
     92                 <stringProp name="Argument.name">districtId</stringProp>
     93               </elementProp>
     94               <elementProp name="areacode" elementType="HTTPArgument">
     95                 <boolProp name="HTTPArgument.always_encode">false</boolProp>
     96                 <stringProp name="Argument.value">${areacode}</stringProp>
     97                 <stringProp name="Argument.metadata">=</stringProp>
     98                 <boolProp name="HTTPArgument.use_equals">true</boolProp>
     99                 <stringProp name="Argument.name">areacode</stringProp>
    100               </elementProp>
    101               <elementProp name="dtype" elementType="HTTPArgument">
    102                 <boolProp name="HTTPArgument.always_encode">false</boolProp>
    103                 <stringProp name="Argument.value">list|page|classes</stringProp>
    104                 <stringProp name="Argument.metadata">=</stringProp>
    105                 <boolProp name="HTTPArgument.use_equals">true</boolProp>
    106                 <stringProp name="Argument.name">dtype</stringProp>
    107               </elementProp>
    108               <elementProp name="districtId" elementType="HTTPArgument">
    109                 <boolProp name="HTTPArgument.always_encode">false</boolProp>
    110                 <stringProp name="Argument.name">districtId</stringProp>
    111                 <stringProp name="Argument.value">${districtId}</stringProp>
    112                 <stringProp name="Argument.metadata">=</stringProp>
    113                 <boolProp name="HTTPArgument.use_equals">true</boolProp>
    114               </elementProp>
    115               <elementProp name="exAppTag" elementType="HTTPArgument">
    116                 <boolProp name="HTTPArgument.always_encode">false</boolProp>
    117                 <stringProp name="Argument.name">exAppTag</stringProp>
    118                 <stringProp name="Argument.value">2045191607</stringProp>
    119                 <stringProp name="Argument.metadata">=</stringProp>
    120                 <boolProp name="HTTPArgument.use_equals">true</boolProp>
    121               </elementProp>
    122               <elementProp name="appSource" elementType="HTTPArgument">
    123                 <boolProp name="HTTPArgument.always_encode">false</boolProp>
    124                 <stringProp name="Argument.value">${appSource}</stringProp>
    125                 <stringProp name="Argument.metadata">=</stringProp>
    126                 <boolProp name="HTTPArgument.use_equals">true</boolProp>
    127                 <stringProp name="Argument.name">appSource</stringProp>
    128               </elementProp>
    129               <elementProp name="appVersion" elementType="HTTPArgument">
    130                 <boolProp name="HTTPArgument.always_encode">false</boolProp>
    131                 <stringProp name="Argument.value">${appVersion}</stringProp>
    132                 <stringProp name="Argument.metadata">=</stringProp>
    133                 <boolProp name="HTTPArgument.use_equals">true</boolProp>
    134                 <stringProp name="Argument.name">appVersion</stringProp>
    135               </elementProp>
    136             </collectionProp>
    137           </elementProp>
    138           <stringProp name="HTTPSampler.domain">mb.51buy.com</stringProp>
    139           <stringProp name="HTTPSampler.port"></stringProp>
    140           <stringProp name="HTTPSampler.connect_timeout"></stringProp>
    141           <stringProp name="HTTPSampler.response_timeout"></stringProp>
    142           <stringProp name="HTTPSampler.protocol">http</stringProp>
    143           <stringProp name="HTTPSampler.contentEncoding">GB2312</stringProp>
    144           <stringProp name="HTTPSampler.path">/json.php?mod=Search&amp;act=page&amp;p=1&amp;pp=20</stringProp>
    145           <stringProp name="HTTPSampler.method">POST</stringProp>
    146           <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
    147           <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
    148           <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
    149           <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
    150           <boolProp name="HTTPSampler.monitor">false</boolProp>
    151           <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
    152         </HTTPSamplerProxy>
    153         <hashTree>
    154           <HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP信息头管理器" enabled="true">
    155             <collectionProp name="HeaderManager.headers">
    156               <elementProp name="Charset" elementType="Header">
    157                 <stringProp name="Header.name">Charset</stringProp>
    158                 <stringProp name="Header.value">UTF-8</stringProp>
    159               </elementProp>
    160               <elementProp name="Content-Type" elementType="Header">
    161                 <stringProp name="Header.name">Content-Type</stringProp>
    162                 <stringProp name="Header.value">application/x-www-form-urlencoded</stringProp>
    163               </elementProp>
    164               <elementProp name="Accept-Encoding" elementType="Header">
    165                 <stringProp name="Header.name">Accept-Encoding</stringProp>
    166                 <stringProp name="Header.value">gzip</stringProp>
    167               </elementProp>
    168               <elementProp name="User-Agent" elementType="Header">
    169                 <stringProp name="Header.name">User-Agent</stringProp>
    170                 <stringProp name="Header.value">Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9502 Build/KOT49H)</stringProp>
    171               </elementProp>
    172             </collectionProp>
    173           </HeaderManager>
    174           <hashTree/>
    175           <RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="获取商品的系统编号" enabled="true">
    176             <stringProp name="RegexExtractor.useHeaders">false</stringProp>
    177             <stringProp name="RegexExtractor.refname">sysNo</stringProp>
    178             <stringProp name="RegexExtractor.regex">&quot;sysNo&quot;:&quot;(.+?)&quot;,&quot;</stringProp>
    179             <stringProp name="RegexExtractor.template">$1$</stringProp>
    180             <stringProp name="RegexExtractor.default">ERROR</stringProp>
    181             <stringProp name="RegexExtractor.match_number">1</stringProp>
    182           </RegexExtractor>
    183           <hashTree/>
    184         </hashTree>
    185         <BeanShellAssertion guiclass="BeanShellAssertionGui" testclass="BeanShellAssertion" testname="BeanShell Assertion - 简单示例" enabled="true">
    186           <stringProp name="BeanShellAssertion.query">import org.apache.jmeter.util.JMeterUtils;
    187 import org.apache.jmeter.samplers.SampleResult;
    188 import org.apache.jmeter.assertions.AssertionResult;
    189 
    190 String exp = vars.get(&quot;exp_sysNo&quot;);
    191 String act = vars.get(&quot;sysNo&quot;);
    192 
    193 if (exp.equals(act)) {
    194     log.info(exp);
    195     log.info(act);
    196     log.info(&quot;Test passed.&quot;);
    197 } else {
    198     log.info(exp);
    199     log.info(act);
    200     log.info(&quot;Test failed to assert : Expected &lt;&quot; + exp + &quot;&gt;, but &lt;&quot; + act + &quot;&gt;.&quot;);
    201 }
    202 
    203 ac = &quot;a&quot;;
    204 
    205 if (exp.equals(ac)) {
    206     log.info(exp);
    207     log.info(ac);
    208     log.info(&quot;Test passed.&quot;);
    209 } else {
    210     log.info(exp);
    211     log.info(ac);
    212     log.info(&quot;Test failed to assert : Expected &lt;&quot; + exp + &quot;&gt;, but &lt;&quot; + ac + &quot;&gt;.&quot;);
    213 }
    214 
    215 </stringProp>
    216           <stringProp name="BeanShellAssertion.filename"></stringProp>
    217           <stringProp name="BeanShellAssertion.parameters"></stringProp>
    218           <boolProp name="BeanShellAssertion.resetInterpreter">true</boolProp>
    219         </BeanShellAssertion>
    220         <hashTree/>
    221         <BeanShellAssertion guiclass="BeanShellAssertionGui" testclass="BeanShellAssertion" testname="BeanShell Assertion - 常用方法" enabled="true">
    222           <stringProp name="BeanShellAssertion.query">
    223 log.info(&quot;
    01.获取请求响应数据:SampleResult.getResponseData()&quot; + SampleResult.getResponseData() + &quot;
    
    &quot;);
    224 log.info(&quot;
    02.获取请求响应返回码:SampleResult.getResponseCode()
    &quot; + SampleResult.getResponseCode() + &quot;
    
    &quot;);
    225 log.info(&quot;
    03.获取请求响应信息:SampleResult.getResponseMessage()
    &quot; + SampleResult.getResponseMessage() + &quot;
    
    &quot;);
    226 log.info(&quot;
    04.获取请求响应头信息:SampleResult.getResponseHeaders()
    &quot; + SampleResult.getResponseHeaders() + &quot;
    
    &quot;);
    227 
    228 log.info(&quot;
    05.获取请求的头信息:SampleResult.getRequestHeaders()
    &quot; + SampleResult.getRequestHeaders() + &quot;
    
    &quot;);
    229 log.info(&quot;
    06.获取请求的标签:SampleResult.getSampleLabel()
    &quot; + SampleResult.getSampleLabel() + &quot;
    
    &quot;);
    230 
    231 log.info(&quot;
    07.获取请求执行结果:SampleResult.isSuccessful()
    &quot; + SampleResult.isSuccessful() + &quot;
    
    &quot;);
    232 log.info(&quot;
    08.设置请求响应的返回码:SampleResult.setResponseCode(&quot;502&quot;)
    &quot; + SampleResult.setResponseCode(&quot;502&quot;) + &quot;
    
    &quot;);
    233 log.info(&quot;
    09.设置请求响应的信息:SampleResult.setResponseMessage(&quot;SampleResult.setResponseMessage&quot;)
    &quot; + SampleResult.setResponseMessage(&quot;设置响应信息:SampleResult.setResponseMessage&quot;) + &quot;
    
    &quot;);
    234 log.info(&quot;
    10.获取请求的返回码:SampleResult.getResponseCode()
    &quot; + SampleResult.getResponseCode() + &quot;
    
    &quot;);
    235 log.info(&quot;
    11.获取请求的响应信息:SampleResult.getResponseMessage()
    &quot; + SampleResult.getResponseMessage() + &quot;
    
    &quot;);
    236 
    237 log.info(&quot;
    12.获取请求的头信息:vars.toString()
    &quot; + vars.toString() + &quot;
    
    &quot;);
    238 
    239 log.info(&quot;
    13.获取请求的头信息:props.toString()
    &quot; + props.toString() + &quot;
    
    &quot;);
    240 log.info(&quot;
    14.获取请求的头信息:ctx.toString()
    &quot; + ctx.toString() + &quot;
    
    &quot;);
    241 
    242 </stringProp>
    243           <stringProp name="BeanShellAssertion.filename"></stringProp>
    244           <stringProp name="BeanShellAssertion.parameters"></stringProp>
    245           <boolProp name="BeanShellAssertion.resetInterpreter">false</boolProp>
    246         </BeanShellAssertion>
    247         <hashTree/>
    248       </hashTree>
    249       <ResultCollector guiclass="AssertionVisualizer" testclass="ResultCollector" testname="断言结果" enabled="true">
    250         <boolProp name="ResultCollector.error_logging">false</boolProp>
    251         <objProp>
    252           <name>saveConfig</name>
    253           <value class="SampleSaveConfiguration">
    254             <time>true</time>
    255             <latency>true</latency>
    256             <timestamp>true</timestamp>
    257             <success>true</success>
    258             <label>true</label>
    259             <code>true</code>
    260             <message>true</message>
    261             <threadName>true</threadName>
    262             <dataType>true</dataType>
    263             <encoding>false</encoding>
    264             <assertions>true</assertions>
    265             <subresults>true</subresults>
    266             <responseData>false</responseData>
    267             <samplerData>false</samplerData>
    268             <xml>false</xml>
    269             <fieldNames>false</fieldNames>
    270             <responseHeaders>false</responseHeaders>
    271             <requestHeaders>false</requestHeaders>
    272             <responseDataOnError>false</responseDataOnError>
    273             <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
    274             <assertionsResultsToSave>0</assertionsResultsToSave>
    275             <bytes>true</bytes>
    276             <threadCounts>true</threadCounts>
    277           </value>
    278         </objProp>
    279         <stringProp name="filename"></stringProp>
    280       </ResultCollector>
    281       <hashTree/>
    282       <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="察看结果树" enabled="true">
    283         <boolProp name="ResultCollector.error_logging">false</boolProp>
    284         <objProp>
    285           <name>saveConfig</name>
    286           <value class="SampleSaveConfiguration">
    287             <time>true</time>
    288             <latency>true</latency>
    289             <timestamp>true</timestamp>
    290             <success>true</success>
    291             <label>true</label>
    292             <code>true</code>
    293             <message>true</message>
    294             <threadName>true</threadName>
    295             <dataType>true</dataType>
    296             <encoding>false</encoding>
    297             <assertions>true</assertions>
    298             <subresults>true</subresults>
    299             <responseData>false</responseData>
    300             <samplerData>false</samplerData>
    301             <xml>false</xml>
    302             <fieldNames>false</fieldNames>
    303             <responseHeaders>false</responseHeaders>
    304             <requestHeaders>false</requestHeaders>
    305             <responseDataOnError>false</responseDataOnError>
    306             <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
    307             <assertionsResultsToSave>0</assertionsResultsToSave>
    308             <bytes>true</bytes>
    309             <threadCounts>true</threadCounts>
    310           </value>
    311         </objProp>
    312         <stringProp name="filename">${__property(JmeterAuto_LogFile)}</stringProp>
    313       </ResultCollector>
    314       <hashTree/>
    315     </hashTree>
    316   </hashTree>
    317 </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 的您一份参考。

    最后,非常感谢亲的驻足,希望此文能对亲有所帮助。热烈欢迎亲一起探讨,共同进步。非常感谢! ^_^

     

  • 相关阅读:
    购物菜单
    数据库
    增删改查
    页面交互
    计算器
    2020.9.21
    团队-团队编程项目中国象棋-项目总结
    团队-团队编程项目作业名称-最终程序
    课后作业-阅读任务-阅读提问-4
    《20171130-构建之法:现代软件工程-阅读笔记》
  • 原文地址:https://www.cnblogs.com/fengpingfan/p/4762068.html
Copyright © 2020-2023  润新知