I have a BeanShell PostProcessor under the setUp Thread Group.
It generates an ArrayList that I want to pass as a system property to the test Thread Groups in the Test Plan.
That array contains the number of threads in the test groups.
What is the syntax? How should I refer an element of that array in the Tread Group "Number of Threads (users)"?
This is what I have in the setUp Thread Group
ArrayList users = new ArrayList();
${__setProperty(users, ${users})};
This is what I put in the Number of Threads
${__P(users).get(0)}
It does not work.
Thanks
If you really need the "ArrayList" you can go it using bsh.shared namespace
In setUp Thread Group put the ArrayList into the "bsh.shared" namespace like:
ArrayList users = new ArrayList();
users.add(5);
bsh.shared.users=users;
In normal Thread Group you can read the value via __BeanShell function as:
${__BeanShell(bsh.shared.users.get(0),)}
However I feel that your test is badly designed and you could get rid of scripting or at least of using arrays.
Related
I have a .csv data file with data like:
Row-1: A
Row-2: B
Row-3: C
When I run the script with 1 user 3 iterations, it is taking the same value A for all 3 iterations. What do I need to do if I would like to use value A for iteration-1 and value B for iteration-2 & etc.? It did not make any difference between placing the data file inside the thread group or outside the thread group.
Please could someone help?
Thanks,
N
In current form your question cannot be answered comprehensively, the missing bits are:
What test element/function do you use for reading the values from the CSV file. The recommended option is CSV Data Set Config
What controller is used for creating the "iterations"
CSV Data Set Config needs to be placed inside that controller
Sharing mode of the CSV Data Set Config needs to be set to "All Threads"
I have two thread groups
Creation of customer
Creation of account
From first thread group I'm capturing a variable called customerId.
How can I use that variable in second thread group?
You can't share a variable, you can convert variable to JMeter property using __setProperty
${__setProperty(propertyName, ${variableName})}
The setProperty function sets the value of a JMeter property.
And use in second thread group use __property
${__property(propertyName)}
You can convert it back to JMeter variable:
${__property(propertyName, newVariableName)}
${__property(user.dir,UDIR)} - return value of user.dir and save in UDIR
I have a folder where many files containing different SOAP requests. I want to run all of them. how ever this files count might vary when new requests are added and some are removed. So I want to set the loop count to the number of files in the folder. So that the user will not have to know the exact count. IS anyone has come across similar scenario and got a solution ?
Thank you in advance.
You can work it around with some scripting as:
Add a Beanshell Sampler to your test plan
Put the following code into the Beanshell Sampler's "Script" area:
File folder = new File("/path/to/your/folder");
File [] files = folder.listFiles();
int loops = files.length; =
vars.put("loops", String.valueOf(loops));
Add Loop Controller after the Beanshell Sampler
Put ${loops} into "Loop Count" input field
See How to use BeanShell: JMeter's favorite built-in component guide for comprehensive information on scripting in JMeter.
My first thread group parses a file and stores all the lines in a List. The second thread group should retrieve objects from the List one by one and send HTTPS request. Now the problem, how to make the list of objects (not just a property value) between thread groups Appreciate any help.
You can use Beanshell Test Elements and bsh.shared namespace to share variables across thread groups
In first thread group after parsing:
bsh.shared.myList = myList;
In second (or whatever thread group)
List myList = bsh.shared.myList;
See How to use BeanShell: JMeter's favorite built-in component for more scripting options.
If you use different scripting language (not Beanshell) - it is still possible to use props pre-defined variable which stands for JMeterProperties instance. JMeterProperties is basically an instance of java.util.Properties so you can store any object in there like:
In first thread group:
List myList = new ArrayList();
//do what you need with the list
props.put("myList", myList);
In second thread group:
List myList = props.get("myList");
// do what you need with the list
I have a fairly simple Linq query (simplified code):
dim x = From Product In lstProductList.AsParallel
Order By Product.Price.GrossPrice Descending Select Product
Product is a class. Product.Price is a child class and GrossPrice is one of its properties. In order to work out the price I need to use Session("exchange_rate").
So for each item in lstProductList there's a function that does the following:
NetPrice=NetPrice * Session("exchange_rate")
(and then GrossPrice returns NetPrice+VatAmount)
No matter what I've tried I cannot access session state.
I have tried HttpContext.Current - but that returns Nothing.
I've tried Implements IRequiresSessionState on the class (which helps in a similar situation in generic http handlers [.ashx]) - no luck.
I'm using simple InProc session state mode. Exchange rate has to be user specific.
What can I do?
I'm working with:
web development, .Net 4, VB.net
Step-by-step:
page_load (in .aspx)
dim objSearch as new SearchClass()
dim output = objSearch.renderProductsFound()
then in objSearch.renderProductsFound:
lstProductList.Add(objProduct(1))
...
lstProductList.Add(objProduct(n))
dim x = From Product In lstProductList.AsParallel
Order By Product.Price.GrossPrice Descending Select Product
In Product.Price.GrossPrice Get :
return me.NetPrice+me.VatAmount
In Product.Price.NetPrice Get:
return NetBasePrice*Session("exchange_rate")
Again, simplified code, too much to paste in here. Works fine if I unwrap the query into For loops.
I'm not exactly sure how HttpContext.Current works, but I wouldn't be surprised if it would work only on the main thread that is processing the HTTP request. This would mean that you cannot use it on any other threads. When PLINQ executes the query, it picks some random threads from the thread pool and evaluates the predicates in the query using these threads, so this may be the reason why your query doesn't work.
If the GrossPrice property needs to access only a single thing from the session state, it should be fairly easy to change it to a method and pass the value from the session state as an argument:
Dim rate = Session("exchange_rate")
Dim x = From product In lstProductList.AsParallel
Order By product.Price.GetGrossPrice(rate) Descending
Select product
Depending on where you use x later, you could also add a call to ToList to force the evaluation of the query (otherwise it may be executed lazily at some later time), but I think the change I described above should fix it.
You should really read the values out of session state and into local variables that you know you need within the LINQ statement. Otherwise you're actually accessing the NameValueCollection instance every single time for every single element in every single thread when the value is essentially constant.