I use JMeter to do performance test of web server. My test case is as following:
step1: send file update request to server.
step2: server will return some files URL as html response
step3: client need to create new request with the URL returned in step2,thus need to parse
the response of step2.
I am new to JMeter, and do not know how to implement it. I basically learned JMeter about the pre-processor and post-processor, but still no clue about how to do.
Ok let's start before the first step :
Right click -> Add -> Threads (Users) -> Thread Group
Add -> Sampler -> Http Request
You have at the bottom part Send Files With the Request
. You can add file attachment if that is what you asked.
Let's assume your response is this :
<Response>
<name>StackOverflow.com</name>
<url>http://stackoverflow.com/questions/11186423/how-to-parse-response-of-sample1-to-create-new-sample-in-jmeter</url>
</Response>
Here is what you do :
Right click on The http request you previously added (in step 1) -> Post Processors -> Xpath Extractor
Reference Name
is the name of the variable in which you want to store the value. Let's name it url
. And Xpath query
is Response/url
or //Response/url
if you get more response tags. If you want the first one //Response[1]/url
and so on..
Xpath Extractor
you don't need it anymore), and change the Server Name or IP
to ${url}
which is the value previously returned. And Voila there you go. Let me know if you got more specific questions. Jmeter is fun.
Per Grace comment :
Wants to extract https://192.168.100.46/updserver/download?action=signature_download&token=
Out of response data :
<responseData class="java.lang.String"><html>
<body>
ERROR=0
MSG=N/A
FILELIST=1555;1340778737370;1526545487;
VERSION=1.002
URL=https://192.168.100.46/updserver/download?action=signature_download&token=
INTERVAL=0
</body>
</html>
</responseData>
This should be pretty simple. Add a post processor -> Regular Expression Extractor
and put the following :
Reference Name : url
Regular Expression : (http[\S]+)
Template : $1$
Match No. (0 for Random): 1
So now you have url
variable that you can use further in your test as ${url}
. Let me know if that works for you. I tested with dummy sampler and it works for me.