Using JsonExtractor Value in Jmeter - jmeter

I have like 3 JsonExtractors in a single thread. How do i use the value extracted from the first to the third ?
The first JsonExtractor extracts 'winSpoke' value from the response json and i am storing in as
Names of created variables: WinSpoke
The third JsonExtractor will extract 'payLevelDetails' value based on the previous WinSpoke value and i am storing in as
Names of created variables: PayLevelDetails
Json Path expressions: $.payLevels[${WinSpoke}]
However i am getting error as -
JSONPostProcessor: Error processing JSON content in Pay Level Details
JSON Extractor, message: Could not parse token starting at position
11. Expected ?, ', 0-9, *
Can someone help me in pointing where i might have gone wrong ?

Your setup should work just fine given you have ${WinSpoke} variable defined, you can double check its value using Debug Sampler and View Results Tree listener combination
Also be aware that PostProcessors are being executed upside down so make sure that the JSON Extractor which extracts your WinSpoke variable is above the one which is referencing the variable.

Related

Jmeter check using if controller, for a variable has a value or not

in one of my steps in the Jmeter script, I'm using json extractor to read a value from a key(address) in the JSON response and store it in a variable called "TypeOfRequest." In the next step, I need to check if the "TypeOfRequest" value is null or not(There can be situations I don't find that key in the JSON response). Then I need to take a different route.
Snippet how I'm getting the TypeOfRequest from Json extractor $.communicationMethods[:1].hTTPS.address
So my question is, how do I check if TypeOfRequest has a value or not in the if controller?
tried using '${__javaScript(vars.get("TypeOfRequest") == null)}(ref https://www.blazemeter.com/blog/jmeter-if-controller and https://sqa.stackexchange.com/questions/32969/how-do-i-check-if-a-variable-is-null-using-a-if-controller) but unable to go through the if condition, can someone help me with this. Thanks in advance
Just use Debug Sampler to see what JMeter Variables are defined and inspect their values, my expectation is that you're "unable to go through the if condition" because your TypeOfRequest variable is not null, i.e. it's present but it's an empty string.
Also the referenced article suggests using __groovy() or __jexl3() function so I believe if you change your condition to something like:
${__groovy(org.apache.commons.lang.StringUtils.isEmpty(vars.get('TypeOfRequest')),)}
you will be able to "go through the if condition"

How to pass the dynamic value in Body data in the Post Request using jmeter

I recorded the .JMX script in Jmeter and one of the request is as below
POST http://www.hello.com/auth/nqa/md/login
Body data:
{"domainId":"nqa","code":"12345skdkdk"}
I would like to send the "code" field dynamically and for that I added the regular expressing extractor as below enter image description here
When i re run the script , the code value is not replaced with the dynamic value.
Not sure what part i am missing in the regular expression extractor or in the Body data field
First of all, you cannot extract the value from the request body using the Regular Expression Extractor, normally you should extract the dynamic values from the previous response so inspect the whole flow using View Results Tree listener and look for your "code" value there
Your regular expression extractor in its current configuration will return random value in the parentheses so it could be domainId, nqa, code or 12345skdkdk. Going forward if you need to get some dynamic data from JSON go for JSON Extractor or JSON JMESPath Extractor
List item
you should do three-step of below
go to the random variable according below picture
Define random variable name . in this case we set variable name to code1 and set min & max value to this
Use ${code1} variable to your data section

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

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.

How to handle dynamically generated values during run time via 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

Resources