Call user defined variable in another variable - jmeter

Is it possible to call a user defined variable within another user defined variable? For example, in the screenshot below I would like to call the variable 'CmsVersion' value in 'ResultsPath'. Right now it is outputting ${CmsVersion} as the folder name and not the variable value.

You cannot, at least not within the bounds of a single User Defined Variables configuration element.
It is possible if you add another User Defined Variables below your original one, this way you will be able to reference the variables define in the above configuration element in the one(s) which is (are) below:
Demo:
More information: Using User Defined Variables

Variables declared in the same User defined variables config element cannot be reused in the same element. You can move it to Test Plan level as per screenshot below
In your case you will need to do another special handling because you are dealing with a windows folder path. the \ is escape character in JAVA. When you say \${CmsVersion} JAVA is treating \$ as an escape sequence.
I have declared 2 variables CmsVersion correlated within the same config element and CmsVersion1 correlated from Test Plan variable.
Result is as below in Debug Sampler

Related

Reseting "Thread Context"

I would like to know if it is possible to reset the thread context (all of its variables) at the begining of a new iteration.
The problem that I am having is that the thread keeps all the variables (and its values) from its previous iterations and sometimes it things can get messy.
If I am not mistaken, on VisualStudio Performance tests you can specify the percentage of "new users" to indicate how many VirtualUsers are going to have its contexts reseted on their next test iteration.
Do we have something similar native on JMeter or do we need to write some code to do it?
Thanks in advance!
I'm not sure you really want/need it, but you can remove all JMeter variables using JSR223 script with remove method:
for (Map.Entry entry : vars.entrySet()) {
vars.put(entry.getKey(), null);
}
It depends on the type of variables you create and how you use them.
For ex:
Regular Expression Extractor
Here It creates a variable regex.var and if the response matches the expression it will have some value assigned to it. If the next iteration does not match the expression, It will still keep the previous iteration value. To avoid this problem, assign a default value or check the 'Use empty default value'. so that every iteration will basically reset the value.
User Designed Variables - Each and every thread will have its own copy of the variable and threads could be modifying its variable value throughout the entire duration of the test. If you want that to be reset for every iteration, it is completely your responsibility.
I think this could be helpful.
JMeter - Understanding Variables Scope

How to declare a set of parameters in omnetpp.ini

I have hosts of two types: wirelessHostA[0..N], wirelessHostB[0..N]. I want to declare each of hosts wirelessHostA[0..N] to send messages to respective wirelessHostB[0..N]. Example: A[0] sends to B[0], A[10] sends to B[10]. Expression-wise I have got something like this:
*.wirelessHostA[0..${N}].app[ * ].destAddresses = "wirelessHostB[0..${N}]"
although this one is not correct. I am a bit unsure about how to declare a variable that can be iterated during a run and not a value per run.
You should not see the lines in the INI file as assignments where you can create procedural constructs like loops etc. Instead think about them as pattern matching rules. When a module needs a parameter, it scans the INI file from start, line by line and tries to match the first part (i.e. the part before =) to the current module path. If it matches, it assigns the second part to the parameter. If not, in continues with the next line in the INI file.
So first, write a pattern rule, then a value that can be evaluated in that context. When you specify the value, you may refer to other parameters (that are available in the module's context) or you may refer to other extra contextual information, such as the matching submodule's index (if it is part of a vector). There are other functions to access the index of parent of etc.
In this case, we have a submodule vector of hosts where each one contains a submodule vector of apps. The index operator would return the index of the current context module (which is the position in the app vector), but we need actually the index of the parent of the app vector (which is the host vector). There is a NED function for this too, called parentIndex(). So the solution would look like this:
*.wirelessHostA[*].app[*].destAddresses = "wirelessHostB[" + string(parentIndex()) + "]"
See https://doc.omnetpp.org/omnetpp/manual/#sec:ned-functions:category-ned for more info.

JMeter-what is difference between use ${} or vars.get() to get value of variable

Today when I was debugging my JMeter script, I found a problem that confused me a lot.
CSV Data Config element: in CSV, I set variable userId to 1001200
Then run script below, and get different value of "userId" when using ${userId} and vars.get("userId"). I think they should be same value, but it seems not. After run vars.put("userId", "-111"), ${userId} and vars.get("userId") get different values:
so it seems ${} and vars.get() have some difference even though their variable is same, does anyone know the reason?
Thanks in advance.
Yes, you need to follow best practices when scripting and avoid using ${value}
When using JSR 223 elements, it is advised to check Cache compiled script if available property to ensure the script compilation is cached if underlying language supports it. In this case, ensure the script does not use any variable using ${varName} as caching would take only first value of ${varName}. Instead use :
vars.get("varName")
Answer provided by #user7294900 refers to the case when Cache compiled script option is checked. But even if it's not checked, your script will resolve variables defined as ${varName} before execution, while vars.get("varName") is resolved during execution.
Before JMeter is about to run any element (sampler, pre- or post-processor), it will take (every) text field and will resolve any variables, functions or inline code, identified by ${...} to their values available at the time of the evaluation. Thus syntax ${...} converts variable into a constant string and your code (for Groovy or any other execution engine) will look like this:
log.info("***" + "1001200" + "***");
log.info("***" + vars.get("userId") + "***");
vars.put("userId", "-111");
log.info("***" + "1001200" + "***");
log.info("***" + vars.get("userId") + "***");
Thus no matter how you change variable during execution, it won't change since it's no longer a variable. But vars.get("userId") on the other hand, is a function call and will check variable value every single time.

Assigning a variable to another variable in JMeter

I have assigned a variable ${WH} to 22 and now want to assign ${WH} to another variable called ${W_ID}. I have tried a couple of things, but none of them seem to be working.
None of below working (used in User Defined variable page):
W_ID=${__eval(${WH})}
W_ID=${__evalVar(WH)}
W_ID=${__V(${WH})}
I can't figure out why the value doesn't get stored in W_ID. How can this be done?
You can add JSR223 Sampler language can be Javascript and write:
vars.put("WS_ID", vars.get("WH"))
This will move WH value to WS_ID variable.
There's an issue if you are using multiple User Defined Variables, later assignment can override previous assignment, try to avoid it. The reason can be found in manual:
Note that all the UDV elements in a test plan - no matter where they
are - are processed at the start.
You can use the __groovy() function available since JMeter 3.1.
The relevant Groovy expression which will read ${WH} variable value and save the result into ${W_ID} variable will look something like:
${__groovy(vars.get('WH'),W_ID)}
Demo:
You can put the function anywhere in your script. See Functions and Variables JMeter User Manual chapter for more information.

JMeter does not replace ${SUBPANEL_RELATE_MODULE_g1} with its value

It's a long story, but I will try make it simple:
I generated MeterMaid XML files with SugarMMM; I chose only the Accounts module:
I converted above files to JMeter format with MeterMaid (I consolidated the tests into one file and named it "filename.xml"):
ruby GenMeter.rb --inputfile=filename.xml --outputfile=filename.jmx
I did the necessary CSV setup. All the CSV file contains is the login details (usr,pwd) for testing concurrent user logins. This part works well indeed.
When I run the test, I can see that a whole bunch of ${} variables are converted into corresponding values. Sadly, ${SUBPANEL_RELATE_MODULE_g1} doesn't get resolved... here's what the GET url (from View Results Tree Listener component) looks like:
http://localhost/sugarcrm/index.php?module=${SUBPANEL_RELATE_MODULE_g1}&action=Popup&hide_clear_button=true&mode=MultiSelect&create=true&metadata=undefined
Note that it's not the only variable that isn't resolved. The following screenshot shows the other tests that fail, all also caused by other variables not replaced by their corresponding values:
Here's how this variable is set up (which is well before the time it's used):
Here's what Debug Sampler says:
JMeterVariables:
CAMPAIGN_ID=CAMPAIGN_ID_ERROR
CAMPAIGN_NAME=CAMPAIGN_NAME_ERROR
CONTACT_ID=997a3171-aa60-b2d6-a457-4e0ba8b0052b
CONTACT_ID_g=4
CONTACT_ID_g0=onclick="send_back('Contacts','997a3171-aa60-b2d6-a457-4e0ba8b0052b');">Prof
CONTACT_ID_g1=onclick="send_back('Contacts','
CONTACT_ID_g2=997a3171-aa60-b2d6-a457-4e0ba8b0052b
CONTACT_ID_g3=');">
CONTACT_ID_g4=Prof
CONTACT_NAME=Prof
CONTACT_NAME_g=4
CONTACT_NAME_g0=onclick="send_back('Contacts','997a3171-aa60-b2d6-a457-4e0ba8b0052b');">Prof
CONTACT_NAME_g1=onclick="send_back('Contacts','
CONTACT_NAME_g2=997a3171-aa60-b2d6-a457-4e0ba8b0052b
CONTACT_NAME_g3=');">
CONTACT_NAME_g4=Prof
FOUND_ID=1
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage#3c1635
MEMBER_OF_ID=d7c26344-cad8-0503-b02a-4e0cb4db3985
MEMBER_OF_ID_g=4
MEMBER_OF_ID_g0=onclick="send_back('Accounts','d7c26344-cad8-0503-b02a-4e0cb4db3985');">searchSearchForm
MEMBER_OF_ID_g1=onclick="send_back('Accounts','
MEMBER_OF_ID_g2=d7c26344-cad8-0503-b02a-4e0cb4db3985
MEMBER_OF_ID_g3=');">
MEMBER_OF_ID_g4=searchSearchForm
MEMBER_OF_NAME=searchSearchForm
MEMBER_OF_NAME_g=4
MEMBER_OF_NAME_g0=onclick="send_back('Accounts','d7c26344-cad8-0503-b02a-4e0cb4db3985');">searchSearchForm
MEMBER_OF_NAME_g1=onclick="send_back('Accounts','
MEMBER_OF_NAME_g2=d7c26344-cad8-0503-b02a-4e0cb4db3985
MEMBER_OF_NAME_g3=');">
MEMBER_OF_NAME_g4=searchSearchForm
OPPORTUNITY_ID=864e402f-0d76-ab6e-b54f-4e0cb42f0249
OPPORTUNITY_ID_g=4
OPPORTUNITY_ID_g0=onclick="send_back('Opportunities','864e402f-0d76-ab6e-b54f-4e0cb42f0249');">value
OPPORTUNITY_ID_g1=onclick="send_back('Opportunities','
OPPORTUNITY_ID_g2=864e402f-0d76-ab6e-b54f-4e0cb42f0249
OPPORTUNITY_ID_g3=');">
OPPORTUNITY_ID_g4=value
OPPORTUNITY_NAME=value
OPPORTUNITY_NAME_g=4
OPPORTUNITY_NAME_g0=onclick="send_back('Opportunities','864e402f-0d76-ab6e-b54f-4e0cb42f0249');">value
OPPORTUNITY_NAME_g1=onclick="send_back('Opportunities','
OPPORTUNITY_NAME_g2=864e402f-0d76-ab6e-b54f-4e0cb42f0249
OPPORTUNITY_NAME_g3=');">
OPPORTUNITY_NAME_g4=value
RANDOM_CHAR=o
RANDOM_CHAR_g=1
RANDOM_CHAR_g0=o
RANDOM_CHAR_g1=o
RANDOM_STRING=value
RANDOM_STRING_g=1
RANDOM_STRING_g0=value
RANDOM_STRING_g1=value
RECORD_NAME=NOT_FOUND
RECORD_NUMBER=3250317d-6c79-b20d-5e36-4e0cb4746e84
RECORD_NUMBER_g=2
RECORD_NUMBER_g0=javascript:lvg_nav('Accounts', '3250317d-6c79-b20d-5e36-4e0cb4746e84
RECORD_NUMBER_g1=javascript:lvg_nav('Accounts', '
RECORD_NUMBER_g2=3250317d-6c79-b20d-5e36-4e0cb4746e84
SEARCH_FIELD=SEARCH_FIELD_ERROR
START.HMS=190308
START.MS=1309453388621
START.YMD=20110630
SUBPANEL_RELATE_MODULE=Accounts
TEAM_ID=seed-Teams8
TEAM_ID_g=4
TEAM_ID_g0=onclick="send_team_to_form('Teams','seed-Teams8');">Ball
TEAM_ID_g1=onclick="send_team_to_form('Teams','
TEAM_ID_g2=seed-Teams8
TEAM_ID_g3=');">
TEAM_ID_g4=Ball
TEAM_NAME=Ball
TEAM_NAME_g=4
TEAM_NAME_g0=onclick="send_team_to_form('Teams','seed-Teams8');">Ball
TEAM_NAME_g1=onclick="send_team_to_form('Teams','
TEAM_NAME_g2=seed-Teams8
TEAM_NAME_g3=');">
TEAM_NAME_g4=Ball
TESTSTART.MS=1309455500088
pwd=user1
usr=user1
UPDATE:
Here's after changing Template to $1$$2$$3$$4$:
And here's the Debug output (the Sampler is put just after regex Controller):
JMeterVariables:
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage#18fde89
RANDOM_CHAR=t
RANDOM_CHAR_g=1
RANDOM_CHAR_g0=t
RANDOM_CHAR_g1=t
RANDOM_STRING=Tanzania
RANDOM_STRING_g=1
RANDOM_STRING_g0=Tanzania
RANDOM_STRING_g1=Tanzania
RECORD_NAME=NOT_FOUND
RECORD_NUMBER=DOCTYPE
RECORD_NUMBER_g=1
RECORD_NUMBER_g0=DOCTYPE
RECORD_NUMBER_g1=DOCTYPE
START.HMS=100932
START.MS=1312531772599
START.YMD=20110805
SUBPANEL_RELATE_MODULE=Accounts
TESTSTART.MS=1312542237235
pwd=user1
usr=user1
Verify in your CSV dataset config, all variables are declared correctly (no typos, no omissions, no spaces before variable names, etc.)
I would also suggest putting a debug sampler high in your tree, as it will show you every variable and its value and can save a lot of time.
Edit:
It looks like your regex is setup incorrectly for creating multiple groups. If you look in your Debug sampler, you have SUBPANEL_RELATE_MODULE=Accounts but not SUBPANEL_RELATE_MODULE_g1= . This implies you don't have GROUPS setup.
In looking at your regex, the line template: $0$ is saying "only give me one group", whereas it looks like you want 4. Thus, you should try template: $1$$2$$3$$4$ the first match should be _g1 the second _g2 and so on. Check out the manual for details.
make judicious use of the ${SUBPANEL_RELATE_MODULE_g1} variable throughout the script after it gets defined by the Regular Expression Extractor. Verify it exists. Use it in Controller titles, test headings, at the beginning of tests, and at the end of tests.
That will help narrow it down
This way you can follow it along in the script to make sure it exists just before the moment it is used, and find where it's breaking down. Basically print statement debugging.
I don't know about sugar CRM or metermaid but for jmeter I had a similar problem with variable that were not resolve.
Check if this variable is declared somewhere or maybe you need to write a reg ex to extract that value from the previous request.
The problem I got It was that I extracted the variable from a CSV files
the variable name was CONTRACTNO, CLIENTNO
my URL : /SomeURL/bla?eventId=contractSelected&contractNoSelected=${CONTRACTNO}&applicationID=BLa
And it wasn't working so I changed the variable name in the csv file to :
CONTRACTNO,CLIENTNO (look that I removed a space)
Jmeter tend to be very picky with space in name and variable definition.
You are expecting the following values
${SUBPANEL_RELATE_MODULE_g1}
but you have configured the Regular Expression Extractor reference name as
"SUBPANEL_RELATE_MODULE"
There two options you can get the values
You have to change the ${SUBPANEL_RELATE_MODULE_g1} into ${SUBPANEL_RELATE_MODULE}
You have to change the Regular Expression Extractor reference name as "SUBPANEL_RELATE_MODULE _g1" to "SUBPANEL_RELATE_MODULE"
After this your values will be replaced properly.
It looks like your regular expression isn't picking up a match, your default value is set to "Accounts" and in your debug output that's the value of the variable. You'll only get match groups if the regular expression matches.
The View Results Tree listener now has a RegExp tester, so you can go to the request that you're trying to extract the variable SUBPANEL_RELATE_MODULE from the result in the results tree and choose RegExp Tester from the dropdown where it says "Text".
You can then run your regular expression on the response data in the RegExp tester and probably find that it doesn't match and then hone your regular expression so that it matches and update it in your Regular Expression Extractor.

Resources