How can I get the value from a hidden input field using JMeter - jmeter

I am trying to get the value from a hidden input field. I researched and found many sites ( including instances on this site ) showing great examples. When I try them, I am not able to retrieve the value from this hidden field using the methods I have learned. I have tried both an xpath extractor and a regular expression extractor, but neither one retrieves the value from the hidden field.
Also, I will note that in the tree on the left side in JMeter, I put the extractors as a child to the HTTP Request where the token first appears. Are the extractors supposed to be children or are they supposed to be at the same level as the HTTP Request, but just after it in the flow of the test?
==============================
Here, I will explain my set up. There is an HTTP request from a form. There is a token on the form. I need to get the value for this token. Here is the html for the page where the token appears:
<form action="/folder1/part1/save/12345-1234-1234-1234-123456789012" method="post" name="mgr" id="mgr" >
<input type="hidden" name="token" value="1234-12-12-12-1234" id="token" />
==============================
For the Regular Expression Extractor, I have tried all of these, one at a time for each test run:
//input[#type="hidden" and name="token"]/#value
//input[#type="hidden"][#name="token"]/#value
//input[#type="hidden"]/[#name="token"]/#value
//input[#type="hidden"][#name="token"]/#value/[#id="token"]
//input[#type="hidden"]/[#name="token"]/#value/[#id="token"]
For the XPath Extractor, I have tried all of these, one at a time for each test run:
//[#id="token"]
/html/body/div/div[2]/div/form/input[1]
//html/body/div/div[2]/div/form/input[1]

Try this one: //input[#type="hidden" and #name="token"]/#value
Also, you could test your expressions exactly in JMeter. For example, this xpath extraction you could check in XPath Tester element in View Result Tree Listener. There you could find Regexp Tester too

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

Single Sign On with JMeter (SAMLResponse not getting Value)

I have a JMeter (v 5.4.1 ) script that login's to an SSO Service, using the following steps which are a result of using BlazeMeter Recorder.
GET on https://stage-aa.example.com/user/login
GET on https://stage-aa.example.com/saml_login
use this to declare SAMLRequest and SAMLResponse, Regular Expression Extractors
SAMLRequest : Regex: SAMLRequest=(.*)RelayState=(.*)
POST on https://sso.example.com/idp/EFUUU/resumeSAML20/idp/SSO.ping
This sample uses parameters:
username: user_1
password: pass_1
The parameters are named as:
pf.username
pf.pass
POST on https://stage-aa.example.com/simplesaml/module.php/saml/sp/saml2-acs.php/default-sp
with Parameter:
RelayState: https://stage-aa.example.com/saml_login
SAMLResponse: PHN8730Kkascnn...uyituNN (AlphaNumeric String )
with the Parameters:
RelayState: https://stage-aa.example.com/saml_login
SAMLResponse : Long String, which i am trying to Dynamically replace using ${SAMLResponse}
SAMLResponse is not getting value for the Regex Extractor !!!!!!!!, used SAMLResponse=(.*)
GET on https://stage-aa.example.com/admin/content
This gets error: 403 Forbidden
Since the user is not logged in, using SSO
Now, without having all results as rendered HTML, I am not sure, how I can get name/value for web elements
to be able to create a regex, which can be used in correlation
I added Debug Sampler, and I am getting values for SAMLRequest but not for SAMLResponse.
here is how SAMLResponse is exhibited in the browser:
RelayState=https%3A%2F%2Fstage-aa.example.com%2Fsaml_login&SAMLResponse=PHNhbWxwOlJlc3B....
here is the Regex Extractor for SAMLResponse
Adding the complete JMeter Test plan ( jmx file ) had to obfuscate the URLs, but this will give you a pretty good idea. I can add the results of the execution if needed.
jmx file gist
Also, getting error in step 5, in the View Results Tree ( Response Body )
<br />
<b>Warning</b>: DOMDocument::loadXML(): Start tag expected, '<' not found in Entity, line: 1 in <b>/var/www/vendor/simplesamlphp/saml2/src/SAML2/HTTPPost.php</b> on line <b>79</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /var/www/vendor/simplesamlphp/saml2/src/SAML2/HTTPPost.php:79) in <b>/var/www/vendor/simplesamlphp/simplesamlphp/modules/redirecterrors/lib/RedirectErrors.php</b> on line <b>18</b><br />
here is a screenshot of SAMLResponse as Payload
Unfortunately we cannot help you with your regular expression without seeing the response data (at least partial) and your Regular Expression Extractor configuration. If you cannot come up with a good regular expression you can consider switching to
Particular your SAML implementation might be different, however my expectation is that SAMLResponse comes in a hidden input field so it makes more sense to consider switching to CSS Selector Extractor configured like:
You may also find How to Load Test SAML SSO Secured Websites with JMeter article useful.

difficulty in handling correlation in jmeter

i have identified the dynamic values in my website which i am handling through "regular expression extractor" still when i run the website the login request fails and throw error as token not found. please help,i m struggling...[this image contain the regEx extractor part and the failed login request also][1]
We cannot help you without seeing the response (at least partial) which you're getting for the /-7 request containing this hidden input with the token, you can try locating it using "RegExp Tester" mode of the View Results Tree listener and see whether your regular expression matches something or not
One thing is obvious: using regular expressions for extracting data from HTML is not the best idea, I would recommend considering switching to CSS Selector Extractor instead:

How to write json path expressions for the below script in jmeter . Ineed two dynamic values session id and csrf

How to write json path expressions for the below script in jmeter . I need to get the two dynamic values session id and csrf
<input type="hidden" name="_txtSession_Id" value="tw-2777518705045647360wor" >
<input type="hidden" name="csrf_token" value="QIuBhc0mxMfA0XMczGIoZ+jPRprc3wfxbxCfjHiAykU=" />
You cannot use JSON Extractor on HTML data, consider using CSS Selector Extractor instead.
The relevant configuration would be something like:
Name of created variable: anything meaningful, i.e. _txtSession_Id
CSS Selector Expression: input[name=_txtSession_Id]
Attribute: value
That's it, you will be able to refer the first value as ${_txtSession_Id} where required.
The same way you can extract csrf_token, just change CSS Selector Expression to input[name=csrf_token]
You can test your CSS Expressions using View Results Tree listener

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.eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo0NDM4Ny9pZHMiLCJhdWQiOiJkOGVjZjYzMi1mNzE0LTQ2MzEtOGViOS1lYmUzMDI5OGNjMGYiLCJleHAiOjE1Mjk1MDE3MTgsIm5iZiI6MTUyOTUwMTQxOCwibm9uY2UiOiI2MzY2NTA5ODIwNTI4Mzc0MTguWW1aa016ZzFNVEV0TXpjeVlTMDBObUppTFdFM016UXRaVFV3WkRrd01ESXdNekEwTWpnM09URTFZVEl0TURJek1DMDBNalF6TFdGbU1HTXRObVExWmpjNU5XWmxNVEUxIiwiaWF0IjoxNTI5NTAxNDE4LCJhdF9oYXNoIjoiN1Y0cGdWWmVpc2pJV3NXM1ZMTTNadyIsImNfaGFzaCI6Ik8wd3ZKanBSS2NIUnJDOExnUkhfeWciLCJzaWQiOiJiZjc4YWJjMDIxMzhkMDBkMmVlYjk4Y2E3ODg2OWQxZiIsInN1YiI6ImU2NWE0M2MwLTllY2EtNDRjYi05YzYzLWU2NjhhMzNhNWQyYiIsImF1dGhfdGltZSI6MTUyOTUwMTQxNiwiaWRwIjoiaWRzcnYiLCJhbXIiOlsicGFzc3dvcmQiXX0.p8Wn1_SPf2wA1YFby4-ftXGfCtLQaHf6_XXaQJQFF_9SdOHDG2ICVKXs3Jx4UwwyQPDDnKl7rTQINRfb1sfNLnhGsuxr5BoDQaddyG24afT4-quwhl3XDb1jPIMEk-3l-6Rnhdr-UIzHXpMZaaYXE9rdCygI7wqT8REbL8nctQv9GTgh3O751NMjY4FYmj4QDBYrsp9sHJEx_sysMCHPscOm6vnIakKfuVGrVE2qBOQu2PfP3i29npDgNmJ2bmBniljnTMFI57w1vSq8mK2LIYMqoJyy6iudcxAlfRTGzEkezetmH3eIChQIipLUHHb-NmyImtOt-tdUUZXh_Rwq6r7YcwW6zfEPmVFunuHfxc5sB9fZEEzsZLoczB7UeWfBekYGMIK1AKp1BTkQA-kwcqbWIn66Hdjrmepnq3A6nD6pEB-I2tHMgbHIogwHqsGM61OBAGC2y7As3BdF-zepm1m9jISmRX7hiU8u6I1TOhwWIz8VKjlkdmqTQf1lY6I7yAq2Rwtu0zrQ--6el_lB7emX1YvD8whSFpQjI4YNpWJWRZ9ALXC7CudIgN5D4tgzSmEpQrcK-NasXWYf6RMfeDhYTYAbAChgwJ3KwWk6u_5OsX2LgQGbAg23BH9O_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.eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo0NDM4Ny9pZHMiLCJhdWQiOiJodHRwczovL2xvY2FsaG9zdDo0NDM4Ny9pZHMvcmVzb3VyY2VzIiwiZXhwIjoxNTI5NTA2MzAzLCJuYmYiOjE1Mjk1MDI3MDMsImNsaWVudF9pZCI6ImQ4ZWNmNjMyLWY3MTQtNDYzMS04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XOfvS5QoDILU6dqYUpRSS1-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..

Resources