10

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?

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

Is this possible?

UPDATE

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

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
James King
  • 2,425
  • 7
  • 30
  • 45

8 Answers8

15

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} 
  • no need for 2 user defined variables config elements, one is enough – UBIK LOAD PACK Aug 06 '13 at 08:00
  • Sadly that doesn't seem to work in JMeter under under defined variables. I found the same resolution as @Dan Seibert which is you have to call one variable after another, such as ${test1}${test2}/file.txt – James King Aug 06 '13 at 08:37
  • Ideally, we wanted to user variables to which would be combined into one, but there doesnt seem to be any way to do that. – James King Aug 06 '13 at 08:40
  • @PMDUBIK-INGENIERIE I am using JMeter 2.9 and the described way is the only possible for me. In one config element the vars are not replaced no matter which order i use. – Christopher Roscoe Aug 06 '13 at 09:50
  • Ah Christopher, you and gentleman and a scholar. I didnt read the part about adding a second user defined variables. I thought you meant just add another variable. Thank you so much – James King Aug 06 '13 at 10:12
3

try this

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

Raghu Ram.k
  • 255
  • 3
  • 8
  • Please explain your approach. This would help all a bit more. – etalon11 Jan 27 '16 at 12:43
  • @Raghu Ram,k Using this approach, the key also gets appended in between values of both variables i.e. value-of-keyword1-keyword1-value-of-keyword2 – TeJas Mar 24 '21 at 13:12
1

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. :-(

Dan Seibert
  • 310
  • 2
  • 4
1

Best way to combine to variables in Jmeter is by using __V() function which can be used to evaluate composite variables.

Example: There are 2 JMeter Variables:

myVar_1 with the value of foo

myVar_2 with the value of bar

The syntax is:

${__V(PREFIX${POSTFIX})} // in this case myVar_ is PREFIX, 1&2 POSTFIX

Lets 'assume you want to use a different variable for each Thread. In this case the you will call __V() function like this

${__V(myVar_${__threadNum})}

Hope this helps!

J.Orlando
  • 61
  • 4
0

You can create a User Defined Variable with name test and value:

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

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

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

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
  • I have tried that, with the following line: testDate.full ${__P(testData.full,${testData.directory}${testData.testCases})} but that still doesnt work. I assume I am just missing something – James King Aug 05 '13 at 15:01
  • Don't use P, just add a User Defined Variable and create a new variable of your choice with value I have goven – UBIK LOAD PACK Aug 05 '13 at 15:02
  • 1
    I now have tried the following: test1 C:\Users\MURPHYA1\Desktop\JMeter bodies test2 \JMeter Basket body files test3 ${test1}${test2} and still nothing. Am I just missing something? – James King Aug 05 '13 at 15:20
  • I have updated with an picture. Not too sure if you can see it – James King Aug 05 '13 at 15:28
0

For example you have 2 variables:

  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})}

__V function

Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
0

BeanShell Prozessor:

String var1 = vars.get("var1");
String var2 = vars.get("var2");
vars.put("var3", var1+"."+var2);
Pascal
  • 13
  • 6
0

Use in BeanShell PostProcessor:

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")

You will end up with concatenating the two variables into

folder = "C:\Users\MURPHYA1\Desktop\JMeter bodies\JMeter Basket body files"
Shai Alon
  • 969
  • 13
  • 21