Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse Jmeter response and make a new request

Tags:

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> 

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; 

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.

like image 326
Simon Wang Avatar asked Jul 03 '12 07:07

Simon Wang


People also ask

Can we extract value from request body in JMeter?

You can use Regular Expression extractor to extract the e-mail address from the request URL. Add Regular Expression Extractor as a child of sampler which sends the post request. In the Regular Expression Extractor select URL in Response Filed to check instead of Body.

What is JSR223 sampler in JMeter?

JMeter Sampler elements allow taking actions in any place in the test, without depending on a specific request. In this example a JSR223 sampler will be used to send HTTP requests to either BlazeMeter or JMeter websites, based on the thread id.


2 Answers

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

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.

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 

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

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}'))}"); 

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

There is always more than one way of solving problems, this one liner looks really ugly but it serves the purpose.

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; 

EDIT :

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

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

like image 181
ant Avatar answered Sep 29 '22 04:09

ant


To capture part of the response use Regular Expression Extractor.

You can test your regex expression on response data using ViewResultsTree listener. Just select Regexp tester in the drop-down box at the bottom of the left hand panel in your ViewResultsTree listener.

like image 41
Marko Bonaci Avatar answered Sep 29 '22 04:09

Marko Bonaci