understanding one of "jMeter - Reducing resource requirements" recommendation - jmeter

Can somebody please explain following recommendation on http://jmeter.apache.org/usermanual/best-practices.html#lean_mean
Rather than using lots of similar samplers, use the same sampler in a loop, and use variables (CSV Data Set) to vary the sample. Or perhaps use the Access Log Sampler. [The Include Controller does not help here, as it adds all the test elements in the file to the test plan.]

This is intended to fix the following:
Suppose you have 2 requests:
test?name=toto
test?name=titi
A basic and bad way to do it would be to create 2 Http Requests one with each request above.
What recommandation says is:
create 1 Http Request with:
test?name=${value}
And create a CSV Dataset with a one column data and a variable named:
value
CSV file will contain:
toto
titi
And use 2 iterations, which will do exactly the same.
Of course here you have 2 rows, but in real life you would have hundreds or thousands.

Related

Jmeter can get parameters?

My question is - if I run a test via Jmeter, for example , if it's a site which enables you to book a flight, and you choose your source and destination when you record it.
Is it possible to pass different values to the destination field? I mean, maybe a txt file with some destinations and pass it to the Jmeter test and then, you will have some tests which each of them is running with a different destination?
If yes, how can I do it?
It's not necessary that it will be a txt file. Just a way to pass different values to one parameter.
Important: I'm using blazemeter plugin for chrome.
Thanks a lot,
appreciated.
You can use CSV Data Set Config. It is very easy to use for parameterizing variables in the test plan.
Check this article on blazemeter to understand the CSV Data Set Config quickly.
Depending on what you're trying to achieve you can go for:
HTML Link Parser. See Poll Example which shows how you can use it for selecting random values from inputs
You can extract all the possible values from the previous response using a Post-Processor, most probably CSS Selector Extractor and configure each thread to use its own (or random) value from the input
And last, but not the least, you can use an external data source like .txt or .csv file and utilize __StringFromFile() function or CSV Data Set Config so each thread (virtual user) would read the next value from file instead of using recorded hard-coded values.

Use Beanshell for parametrization in jmeter

Currently my test structure is:
User Defined Variable (Name:CAMPAIGN_ID, Value:100)
Thread Group
CSV Data Set Config (to read external txt file of user ids)
HTTP Request
Beanshell Assertion (use JSON path extractor to extract value of a field using CAMPAIGN_ID configured in UDV)
So my test runs fine with one CAMPAIGN_ID.
Now i want to enhance this test and execute it for 10 Campaigns without updating it in User Defined Variable everytime.
So i created a campaign.txt file as below
Campaign1 100
Campaign2 101
Campaign3 103
Questions:
1. What is best approach to achieve this goal ? should i use beanshell prepocessor to read from txt file and store it in vars.put("Campaign1",100) and use for Each loop to loop through.
2. Can someone please help me with the new test structure and code sample ?
Any help is much appreciated !
Are you trying to loop 2 csv files?
For every rows in an outer CSV file (CAMPAIGN_ID), you need to run all the rows of inner csv file (user_id),then take a look at below example.
http://www.testautomationguru.com/jmeter-looping-2-csv-files/

JMeter: how to vary request inside Thread Group

I have to write load tests for web application using JMeter. The application has items available for booking, each item has a 'Book' button. If some user clicks this button for item, it becomes unavailable for other users. My question is:
Is it possible to make JMeter threads to book different items (to make different requests) and how to implement it?
You should be able to determine what parameter is being posted by different "Book" buttons and modify nested requests as needed. Test plan structure should be something like:
Open Booking Page - HTTP Request
Get all Booking IDs - Post Processor
Book - HTTP Request
Where "Post Processor" can be
Regular Expression Extractor
CSS/JQuery Extractor
XPath Extractor
In case of multiple matches Post Processor will return multiple variables like
BookindID_1=some value
BookindID_2=some other value
BookindID_3=some other value 2
....
BookindID_matchNr=10
There are at least 2 options on how to proceed with these values:
Iterate all the values using ForEach Controller
Stick to current virtual thread number via __threadNum function so thread #1 will take BookindID_1 variable, thread #2 - BookingID_2 variable value, etc.
It is also possible to take random value using __Random function but it may result in request failure if item is not available.
The correct way of 2 variables combination looks like:
${__V(VAR1${VAR2})}
So combining BookingID_N and __threadNum will look like
${__V(BookingID_${__threadNum})}
See How to use JMeter Functions post series for more on what can be done via functions.
yes, If every item has static(predefined) unique id,descriptor,identifier then that can be parameterized using a csv config file or random no. generator and selector
Random no generator and selector will work only for integers but csv config is better/standard practice. If you need more help please paste your test plan here with explaination of your need.

Read a string from a file with a dynamic name in JMeter

My test plan contains a thread group that looks like that :
Only once controller : Login to application
CSV Data Set Config : Info used to login to application
Only once controller
HTTP Request : POST login information
Loop controller (10 times)
HTTP Request : POST add a "comment" to a "question"
My CSV dataset contains these fields :
username
password
group_id
A user have access to a question depending on it's group_id. I want to add 10 comments per thread to different questions.
My idea was to build a file like questions_by_group_${group_id}.txt containing some ids of questions that the ${group_id} would have access. Then I could do ${__StringToFile(questions_by_group_${group_id}.txt)} in the POST parameter value to add a comment. Using __StringToFile function should loop through lines of my file at every call. That way I can add many comments to many different questions.
The problem is that JMeter seems to open the file one time and share it for every thread (even thought I know that the ${group_id} changes for every thread.
I tried many things like
${__StringFromFile(questions_by_group_${group_id}.txt)}
${__StringFromFile(${__eval(questions_by_group_${group_id}.txt)})}
${__eval(${__StringFromFile(${__eval(questions_by_group_${group_id}.txt)})})}
but nothing works.
StringFromFile works this way by default, read:
__StringFromFile
You could organize your csv like this:
username, password, group_id , commentID1, commentID2....
Then put CSV Data Set Config before Once Only Controller.
Set Sharing Mode to All threads for example.
Finally just use variables instead of using __StringFromFile.
It's not the best solution as you have to build this file and repeat group_id ids.
Another option, if your number of groups is not very big, would be to do this in a setUp Thread Group:
read a CSV file containing:
groupID1, IDA1, IDA2,....
groupID2, IDB1, IDB2,....
...
set one property per group __setProperty or calling this inside a Beanshell Sampler:
JMeterUtils.setProperty(propertyName, propertyValue);
Then in your controller, use a Beanshell Sampler to get ids using:
JMeterUtils.getProperty(propertyName);
I must say I hate all these solutions :-)

JMeter : how to use the timestamp of the parent

I'm testing a group of urls for performance tests. We have an SLA that states that a certain group of URLS must have an average of 80% success within a certain timerange.
The logic of the sla is done in a separate application. The data is fed from JMeter output into a database.
I need a way to identify the 5 tests of these urls, so that the application knows they belong to the same test. I use a Transaction Controller to group all the URL tests, but I still don't see how I can put an identifier in the generated output file (done by View Results Tree Listener). If I could reuse the timestamp of the parent, i.e. the Transaction Controller for the individual HTTP Requests, that would make my day. I tried adding User Defined Variables under the Transaction Controller, but I don't see how I can output the value of my variable into the output file.
Is anything similar possible?
Best regards,
Wim
Store your value in jmeter context using a Beanshell sampler then in jeter.properties uncomment sample_variables ans add the name under which you stored your value:
Optional list of JMeter variable names whose values are to be saved in the result data files.
Use commas to separate the names. For example:
sample_variables=SESSION_ID,REFERENCE
Regards
Philippe M.

Resources