0
votes

How do I get data from below service response using regular expression extractor in Jmeter?

Extract token ID:

<ValidateUserResponse xmlns="http://tempuri.org/"><ValidateUserResult xmlns:a="http://schemas.datacontract.org/2004/07/ISOS.Medtrack.Mobile.Entity" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><a:ErrorKey i:nil="true"/><a:ErrorMessage i:nil="true"/><a:SystemId>0</a:SystemId><a:Type>0</a:Type><a:status>SUCCESS</a:status><a:IsAuthenticated>true</a:IsAuthenticated><a:IsDashboardLanding>true</a:IsDashboardLanding><a:IsEmployee>true</a:IsEmployee><a:IsMobileAppEnabled>true</a:IsMobileAppEnabled><a:IsPwdChgRqd>false</a:IsPwdChgRqd><*a:TokenID>**9de2dbfbcc94241002f57275e8dc78e60f26baabc05c1eebe39088d02e6e454f***</a:TokenID><a:UserStatus>ACTIVE</a:UserStatus></ValidateUserResult></ValidateUserResponse>
3
That is XML, use an XML parser and not an regex.Sirko
can you share how to do it i m new to it , Thanks in advanceShreesh Srivastava

3 Answers

0
votes

Theoretically you can do it with regular expressions, however I would rather go for XPath Extractor for dealing with XML data instead.

Follow the next steps to extract your TokenID value:

  1. Add the following line to user.properties file (lives under /bin folder of your JMeter installation)

    xpath.namespace.config=my.properties

  2. Create "my.properties" file in the same location and add next 2 lines there:

    a=http://schemas.datacontract.org/2004/07/ISOS.Medtrack.Mobile.Entity
    i=http://www.w3.org/2001/XMLSchema-instance
    
  3. Restart JMeter

  4. Add XPath Extractor as a child of the request which returns that XML
  5. Configure the XPath Extractor as follows:

    • Check "Use Namespaces" box
    • Put //a:TokenID/text() line into "XPath Query" input
    • Set "Reference Name" to something meaningful, i.e. TokenID

You should be able to access extracted value as ${TokenID} after XPath Extractor execution.

Hope this helps.

0
votes

Though Regex should not be used in XML cases as it is a bad practice. but XPath Extractor should be avoided in actual performance tests because they are heavy in nature as compared to Regex.

XPath builds a DOM tree so it consumes CPU and memory and you might run out of memory or overload CPU during performance tests which in turn could result in invalid results. Thus prefer Regular Expression extractor whenever possible.

Simple Regex expression could be,

TokenID>\*\*(\w+)\*\*\*

extracted value can be used as $1$.

0
votes

The best way to solve the problem with namespaces in XPath Extractor, that simple use the impruved iXpath (improved jmeter xpath plugins)

http://sourceforge.net/p/i-jmeter-xpath/wiki/Home/