JMeter - 响应正文中多个值的模式匹配并迭代它们

问题描述 投票:0回答:1

我目前正在尝试收集多个正文响应,这些响应向我指示需要根据返回给我的内容发送哪些请求。我需要迭代收到的匹配,但我很难弄清楚其中的逻辑。

以下是我目前收到的内容..我发现类似“name=

pyLoadingMessage_D_CreditCardAccount_pa532535232pz.pxResults(1)_3

”的内容

我需要的只是 pa

532535232
和 pz 之间的最小数字,还有
pxResults(1)
中传递的参数。这个参数让我知道需要发送多少个请求,所以假设正文响应中最多可以发送 8 个请求。

我能够提取两者并将其连接起来;但是,我不太确定如何编写逻辑来执行此操作。

它们是 AJAX 请求,因此稍后我将利用并行控制器同时运行它们(一次最多 6 个)。在请求中,它们是相同的,例如我唯一需要的是

D_CreditCardAccount_pa532535232pz.pxResults(1)
。我考虑使用循环控制器,起初我计划让它循环遍历找到的匹配数量,但这没有意义,因为我是并行运行这些而不是顺序运行。

如果有任何提示可以写出这些逻辑,我们将不胜感激。

def i = 1
def results = []
 
// Iterate through all matches using a while loop
while (vars.get("accountInfo_" + i) != null) {
    // Get the current match value
    def match = vars.get("accountInfo_" + i)
    // Use a regular expression to extract the parts of interest
    def paPzPattern = /pa(\d+)pz\.pxResults\((\d+)\)/
    def matcher = (match =~ paPzPattern)
    if (matcher) {
        // Extract the number between pa and pz, and the number in pxResults()
        def paNumber = matcher[0][1]
        def pxResultNumber = matcher[0][2]
        // Concatenate the results in the desired format
        def concatenatedResult = "pa${paNumber}_pxResult(${pxResultNumber})"
        // Store or log the result
        results.add(concatenatedResult)
        log.info("Extracted and processed match: ${concatenatedResult}")
    }
    // Increment the counter
    i++
}
 
// Optionally, return or use the list of results
return results.join(', ')  ```

groovy jmeter performance-testing jmeter-5.0
1个回答
0
投票

我认为并行控制器不会为您解决问题,我建议如下:

  1. 而不是

    return results.join(', ') 
    ,将其
    results
    放入JMeter变量中,例如:

    vars.putObject('results', results)
    
  2. 然后在需要发送AJAX请求的地方添加一个Parallel Sampler(一个空的)

  3. 添加 JSR223 PreProcessor 作为并行采样器的子级,并将以下代码放入“脚本”区域:

    vars.getObject('results').each { result ->
        sampler.addURL('http://example.com?parameter=' + result)
    }
    

    当然根据你的需要修改URL

© www.soinside.com 2019 - 2024. All rights reserved.