Mocking response with 2 variables using SoapUi - xpath

Is it possible to check two or more variables when mocking a response using SoapUi?
Here's a sample of the request:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:crm="http://www.example.com/project/wsdl/crm/">
<soap:Body>
<crm:SearchCustomer>
<FirstName>Francis</FirstName>
<LastName>Zabala</LastName>
</crm:SearchCustomer>
</soap:Body>
</soap:Envelope>
Here's the Extract Xpath
declare namespace crm='http://www.example.com/project/wsdl/crm/';
declare namespace soap='http://www.w3.org/2003/05/soap-envelope';
//crm:SearchCustomer[1]/FirstName
Expected value:
Francis
What about if I also want to check the last name?

You can try using the follow XPath expression which check for the text content of the <FirstName> and <LastName> and use boolean() XPath function to check if the expression it's accomplished or not. Also SOAPUI supports the use of * as a wildcard for namespaces so your expression could be:
boolean(//*:FirstName[text() = 'Francis'] and //*:LastName[text() = 'Zabala'])
And as expected value:
true

Related

Capture response using Xpath extractor in Jmeter

I need to extract uuid from the below XML response using xpath extractor in jmeter. Can anyone help me with the expression>
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="schemas.xmlsoap.org/soap/envelope/" xmlns:awsse="xml.test.com/2010/06/Session_v3" xmlns:sca="www.w3.org/2001/05/addressing"><soap:Header><sca:To>www.w3.org/2005/08/addressing/anonymous</sca:To><sca:From><sca:Address>nodeA1.test.webservices.test.com/1ASIRFCUCPA</sca:Address></sca:From><sca:Action>webservices.test.com/test_Shopping_18.1</sca:Action><sca:MessageID>urn:uuid:ba154abc-636c-33b4-3947-6b50651b3f5b</sca:MessageID><sca:RelatesTo RelationshipType="www.w3.org/2005/08/addressing/reply">urn:uuid:55c875fa-bda3-461e-aa06-56c28f11ad38</sca:RelatesTo>
Assuming that you're looking for the MessageID:
You can use XPath name() function to extract the value like urn:uuid:ba154abc-636c-33b4-3947-6b50651b3f5b. The relevant expression would be:
(//*[name() = 'sca:MessageID'])/text()
If you want just this ba154abc-636c-33b4-3947-6b50651b3f5b part - go for substring() function like:
substring((//*[name() = 'sca:MessageID'])/text(),10)
More information:
XPath Tutorial
Using the XPath Extractor in JMeter

JMeter XPath getting multiple values and odd output order

Preamble
I have a JMeter script with an XPath Extractor, in this I have specified a query that gets multiple values from the XML document. This all works fine
XML
<?xml version="1.0" encoding="UTF-8"?>
<InventoryAvailabilityAdvice>
<Warehouse>WFC2</Warehouse>
<Timestamp>2019-07-31T23:00:02.177</Timestamp>
<InventoryItem>
<ItemNumber>80903</ItemNumber>
<AvailableQuantity UnitOfMeasure="EA">13</AvailableQuantity>
</InventoryItem>
<InventoryItem>
<ItemNumber>80901</ItemNumber>
<AvailableQuantity UnitOfMeasure="EA">17</AvailableQuantity>
</InventoryItem>
</InventoryAvailabilityAdvice>
Problem
When I then try to get these values in a loop using a JSR232 Sampler they don't seem to come out in the order declared in the XPath Query.
I expected theData_2 to contain the UnitOfMeasure attribute and theData_3 to contain the quantity, but as you can see they are reversed.
Question
Is this expected behavior? If so, when an element has multiple attributes how do I know which order those will be made available as?
Thanks
The order of XPath nodesets produced by union operator is not guaranteed, you can see putValuesForXPathInList() function for implementation details
Actually if you've decided to go for Groovy - you don't even need the XPath Extractor, you can use XmlSlurper class for parsing the XML response.
Example code:
def response = new XmlSlurper().parseText(prev.getResponseDataAsString())
response.InventoryItem.eachWithIndex { item, index ->
log.info('Item: ' + index)
log.info('ItemNumber: ' + item.ItemNumber)
log.info('AvailableQuantiry: ' + item.AvailableQuantity)
log.info('UnitOfMeasure:' + item.AvailableQuantity.#UnitOfMeasure)
}
Demo:
References:
Groovy: Processing XML
Apache Groovy - Why and How You Should Use It

not able to get xpath value from soapui

I am not able to get xpath value "MatchFound" for the below xml in soapui .
I am trying property transfer functionality .
I tried following XPath :
declare namespace ns0='http://KYC/';
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
/soapenv:Envelope/soapenv:Body/BarclaysCustomerValidationResponse/oCasaDetailByRefNoDetails/oCasaStatusByRefNoDetails/oRiskProfileClientData/oGetFraudInformationData/oAddressVerificationDetails/ns0:matchedFound
XML :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<BarclsCustomerValidationResponse xmlns="http://BHKYC/BarclaysCustomerValidation.tws">
<oCasaByIdNoDetails>
<ns0:casaByIdNoResults xmlns:ns0="http://KYC">
<ns0:item/>
</ns0:casaByIdNoResults>
</oCasaByIdNoDetails>
<oCasaDetailByRefNoDetails/>
<oCasaStatusByRefNoDetails/>
<oRiskProfileClientData/>
<oGetFraudInformationData/>
<oAddressVerificationDetails>
<ns0:enquiryid xmlns:ns0="http://KYC">51644325</ns0:enquiryid>
<ns0:enquiryresultid xmlns:ns0="http://KYC">52146422</ns0:enquiryresultid>
<ns0:matchedFound xmlns:ns0="http://KYC">false</ns0:matchedFound>
<ns0:numberOfMatches xmlns:ns0="http://KYC">1</ns0:numberOfMatches>
<ns0:firstMatchUpdatedDate xmlns:ns0="http://KYC">2016-03-31</ns0:firstMatchUpdatedDate>
<ns0:secondMatchUpdatedDate xmlns:ns0="http://KYC"/>
<ns0:mostRecentAddressIsMatched xmlns:ns0="http://KYC">false</ns0:mostRecentAddressIsMatched>
</oAddressVerificationDetails>
<oCasaPS/>
<pid>21691</pid>
</BarclsCustomerValidationResponse>
</soapenv:Body>
</soapenv:Envelope>
Here are some of the problems :
namespace URI assigned to ns0 in the XPath/XQuery doesn't match the one in the XML
the XML has default namespace declared at BarclsCustomerValidationResponse element. This means BarclsCustomerValidationResponse and all the descendant elements without prefix are in the same namespace. You need to declare another prefix, map it to the default namespace URI, and use the prefix accordingly in the XPath
The following works for me :
declare namespace ns0='http://KYC';
declare namespace d='http://BHKYC/BarclaysCustomerValidation.tws';
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
/soapenv:Envelope
/soapenv:Body
/d:BarclsCustomerValidationResponse
/d:oAddressVerificationDetails
/ns0:matchedFound
Demo: http://www.xpathtester.com/xquery/b8f1f1e9e0c64af37a2e398d5b911569
BarclaysCustomerValidationResponse is in namespace http://BHKYC/BarclaysCustomerValidation.tws, so your XPath expression /BarclaysCustomerValidationResponse/ cannot find it. Same goes for its child elements unless they have a particular namespace prefix like ns0:.
Just for reading XML in SoapUI, you do not need to bother with namespaces. As you have discovered, they make the XPath unnecessarily complicated. For your case, something as simple as this will suffice.
//*:matchedFound

Jmeter - Extract multiple values from SOAP response and give that value as input to other SOAP request

I am new to Jmeter. I am hitting a web service and getting a SOAP response as below.
SOAP response :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:getResponse ............>
<ns1:return>
<ns2:Config ..........>
.........
.........
<ns2:id>1</ns2:id>
.........
.........
</ns2:Config>
<ns2:Config .........>
.........
.........
<ns2:id>2</ns2:id>
.........
.........
</ns2:Config>
</ns1:return>
</ns1:getResponse>
</soap:Body>
</soap:Envelope>
I need to get these two id values ( ) from both the tags ( ) and give that as input to other SOAP request through loop.
I have tried this by using Regular Expression Extractor.
Reference name : id
Regular Expression : (.+?)
Template : $1$
After which used the ForEach controller and gave the input taken from extractor.
Input variable prefix : id
Output variable name : idValue
And tried to use this idValue to next SOAP request. But not getting the id value in the Regular Expression extractor step itself due to which the second SOAP request is not going at all.
Any suggestions on this would be highly helpful.
Thanks
In Regular Expression Extractor, I have added the Match no as -1 which solved my problem.
Reference name : id
Regular Expression : <ns2:id>(.+?)</ns2:id>
Template : $1$
Match No. : -1
In foreach Controller, I gave the same details.
Input variable prefix : id
Output variable name : idValue
Thanks
In this case you should rather user:
http://jmeter.apache.org/usermanual/component_reference.html#XPath_Assertion
It uses XPath syntax :
https://en.wikipedia.org/wiki/XPath
You can test your XPath queries in View Results Tree using XPath Tester

PL/SQL XMLTYPE ORA-30625

I'm working with a web service that returns the output below. I'm having a hard time building the XMLTYPE variable from the output. I get the following error when trying to output the CreateUserSessionFromInstanceResult
ORA-30625: method dispatch on NULL SELF argument is disallowed
procedure xmltest is
str_xml varchar2(32000);
v_xml XMLTYPE;
BEGIN
str_xml :='<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CreateUserSessionFromInstanceResponse xmlns="http://archer-tech.com/webservices/">
<CreateUserSessionFromInstanceResult>4FFABEE05C4910A31FEC75D5FEDCDFB5</CreateUserSessionFromInstanceResult>
</CreateUserSessionFromInstanceResponse>
</soap:Body>
</soap:Envelope>';
v_xml := XMLTYPE(str_xml);
HTP.P(v_xml.extract('//CreateUserSessionFromInstanceResult/text()').getstringval());
END;
The error is on this line
HTP.P(v_xml.extract('//CreateUserSessionFromInstanceResult/text()').getstringval());
You're getting an error because your XPath expression
//CreateUserSessionFromInstanceResult/text()
matches nothing, and so extract(...) returns NULL. Of course, you can't call getstringval() on NULL, hence the error you see.
The reason your XPath isn't matching is because of namespaces. The xmlns attribute on the <CreateUserSessionFromInstanceResponse> element sets the namespace of this element and of the <CreateUserSessionFromInstanceResult> element it contains to be "http://archer-tech.com/webservices/". On the other hand, your XPath expression is searching for the element with the name CreateUserSessionFromInstanceResult in the default namespace, "".
The fix is to add a third parameter to extract that declares this namespace. You do this in the same way as it appears in the XML:
HTP.P(v_xml.extract('//CreateUserSessionFromInstanceResult/text()',
'xmlns="http://archer-tech.com/webservices/"').getstringval());
I came across a similar case and adding the extra parameter didn't work for me.
For me, the solution was to check if node exists and do a null check before using getstringval, like this:
if v_xml.existsnode('//CreateUserSessionFromInstanceResult', 'xmlns="http://archer-tech.com/webservices/"') > 0 and v_xml.extract('//CreateUserSessionFromInstanceResult/text()', 'xmlns="http://archer-tech.com/webservices/"') is not null then
HTP.P(v_xml.extract('//CreateUserSessionFromInstanceResult/text()', 'xmlns="http://archer-tech.com/webservices/"').getstringval());
end if;
Doing only the null check is probably enough.

Resources