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.
Related
How to add multiple products in cart by using loop controller in jpetstore application and by using one request we need add multiple items to cart
Just normally trying in jmeter
Loop Controller basically executes its child(ren) defined number of times.
I don't know whether it's 100% suitable for adding items to cart, my expectation is that you need to pass the ID of the item you're adding to the cart which means that you need to determine this ID somehow, i.e. open the list of the items and use a relevant Post-Processor like Regular Expression Extractor or Boundary Extractor
This way you will get the following JMeter Variables:
ItemID_1=foo
ItemID_2=bar
etc.
ItemID_matchNr=2
If you want to add all the items - then put ${ItemID_matchNr} as the Loop Count of the Loop Controller
and use __V() and __intSum() functions combination in the HTTP Request sampler to refer the current ItemId like:
${__V(ItemId_${__intSum(${__jm__Loop Controller__idx},1,)},)}
where required:
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 a series of interconnected pages to test using JMeter. The problem is that the initial page has a Javascript variable in source section which is more of a session variable. This variable is passed in the URL for subsequent pages.
So basically I would like to fetch this javascript variable when I load the initial page from the source section and pass it to next URL(s).
Is there a way I can achieve this using JMeter.
Are you able to see the session variable in the response of initial page?
(in view result tree listener)
If yes, then correlate this value and pass the variable in to next request (use regular expression extractor for fetching the value, still if you are finding some issue in correlating the value than please share the response of first request over here so that I can provide you regx for that)
People mostly Regular Expression Extractor to fetch dynamic values from previous responses, in general the process looks like:
Add Regular Expression Extractor as a child of the request which returns desired data
Use Perl5-style regular expression to match what you're looking for
Provide a template to choose match group - ususally $1$ if you looking for a single value
Provide a reference name to refer the extracted value, i.e. foo
Use extracted value as ${foo} where required
You can visualise JMeter Variables using Debug Sampler and View Results Tree listener combination.
The easiest way to debug your regular expressions is using View Results Tree listener in "RegExp Tester mode"
See How to debug your Apache JMeter script article for more information on troubleshooting your JMeter test.
I would like to perform a load test on a SOAP webservice.
There are two requests :
createDocument. Input: name, size, date. Output: id's document newly created
getDocument. Input: document id. Output: id, name, size, date
I would like to perform a load test on the createDocument method. Not rocket science, I use the SOAP sampler, very simple.
But in a second step, after the load test (for performance reason) I would to check if the document are really created by calling getDocument with the id.
My idea :
Create a Thread Group for the SOAP sampler
On the Thread Group, add a postprocessor Beanshell
in the postprocessor, store the document id in a Java list
Create an other Thread Group for the verification
In the Test Plan, check "Run Thread Groups consecutively"
In the verification Thread find a way to loop the Java list
For each id, perform a SOAP call
I don't know how to loop over a Java list and call a SOAP sampler for each iteration. Any idea ?
Or generally, do you have a solution more jMeter compliant ?
Thank you
In the second thread group:
Add a Beanshell Sampler which will iterate through the list with document IDs and store them into JMeter Variables, something like:
List IDs = bsh.shared.IDs;
int counter = 1;
for (String ID : IDs){
vars.put("ID_" + counter,ID);
counter++;
}
This will result in variables like:
ID_1=somedocumentid
ID_2=someotherdocumentid
....
etc.
Add a ForEach Controller and configure it as follows:
Input Variable Prefix: ID
Output Variable Name: anything meaningful, i.e. CURRENT_ID
Make sure that "Add "_" before number" is checked
ForEach Controller will iterate through all defined variables with ID_ prefix and you will be able to refer the current value as ${CURRENT_ID}
Reference material:
Sharing Variables chapter of JMeter's User Manual Best Practices
How to use BeanShell: JMeter's favorite built-in component guide
ForEach Controller documentation entry
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.