Parsing multiple values from string in jmeter response - regex

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.

Related

how to use Regular expression extractor to extract value from response in jmeter

<input
name="formToken" type="hidden"
value="19225544fb878c9a8c77dafdfe616454a13e3c96"
/>
above is the line having lot of space in between. i want to extract value using regular expression in Jmeter. so please help me for regular expression to extract.
Try doing a find on this regex:
value="([^"]+)"
And then access the following in the template:
$1$
See the demo link below for an example of this working.
Demo
Be informed that using Regular Expression Extractor for parsing HTML is not the best idea, I would recommend going for CSS Selector Extractor instead, the relevant configuration would be as simple as:
Selector: input[name=formToken]
Attribute: value
Demo:
More information: How to Use the CSS/JQuery Extractor in JMeter
Try with the following Regex:
value="(.+?)"

How to get viewstates from same array point via regular expression

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

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 Token value extraction

Using Jmeter I was trying to extract the value of a token from the following, using the regular expression extractor:
<input name="__RequestVerificationToken" type="hidden"
value="BeRYiSIRjZoQHq4VW8qbkgXlnnzdUINpFNoYF_ugx-FRk0tkImbQPhwyYjyz_0Q-w6F2A0gDOfMZrdklD6rVn6-QnYggfImb55f90V7nrD_kbSkT3-y3gPqoTFg0ynTBLyX5Lw2" />
When I used the following expression:
name="__RequestVerificationToken" type="hidden" value="(.+?)"
the value was not extracted.
After a few searches I used the following expression:
name="__RequestVerificationToken" type="hidden" value="([A-Za-z0-9-_]+?)"
which worked, but I don't know why :d.
My question: why the first expression didn't worked since basically tells to extract any character that matches one or more times.
use this
name="__RequestVerificationToken" type="hidden"\s*value="(.+?)"
or the best is
name="__RequestVerificationToken" type="hidden"\s*value="([^"]*)"
Both of yours will not work as between type and value there is a \n which you have not taken care of.Now it works.See demo.
http://regex101.com/r/dK1xR4/14
First of all, don't use Regular Expressions to extract data from HTML. It is complicated and very fragile in case of even slight DOM changes.
JMeter provides the following components to extract data from HTML responses:
XPath Extractor
CSS/JQuery Extractor
XPath Extractor Guide
Add Xpath Extractor as a child of the request which produces that response
Configure it as follows:
Reference name: anything meaningful, i.e. token
XPath query: //input[#name='__RequestVerificationToken']/#value
If your response is not valid XHTML check Use Tidy box
Refer to extracted value as ${token} or ${__V(token)} where required. Remember that JMeter Variables scope is limited to current thread group only.
For more information see Using the XPath Extractor in JMeter
CSS/JQuery Extractor Guide
Add CSS/JQuery Extractor as a child of the request which produces that authentication token response
Configure it as follows:
Reference name: anything meaningful, i.e. token
CSS/JQuery expression: input[name=__RequestVerificationToken]
Attribute: value
Refer to extracted value as ${token} or ${__V(token)} where required. Same restriction on JMeter Variables scope apply.
See JSoup selector syntax guide for a reference on how to build CSS selectors.
Hope this helps.

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