How to get viewstates from same array point via regular expression - regex

I want to get viewstates from diffent types.
One is in html :
id="j_id1:javax.faces.ViewState:0" value="GKILT9kVeCjgGmRutjLtzOO840X+LyZk" autocomplete="off" />
The other is in xml :
id="j_id1:javax.faces.ViewState:0"><![CDATA[GKILT9kVeCjgGmRutjLtzOO840X+LyZk]]></update>
When I run my regular expression, the result array is diffrent. The One result is array[1][3] the other result is array[1][4]
My Regex like this :
id="j_id1:javax.faces.ViewState:[\d]+"(><!\[CDATA\[(.+)\]\]|\svalue=")(.+)(\]\]><|"\sautocomplete)
How can I get result same array data?
Thank you.

If you want a single Regular Expression to work for both scenarios you can use something like:
(?:(id="j_id1:javax.faces.ViewState:(\d+)" value="(.+?)" autocomplete="off" />)|(id="j_id1:javax.faces.ViewState:(\d+)"><\!\[CDATA\[(.+?)\]\]></update>))
This will match ViewState value from both inputs as it evidenced by the RegExp Tester mode of the View Results Tree listener.
More information:
JMeter: Regular Expressions
Perl 5 Regex Cheat sheet
Using RegEx (Regular Expression Extractor) with JMeter

Related

Need help in understanding Reg Ex in Jmeter

Response text from sampler is :
<input type="hidden" name="pid" value="PID_1498281212971253461">
The basic reg ex extractor mentioned for most of the correlations is (.+?). I have read the basics of the reg ex by googling and trying to understand reg ex better Base on the understanding, I tried Reg Ex (2nd Reg Ex) which I am not getting any matches.
Extractor1: RegEx1
Extractor2:RegEx2
Pls. help me in understanding. Appreciate your help.
This is my first post in any channel, pls ignore any comm errors.
You're almost there, your regular expression is basically missing a repetition meta character to wit +. In its current state it will match only something like <input type="hidden" name="pid" value="PD_1">
So you need to add + sign to the end of each character classes groups and your regular expression should start working as expected
References:
JMeter: Regular Expresions
Perl 5 Regex Cheat sheet
When it comes to parsing HTML responses using regular expressions is not the best option, you might want to consider using CSS/JQUery Extractor instead
You could use the XPath Extractor instead, will be simpler, here is the XPath to use
//*[#name='pid']/#value
Please make sure, you check the options, Use Tidy and Quiet in the XPath Extractor

JMeter: How to know why my regular expression extractor in JMeter is not extracting the data

I would like to know why regular expression extractor in JMeter is not extracting the data after parameterization. Response message: Internal Server Error
Expression added are:
name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.+?)"
name="__VIEWSTATE" id="__VIEWSTATE" value="(.+?)"
POST data:
__VIEWSTATE=%24%7BviewState%7D&__EVENTVALIDATION=%24%7BeventValidation%7D&txtUserID=1001201&txtPWD=CFL&BtnSubmit=Submit&hdnE=5&hdnN=323&hdnD=173
Your regexp is probably wrong.
To debug it, run your test then use View Results Tree and select Regexp Tester:
You can then test your regexps and see what happens.
As I don't have the response content that contains the 2 tokens, I can only guess that regexp should be :
name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="([^"]+?)" , see https://regex101.com/r/aG1gX2/1
name="__VIEWSTATE" id="__VIEWSTATE" value="([^"]+?)" , see https://regex101.com/r/iM5cZ3/1

Not able to login using jmeter - Have followed almost all guide available on stack overflow and internet

Code is:
<input name="__RequestVerificationToken" type="hidden" value="Yekn8BJNbXaydRs8yq1GEmDogsFoSh8AGyOKmjLn0zFvhmADPYrqU43/foLoEzJk4yEeNSg78pCIJh6uxuyWf9foM7VsZayC2trOXwUA2hyUWSAf9mBC8vN60ccAVki37fC1LNHhAlDkthgmsM3WNxJwvVGWMj2TMqoONGI0aj5b2hJkQMMClKx0zhthqtD8" />
My Jmeter config. is given below as screenshot :
What is incorrect I did here :( It is not logging & giving error : Object moved to here
In your regular expression extractor, your regular expression needs to be
<input name="__RequestVerificationToken" type="hidden" value="(.+?)"
instead of what you have now. It should work once you change that.
This is why you shouldn't use regular expressions for parsing HTML: one of the reasons is that HTML-oriented regular expressions would be very fragile and sensitive to any line-break, space, tags order, etc.
So the options are:
CSS/JQuery Extractor. Relevant config would be:
CSS/JQuery Expression: input[name=__RequestVerificationToken]
Attribute: value
XPath Extractor. Configure it as follows:
XPath Expression: //input[#name='__RequestVerificationToken']/#value
if your response is not XML/XHTML-compliant you'll also need to check Use Tidy (tolerant parser) box

Parsing multiple values from string in jmeter response

I have a string in a jmeter response that has 5 values that I am trying to parse into separate variables. Does anyone have any guidance on how I may achieve this? Or is there a better post processor I should be using?
<a role="button" aria-label="Application RANUM20770" href="javascript://" onclick="changenew('ajLQ6VdK5xA3$pyWV$pII4Imx2WoN$p6OMtXEapDOiKzHYLh', 'aH$sRRQGllagYsNakUyuWhv6yV7x3q1S6HfC8Z$ptwPdTMo', 'arfpB11JptWMaFvd2xwkJyNlgHL$spkcuHbJhank$s6DONv', 'aQ877kS6ozZdrGgAFxb6mqEnzCFa09$sVWL$s68yj0rmcwr', 'a4oVRp9kcV4iber3oJSH2xQr3F6XsGB4DpCxgrMNI9y7U', 'no')" ><img src="/tm/images/idoc.gif" alt="Application RANUM20770" border=0></a>
I am using regex extractor to pull the values, for some reason the results aren't consistent. Sometimes the 2nd value pulls fine and other times it doesn't- without me changing anything.
Below are the regex expressions I am using :
${h_docname}" href="javascript:\/\/" onclick="changenew\('(.+?)',
'${p_vchnum_v}', '(.+?)', '
'${p_vchnum_v}', '(.+?)', '${p_ssn}'
'().+?', 'no'\)" ><img src="\/tm\/images\/idoc.gif" alt="Document ${h_docname}"
- name="vchdoctype" value="(.+?)">
Any help is greatly appreciated.
JMeter uses Perl5-style regular expressions, hence try the following configuration of the Regular Expression Extractor:
Reference Name: anything meaningful, i.e. value
Regular Expression: changenew\('(.+?)', '(.+?)', '(.+?)', '(.+?)', '(.+?)', 'no'\)
Template: $1$
This will result in variables like:
value=ajLQ6VdK5xA3$pyWV$pII4Imx2WoN$p6OMtXEapDOiKzHYLh
value_g=5
value_g0=changenew('ajLQ6VdK5xA3$pyWV$pII4Imx2WoN$p6OMtXEapDOiKzHYLh', 'aH$sRRQGllagYsNakUyuWhv6yV7x3q1S6HfC8Z$ptwPdTMo', 'arfpB11JptWMaFvd2xwkJyNlgHL$spkcuHbJhank$s6DONv', 'aQ877kS6ozZdrGgAFxb6mqEnzCFa09$sVWL$s68yj0rmcwr', 'a4oVRp9kcV4iber3oJSH2xQr3F6XsGB4DpCxgrMNI9y7U', 'no')
value_g1=ajLQ6VdK5xA3$pyWV$pII4Imx2WoN$p6OMtXEapDOiKzHYLh
value_g2=aH$sRRQGllagYsNakUyuWhv6yV7x3q1S6HfC8Z$ptwPdTMo
value_g3=arfpB11JptWMaFvd2xwkJyNlgHL$spkcuHbJhank$s6DONv
value_g4=aQ877kS6ozZdrGgAFxb6mqEnzCFa09$sVWL$s68yj0rmcwr
value_g5=a4oVRp9kcV4iber3oJSH2xQr3F6XsGB4DpCxgrMNI9y7U
So you will be able to use:
${value_g1} - for 1st variable
${value_g2} - for 2nd variable
etc.
See
JMeter's User Manual Entry for baseline information on regular expressions
Using RegEx (Regular Expression Extractor) with JMeter guide for more information and examples.

jmeter extract regular expression not get correct result

This is my html
<input name="__RequestVerificationToken" type="hidden" value="A9y6Ndf7Q2XP2Yz6zhaVChoIvpQGUrZRTvu9D_HnHnUcFBVInerxCjU4vpOXQYVhFwnzl-zAzkvtto7BLAVVr">
I want to extract value in jmeter Regular Expression Extractor.
This is my regx window but when i post it i will not get expected token it is something like this __RequestVerificationToken=%24%7Bauth_token%7D.
Try using $1$ as a Template, it should resolve your issue.
Looking into your request I can see that you're sending %24%7Bauth_token%7D which being decoded looks like ${auth_token} so you use case is not correct.
You need 2 requests:
GET request to get the page and extract RequestVerificationToken and store it to auth_token variable.
POST Request which will use auth_token variable.
See Using Regular Expressions in JMeter guide for more details.
By the way, you can use combination of Debug Sampler and View Results Tree listener to see if there are any matches. It should be more convenient w.r.t. groups and variables.
In general, it isn't recommended to use Regular Expressions to parse HTML. I would suggest to use XPath Extractor instead. Relevant XPath expression will look like:
//input[#name='__RequestVerificationToken']/#value
Few things to notice:
If you page isn't XHTML compliant you'll need to check Use Tidy box in XPath Extractor
JMeter 2.11 provides nice XPath Tester right in View Results Tree Listener
We need to set the following Regular Expression Extractor values to extract the auth token values
Reference Name : Auth_Token
Regular Expression : <input\sname="__RequestVerificationToken"\stype="hidden"\svalue="(.+)">
Template : $1$
Match No : 1
Default values : NOT FOUND TOKENS