Unable to read the token id from json response code using regular expression extractor in JMeter - jmeter

I have to do performance testing for ipad application.
There is scenario in which i have to read the token id from the response and use this token id in my next request.
I used the regular expression extractor, but when i used the variable in next request i.e. ${tokenid}, it wasn't replaced with the captured value. When i look at View Result tree, it is simply requesting the variable instead of token.
Here is the regular expression extractor

There is at least an error where you must check:
Body
instead of checking :
Response Code
in Regular Expression Extractor
You can use View Result to check your regexp:
Finally regexp should be:
"Token":"([^"]+?)"

Related

JMeter - __Request Verification Token Failed for New user registration in MVC project

Request Verification Token is not identifying or getting assigned to a variable by JMeter for a new user registration
In GET, Request header - Request Verification Token is passed as Static one
In POST, Request header - Static request verification token is called and in PAYLOAD - Another dynamic Request Verification Token is displaying.
In POST url, I have used below Regular Expression Extractor:
Field to check: Request Headers
Name of created variable: Token
Regular Expression: input name="__RequestVerificationToken" type="hidden" value="([A-Za-z0-9+=/-_]+?)"
Template: $1$
Match no: 0
Queries:
Do I need to use Regular Expression Extractor in GET URL also, If yes what regular expression need to be used?
How to pass Static request verification token value in GET & POST URL?
Do we need to use 2 Regular Expression Extractor in GET & POST URL?
Could you please provide solution?
Field to check - needs to be Response Body
Using regular expressions for extracting data from HTML is not the best idea, consider switching to CSS Selector Extractor instead.
We don't know the answers to your questions because we're not familiar with the application you're testing, if you have doubts with regards to which values need to be correlated - record the same test scenario 2 times and compare the generated test plans. All parameters which differ are a subject to correlation.

Extracted Regex Value not getting passed into next POST request body in Jmeter

In my first request I am able to extract the value using Regular Expression Extractor which is clearly visible into the debug sampler. The value is extracted by setting the following options in Regular Expression Extractor:-
Name of Created Variable:- instanceUID
Regular Expression:- "InstanceUid":"(.*?)"
Template:-$1$
Match No:-1
Default Value:- (Blank)
The value that I want to pass in the next POST request is visible as:-
instanceUID_g1=2ab5dfb8-a217-4ff2-9025-523565b7b7ad
And the body for the next HTTP POST request is set like this:-
${"iInfo":{"InstanceUid":"${instanceUID_g1}","Registry":"${Registry}"}}
When this request seen in detail inside View Results Tree looks like:-
${"iInfo":{"InstanceUid":"${instanceUID_g1}","Registry":"AAX"}}
As seen the value of ${instanceUID_g1} did not get substituted in the POST body as was for variable ${Registry} which was taken from CSV config.
Being new to Jmeter can anyone suggest what did I miss?
Most probably your Regular Expression Extractor placement is not very correct, be informed about JMeter Scoping Rules concept
If you place Regular Expression Extractor as a child of the request - it will be applied to this request only
If you place Regular Expression Extractor at the same level as several requests - it will be applied to all of them
in the latter case it will be applied 1st to 1st sampler, then to Debug Sampler, then to 3rd sampler so on 2nd step it will be overwritten, most probably that's your problem
Also it appears that you're getting the data from JSON so it makes more sense to use JSON Extractor or JMESPath Extractor

How to retrieve variable from a request body

In my JMeter script I have a request which uses a token as part of the request body:
I've got a regex extractor to retrieve this value but I can't seem to get it back. I've tested using all the "Field to check" values e.g. Request Header etc. The regext I'm using is "token=(.*?)"
This token is needed as other calls explicitly reference it and I need to pass them this variable
Switch "Field to check" to URL as in your case the token is not in the request body, it's in URL's Query String
Amend your regular expression to look like: token=(.*)
This way you will get the token value into the ${TOKEN} JMeter Variable.
More information:
JMeter: Regular Expressions
Using RegEx (Regular Expression Extractor) with JMeter
Perl 5 Regex Cheat sheet
Query parameters are part of the url, so choose URL as Field to check
Also you are building the URL, so can't you use save the token value before?

Getting oauth token using Jmeter xpath extractor and using it in path of other Http Request

What should be the Regular expression if I want to extract the value for access token, So that i can use it in Path of other Http request ie like access_token=93ee29b4-74dc-4uu7-8e10-6eac6845511b from below http response.
{
"access_token":"93ee2tum-1234-56789-8e10-6eac684551tum",
"token_type":"Bearer",
"expires_in":3600,
"scope":"test"
}
I have given regular expression as
"access_token":"([^"]+)"
And also where can i check the value of regular expression I am getting
You can test your Regular Expressions using View Results Tree listener in RegExp Tester mode like:
Also you can use Debug Sampler to see the associated JMeter Variables. See How to Debug your Apache JMeter Script article for details.
Starting from JMeter 3.0 it's more handy to use JSON Path PostProcessor, in that case the relevant JSON Path Expression would be as simple as:
$.access_token
You can add following regex. It will get the token and depending on the name variable you set, you can add one BeanShell Post-processor to print the token in console for you to verify. Just add the following to it:
log.info(vars.get("token"));
// token is the variable name which you specify in Regular Expression Extractor.

How to Re-use data generated by one Response to other request?

In my application while executing the first request one unique key is generated which key is required for Next all the request. let me how to automate such scenario in Jmeter.
The process should look as follows:
Add Post Processor to the first request
Configure it to extract the required value and store it into a JMeter Variable
Use JMeter Variable from step 2 in your next request.
Depending on response data type you have the following choices:
Regular Expression Extractor - for text
CSS/JQuery Extractor - for HTML
XPath Extractor - for XML and XHTML
JSON Path Extractor - for JSON
It is also possible to extract data from files i.e. if response is in PDF format, but it's a little bit tricky
Example configuration to store the whole response:
Reference Name: any suitable variable name, i.e. response
Regular Expression: (?s)(^.*)
Template: $1$
You can refer the extracted value as ${response} where required. You can also amend the regular expression to extract response part instead of the whole response. JMeter uses Perl5-compatible regular expressions, see Regular Expressions User Manual Chapter for details
You can use regular expression extractor to extract the key from the response of your first request and use the extracted key for subsequent requests. To achieve this:
Right click on the first request and add post processor: Regular Expression Extractor.
Create your regular expression and provide values in other required fields. Please refer to JMeter component reference http://jmeter.apache.org/usermanual/component_reference.html#Regular_Expression_Extractor
Extracted value will be saved in the variable given as reference name
Use this variable in subsequent requests
Here is an example test plan with results.

Resources