Can any one help me on Drop downlist correlation in JMeter?
I Have a scenario to select City names from dropdown list, During execution i would like to pass randomly one value on each iteration. (I aware in Loadrunner as we can achieve it using lr_paramarr_random methods). How to store and pass randomly to the script ?
Ex: City_ddl - (Length is 5)
Hyderabd
Banglore
Chennai
Pune
Delhi
Thanks in advance !!
There is __chooseRandom() function available via JMeter Plugins. Using it is as simple as below:
${__chooseRandom(Hyderabad,Bangalore,Chennai,Pune,Delhi,randomCity)}
If you're getting dropdown values via XPath or CSS/JQuery Extractor, they are stored in JMeter Variables like:
CITY_1=Delhi
CITY_2=Pune
CITY_3=Chennai
..etc.
CITY_matchNr=5
In that case you should be able to choose random value without JMeter custom functions plugin using just __Random and __V built-in functions as follows:
${__V(CITY_${__Random(1,${CITY_matchNr},)})}
For more details on using JMeter's functions refer to How to Use JMeter Functions posts series.
Related
In JMeter, I am able to connect to DB and retrieve DB values.
I can view the DB_Value using variable which I specified in JDBC request(Variable Names field).
Example: with index of column value as CustomerID_1
I used BeanShell Sampler with below code:
${__BeanShell(vars.put("p_CustomerID_New","${CustomerID_1}"))}
with this p_CustomerID_New i am able to get db value and that works.
Now i have another random variable to replace above "1" with random numbers, so that i will be able to use different customers from DB and substitute in my API_Request.
When i use beanshell script with ${CustomerID}_${randomNo}, it only stores random number and CustomerID is not retrieved.
Any help would be much appreciated.
Thanks in advance.
You don't need to use any scripting at all, just to for __V() and __Random() function combination:
${__V(CustomerID_${__Random(1,${CustomerID_#},)},)}
According to JDBC Request Sampler documentation the following variables are getting generated when you run a Select statement:
Customer_ID_# - number of rows returned
Customer_ID_1 - value from the first row
Customer_ID_2 - value from the second row
etc.
So
${__Random(1,${CustomerID_#},)} function returns a random number between 1 and the number of returned rows
__V() function evaluates the generated expression and returns the random value
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
Going forward be informed that since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting
First of all using of Beanshell is deprecated and it is not a recommended to use it in Testplan.
It is recommended to use JSR223 pre/post-processor according to your needs.
I used pre-processor for the sampler - it works well
import java.util.Random;
Random rand = new Random();
def varName= "CustomerID_";
int randBoundary = rand.nextInt(100);// this will generate values between 0-100
varName = varName + randBoundary;
vars.put("p_CustomerID_New", vars.get(varName));
You can use this sample code and modify according to your requirements.
I am capturing bunch of available seat list using JSON Extractor (Please refer "1_JSON_Extractor" ) , I am using -1 to capture all the ordinals, it is working fine (Refer "2_Debug_Sampler").
I need to take the random value from the list, Instead of using 0 for Random Ordinal, I am trying to use Random Variable here,( Please refer "3_Random_variable"). But it is not working fine.
I am planning to use the the Random variable "C_Seat_1" in the place of JSON Extractor Match No and get the random value. (Please refer "4_Json_Extractor")1_JSON_Extractor .2_Debug_Sampler3_Random_variable4_Json_Extractor
Can you help ?
Take a look at JMeter Test Elements Execution Order
0. Configuration elements
Pre-Processors
Timers
Sampler
Post-Processors (unless SampleResult is null)
Assertions (unless SampleResult is null)
Listeners (unless SampleResult is null)
Random Variable is a Configuration Element
JSON Extractor is a Post-Processor
Hence when Random Variable is evaluated JSON Extractor hasn't been executed yet therefore ${C_Selected_Seat_All_matchNr} is not defined
You can just go for __Random() and __V() functions combination to pick a random seat directly where required without any extra configuratino elements, something like:
${__V(C_Selected_Seat_All_${__Random(1,${C_Selected_Seat_All_matchNr},)},)}
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
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.
I am very new to Jmeter and trying to use it for doing load testing my application.
In my application, every time we click on a template, application will allocate a unique id which to the template...when I recorded the steps using jmeter, a particular unique id was recorded...but when I tried to play the recorded case...it is looking for the same unique id....how do I tell jmeter to get the new id from the application?
Here are the steps
Login as a user,
click on a particular link,
click on a button which will then popup a window asking to select a template,
After selecting a template, my application will create a unique id for that template
It very much depends on whether that template ID is created on the client (i.e. by JavaScript), or on the server (i.e. you can actually record a template ID returned by the server).
If second is your case, then server returns template ID in the response to template selection, so you can use one of the post-processors - a supporting element invoked after the parent request; it usually extracts data from the response and saves it as a variable(s). In your case you'd extract template ID and save it as variable. Later samplers can use the variable in format ${your_name} instead of the recorded hard-coded string. So in that case your plan could look like this:
Which post-processor to use and how to use it depends on the response you are receiving form the server, so cannot be more specific here.
If the first option is your case (JavaScript on the client generates template ID; and your recording only contains usage of said ID), then you can simulate what JavaScript is doing by generating a similar ID using one of the JMeter script-related features: it could be random function, an inline piece of JavaScript code, a scriptable sampler, such as JSR223 Sampler, or... There are many options really, depending on concrete needs of that generated template ID. Again, a more specific question would help to narrow down your choices.
Classic "correlation" example.
Look for that generated ID in the previous responses (you can do it with the View Results Tree listener)
Once you detect it you need to extract it and convert into a JMeter Variable with a PostProcessor (the most commonly used is Regular Expression Extractor, however depending on the nature of your request you may consider to use others
Once you get the ID extracted and stored in the variable - substitute hard-coded value obtained via recording with the JMeter Variable
Repeat steps 1-3 for any other dynamic parameters or values. Or, consider a faster way of creating a JMeter test via alternative recording solution which performs the above steps automatically so you won't have to worry about detecting and handling dynamic elements. See How to Cut Your JMeter Scripting Time by 80% article for details.
You need to check response of the previous request. Normally ID will be created and can be found in the response of previous request and you can use that ID for next request.
You need to first find in which response the ID is being generated and the format of the ID. You can use firebug to see the response in HTML format and find where the id is.
Once you have the format of the id, create regular expression around it. Test it using regex tester that comes with JMeter. Or you can use rubular.com to check the correctness of your regex.
Once you have correct regex, use regular expression postprocessor on the request which returns the id and then use that variable in actual request that uses unique id.
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.