How to handle dynamically generated values during run time via Jmeter - jmeter

Scenario: I am recording a script which is fetching values from CSV name and email. I have used ${email} and ${name} at the time which candidate is registering. Every time candidate register, unique instance Id is generated on the basis of which further action is performed.
Ex:
Candidate registers -> Unique Id (say 12345) -> ST : Start some test
on the website -> Some responses saved for 12345 -> FT : Finish test
on website
Need to perform the same for say 500 candidates. I am fetching unique email and name from csv.
How do i store/handle unique instance Id for each candidate dynamically and perform the entire operation?
Currently each operation is getting performed for same unique instance Id (12345) with 0% error.
Let me know if any other details needed for the same.
UPDATE from comments:
I can use say UniqueId whenever candidate registers using a RegEx Extractor or a XPath Extractor and i can pass that value in further process.
Now issue is i have to pass the stored variable in JSON.
No clue about that.

Since you've extracted UniqueId value using any extractor component it's stored in jmeter variable (pointed in the extractor's configuration) and can be referred as e.g. ${uniqueId}.
To pass into the further request you can use HTTP Request where in Post Body you can set your JSON request code with ${uniqueId} inserted in the right place.

You can use regular expression extractor in jmeter to extract required variable value and store reference it with a variable name .
Later it can be used in later requests by usin ${variablename}
In the regular expression extractor you can use perl5 regular expressions
Refer to this link for additional information:
http://www.jmeter4u.com/2013/04/chapter-6-handling-dynamic-server-values.html

Related

Jmeter - My response has multiple values of same id. I want to extract and pass these values incrementally to the next request

My response to a save action is somewhat like this-
"diagnosisId":45686,"confidence":0.0, --other text--
"diagnosisId":45966,"confidence":0.0,--other text-- etc. Say there are 27 diagnosis Ids.
Now i want to send request for the 1st Diagnosis Id in loop till the last id (multiple records/rows to save depending upon the diagnosis Ids).
Request is something like this -
"diagnosisId":45686,"confidence":0," etc.
I have extracted the Diagnosis Id using Regular Expression extractor and matched the first value -
"diagnosisId":(.+?),
How do I pass the values incrementally now?
Given you provide "Match No:" as -1 in the Regular Expression Extractor:
You will get the following JMeter Variables as the result (viewable via Debug Sampler):
At this stage you can add ForEach Controller and configure it like:
Input variable prefix: diagnosisId
Output variable name: anything meaningful, i.e. id
That's it, you can reference each consecutive ID as ${id} in the request(s) which will be the children of the ForEach Controller:
Another example: Using Regular Expressions in JMeter

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.

Jmeter performance testing :

I have a requested in jmeter that request created new one request, so I need that new one request url in a variable because new one request having a user I'd.
You can handle this situation in at least 2 ways:
Extract the dynamic part using Regular Expression Extractor:
Add Regular Expression Extractor as a child of the 1st request
Configure it as follows:
Field to check: URL
Reference Name: anything meaningful, i.e. id
Regular Expression:userId=(.*)
Template: $1$
Assuming everything goes well you should be able to refer extracted value as ${id} where required (manually add it to the end of each and every request)
You can semi-automate the process using Using the HTTP URL Re-writing Modifier, just add it as a child of the first request and put userId into "Session Argument Name" input field, JMeter should be smart enough to automatically add these "userId" postfixes to subsequent requests.

jmeter how to replay recorded unique id from application

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.

Extract Entire(a single string) response Using JMeter

I am testing a site using JMeter. I am creating a GET request for getting an account number by an unique id. Which returns only the account number(in String). How can I get the account number in to a Reference Name of JMeter extractor?
Use Regular Expression Extractor.
Add Regular expression extractor (under Post Processors) as a child of your request. Provide Reference Name of your choice. Provide Regular expression as (.+?).
As you say the response has only the Account Number you are looking for,
Use a Beanshell post processor,
vars.put("ACCOUNTNUMBER", prev.getResponseDataAsString());
Then you can use ${ACCOUNTNUMBER} , in your test to get the value.

Resources