问题描述
我使用 JMeter 做 Web 服务器的性能测试.我的测试用例如下:
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.
我是 JMeter 的新手,不知道如何实现它.JMeter的前处理器和后处理器基本都学过,但是还是不知道怎么做.
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 :
右击->添加 ->线程(用户)->线程组
- 现在是实际的第一步(如果您使用 REST):
添加 ->采样器 ->Http请求
您在底部随请求发送文件
.如果这是您的要求,您可以添加文件附件.
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>
这是你要做的:
右键单击您之前添加的 http 请求(在步骤 1 中)->后处理器 ->Xpath 提取器
Reference Name
是要在其中存储值的变量的名称.我们将其命名为 url
.而 Xpath query
是 Response/url
或 //Response/url
如果你得到更多的响应标签.如果你想要第一个 //Response[1]/url
等等..
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..
- 重复第 1 步(复制/粘贴采样器并删除您不再需要的
Xpath Extractor
),并将Server Name or IP
更改为${url}
这是之前返回的值.
- Repeat step 1 (copy/paste sampler and remove the
Xpath Extractor
you don't need it anymore), and change theServer Name or IP
to${url}
which is the value previously returned.
瞧,你去吧.如果您有更具体的问题,请告诉我.Jmeter 很有趣.
And Voila there you go. Let me know if you got more specific questions. Jmeter is fun.
Per Grace 评论:
想提取https://192.168.100.46/updserver/download?action=signature_download&token=
响应数据不足:
<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
所以现在你有了 url
变量,你可以在测试中进一步使用它作为 ${url}
.让我知道这是否适合您.我用虚拟采样器进行了测试,它对我有用.
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.
这篇关于如何解析 sample1 的响应以在 JMeter 中创建新样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!