Jmeter -- how to combine variable name & counter() - variables

I've got the following problem:
I do gather that ProductId variable is assigned with the first value and then only that value is used when I refer to ${productId}.
I was trying to apply ${__counter()} to reference name in RegexExtractor,
but then BeanShellAssertion fails to set the property.
How should I properly work this around?

You can use __V() function in order to combine 2 variables.
I.e. if you have 2 variables like:
productId
counter
And would like to evaluate i.e. ${productId_1}, ${productId_2}, etc.
It should be as simple as:
${__V(productId${counter})}
Same approach applies to __counter() function:
${__V(productId_${__counter(,)})}
Demo:
See How to Use JMeter Functions posts series for comprehensive information on above and other functions

ProdGroup
please store the product Id property as prod_id_1, prod_id_2,...prod_id_n or according to you convenience
How to to that ?
in post processor "Parameters" section use ${__counter(FALSE,)} and in the script part try getting that String counter = arg[0] and convert that to integer and store it to a script variable by default arg[0] value is String
int c= arg[0] as Integer //this is groovystyle check in your way to convert as int
now props.put("prod_id_"+c,"extractedfrom_response")
BID:
In you Bid group add a user defined variable section add the variable
"prod_id" and value is empty
Define a counter start with the same counter 1 and give counter reference name [if your counter value in prod group was 0 then here also it must start with zero]
script sampler convert all the props to the variables
Enumeration e = props.propertyNames();
while (e.hasMoreElements()) {
String propertyName = e.nextElement().toString();
if (propertyName.startsWith("prod_id_")) {
vars.put(propertyName, props.getProperty(propertyName));
}
}
With this you have converted properties to variables named prod_id_1 ...to ... prod_id_n
In http sampler user reference as ${__V(prod_id_${counterreference in step 2})} will do your job
For each thread the counter will increment by default
user ${__threadNum} or ${counter reference name} in sampler labels for debugging.
Hope this helps. Please let us know if still problem is there.

Related

TestComplete - How to define dynamic variable in testComplete like we do in Soapui with $ sign "${#Var2}"

Ive got two project level variables in TestComplete:
Var1 = ${#Var2} and Var2 = 123456789
using Log.Message(Project.Variables.Var1) should evaluate to "123456789" but it just prints ${#Var2} as string.
is there any way we can make it dynamic?
in particular I want to update the value of a variable defined in "ReadyAPI-Test Edit-Properties" page with the value from project's local or persistent property value. The reason is that this variable is not accessible using script, the only option available is to execute i.e. ReadyAPI.TestCase.Execute()
Thanks
This is not something that is usually done in TestComplete.
If you need to use this in a script, you can use the eval function. However, the syntax of the variable should contain a valid JavaScript code:
Var1 = "Var2"
Var2 = 123456789
Log.Message(eval(Var1));
If you do not have control over the format of the Var1 variable, you will need to create code that will parse the value of the variable and do the needed replacements.

having trouble using variable inside a variable

I am facing problem while using a variable inside another variable name for example check this : ${email_${count}} .
Here email is the variable name storing data from JDBC request sampler and as you might know data into variables gets stored like this : email_1 , email_2 and so on based on the rows we are extracting.
Now i don't want to write 10 variables manually like email_1 , email_2 , email_3 upto email_10 . i am using counter from 1 to 10 and counter reference variable name is count so my syntax is becoming as : ${email_${count}} . where email would be the variable from JDBC sampler and count is counter variable name . Basically i am appending counter variable to JDBC variable , but jmeter is treating it as a standalone variable .
Can anyone please help me in this matter. if you need further clarification let me know.
I am attaching screenshots below for more clarification.
Use __V function for evaluating variable inside a variable
${__V(A${N})} - works OK. A${N} becomes A1, and the __V function returns the value of A1
You should use it in your case:
${__V(email_${count})}
Or use __evalVar with similar syntax:
${__evalVar(email_${count})}
The evalVar function returns the result of evaluating an expression stored in a variable.

Jmeter use variable to create variable and retrieve value

I know the title may be confusing but this is what I need to do:
I have a list of variables I am pulling from Jquery extractor.
myVar_1 = 343
myVar_2 = 98763
myVar_3 = 5622
etc
I generate a random number between 1 and myVar_matchNr.
Then I want to navigate to a URL that has an ID of one of the randomly selected variables. For instance, this would be the path I would like as an example:
//mydomain.com/api/resource/${myVar_${randomNumber}}
Which would translate to ( in the case my random number was 2):
//mydomain.com/api/resource/98763
I have the random number, and I have the list of variables from the Jquery extractor, but I have been unsuccessful getting the value out of the combination.
I have tried the above URL directly.
I have tried a beanshell script that looked something like:
String myvarString = "myVar_" + get("myRandNumber");
String myVar = get(myvarString);
set("mySelectedVar", myVar);
That seemed to always come up an empty string.
Any suggestions on how to accomplish this?
You can combine 2 variables using __V() function like
${__V(myVar_${randomNumber})}
In regards to Beanshell, you need to use vars object which stands for JMeterVariables class instance to manipulate the JMeter Variables like
String myvarString = "myVar_" + vars.get("myRandNumber");
String myVar = vars.get(myvarString);
vars.put("mySelectedVar", myVar);
See Here’s What to Do to Combine Multiple JMeter Variables article for more information on the topic.
One more option is Random Controller, you can create 3 different request and place it under Random Controller.i hope this will serve the purpose.

How to use Get command in Monkey talk?

Does anybody know how to use the Get command in monkey talk?
In monkey talk guide only the command is written but no syntax is present.
Here is an example for you,
var x = app.label("label1").get("x","value")
Above line will get the value of label1 and store it in variable x. You can change the second parameter "value" to ".text" or ".size" depending on your needs
since the question is not marked Answered and For the future reference i am answering this.
‘GET’ ACTION RETRIEVES COMPONENT PROPERTY VALUES
Syntax:
ComponenType MonkeyId Get varName propName
Works like an assignment statement (varName= propName)
The default property is “value”
// Get label value currently displayed
Label lastname Get name
// Enter name into input field
Input query EnterText ${name}
// Get the first table item
Table countries Get country items1
// Enter into input field
Input * EnterText ${country}
you can refer this document here, thanqs
I will try to explain using example. Suppose there is a ListView(Table) and you want to scroll till its last item.
//Define a variable
Vars * Define row
//Store size of list in variable row using Get. Check use of "Get" here
Table * Get row size %thinktime=20000
//Now stored variable can be used as per need. here I am using for scrolling
Table * ScrollToRow ${row} %thinktime=2000
Hope it helps you !!

Use single value of parameter List in queryString

I am using JasperStudio 5.6.0.final and the report is not generated dynamically from java code.
I have a problem with getting single value from parameter.
In the report I have a parameter A of a type List.
It is not a problem to use it in a clause as IN statement:
AND $X{IN, USER.ID_USER, A}
But I have a problem to get a single value from that list.
I know that my List has always 10 values.
So I want to use it in query, but I don't know how to write the statement:
AND USER.ID_USER = *first_value_of_list_A*
e.g.
AND USER.ID_USER = $P!{Atrybuty}.get(1)
doesn't work
I tried also to assign parameter value to a variable, but as I know it isn't possible to use variables in queryString.
So my question: How to get single value from parameter List in queryString.
What you need to do for this is use
AND $X{IN, USER.ID_USER, A}
Set A type as Collection and that will allow you to even have a single selection or multi selection or just a single value.
Hope that this helps.