How can i get this value with XPATH in JMeter - xpath

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.

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

Issue while Executing XPath Function in Automation anywhere

I'm trying to use Execute XPath Function in automation anywhere.
In the response I'm getting the value as "MS.Internal.XML.XPath.XPathSelectionIterator"
XPath looks like :
//GetEmployees/Employee/text()
I'm sure that xpath is correct since I have tested with Java code.
Looks like the control is returning an object instead of text string.
Is there a way we can do it ?
Got the answer to this one by trial and error.
Was trying to parse soap response and I believe it was facing an issue with namespace.
got wit working by using the following expression
string(//soap:Envelope/soap:Body/*[name()='GetEmployees']/*name()='Employee'])
Hope this helps and some one could improve it further.

How to use xpath extractor in 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.

XPATH Dispatch in SoapUI Mock service/ Mock operation

I am new in SoapUI, and was trying to understand the use of XPATH dispatch for a mock operation in a mock service.
Here is what I have done so far
Created a mock service for a calculator
Added mock operation substract
Following is a sample request for the operation
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
<soapenv:Header/>
<soapenv:Body>
<cal:subtract>
<cal:x>1</cal:x>
<cal:y>1</cal:y>
</cal:subtract>
</soapenv:Body>
</soapenv:Envelope>
Following is a sample response for the same
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
<soapenv:Header/>
<soapenv:Body>
<cal:subtractResponse>
<cal:Result>?</cal:Result>
</cal:subtractResponse>
</soapenv:Body>
</soapenv:Envelope>
I was able to understand about other dispatch but not about XPATH as following is what I have entered in the XPATH dispatch
declare namespace cal='http://www.parasoft.com/wsdl/calculator/';
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
//cal:subtract/cal:x
It was also observed that if I have already used SCRIPT dispatch and switch to XPATH from the dropdown, the script is visible in the declaration/scripting box/area
Following are the questions:
Is XPATH and SCRIPT dispatch same
If not, how does the XPATH dispatch actually work to identify what response to dispatch out of all form MockResponses list
Kindly help me with this.
PS: I have already gone through
http://www.soapui.org/soap-mocking/reference/mockoperation.html
http://www.soapui.org/soap-mocking/mockoperations-and-responses.html
The soapUI documentation that you mentioned in your question is the right location to get the information. However, the information available is not complete.
After searching for sometime, found the details.
Initially, got confused between Xpath and Script Dispatch methods.
Here is the additional information than what you are looking for:
Is XPATH and SCRIPT dispatch same
Answer is NO. Both are different
If not, how does the XPATH dispatch actually work to identify what response to dispatch out of all form MockResponses list
The following information found in the documentation:
XQUERY - This is similar to the QUERY_MATCH but not quite as powerful; an XPath expression is applied to the incoming request and the resulting value is used for selecting which MockResponse to be returned. In our previous example of search results, we could set the XPath expression to select a search term and then create MockResponses named after each expected value. The advantage being that we don’t need to add new XPath statements for new search criteria, just another MockResponse.
Assume that you created multiple responses say PositiveResponse, NegativeResponse, ZeroResponse for subtract operation of Mock Service.
Here are the sample conditions that you may want to apply on the request and dispatch appropriate response. Of course, you may have as many as you require.
PositiveResponse - if x, y values are 10, 5 respectively.
NegativeResponse - if x, y values are 5, 10 respectively.
ZeroResponse - otherwise (this is mandatory if none of the above satisfy).
Here is how you need to write in the editor given for XPATH Dispatch mode
declare namespace cal='http://www.parasoft.com/wsdl/calculator/';
if (//cal:subtract/cal:x[. = '10'] and //cal:subtract/cal:y[. = '5']) then
'PositiveResponse'
else
if (//cal:subtract/cal:x[. = '5'] and //cal:subtract/cal:y[. = '10']) then
'NegativeResponse'
else
'ZeroResponse'
Hope you are now aware and differentiate the SCRIPT Dispatch mode.
I think the confusion created because both SCRIPT and XPATH shows an editor of same type. But the content inside of it will be entirely different. Also you can easily see a message on top of the editor that log, context, mockRequest availability of variables if you select SCRIPT Dispatch mode and it vanishes when XPATH is choosen.
Just giving SCIRPT example in case if you are interested in it:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def x = holder.getNodeValue("//*:x") as int
def y = holder.getNodeValue("//*:y") as int
context.result = x - y
A simple test can be (to differentiate between the two), copy the above script for xpath and try testing and soap fault is received saying does not know groovyUtils. This test will confirm that xpath and script are different.
Here you may not needed to create multiple responses as the above code can handle dynamic input values and set the result in the response.
MockReponse for subtract operation may look like below with place holder as ${result}.
MOCKRESPONSE for SCRIPT:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
<soapenv:Header/>
<soapenv:Body>
<cal:subtractResponse>
<cal:Result>${result}</cal:Result>
</cal:subtractResponse>
</soapenv:Body>
</soapenv:Envelope>
Hope this clarifies.

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.

Resources