JMeter __RandomFromMultipleVars not working - jmeter

Using JMeter 5.4, I'm trying to use __RandomFromMultipleVars function
The RandomFromMultipleVars function returns a random value based on the variable values provided by Source Variables.
Even from examples from documentation:
${__RandomFromMultipleVars(val)}
will return a random string based on content of variable val taking into account whether they are multi-value or not
${__RandomFromMultipleVars(val1|val2)}
will return a random string based on content of variables val1 and val2 taking into account whether they are multi-value or not
${__RandomFromMultipleVars(val1|val2, MYVAR)}
But I don't get any value and not error in log (MYVAR is empty)
What is wrong? can it be used in a specific settings?

These variables need to be present (either come from a Post-Processor or declared via User Defined Variables configuration element)
So just make sure that your varl1 and val2 variables exist and have their respective values using Debug Sampler

Related

Variable value not updated in each iteration in Jmeter

I am using timestamp as a value in my script to keep it unique and distinguishable in each of the iterations. I am using ${__time(/1)} function and storing it in the user defined variable inside a transaction controller and later using same variable in other transactions and json payload as well. This works well for single iteration.
I expected that in each iteration timestamp will be updated. but I can see that in each iteration same timestamp is being used. How could I make it updating timestamp in every iteration as I need to use only one timestamp value in an iteration and not repeating in successive iterations.
The User-Defined Variable config element is processed only once at the start. It is processed after the test plan. It is not suitable for your use case.
UDVs should not be used with functions that generate different results each time they are called. Only the result of the first function call will be saved in the variable.
There could be a number of options.
Using User Parameters Pre-processor
You may set the Update Once Per Iteration to suit your requirement.
Using Set Variables Action plugin
Set the value in JSR223 Pre-processor
You may place the controller below the Test Plan.
As per User Defined Variables documentation:
Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.
So the variable is evaluated only once, when the test starts, if you want it to return you the current timestamp each time it's called - just use __time() function directly where required, there is no need to declare it as the variable.
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
I also don't think that /1 bit in your ${__time(/1)} function does anything meaningful, maybe it worth considering removing it completely
Adding value to a variable will save time only once on load, you can put the time function inside payload to get different times
Another option is to use pre processor as User Parameters over User Defined Variables
For defining variables during a test run, see User Parameters. UDVs are processed in the order they appear in the Plan, from top to bottom

Jmeter variables value is not getting set after each loop

I am using the loop controller to loop an array & give HTTP request for each value. But in some cases, variable values are set with current value from the array
It might be the case the array simply doesn't have the variable matching the current loop index, double check the JMeter Variables which are in scope for each loop using Debug Sampler and View Results Tree listener combination.
I cannot reproduce your issue using the following simple setup:
JMeter Variables defined:
The variables referenced using __V() and __intSum() functions combination like:
${__V(var_${__intSum(${__jm__Loop Controller__idx},1,)})}
See Here’s What to Do to Combine Multiple JMeter Variables for the clarification of the syntax used.
If you just need to iterate JMeter Variables it might be easier to go for the ForEach Controller:

How to use a variable value from mapping for taking a decision to send an email or not

I'm working on a requirement where i have to call a Stored Procedure from Informatica Mapping and store the returned value in a variable and pass that variable value to workflow level and then se it in taking decision for sending email or not.
I have created the mapping but not sure how to pass the variable value into the email task.
Any suggestions on this?
Thanks
Use Mapping Variable and set it with SetVariable function. Next, create a Workflow variable and use it on your session Components tab, in Post-session on success variable assignment to pass the value from your mapping variable, to your workflow variable. Then use the workflow variable in your email task - or anywhere else in the workflow.
It's a very good idea to initialize your variable with some default value, like -999 for example, using Assignment task in the workflow and then also use the Pre-session variable assignment to pass the default value to the mapping variable. Otherwise you may be processing with the value persisted in the repository.

How to use different properties of a Object type jmeter variable?

I have a jmeter variable suppose ${employee} whose value is {empid:"E101",empname:"XYZ",empcity:"Chennai"}.
I want to use this variable in different Http calls for e.g.
demo.exmaplecode.com?Id=${employee}.empid
demo.exmaplecode.com?Name=${employee}.empmname
demo.exmaplecode.com?City=${employee}.empcity
I am not able to extract values by using "." operator.
Please suggest extracting values from an object type variable in jmeter.
You can achieve this fairly easily using __groovy() function available since JMeter 3.1, the relevant expressions would be something like:
${__groovy((new groovy.json.JsonSlurper().parseText(vars.get('employee'))).empid,)}
${__groovy((new groovy.json.JsonSlurper().parseText(vars.get('employee'))).empname,)}
${__groovy((new groovy.json.JsonSlurper().parseText(vars.get('employee'))).empcity,)}
Demo:
More information: Groovy: Parsing and producing JSON
Use JSON Extractor and choose radio button JMeter Variable and enter variable name
to get for example empid use the following setting:
Variable Names: empid (your new variable name for id)
JSON Path Expressions: $.empid
Match No.: 1

How to submit different value in same field for each user

I have a scenario in which user logon into system and submit some entry , but as system does not allow to submit duplicate records , i need to change on of filed value .
How this can be done , an sample code will be much more helpfull.
You have a number of options, feel free to choose the one which suits you best:
__threadNum() function - returns current user number, i.e. 1 for first user, 2 for second, etc.
__Random() function - returns a random number in the given range
__time() function - returns current timestamp in the different formats
__UUID() function - returns random (type 4) UUID structure - probably the most "unique" option
You can use functions anywhere in your test plan, i.e. directly as a parameter value.
See the following references:
Function helper dialog - a tool which helps to generate correct JMeter Function Syntax
JMeter Functions and Variables
How to Use JMeter Functions
you can map columns of a csv file with CSV_Data_Set_Config by setting variables names to : user,pwd...
after that you can use them to logon like this '${user}'

Resources