Java JMeter - 我可以将 2 个用户变量合二为一吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18061085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:07:50  来源:igfitidea点击:

JMeter - Can I combine 2 user variables into one?

javaapachejmeteruser-variables

提问by James King

I was wondering if you are able to combine two user variables into one. For example I have one user variable which is defined as the location of a root folder, and a second variable defined as a location from the root, down into a subfolder, and what I'm asking if its possible to put variable 1+variable 2 = a full path way?

我想知道您是否能够将两个用户变量合二为一。例如,我有一个用户变量定义为根文件夹的位置,第二个变量定义为从根到子文件夹的位置,以及我问是否可以将变量 1+variable 2 = 全路径方式?

so for example I have one variable as:

所以例如我有一个变量:

testData.directory = ${__P(testData.directory,C:\Users\MURPHYA1\Desktop\JMeter bodies)}
testData.testCases = ${__P(testData.testCases,\JMeter Basket body files)    

and what i want to produce is: C:\Users\MURPHYA1\Desktop\JMeter bodies\JMeter Basket body files

我想生成的是:C:\Users\MURPHYA1\Desktop\JMeter body\JMeter Basket body files

Is this possible?

这可能吗?

UPDATE

更新

I now have the following config and quite a few test variables just for testing: JMeter Config

我现在有以下配置和相当多的测试变量仅用于测试: JMeter Config

采纳答案by Christopher Roscoe

Add a second "User Defined Variables" element after yours. There every variable will be replaced by the values defined in your first element.

在您的元素之后添加第二个“用户定义的变量”元素。每个变量都将被您的第一个元素中定义的值替换。

- User Defined Variables
- - test1 = a/
- - test2 = b
- User Defined Variables 2
- - test3 = ${test1}${test2} 

回答by UBIK LOAD PACK

You can create a User Defined Variable with name testand value:

您可以使用名称test和 value创建用户定义的变量:

  • ${testData.directory}${testData.testCases}
  • ${testData.directory}${testData.testCases}

And then use : ${__evalVar(test)} in place

然后使用: ${__evalVar(test)} 到位

Also it is better to use / instead of \ for path properties and variables as they will work both in Linux and Windows.

此外,最好对路径属性和变量使用 / 而不是 \,因为它们在 Linux 和 Windows 中都可以使用。

回答by Dan Seibert

I was NOT able to combine 2 variables into one in jmeter. I tried several approaches, but ended up using the two variables side by side in the rest of the test plan. :-(

我无法在 jmeter 中将 2 个变量合并为一个。我尝试了几种方法,但最终在测试计划的其余部分并排使用了这两个变量。:-(

回答by Dn Ghenadie

For example you have 2 variables:

例如,您有 2 个变量:

  1. A variable from Regular Extractor: ${employeeID}
  2. Second variable is a simple Variable defined in User Defined Variables: Test1 = ${__Random(14,25,)}

  3. Now we concatinate/combine this 2 variables, it will look like this:

    ${__V(employeeID_${Test1})} ${employeeID} + $ {Test1} = ${__V(employeeID_${Test1})}

  1. 来自常规提取器的变量: ${employeeID}
  2. 第二个变量是在 User Defined Variables 中定义的一个简单变量: Test1 = ${__Random(14,25,)}

  3. 现在我们连接/组合这两个变量,它看起来像这样:

    ${__V(employeeID_${Test1})} ${employeeID} + $ {Test1} = ${__V(employeeID_${Test1})}

__V function

__V 函数

回答by Raghu Ram.k

try this

尝试这个

${__V(${keyword1}${keyword2})}

${__V(${keyword1}${keyword2})}

回答by Pascal

BeanShell Prozessor:

BeanShell 处理器:

String var1 = vars.get("var1");
String var2 = vars.get("var2");
vars.put("var3", var1+"."+var2);

回答by Shai Alon

Use in BeanShell PostProcessor:

在 BeanShell 后处理器中使用:

vars.put ("folder", vars.get("testData.directory") + vars.get("testData.testCases"))

So once you have: var testData.directory = ${__P(testData.directory,"C:\Users\MURPHYA1\Desktop\JMeter bodies")} var testData.testCases = ${__P(testData.testCases,"\JMeter Basket body files")

所以一旦你有了: var testData.directory = ${__P(testData.directory,"C:\Users\MURPHYA1\Desktop\JMeter body")} var testData.testCases = ${__P(testData.testCases,"\JMeter Basket正文文件")

You will end up with concatenating the two variables into

您最终将把两个变量连接成

folder = "C:\Users\MURPHYA1\Desktop\JMeter bodies\JMeter Basket body files"