【问题标题】:I have a dynamic value in response but it keep on changing the position. How can i capture it我有一个动态值作为响应,但它不断改变位置。我怎样才能捕捉到它
【发布时间】:2018-12-06 05:18:46
【问题描述】:

我有一个动态值作为响应,但它不断改变位置。我怎样才能捕捉到它。 例如:第一次迭代值是第二个位置 第 2 次迭代值是第 4 位 第三次迭代值是第一个位置......就像那样

请您指导我如何使用正则表达式提取器或任何其他提取器来捕获此值。

【问题讨论】:

    标签: jmeter jmeter-3.2 jmeter-4.0


    【解决方案1】:

    也许正则表达式提取器不是最佳选择,especially when it comes to HTML response type 所以一定要使用合适的Post-Processor,即

    今后在您的问题中包含(至少部分)回复,并指出您想要提取的值,以便我们提出最有效的方法。

    【讨论】:

      【解决方案2】:

      从 JMeter 3.0 开始,使用 JSON 变量提取器从 JSON 响应中提取数据要容易得多。 JSON 是一种极其简单的数据格式,几年前就已经取代了 XML。

      越来越多的 REST API 和服务器正在使用 JSON 作为它们的主要数据交换格式。在这里,我们将使用 JMeter 来解析 JSON 响应。 假设我们有如下 JSON 响应:

           {
              "store": {
                  "book": [
                      {
                          "category": "reference",
                          "author": "Nigel Rees",
                          "title": "Sayings of the Century",
                          "price": 8.95
                      },
                     {
                          "category": "fiction",
                          "author": "Evelyn Waugh",
                          "title": "Sword of Honour",
                          "price": 12.99
                      }
                  ],
                  "bicycle": {
                      "color": "red",
                      "price": 19.95
                  }
              },
              "expensive": 10
          }
      

      要使用 JMeter 解析上述 JSON,我们需要将 JSON Extractor 添加到我们的测试计划中。

      右键单击测试计划 -> 添加 -> 后处理器 -> JSON 提取器

      jmeter json 提取解析器

      现在,我们应该看到以下视图:

      json 提取器 jmeter

      在 JSON 路径表达式字段中,我们可以插入我们的 JSON 路径来解析 JSON 响应

      以下是一些示例 Json Path 表达式,可用于从上面公开的 Json 文档中提取数据:

      JSONPATH    RESULT
      $.store.book[*].author  The authors of all books
      $..author   All authors
      $.store.*   All things, both books and bicycles
      $.store..price  The price of everything
      $..book[0,1]    The first two books
      $..book[:2] All books from index 0 (inclusive) until index 2 (exclusive)
      $..book[2:] Book number two from tail
      $..book[?(@.isbn)]  All books with an ISBN number
      $.store.book[?(@.price < 10)]   All books in store cheaper than 10
      $..book[?(@.price <= $[‘expensive’])]   All books in store that are not “expensive”
      $..book[?(@.author =~ /.*REES/i)]   All books matching regex (ignore case)
      $..*    Give me every thing
      $..book.length()    The number of books
      

      【讨论】:

        猜你喜欢
        • 2010-12-29
        • 1970-01-01
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多