简体   繁体   English

我想在 Jmeter 中使用其他 controller 中使用 JSON 提取器提取的几个变量

[英]I want to use few variables that are extracted using JSON extractor in other controller in Jmeter

In Jmeter,From an api I have extracted two variables which has many values using a json extractor the extracted variable are something like this在 Jmeter 中,我使用 json 提取器从 api 中提取了两个具有许多值的变量,提取的变量是这样的

First variable is name which has data like {abc,asd,qwe,dff,hjk,lku,ghs,jjss} So used the json extractor with variable name as name and have given path expression as $..name and match number as -1 and checked the suffix ALL第一个变量是名称,其中包含 {abc,asd,qwe,dff,hjk,lku,ghs,jjss} 这样的数据所以使用了 json 提取器,变量名称作为名称,路径表达式为 $..name,匹配编号为 - 1 并检查后缀ALL

And second variable is id which has data like {123,344,6383,0298383,8282} Again used json extractor with variable name as id path expression is $..id with match number-1 and checked the suffix ALL第二个变量是 id,它有像 {123,344,6383,0298383,8282} 这样的数据 再次使用 json 提取器,变量名作为 id 路径表达式是 $..id 匹配 number-1 并检查后缀 ALL

These two variables are from a get api that is placed inside a for each controller1.这两个变量来自 get api,它被放置在每个 controller1 的 a 中。

Now there is a other for each controller2 which has other get api same in this I have used json extractor and extracted two variables naming idd and namee And I have written a compare code in this controller using bean shell assertion.(used the general compare code)现在每个 controller2 都有一个 other get api 与此相同 我使用了 json 提取器并提取了两个变量命名 idd 和 namee 我在这个 controller 中使用 bean shell 断言编写了一个比较代码。(使用通用比较代码)

When the script is run I get a assertion error.运行脚本时出现断言错误。 Like the expected data field is empty, this expected data has to have the foreach controller1 variable data... Actual data ie, foreach controller2 data is shown correctly.就像预期数据字段为空一样,此预期数据必须具有 foreach controller1 变量数据...实际数据,即 foreach controller2 数据已正确显示。

If I don't place these 2 api's in for each controller the assertion works fine, but I need to use a controller as looping is needed如果我不为每个 controller 放置这两个 api,断言工作正常,但我需要使用 controller 因为需要循环

How to use one controller variables in other controller?如何在其他 controller 中使用一个 controller 变量?

I have tried using我试过使用

${__setProperty(name,${name})} in bean shell for first for each controller ${__setProperty(name,${name})} 在 bean shell 中首先为每个 controller

Then used ${__property(name)} in the controller 2 beanshell assertion in the compare code to compare然后在比较代码中的controller 2 beanshell断言中使用${__property(name)}进行比较

This didn't work这没有用

If you have JMeter Variables like:如果您有JMeter 变量,例如:

id_1=123
id_2=344
id_3=6383
etc.

from the first sampler来自第一个采样器

and variables like:和变量,如:

idd_1=123
idd_2=344
idd_3=6383

from the second sampler来自第二个采样器

and want to compare them one by one using ForEach Controller it needs to be configured as follows:并想用ForEach Controller来一一对比,需要配置如下:

在此处输入图像描述

Then in JSR223 Assertion you will be able to refer current value of idd variable as vars.get('idd') and current value of the relevant id variable as vars.get('id_' + ((vars.get('__jm__ForEach Controller__idx') as int) + 1))然后在JSR223 断言中,您将能够将idd变量的当前值引用为vars.get('idd')并将相关id变量的当前值引用为 vars.get('id_ vars.get('id_' + ((vars.get('__jm__ForEach Controller__idx') as int) + 1))

Example code:示例代码:

def expected = vars.get('idd')
def actual = vars.get('id_' + ((vars.get('__jm__ForEach Controller__idx') as int) + 1))

log.info('idd variable value: ' + expected)
log.info('id  variable value: ' + actual)

if (expected != actual) {
    AssertionResult.setFailure(true)
    AssertionResult.setFailureMessage('Expected: ' + expected + ', actual: ' + actual) 
}

Demo:演示:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM