How to use xpath extractor in jmeter - jmeter

Below is a sample response from Jmeter tool
<ns2:Attribute Name="GUID" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
<ns2:AttributeValue>8b0f3dfe-21d3-1035-a063-f6571edcc101</ns2:AttributeValue>
</ns2:Attribute>
<ns2:Attribute Name="SCODES" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
<ns2:AttributeValue>S0336492^S0309824</ns2:AttributeValue>
</ns2:Attribute>
<ns2:Attribute Name="MODE" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
<ns2:AttributeValue>2</ns2:AttributeValue>
</ns2:Attribute>
</ns2:AttributeStatement>
I need to extract "AttributeValue>2" from the response. Tried using regex but that isn't working here. Can we do it with xpath extractor? Any help would be appreciated.

Disclaimer: the below XPath query isn't guaranteed to work as I need to see full response, next time please provide as much information as you can:
Using local-name function like:
//*[local-name()='Attribute']/text()='MODE'/child::*/text()
Using XPath Namespaces functionality:
define ns2 namespace under namespaces.config file (lives in the "bin" folder of your JMeter installation)
restart JMeter to pick the property up
you should be able to use the following XPath query
//Attribute[#Name='MODE']/AttributeValue/text()
See Using the XPath Extractor in JMeter guide for more information.

Related

JMeter -XPath2 Extractor not working as XPath

I tried to use JMeter recommendation to move to XPath2 over XPath Extractor
Since JMeter 5.0, you should use XPath2 Extractor as it provides better and easier namespace management, better performances and support for XPath 2.0
But for simple query I get no results, for output
<Object classId="QueryResultRow"><Property i:type="fn40:SingletonId" propertyId="Id"><Value>{abc-def}</Value></Property><Property i:type="fn40:SingletonString" propertyId="DCN"><Value>D112345</Value></Property></Object>
I use query /Object/Property/Value or //Object//Property//Value and it works only in XPath and not XPath2
Results:
Value={abc-def}
Value_1={abc-def}
Value_2=D112345
Value_matchNr=2
Same results with /*[local-name()='Object']/*[local-name()='Property']/*[local-name()='Value'] as #EdBangga suggested
Is there an issue with XPath2 Extractor or major change of syntax?
Your issue is due to namespaces in your XML (i)
Once you show the full XML with namespaces I can give more information but to summarize:
you'll need to configure alias i to match the full namespace (you can use XPath2 Tester and Show Namespaces aliases)
then it should work

Extracting a link with jmeter

So I need to delete an "onclick" dynamic link using jmeter.
Here is the sample of one of the links:
"Delete"
What I need is to extract number and post it in order to do the delete action. Every link is the same except the number.
I have tried to implement some of the solutions I've found on this site but it didn't work.
Thanks in advance
Peace
If you need to do it with XPath you could try going for substring-after function like:
substring-after(//a[text()='Delete']/#href,'param=')
The above expression returns everything which is after param= text in href attribute of a HTML tag having Delete text.
You can test your XPath expressions against actual server response using XPath Tester tab of the View Results Tree listener.
References:
substring-after Function Reference
XPath 1.0 Language Reference
Using the XPath Extractor in JMeter
XPath Tutorial

How can i get this value with XPATH in JMeter

I have a webservice response as such :
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<FileResponse xmlns="http://xxx.x.sx.be">
<id>090150e080249d09</id>
</FileResponse>
</soap:Body>
</soap:Envelope>
I am trying to extract the value of "id" but i can't seem to figure out the right query. I used an online generator which provided :
/soap:Envelope[#xmlns:soap="http://www.w3.org/2003/05/soap-envelope"]/soap:Body/FileResponse[#xmlns="http://xxx.x.sx.be"]/id/text()
But it doesn't seem to work in Jmeter as the response is always null.
I found this to be the answer : //*[local-name() = 'id']
Your test for the namespace is invalid. Xpath queries do not support this.
Instead you will need to JMeter to pass in the namespaces declarations along with the xpath query. I dont know how JMeter does that but I can give you an xpath expression that may work around it.
//*[local-name()='FileResponse']/*[local-name()="id"]/text()
The xpath will test the name of the node and ignoring the namespaces. Its not recomended practice to test without namespaces and could be slow but it'll work.

How to extract a response value when doing http post using Jmeter

Can anyone please help me here? I'm trying to do an http post in Jmeter, http works fine, but I'd like to extract the LastName value from the response to use in next http request. I've tried several methods using Xpath Extractor but the Debug sampler shows nothing. I've added XPath_Extractor as a child of HTTP Sampler.
what am I doing wrong here?
Here is what I setup in the XPath Extractor
Reference Name = lstname (which is the variable I carry to next http request)
XPath Query = //*[local-name()='LastName']/text()
also tried
/Reply/CustomerData/#LastName
Main Sample checked
Use NameSpaces- checked
Ingnore whitepspaces checked
Here is my http response
<?xml version="1.0" encoding="UTF-8"?>
<dm:reply xmlns:dm="http://www.xx.com/dm" version="1.0">
<Session>
<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062362"/>
<Reply type="Connection">
<ErrorMessage/>
<ErrorCode>0</ErrorCode>
</Reply>
<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062504"/>
<Reply type="Execute">
<CustomerData FirstName="" LastName="Moni" Address="SD" Chassis="AWD" CountryOfBirth="" CountryOfOriginFullName= Year="2010">
<RecordSet>
</RecordSet>
<ErrorMessage/>
<ErrorCode>0</ErrorCode>
</CustomerData>
</Reply>
<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062590"/>
</Session>
</dm:reply>
You can use regular expression extractor - Post Processor to achieve this.
You need to fill in following parameters
Reference Name: LastName
The regular expression (would look like): LastName="(.*?)"
Template: $1$
Match : 1
Default Value: NotFound
Use ${LastName} in next request to access extracted value of LastName.
Add debug sampler to check if you are extracting correct value.
Why do you need all this namespaces stuff?
Don't check any boxes in the extractor
Use //CustomerData/#LastName as XPath expression
That's it
By the way, you can evaluate XPath Expressions directly against response using XPath Tester mode of the View Results Tree listener. See How to debug your Apache JMeter script article for more tips on getting to the bottom of your JMeter test issue.

Jmeter - values from Regular expression extractor is not getting written in the file

I have added a regular expression as below in order to extract the response value inside the xml.
p400="http://newman.services.premium.hellocorp.com">(.+?)</p400:newman></soapenv:Body>
the reference name is "output_xml"
I have added a simple data writer as well and added "output_xml" to the sample variables in Jmeter properties file also. Still I am not able to see the xml getting written in the file.
Please advice me on this. Thanks!
I'm not sure, that it's possible with simple file writer, try FlexibleFileWriter plugin http://jmeter-plugins.org/wiki/FlexibleFileWriter/?utm_source=jpgc&utm_medium=link&utm_campaign=FlexibleFileWriter
And have you checked, that this extractor works on your data?
Try to add Debug Postprocessor (ensure that "JMeter variables" is set true) and View Results Tree elements to you project and inspect variables.
The given xml formats
p400="http://newman.services.premium.hellocorp.com">(.+?)</p400:newman></soapenv:Body>
You need to update the following regex formats to extract the response values
Regular expression formats
http://newman.services.premium.hellocorp.com">(.+)</p

Resources