jmeter how to replay recorded unique id from application - jmeter

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.

Related

How to capture a dynamic ID from a URL whose request is failing in JMeter?

This is in addition to the question already asked:
Please refer the image displayed on clicking the link : https://i.stack.imgur.com/O0lSD.png
Questions:
Is it possible to extract the highlighted values - Blazor ID and Timestamp in JMeter even when the response fails? (Since these values are unique, dynamic and change for each session - it fails on rerunning them)
Is it possible to create/record > amend > run JMeter scripts when we have such dynamic and unique values involved?
I have tried to capture the Blazor ID through Regular Expressions.
But JMeter is not able to capture it from URL (Tried it with all options in JMeter - URL, Body, Headers, Response etc).
Is this because the request is failing? Please have a look at the SS and let me know if anything has to be corrected from my end.
https://i.stack.imgur.com/jK1SF.png
https://i.stack.imgur.com/B2ZNm.png
I guess the Regex Expression need to be change,
for id use id=([^&]*)
and for time use &_=([^&]*)

field name is getting changed in response data

Field name is getting changed after executing the script.
A. After executing the script,the field name is not getting displayed in response data but the parameters are displayed with slight changes.
In sampler below details are getting displayed.
Name : aura.token
Parameters : HCQAHBgEMTAwMBQCGAcxMDAwMjA5GAcxMDAwMjA5ABQCGfMQscHV8XF654tDbfY0XD3yRxaSwbvRh1oAGfMgzIG_YaBrAZdWB-IAMP_0iAQiYMHheBA3BA0SoXzWh4kA
but after execution of a script below details are getting displayed in response data.
*/{"event":{"descriptor":"markup://aura:invalidSession","attributes":{"values":{"newToken":"HCQAHBgEMTAwMBQCGAcxMDAwMjA5GAcxMDAwMjA5ABQCGfMQkaKR6n5r5QqE7gz5Qk1l1Rb67KOtiFoAGfMgtKaMHHWJZiXEOt8pU6zs1edK_Q4dQo5VL2ea8y2qi3gA"}}},"exceptionEvent":true}/*ERROR*/
It's name is "newToken". So why do you think this should not be changed?
Most probably you need to perform correlation of this field, to wit you will not be able just to record and replay the script as this "token" is being generated dynamically and has new value each time you access the application.
The main idea of the correlation is
Identifying dynamic elements. The easiest way is to record your test scenario one more time using HTTP(S) Test Script Recorder and compare the recorded scripts. All parameters which are different needs to be handled properly.
Wherever you detect a dynamic parameter look into previous sampler response data (body, headers, Cookies, URL) - the value should be there
Apply a relevant Post-Processor to the previous sampler in order to extract the dynamic value and store it into a JMeter Variable
Replace recorded value with the JMeter Variable from the previous step
You should be good to go now.

Fetch Javascript variable in source section using Jmeter

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.

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.

How to extract value passed in the URL and use it as parameter in Jmeter?

I am using Jmeter for my performance testing and I am stuck at the point where I need to extract the value from the URL and pass it to Jmeter.
Here is the example:
Application requires user to create an order and then submit it on the next page
I am at a point where I can create an order using Jmeter.
In order to create a script to submit an order I have copied the url from the web page as passed it as a GET method '/order/submit/23'. This '23' number changes everytime I create a new order
The issue I am having here is when I run my jmeter script it creates another order with another number which then mismatch with the '/order/submit/23' url I have passed.
Is there any way to extract this number from the HTML code and pass it to Jmeter?
I looked into the HTML code and this number is a part of URL so not sure how I can extract it. Any suggestions please
I am looking for something like /order/submit/${var}
Thanks
If I understood you correctly, you need to extract some value from response. You can do it with two samplers:
XPath Extractor
RegEx extractor
I think xpath extractor more appropriate in your case

Resources