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
Related
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
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.
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})}
I am trying to create some dynamic user defined variables, use them within http requests in JMETER and also save them to file. Basically I'm testing the creation of accounts and would like to save the accounts I've created.
The problem is when I use User Defined Variables and then set the values as below, it only generated the random strings once and in subsequent loops it uses the same data and fails as email already exists:
FIRSTNAME1 Bob${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}
LASTNAME1 Surname${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}
EMAIL1 Bob${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}#emailaddres.com
To save this to file I use:
name1 = vars.get("EMAIL1");
name2 = vars.get("FIRSTNAME1");
name3 = vars.get("LASTNAME1");
f = new FileOutputStream("C://test/Register_new_user_Jmeter.csv", true);
p = new PrintStream(f);
this.interpreter.setOut(p);
p.println(name1 + "," + name2 + "," + name3);
f.close(
How do I set this up so I can generate random strings, use them to create new accounts and also save the info to file? Thanks
Yes, User Defined Variables are used for defining once (static) variables, use other component, especially User Parameters for dynamic values.
If a runtime element such as a User Parameters Pre-Processor or Regular Expression Extractor defines a variable with the same name as one of the UDV variables, then this will replace the initial value, and all other test elements in the thread will see the updated value.
User Parameters are creating variables same as User Defined Variable, but can override pervious values
If there are more threads than values, the values get re-used. For example, this can be used to assign a distinct user id to be used by each thread. User variables can be referenced in any field of any JMeter Component.
I know compact() is a standard php function. And set() is a cake-specific method.
I am running a simple test of passing a value to a view generated with ajax (user render() in my controller), and it only passes the value from the controller to the view if my setup is like so:
$variable_name_to_pass = "Passing to the view using set() can compact()";
$this->set(compact('variable_name_to_pass'));
From reading the manual, it appears set() should work along w/out compact.
Can anyone explain why set() will not work alone? Like
$this->set('variable_name_to_pass');
According to the CakePHP API:
Parameters:
mixed $one required
A string or an array of data.
mixed $two optional NULL
Value in case $one is a string (which then works as the key). Unused if $one is an associative array, otherwise serves as the values to $one's keys.
The compact function returns an associative array, built by taking the names specified in the input array, using them as keys, and taking the values of the variables referenced by those names and making those the values. For example:
$fred = 'Fred Flinstone';
$barney = 'Barney Rubble';
$names = compact('fred', 'barney');
// $names == array('fred' => 'Fred Flinstone', 'barney' => 'Barney Rubble')
So when you use compact in conjunction with set, you're using the single parameter form of the set function, by passing it an associative array of key-value pairs.
If you just have one variable you want to set on the view, and you want to use the single parameter form, you must invoke set in the same way:
$variable_to_pass = 'Fred';
$this->set(compact('variable_to_pass'));
Otherwise, the two parameter form of set can be used:
$variable_to_pass = 'Fred';
$this->set('variable_to_pass', $variable_to_pass);
Both achieve the same thing.
Compact returns an array. So, apparently set is checking it's parameters and if it's an array. It knows that it's from compact. If not it expects another parameter, the value of variable.