如何解析Jmeter响应并提出新请求 [英] How to parse Jmeter response and make a new request

查看:86
本文介绍了如何解析Jmeter响应并提出新请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jMeter测试Tomcat应用程序.我需要解析jMeter响应并提出第二个请求.第一个响应如下所示:

I'm using jMeter to test a Tomcat application. I need to parse the jMeter response and make a second request. The first response looks like this:

<responseData class="java.lang.String">&lt;html&gt;&#xd;
&lt;body&gt;&#xd;
ERROR=0&#xd;
MSG=N/A&#xd;
FILELIST=1555;1340778737370;1526545487;&#xd;
VERSION=1.002&#xd;
URL=https://192.168.100.46/updserver/download?action=signature_download&amp;token=&#xd;
INTERVAL=0&#xd;
&lt;/body&gt;&#xd;
&lt;/html&gt;&#xd;
</responseData>

我需要提取"FILELIST"和"URL"变量,并将它们注入新的URL:

I need to extract the "FILELIST" and "URL" variables and inject them into a new URL:

https://192.168.100.46/updserver/download?action=signature_download&amp;token=1555;1340778737370;1526545487;&#xd;

我知道有一些后处理器可以做到这一点,但是不知道如何做到这一点.顺便说一句,第二个请求将从Tomcat servlet下载一些文件,有没有办法让jMeter仅仅下载流而不写入物理文件?这样我就可以对我的servlet进行负载性能测试.

I know there is some post-processor to do that, but no clue how to do it. BTW, the second request will download some file from the Tomcat servlet, is there a way to let jMeter just download the stream but without writing to a physical file? So that I could do a load performance test against my servlet.

推荐答案

好,所以您已经知道如何从响应中提取URL,我在上一个答案中描述了如何:

Ok so you already know how to extract url out of your response, I described how in my previous answer :

https://stackoverflow.com/a/11188349/169277

但是在这里,我将对此进行扩展.因此,您有采样器,并且已经有了$ {url}.现在,您需要FILELIST并组装新的URL.

But here I'll just expand on that. So you have your sampler and you already got ${url}. Now you need FILELIST and assemble new url.

假设您已经有请求和URL提取器.添加一个新的Regular expression extractor.

Assuming you already have request and url extractor in place. Add a new Regular expression extractor.

Right click on request sampler -> Post Processors -> Regular Expression Extractor

Reference Name : FILELIST
Regular Expression : FILELIST=(\S+)
Template : $1$
Match No. (0 for Random): 1

因此,现在您有1个请求采样器和2个正则表达式提取器.您需要添加其他后处理器才能组合新的网址.

So now you have 1 request sampler and 2 regular expression extractors. You need to add additional post processor to be able to assemble the new url.

Right click on request sampler -> Post Processors -> BSF PostProcessor

Script language下的语言下拉列表中选择beanshell,并在大字段Script:中将其粘贴:

Choose the beanshell from the language droplist under the Script language and in the big field Script: paste this :

vars.put("NEW_URL", "${__javaScript('${url}'.replace('&#xd;'\,'${FILELIST}'))}");

现在您有${NEW_URL}可以在测试中进一步使用.

And now you have ${NEW_URL} to use further in your tests.

解决问题总是有不止一种方法,这种衬里看起来确实很丑,但是可​​以达到目的.

在我的测试中,结果如您所愿(调试采样器):

In my test the result is as you requested (Debug Sampler) :

url=https://192.168.100.46/updserver/download?action=signature_download&amp;token=&#xd;
FILELIST=1555;1340778737370;1526545487;&#xd;
NEW_URL=https://192.168.100.46/updserver/download?action=signature_download&amp;token=1555;1340778737370;1526545487;&#xd;

我想我不明白您如何命名变量.但是最终结果是您在问题中描述的结果.请参阅附带工作示例的.jmx测试:

I think I don't understand how you name your variables. But the end result is the one you described in your question. Please see the .jmx test attached with working example :

http://www.filefactory.com/file/1q7nfitmh4qd/n/so_11309469_jmx

这是一个适用于2.6+版本的jmeter的jmeter .jmx文件

It's a jmeter .jmx file working with 2.6+ version of jmeter

这篇关于如何解析Jmeter响应并提出新请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆