Jmeter, Name and value pairs are dynamic in jmeter - jmeter

I have situation where name and value pair are dynamic,
I did two correlations for name and Value separately.
I have used foreach controller and gave input-value as reference name of "Value" regularexpression. which is executing the loop correctly as the match number of Value.
ForEach controller input index is "Cor_OutputValue" and output index is "Cor_OutputValue1".
Problem is how do i change the "Name" for each request .
Regards,
Sai

ForEach Controller save index of loop in a special variable you can use:
JMeter will expose the looping index as a variable named jm__idx. So for example, if your Loop Controller is named FEC, then you can access the looping index through ${__jm__FEC__idx}. Index starts at 0
So in case of your controller name is ForEach Controller to get corresponding value of Value variable use __V function:
${__V(Value_${__jm__ForEach Controller__idx})}
If your values start with index 1 you can increment different variable,as idx inside JSR223 PreProcessor:
vars.put("idx", String.valueOf(Integer.parseInt(vars.get("__jm__ForEach Controller__idx"))+1));
And use it later
${__V(Value_${idx})}

Related

How to read values from a database like a csv file in jmeter

I would like to read values from a select query and use the values sequentially in a API call.
Since the database values get stored as var_1, var_2 ... var_N
So how do i increment the number for the variable?
I used a counter and pre processor to increment the number in variable
vars.put ("email", "email"+"_"+vars.get("counter"))
But the final variable is not getting replaced by the value from the select query
eg select query result from a debug sampler
email_1=hata.pd.h13u#yopmail.com
email_2=hata.pd.h13u#yopmail.com
email_3=hataiot.test13#mailinator.com
email_4=hataiot.test12#mailinator.com
--combining the variable and counter:
vars.put ("email", "email"+"_"+vars.get("counter"))
--using the variable in the API post body
{
"username":"${email}",
"password":"test1234"
}
Actual result:
POST data:
{
"username":"email_1",
"password":"test1234"
}
Expected result:
{
"username":"hata.pd.h13u#yopmail.com",
"password":"test1234"
}
TIA
${__V(email_${counter})}
Try this one, see also the documentation: http://jmeter.apache.org/usermanual/functions.html#what_can_do
Note that variables cannot currently be nested; i.e. ${Var${N}} does not work. The __V (variable) function can be used to do this: ${__V(Var${N})}. You can also use ${__BeanShell(vars.get("Var${N}")}.
Have you considered using ForEach Controller? It's super-handy for iterating the variables from extractors or JDBC test elements.
If you still want to continue with the current approach you need to change this line:
vars.put ("email", "email"+"_"+vars.get("counter"))
to this one:
vars.put ("email", vars.get("email"+"_"+vars.get("counter")))
Because you're putting into email variable stuff like email_1, email_2, etc. instead of actual ${email_1} variable value.
References:
JMeter Functions and Variables
How to Retrieve Database Data for API Testing with JMeter

__V for property variable in jmeter

I have JMX structure such as,
ThreadGroup-1
Set propertyVariable-Content_0,Content_1,Content_3 etc
ThreadGroup-2
LoopController
Counter-counterNum
HTTPRequest--use PropertyValue as ${__V(__P(Content)_${CounterNum})}
above variable is not fetching value.
Got stuck on how to use __V for this case as it has property variable.
can someone explain me how to use __V when we have property variable.
You don't need __V() function here, you can access property value using __P() function directly like:
${__P(Content_${CounterNum},)}
Demo:
In case of malfunction double check that you're really setting the properties values using Debug Sampler and View Results Tree listener combination
you need to use this
${__V(MainVriableName_${CounterNo})}
1) Add Loop Controller
2) Under Loop Counter -> Add Counter (Starting value= 1, Increment = 1, Maximun value = ${MainVriableName_matchNr} and Exported Variable Name = CounterNo
3) After in the below Request(s) use ${__V(MainVriableName_${CounterNo})}
this works fine.

How to pick values from array one by one jmeter

EX.hitList values=233,234 Stored in Id_1=233 and id_2=234.I want use this two values one after one.
Use ForEach Controller, Set Input variable prefix = Id and Output variable = currentId
and then inside ForEach Controller you will able to use the variable: ${currentId} in 2 iterations

Passing two variables in a ForEach controller in jmeter

I am running a ForEach controller in which I want the controller to run the service underneath it for changes in sets of latitudes and longitudes. example-
Input variable prefix: latitude
Output variable name: Latitude
I want to run the controller for changes in both "latitude" and "longitude". I tried doing this-
Input variable prefix:latitude, longitude
but it does not work. Is there any other way to pass two variables in ForEach controller?
Unfortunately you cannot do it using ForEach Controller, but you can work it around using __V() and __counter() function combination.
For example you have 4 JMeter Variables:
latitude_1=40.7128° N
longitude_1=74.0059° W
latitude_2=32.0853° N
longitude_2=34.7818° E
And you want to iterate them both using ForEach Controller. In that case the relevant configuration would be:
Input variable prefix: latitude
Output variable name: anything meaningful, i.e. current_latitude
You can refer matching longitude value using the following expression:
${__V(longitude_${__counter(,)})}
Demo:
See Here’s What to Do to Combine Multiple JMeter Variables for detailed explanation of where did the above expression come from.
I encountered same problem and google a lot to find the best possible solution but
did not get success. I am sharing my work-around (and I am not saying it's a great solution ) -
Mention your Input variable name (ex - inputVar) as well as Output variable name (outputVar) on ForEach Controller
(lets say http://website.com/folder_A/folder_B/123_latitude/456_longitude) and you like to take care these two : latitue and longtitude
Use regular expression extractor :
Name of created variable : inputVar
Expression : http://website.com/folder_A/folder_B/(.*)
Template : $1$
match No : -1 // (yes -1 , this will give you complete group)
Handle with regular expression (just search it out )
so for above example : that would be -
http://website.com/folder_A/folder_B/${outputVar}
http://website.com/folder_A/folder_B/${outputVar} URL will be able to print / give you latitue and longtitude in your response code

jxls forEach tag : how to define local variables?

Can we define local variables in jxls which can be used to set an incrementing count for a column.
For eg: Consider the following
<jx:forEach items="${myList}" var="myVar">
-- i need to define a local integer variable here which will have an initial value as 0
-- and i will increment it and display in the output xls's first column
</jx:forEach>
Basically my requirement is to have somekind of local variable declaration in jxls code which i would increment and display in xml.
Any other alternatives are welcome.
Regards,
Rahul
jx:forEach tag support varStatus attribute which defines a name of loop status object which will be passed into bean context for each iteration. The loop status object is an instance of LoopStatus class which has single 'index' property identifying the index of the current item in the collection being iterated
<jx:forEach items="${employees}" var="employee" varStatus="status">
| ${status.index} | ${employee.name} | ${employee.payment} | ${employee.bonus}
</jx:forEach>
Figured it out.... We can use <jx:out expr="hssfRow.getRowNum()" /> in the column where we want to display the numbering. We can keep the above piece of code inside <jx:forEach items="${myList}" var="myVar"> tag

Resources