I need some help in getting a value using regular expression extractor. I am getting no value out - jmeter

I am new to JMeter and learning, practicing using the Regular expression extractor.
I have created a test plan using the recorder. I have added a regular expression extractor as i want to get the text "Your Account" from my webpage into a variable.
I use the debug sampler to check if my variable has got the value "Your Account" in there.
I am seeing the default value "your_account_NONE" in the variable when i run the test.
I think my regular expression is wrong. Please advise, help. Thanks.
I know I am on the correct page when the test runs because i have inserted a Response Assertion, pattern to test is set to "Your Account"
The assertion passes. If i change to pattern to "Your Accounttttttttttt"
The assertion fails. So I am on the correct page.
I would like to get the value "Your Account" into a variable.
My regular expression has the following config:
Reference Name: YourAccount
Regular Expression: <h1>"Your " <span>Account</span> </h1>
Template: $1$
Match: 1
Default Value: your_account_NONE
My test plan is as follows:
Test Plan
Thread Group
Http Request defaults (Server Name: a URL to go to homepage)
Recording Controller
Http Cache Manager
Http Cookie Manager
Http request (sign in)
http request (Homepage)
Regular Expression Extractor
Response Assertion

The solution to this issue is to use Regular Expression Character Groupings. These are then referenced in the "Template" portion of the regular expression extractor.
Simply encase the part of the match you want in ().
For example:
Regular Expression: <h1>"(Your )" <span>(Account)</span> </h1>
The line above places a character grouping around "Your " and "Account".
Then, to build that into one reference variable you want your "Template" to be this:
$1$$2$
That will concatenate the two character groupings into the variable "YourAccount".

Related

Token cannot be pulled by Jmeter

I recorded login steps using Jmeter Recorder, and I am trying to use the authorization token dynamically so I can simulate logging users to the system.
Here is my setup for the test
Here is my css-selector extractor
Here is my Login page HTTP-request
The token is inside the HTML page like this
<input name="__RequestVerificationToken" type="hidden" value="n8H4dNHGkK7Fpqkue5wdqq419hVAG88AgqQiOmqsIUeBZS5L3uwwQYubC4pwKgulTbXBcQx22L4luV7NxwmQXw_PWG1xCdNwvfolB-c7obs1">
Now each time I run, my login still failed and the ${token} has a different token number than the one in the header response
Where did I go wrong here?
You have an error in "Match No" field, $1$ is a template for the Regular Expression Extractor.
For the CSS Selector extractor in case of multiple matches the field allows you to:
Pick a specific match value if you provide a positive number
Pick a random match value if you provide 0
Save all matches if you provide -1
given you have only 1 match you can:
leave the field blank
use 1
or use 0
More information: How to Use the CSS/JQuery Extractor in JMeter

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?

JMeter variable not being used in POST request

I am extracting several variables from a login response, using "Regular Expression Extractor" post processors. Most of them work when I reuse the variable, but one doesn't.
The regex extractor has the following settings:
Apply to: Main sample only
Field to check: Body
Name of variable: id_token
Regular Expression: <input type="hidden" name="id_token" value="([^"]+)"
Template:
Match No.:
Default Value:
Use empty default value: (unchecked)
Then in a later POST HTTP request I use the parameter:
Name, Value, URL Encode?, Content-Type, Include Equals
id_token, ${id_token_g1}, true, text/plain, true
When running the test in the "View Results Tree" listener the same POST request's POST data contains
&id_token=%24%7Bid_token_g1%7D
Instead of the value of id_token_g1.
Other variables in the same POST data are being completed correctly.
The Debug PostProcessor from the previous request contains
id_token_g1=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjVEbHphYTlvNEdveWFtWXdLNl9MUS16akFZTSIsImtpZCI6IjVEbHphYTlvNEdveWFtWXdLNl9MUS16akFZTSJ9.eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo0NDM4Ny9pZHMiLCJhdWQiOiJkOGVjZjYzMi1mNzE0LTQ2MzEtOGViOS1lYmUzMDI5OGNjMGYiLCJleHAiOjE1Mjk1MDE3MTgsIm5iZiI6MTUyOTUwMTQxOCwibm9uY2UiOiI2MzY2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sX2LgQGbAg23BH9O_9rGg84DTgHM6IMlQG_loX2PnL8B5yqxydbJsz6CBdiLqKg
I have the same issue with session_state_g1
session_state_g1=XZkcgcg9i_FqlFIS-scHuHqMdm5jepyCSSFkF_S4Dx8.99d68c0a8e802c8767d22fb019bd34b5
But not with
access_token_g1=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjVEbHphYTlvNEdveWFtWXdLNl9MUS16akFZTSIsImtpZCI6IjVEbHphYTlvNEdveWFtWXdLNl9MUS16akFZTSJ9.eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo0NDM4Ny9pZHMiLCJhdWQiOiJodHRwczovL2xvY2FsaG9zdDo0NDM4Ny9pZHMvcmVzb3VyY2VzIiwiZXhwIjoxNTI5NTA2MzAzLCJuYmYiOjE1Mjk1MDI3MDMsImNsaWVudF9pZCI6ImQ4ZWNmNjMyLWY3MTQtNDYzMS04ZWI5LWViZTMwMjk4Y2MwZiIsInNjb3BlIjpbIm9wZW5pZCIsInByb2ZpbGUiLCJkeW5hbWljY2xhaW1zIiwiZmlsZXN0cmVhbWluZ2FwaSIsInVzZXJtYW5hZ2VtZW50YXBpIl0sInN1YiI6ImU2NWE0M2MwLTllY2EtNDRjYi05YzYzLWU2NjhhMzNhNWQyYiIsImF1dGhfdGltZSI6MTUyOTUwMjcwMSwiaWRwIjoiaWRzcnYiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJhbmdlbGFjIiwibG9jYWxlIjoiZW4tR0IiLCJuYW1lIjoiQW5nZWxhIENhdGFsZG8iLCJhdWRpdF9yZWFkX2JpdG1hc2siOiIwIiwiYXVkaXRfd3JpdGVfYml0bWFzayI6IjAiLCJhbXIiOlsicGFzc3dvcmQiXX0.Z2RTMN6NGwC1e8bJANmzvA9rUyo03vCpA3TTNylbdR8EpOvaktgHXHjWCFzxlaXeiL-24DlmVoq3qPHRx0u03nr8ZRD2fb9R_OeHxZ-gVr-2D1Ash1f_429J_4U7zjQfAQSOKHHamzTocSl0orLuvQdc9-oAydPCzpp82UbEDwsnQl_E52dK_LEB4eSiV3sB8rSpmZkmnhCmuSh9iUuMEOmA_zIs2cH_exFWjv5WXbZ8gKR-ATrPNuzoDpghMNZs-Of-dZwsaHfSJpV8C12DQ6wZq-w7m6v2szUpgJh1kHafKzM8Gm8-nMAAPV83hbdALFVvsF9tfcLjin3OEdytsfsfRLDEHLh4E-vo-LyAeHV-TKGuvX60-6tdQsSQXY-egVx1W7NiObmLbFzdRGAiV--tk8QHJ8Vf-nVAT00YXeQxEdMl1lqJFNuNOFxoNXL1ud_frUv1c2xwcnCH0hBpt2avWqN72Bj-15j6uube7IPIVp20NpT0M7FujohB-wQLfVJ8d7Ac_AVNScqasdijpTP5DzmsFybvXAu8n0MEcYHYF0-C8_d0EWW7GxpSEeeVFqKNk7JFgXEo1ta_5Yu7XDpwG7evzMFMw49cImZgcQlxrq3oDnl-qo6r9UXOfvS5QoDILU6dqYUpRSS1-Mz4_JbOmEs78v5ixcrm94PfNis
I have the same problem if I update the name of the HTTP Request sampler (it shows as ${id_token_g1} in the "View Results Tree" listener)
Any ideas what I'm doing wrong?
Make sure your setup is following JMeter Scoping Rules, i.e. you should have setup like:
Open Login Page
Regular Expression Extractor
Perform Login
Make sure you have this hidden input with name id_token in the response data. JMeter can be configured to store response data in .jtl results file, you need to add next 2 lines in user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
Don't forget to restore the default configuration once you figure out the cause of the problem. See Results file configuration for more details.
Regular expressions is not the best choice for parsing HTML responses as they can be very fragile in case of markup change (changed order of HTML attributes or the input definition becomes multi-line). So consider switching to CSS/JQuery Extractor instead, the relevant configuration would be something like:
Reference Name: anything meaningful, you can keep id_token
CSS/JQuery Expression: input[id=name]
Attribute: value
In 2nd POST request you can refer the extracted value as ${id_token}
1.Follow Jmeter Scoping Rules.
2.To your regular expression you can give template as $1$ and use ${id_token} instead of ${id_token_g1}.
For more information on regular expression extractors
follow this link.
You can use this website to test your regular expressions.
Let me know if it helps..

How to use regular expression extractor using JMeter

I am new to JMeter and need to simulate a scenario of about 200 users logging into the application.
using the recording controller I have recorded the steps
Note: I have replaced the actual website name with myapplication.com
Step 1 (GET): navigates to https://myapplication.com/login
Step 2(GET): There is an auto-redirect to
auth.org.domain.com/idp/saml2/idp/SSOService.php
Step 3 (POST): There is an auto-redirect to
auth.org.domain.com//idp/module.php/core/loginuserpass.php?AuthState=xxxx
Now the response data in Step 2 provides me with the AuthState token in following format in the body of the response
You were redirected to: <a id="redirlink" href="https://org.domain.com/idp/module.php/core/loginuserpass.php?AuthState=_b68bdd977f7cf900eb1b4512b56bc2d0b13dc734e2%3Ahttps%3A%2F%2Fauth.org.domain.com%2Fidp%2Fsaml2%2Fidp%2FSSOService.php%3Fspentityid%3Dhttps%253A%252F%252Forg.domain.com%26cookieTime%3D1481072747">https://org.domain.com/idp/module.php/core/loginuserpass.php?AuthState=_b68bdd977f7cf900eb1b4512b56bc2d0b13dc734e2%3Ahttps%3A%2F%2Fauth.org.domain.com%2Fidp%2Fsaml2%2Fidp%2FSSOService.php%3Fspentityid%3Dhttps%253A%252F%252Forg.domain.com%26cookieTime%3D1481072747
I can see that Auth state is repeated twice. How do I extrate the auth state here which is
"_b68bdd977f7cf900eb1b4512b56bc2d0b13dc734e2%3Ahttps%3A%2F%2Fauth.org.domain.com%2Fidp%2Fsaml2%2Fidp%2FSSOService.php%3Fspentityid%3Dhttps%253A%252F%252Forg.domain.com%26cookieTime%3D1481072747"
Your help is appreciated
Use the following regular expression configuration:
Apply to: Main sample and sub-samples
Field to check: Body
Reference Name: anything meaningful, i.e. authstate
Regular Expression: AuthState=(.+?)"
Template: $1$
Refer the extracted value as ${authstate} where required like
/idp/module.php/core/loginuserpass.php?AuthState=${authstate}
Demo:
References:
JMeter Regular Expressions
Jakarta ORO Regular Expressions Pattern Matching Characters
Using RegEx (Regular Expression Extractor) With JMeter

Unable to read the token id from json response code using regular expression extractor in 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":"([^"]+?)"

Resources