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

Sim*_*ang 13 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.
Run Code Online (Sandbox Code Playgroud)

我是JMeter的新手,不知道如何实现它.我基本上学习了关于预处理器和后处理器的JMeter,但仍然没有关于如何做的线索.

ant*_*ant 27

好的,让我们在第一步之前开始:

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>
Run Code Online (Sandbox Code Playgroud)

这是你做的:

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>
Run Code Online (Sandbox Code Playgroud)

这应该很简单.Add a post processor -> Regular Expression Extractor并提出以下内容:

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

所以现在你有url变量可以在测试中进一步使用${url}.如果这对您有用,请告诉我.我用虚拟采样器进行了测试,它适用于我.