我使用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
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 query
为Response/url
或者//Response/url
如果你得到更多的响应标签.如果你想要第一个//Response[1]/url
等等..
Xpath Extractor
不再需要它),然后将更Server Name or IP
改为${url}
先前返回的值.你去的是Voila.如果您有更具体的问题,请告诉我.Jmeter很有趣.
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>
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}
.如果这对您有用,请告诉我.我用虚拟采样器进行了测试,它适用于我.