aspose file tools*
The moose likes Testing and the fly likes xpath & regexp extractor in Jmeter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "xpath & regexp extractor in Jmeter" Watch "xpath & regexp extractor in Jmeter" New topic
Author

xpath & regexp extractor in Jmeter

Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
Hi,
I have the following content in the html response


I have to extract the value of the above input tag.I have tried both regexp and xpath extractor but neither is working for me.

regexp pattern

I tried the below pattern also


I verified the above pattern in java & it works.I was able to fetch the value with matcher.group(1)

xpath query


In XPATH Assertion listener I got the error -> No node matched
I modified the xpath query to below


The above does not give any error.The moment I add the actual name,I get the error -> No node matched.

Kindly suggest me how to resolve the issue.
sugan san
Ranch Hand

Joined: May 23, 2013
Posts: 47
Add regular expression extractor and give exp as value='[*+?]', for detailed answer
please visit the below URL

http://www.technix.in/jmeter-problems-and-solutions/
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

sugan san wrote:Add regular expression extractor and give exp as value='[*+?]', for detailed answer
please visit the below URL

http://www.technix.in/jmeter-problems-and-solutions/


You have no groups in your regular expression - this won't work.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
sugan san
Ranch Hand

Joined: May 23, 2013
Posts: 47
Sorry,
You have to give value='[.+?]'.This will work.

This is the one I'm using , it works for me
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

Max White wrote:I have the following content in the html response


Technically speaking, you have the following in your response. It is irrelevant that you, a human, know that this is a html response - all JMeter cares about is that this is a response. It could be plain text, JSON, XML, or some other format.

Max White wrote:
I have to extract the value of the above input tag.I have tried both regexp and xpath extractor but neither is working for me.

regexp pattern


It is difficult to see from this, but is your match number -1 or is the dash in there just to indicate what the value is? (-1 has a special meaning to JMeter regular expressions. From the JMeter manual: If the match number is set to a negative number, then all the possible matches in the sampler data are processed).

I suspect the problem is with the posix characters. Try changing your pattern to:


Max White wrote:xpath query


In XPATH Assertion listener I got the error -> No node matched
I modified the xpath query to below


The above does not give any error.The moment I add the actual name,I get the error -> No node matched.


You changed two things simultaneously - you removed the contents you expect to find in the "name" attribute, and you removed the "@value" path. I believe only the later removal was needed.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

sugan san wrote:Sorry,
You have to give value='[.+?]'.This will work.

This is the one I'm using , it works for me


Nope.

That is the regular expression that matches on '.' (which is any character), or the plus sign (+), or the question mark (?). It will only match on one of those, zero repeats. It will not do anything with that matched character because it is not in a group.

In the Regular Expressions tutorial, there is a Test Harness. When run with your example and the provided input, it tells us that it failed to find any matches:

sugan san
Ranch Hand

Joined: May 23, 2013
Posts: 47
That should work with preprocessor=> regular expression extractor in jmeter. Please check once again. And add that to your http request from where you have to extract the content. And use "Regex Tester" to find it is working or not.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

sugan san wrote:That should work with preprocessor=> regular expression extractor in jmeter.

I think you mean Post Processor. The Pre Processors do work just prior to a sampler, and in this case we are looking at the result from a sampler. There is a "RegEx User Parameters" pre processor, however it relies on you previously running a Post Processor Regular Expression Extractor.

sugan san wrote:Please check once again. And add that to your http request from where you have to extract the content. And use "Regex Tester" to find it is working or not.


RegExPal shows no matches:



RegEx Tester shows no matches (see bottom line):



Putting the regular expression into JMeter:



And running it against this sampler response:



Provides this output:



See the second last line in the Response Data pane? It shows that the Regular Expression Extractor failed to match, and it went with the default value I had entered.

I tried your examples both with and without the single quotes in all 3 tools. As expected, according to the rules of regular expressions, they failed in every case.

Max had a regular expression that was almost correct - it just used posix where it shouldn't have. Mine works.
sugan san
Ranch Hand

Joined: May 23, 2013
Posts: 47
In Regular Expression text box give value='[.+?]'.

You gave only [.?+].
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

Andrew Monkhouse wrote:I tried your examples both with and without the single quotes in all 3 tools. As expected, according to the rules of regular expressions, they failed in every case.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

sugan san wrote:In Regular Expression text box give value='[.+?]'.

You gave only [.?+].


I think I misunderstood you. You mean:



However it still does not have any groups, and the single character match in the value field ensures that it will not work. So my result after the above change still shows RegExFailed:


sugan san
Ranch Hand

Joined: May 23, 2013
Posts: 47
First let me know ,Where are you adding Regex expression extractor? and no need to check in debug post processor,
follow the below steps to verify your reular expression
1) Add regex to http request where you need to extract the data
3) Add view results tree to thread group or to the particular http request
4) Run the script Simply once.
5) In view results tree select 'RegExp Tester' ,give the expression I gave and enter , and share the screenshot
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

sugan san wrote:First let me know ,Where are you adding Regex expression extractor?


Here is my simplistic test plan:



sugan san wrote: and no need to check in debug post processor,


True, there are many ways of testing a regular expression. Using the debug mode is almost always the easiest way as it gives details on what was actually run.

sugan san wrote:In view results tree select 'RegExp Tester' ,give the expression I gave and enter , and share the screenshot


How many ways do I have to prove that your RegEx doesn't work? You asked for it in "Regex Tester", so I used both RegExPal and RegEx Tester. I proved it doesn't work in JMeter. I even proved it didn't work using Java's Regular Expression Test Harness. Now you want an alternate test within JMeter? You are missing the point - the regular expression is bad - it will not do what you want no matter which tool you put it in. But here is the screenshot to prove that it does not work here either:



Can you provide any screenshots of your regular expression working in any environment?
 
Consider Paul's rocket mass heater.
 
subject: xpath & regexp extractor in Jmeter