Jmeter Property with array of values - arrays

Requirement: Need to store 50+ values to a Jmeter property and use with idx
In the case of normal variable we can use Country_1 or Country_2.
Do we have any function to set an array of values to jmeter Property and how to get value using index?
Note: In this case,value has to be used in different thread group.

Your ArrayList initialization is not correct, you should be doing something like:
List myList = Arrays.asList('India', 'USA', 'UK')
There is no putObject method in props shorthand (which is basically an instance of java.util.Properties class so you will need to amend your code like:
props.put('Middle', myList)
Once done you will be able to access individual list members using __groovy() function like:
${__groovy(props.get('Middle').get(0),)} - for first member
${__groovy(props.get('Middle').get(1),)} - for second member
${__groovy(props.get('Middle').get(2),)} - for third member
etc.
Demo:
See Apache Groovy - Why and How You Should Use It article for more details on using Groovy scripting in JMeter tests.

Related

How to access object values using object["key"] approach

In the code I am referring, object attributes are accessed using the object["key"] method instead of calling object.key to access attribute values.
But when I try to create a simple object array and access attributes using above approach, I am getting below error.
if bank_record.effective_date.strip() == "25/07/2019" and bank_record["description"].__contains__("50036"):
TypeError: 'COM' object is not subscriptable
The reason given for object is not subscriptable error is missing __getitem__ method for the class. But in the code I am referring, it doesn't contain such method for any of the dto classes. But the above object["key"] method works just fine. What am I missing. I have been trying to figure this out for a while.
I just want to loop through a object array and access object attributes and modify them on the run. In order to make the function generic, I want to access these object attributes using object["key"] approach. Please help..
My mistake, I have missed set of steps. In the code I am referring, they are looping a json object array, which is created by dumping, python object array values into a json string and loaded back to a json object array.
excel_dto_list = []
#add objects to the list
#...
json_string = json.dumps([ob.__dict__ for ob in excel_dto_list])
#done in another method
downloaded_object = json.loads(json_string)
for x in downloaded_object:
print(x["comment"])

Laravel Eloquent - Working with an array of JSON objects

I have an array of JSON objects within my database (as depicted by the image below)
How do I search for a specific value within it? Say I want the record where the "ends_at" field is equal to "2018-11-24 08:00:00"
I've tried using
->where('column->starts_at', '2018-11-24 08:00:00')
or even tried
->whereJsonContains('column->starts_at', '2018-11-24 08:00:00').
Within the model I've cast the column to an array - am I missing something, or can this not be done?
Use this:
->whereJsonContains('column', ['starts_at' => '2018-11-24 08:00:00'])

Storing array data in firebase, and how ID's are generated

I have a set of objects in my firebase data that all have an array under them. When I create the initial object, I create the initial array with its first object with a line of code like this:
ref.child('items').set([{firstobject: id123}])
this seems to set the id to zero, as the first item in the array. However when I later try to push() a new item to the array with this line of code, I get a more complex id (ZwPiVMIrzbSdvfwxkts).
ref.child('items').push(someNewObject);
In your first line of code, you're calling the Firebase.set() method passing it a JavaScript array that contains a single object.
In your second line of code, you're calling the Firebase.push() method with an object.
Given that Firebase lists/collections are not the same as JavaScript arrays, you end up with a mismatch.
Unlike JavaScript arrays, Firebase's lists are architected to scale well in highly concurrent, multi-user scenarios. I'd recommend to use them instead of arrays from the start.
ref.child('items').push({firstobject: id123});
ref.child('items').push(someNewObject);
With this snippet, all your items will be stored under so-called push ids.

I am getting this error when executing Testng in selenium

Data Provider public java.lang.Object[] as.get() must return either Object[][] or Iterator<Object>[], not class java.lang.Object;
As the documentation says:
The Data Provider method can return one of the following two types:
An array of array of objects (Object[][]) where the first dimension's
size is the number of times the test method will be invoked and the
second dimension size contains an array of objects that must be
compatible with the parameter types of the test method. This is the
cast illustrated by the example above.
An Iterator<Object[]>. The only
difference with Object[][] is that an Iterator lets you create your
test data lazily. TestNG will invoke the iterator and then the test
method with the parameters returned by this iterator one by one. This
is particularly useful if you have a lot of parameter sets to pass to
the method and you don't want to create all of them upfront.
So, I suppose you current data provider method is returning Object instead of one of the 2 supported types.

Jmeter how to loop through a list of different properties in a single thread group or controller?

How to do a basic loop through different properties for a fixed set of controllers? Loop controller runs a set group a certain number of times, does not use properties though.
I can do modules, and set the values to properties for multi thread group usage, but how to pass the next iteration of the property, and run the loop again?
property x
do module (points to controllers)
next property
Say I have a list of 44 characters, and I want to loop through those characters in a ${name} while I'm doing a test. I'd very much not like to build 44 sets of controllers for one character change.
Please Note I cannot add extra files to my computer. It has to work via the stock available controllers. I'm using Jmeter 2.4 r961953
Thanks
I will elaborate slightly more about the BeanShell method. My assumption is that you'd like to do it within one User Thread, if so my proposal would be:
Create a Loop Controller.
Logic Controller->Loop Controller
Inside Loop Controller add following entries:
Config Element -> Counter
Preprocessors -> BeanShell preprocessor
Sampler -> yourSampler
The Counter element will be used as an index that will be used to choose valid value from our array, hence we need to specify a Reference Name for the Counter - let's say that it will be loopCounter.
Now we have to switch to BeanShell preprocessor and define the array of values. A great thing is that we have vars variable available and it gives us CRUD access to variables used in the scenario:
String[] varArray = {"Value1", "Value2"};
idx = Integer.parseInt(vars.get("loopCounter"))-1;
vars.put("myVariable", varArray[idx]);
And for the final step, inside mySampler we can use a variable in a regular JMeter way : ${myVariable}
JMeter API can be very helpfull if you want a more sophisticated solution.
There are a handful of different ways to loop through different values without adding external files:
Use beanshell controller, and write javascript to set your variable
Use a counter to increment by one
Use User Parameters
You can set it up so each loop gets a different value.
Check out the various configuration controllers to find one that works best for you.
EDIT:
I meant user parameters, not user define variables.
User Parameter
You'd need one row per variable with 44 columns. Sorry for the confusion.
User Parameter Structure
test plan
- Thread Group looped 44 times
-- User parameter
-- Request
Beanshell Method
Alternately, you could do an array in javascript in connection with a counter. The Beanshell samplers have access to Jmeter variables and properties, allowing the beanshell sampler to read the counter value. This may be a faster, cleaner way then using User Parameters.
Beanshell structure
test plan
- Thread Group looped 44 times
-- Counter
-- Request
---- Beanshell pre-processor
Beanshell Pseudo code would be
def counter = value of Jmeter Counter
def array = array of values
declare the variable "sampler_value" to be used by sampler
def sampler_value = array # counter
Counter with CharAt function
If you only need to generate characters, you could use the javascript function to utilize the function charAt, using the value from the Counter. Basic structure would be:
test plan
- Thread Group looped 44 times
-- Counter
-- Request
with the request using something like ${__javaScript(charAt(${counter})) as the parameter value. You may have to use JEXL instead of javaScript or evalVar/V/eval inside the charAt function.

Resources