gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:10:02 24 4
gpt4 key购买 nike

我使用 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}这是之前返回的值。

  • 瞧,你去吧。如果您有更具体的问题,请告诉我。 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} .让我知道这是否适合您。我用虚拟采样器进行了测试,它对我有用。

    关于jmeter - 如何解析 sample1 的响应以在 JMeter 中创建新样本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11186423/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com