如何解析sample1的响应以在JMeter中创建新样本


问题内容

我使用JMeter进行Web服务器的性能测试。我的测试用例如下:

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,但仍然不知道如何做。


问题答案:

好吧,让我们从第一步开始:

Right click -> Add -> Threads (Users) -> Thread Group

  • 现在是实际的第一步(如果使用REST):

Add -> Sampler -> Http Request

您在底部Send Files With the Request。您可以根据需要添加文件附件。

  • 从服务器提取响应:

假设您的答复是这样的:

<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>

这是您的工作:

Right click on The http request you previously added (in step 1) -> Post Processors -> Xpath Extractor

Reference Name是要在其中存储值的变量的名称。命名吧url。并且Xpath queryResponse/url还是//Response/url如果您获得更多响应标签。如果要第一个//Response[1]/url,依此类推。

  • 重复步骤1(复制/粘贴采样器并删除Xpath Extractor不再需要的采样器),然后将更Server Name or IP改为${url}先前返回的值。

Voila,你去了。让我知道您是否还有其他具体问题。Jmeter很有趣。

Per Grace评论:

要提取
https://192.168.100.46/updserver/download?action=signature_download&amp;token=&#xd;

超出响应数据:

<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>

这应该很简单。Add a post processor -> Regular Expression Extractor并放置以下内容:

Reference Name : url 
Regular Expression : (http[\S]+)
Template : $1$
Match No. (0 for Random): 1

因此,现在有了url变量,您可以在测试中进一步使用它${url}。让我知道这是否适合您。我用虚拟采样器测试过,它对我有用。