What is the regular expression in Jmeter for a dynamic string? - regex

This is getting generated in a request output in Jmeter and I need to capture the dynamic value.
<update id="javax.faces.ViewState"><![CDATA[-8480553014738537212:-8925834053543623028]]></update>
the - (hyphen) symbol coming in the output is also dynamic.
I have tried handling this using
<update id="javax.faces.ViewState"><![CDATA[(.+?)]]></update>
But this is not helping. Please suggest.

The correct way to grab the data is by using the XPath Extractor with the following XPath:
//update[#id='javax.faces.ViewState']/text()
It gets the update tags that have id attribute with the javax.faces.ViewState value and extracts the text from these nodes.
Your regex is not correct because the [ (and literal dots) must be escaped in the regular expressions, and can be fixed as <update\s+id="javax\.faces\.ViewState"><!\[CDATA\[([^\]<]+)]]></update>. See the regex demo.

Related

How to use regex to get value from response header in Jmeter

I am using regex to get value from response header in JMeter,
I try to get the last value in query tt_unixtime and I failed.
Can someone please advise how to user regex to get the last value?
I Created a variable called time44444444 and I want it to get the value from the response,
the problem is that it stored nothing.
You have a few issues in your Regular Expression Extractor settings for getting the value matched:
Apply To: Response Headers
Regular expression should be (\w+) - any alphanumeric characters
Template should be $1$ - first group
Match No. should be be 1 - find first match
The template used to create a string from the matches found. This is an arbitrary string with special elements to refer to groups within the regular expression. The syntax to refer to a group is: '$1$' to refer to group 1

Jmeter parameter extraction

I am getting a result in my jmeter test that I don't understand:
I am trying to extract the "totalRunning" value from this Json response:
{"notifications":[],"taskNotificationInfo":{"totalRunning":0,"totalCompleted":0,"totalCompletedWithErrors":0,"totalFailed":0,"totalPending":0,"requestTime":1458628767436,"hasRecords":false}}
My regex is configured as following:
Reference Name: TotalRunning
Regular Expression: "totalRunning":"(.+?)"
Template: $1$
Match: 1
Default Value: 1
screen shot:
I keep getting the default value instead of "0" in this case.
Am I extracting it from the wrong place?
Any help would be appreciated.
There is no problem with your regex totalRunning":(.+?),"totalCompleted"
only you need to select radio button Body instead of Body As a Document
refer snapshot:-
Change your regular expression as below:
Regular Expression: "totalRunning":(\d+)
In the question "totalRunning":"(.+?)" is being used as regular expression. Since values of totalRunning is not surrounded by quotes. So none was being matched and default value is being picked.
Below regex can also be used:
"totalRunning":(.+?),
Change your "Field to check" to "Body" as "Body as a document" is for binary files like Word, Excel, PDF, etc. see How to Extract Data From Files With JMeter article for more details. JSON is a usual text so it should be treated as "normal" response.
Also there is a special Post Processor - JSON Path Extractor available via JMeter Plugins project. In case of complex JSON, multiple or conditional matches, etc. it might be better and easier to use it.
The relevant JSONPath expression will be: $..totalRunning[0]

Regex HTTP Response Body Message

I use a jmeter for REST testing.
I have made a HTTP Request, and this is the response data:
{"id":11,"name":"value","password":null,"status":"ACTIVE","lastIp":"0.0.0.0","lastLogin":null,"addedDate":1429090984000}
I need just the ID (which is 11) in
{"id":11,....
I use the REGEX below :
([0-9].+?)
It works perfectly but it will be a problem if my ID more than 2 digits. I need to change the REGEX to :
([0-9][0-9].+?)
Is there any dynamic REGEX for my problem. Thank you for your attention.
Regards,
Stefio
If you want any integer between {"id": and , use the following Regular Expression:
{"id":(\d+),
However the smarter way of dealing with JSON data could be JSON Path Extractor (available via JMeter Plugins), going forward this option can be much easier to use against complex JSON.
See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") to learn more on syntax and use cases.
I suggest using the following regular expression:
"id":([^,]*),
This will first find "id": and then look for anything that is not a comma until it finds a comma. Note the character grouping is only around the value of the ID.
This will work for ANY length ID.
Edit:
The same concept works for almost any JSON data, for example where the value is quoted:
"key":"([^"]*)"
That regular expression will extract the value from given key, as long as value is quoted and does not contain quotes. It first finds "key": and then matches anything that is not a quote until the next quote.
You can use the quantifier like this:
([0-9]{2,}.+?)
It will catch 2 or more digits, and then any symbol, 1 or more times. If you want to allow no other characters after the digits, use * instead of +:
([0-9]{2,}.*?)
Regex demo

extract href in jmeter with Regular Expression Extractor?

After a Successful Login my page contains a Tab "Offers".Link is provided below I want to know how Regex can extract it.
a href="/Offers/OfferApproval"> Offers<a/>
This is required regex for extracting /Offers/OfferApproval value,
href="(.+)"> Offers<a/>
Use Regular expression post processor.

Searching a number in a specific string with regexp in jmeter

I want to find a specific number from a HTML response.
For example, I want to extract 3 from publicationID3publicationID.
Does someone know a solution with regexp?
Add Regular Expression Extractor Post Processor as a child of the request, which returns to you this string.
Configure it as follows:
Reference Name: publicationID (you can use any variable name here)
Regular Expression: publicationID(\d+)publicationID
Template: $1$
other fields can be left blank.
You can later refer publication ID as ${publicationID} or ${__V(publicationID)}
You can see what matches does your Regular Expression return using View Results Tree Listener (select RegExp Tester from dropdown). Another option is Debug Sampler again with combination with View Results Tree.
you can use \d to match a number using regex.