How to get Property Transfer in SoapUI testcase to work? - xpath

I'm trying to transfer a value from the response of one WS call to the request of another using SoapUI's Transfer Property TestStep.
First WS response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<ns5:PSResponse xmlns:ns5="http://www.ab.com/abonline/service/PaymentService/1.0/" xmlns:ns6="http://www.ab.com/abonline/service/CustomerCard/1.0/" xmlns:ns7="https://secure.incab.se/DTServerModuleService/v1">
<ns5:abTransactionReference>1085-0</ns5:abTransactionReference>
<ns5:status>0</ns5:status>
</ns5:PSResponse>
</soapenv:Body>
</soapenv:Envelope>
Parsing the property works fine using an expression like:
declare namespace ns5="http://www.ab.com/abnline/service/PaymentService/1.0/"
//ns5:abTransactionReference
The next request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.ab.com/abonline/service/PaymentService/1.0/">
<soapenv:Header/>
<soapenv:Body>
<UpdatePaymentRequest>
<abTransactionReference>30</abTransactionReference>
... ...
I try inserting the property into the next request using:
//abTransactionReference
Gives me: [Missing match for Target XPath [//abTransactionReference]]
I also tried a full xpath:
declare namespace soapenv="http://schemas.xmlsoap.org/soap/envelope/"
//soapenv:Envelope/soapenv:Body/UpdatePaymentRequest/abTransactionReference
...resulting in similar error.

it seems you should set the default namespace to http://www.ab.com/... as well

You cannot use "" for the namespace definition. For example, in the case above >>
declare namespace soapenv="http://schemas.xmlsoap.org/soap/envelope/"
should be
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';

Try to add XPath Assertions to UpdatePaymentRequest request message. Click on the Declare button on the XPath Match Configuration dialog and you will see what prefix soapUI uses for 'http://www.ab.com/abonline/service/PaymentService/1.0/' namespace. I think it will be like:
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns1='http://www.ab.com/abonline/service/PaymentService/1.0/';
(see http://testautomationnoob.blogspot.com.by/2013/12/xpath-in-soapui-part-1-xpath-assertions.html). Then there is no need to have XPath Assertions - you can remove it. So, use "ns1" prefix in your xpath. In the end you will have the following xpath:
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns1='http://www.ab.com/abonline/service/PaymentService/1.0/';
/soapenv:Envelope/soapenv:Body/ns1:UpdatePaymentRequest/ns1:abTransactionReference

Related

XPath JMeter Assertion : Error "prefix must resolve to a namespace"

I am trying to use JMeter XPath Assertion on a tag value as below with XPath assertion command:
//m:CurrencyNameResul/text() = Pounds
Webservice Response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<m:CurrencyNameResponse xmlns:m="http://www.oorsprong.org/websamples.countryinfo">
<m:CurrencyNameResult>Pounds</m:CurrencyNameResult>
</m:CurrencyNameResponse>
</soap:Body>
</soap:Envelope>
I am getting error
prefix must resolve to a namespace
and after referring to JMeter manual below:
NAMESPACES As a work-round for namespace limitations of the Xalan XPath parser implementation on which JMeter is based, you can provide a Properties file which contains mappings for the namespace prefixes:
prefix1=Full Namespace 1
prefix2=Full Namespace 2
…
You reference this file in jmeter.properties file using the property:
xpath.namespace.config
I don't get it, so my questions are:
what should be the content of Properties file?
where to put its path?
Here is how to proceed:
Create in jmeter/bin folder a file named namespaces.properties containing:
m=http://www.oorsprong.org/websamples.countryinfo
In user.properties set:
xpath.namespace.config=namespaces.properties
Finally fix your assertion to contain:
//m:CurrencyNameResult = 'Pounds'
And check "Use Namespaces"
To end up with:
You can amend your XPath query to use name() function like:
(//*[name() = 'm:CurrencyNameResult'])/text()
and you will not have to mess up with amending properties, restarting JMeter, etc.
Moreover if you go for local-name() function instead you will not have to include the namespace prefix into your query:
(//*[local-name() = 'CurrencyNameResult'])/text()
More information:
XPath language specification
Using the XPath Extractor in JMeter
XPath Tutorial

How to turn a file into a Nokogiri::XML object?

I have a sample XML file (let's call it example.xml for the sake of this question) and want to turn it into a Nokogiri object.
According to documentation and lots of other online sources, this should work:
xml = Nokogiri::XML(File.read("example.txt"))
But the value of xml.to_xml is only:
"<?xml version=\"1.0\"?>\n"
In other words, it's ignoring the rest of the file. There are many tags afterwards and none of them are in the xml object.
How do I get Nokogiri to get all the tags?
Here's the XML I'm using:
<? xml version="1.0" encoding="UTF-8" ?>
<Document>
<Test>Test</Test>
</Document>
It looks like you are trying to parse an invalid XML doc.
This can be fixed by removing the spaces in the XML declaration:
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<Test>Test</Test>
</Document>
How I figured this out
By default, when Nokogiri has errors parsing a document it populates an errors array.
xml = Nokogiri::XML(File.read("example.txt"))
p xml.errors
# => [#<Nokogiri::XML::SyntaxError: xmlParsePI : no target name>, #<Nokogiri::XML::SyntaxError: Start tag expected, '<' not found>]
You can also configure Nokogiri to raise an exception of it has parsing errors:
xml = Nokogiri::XML(File.read("example.txt")) do |config|
config.strict
end
Both of these cases show that there were issues parsing the document

eBay API SOAP request works in SoapUI but not from shell

The below works perfectly in SoapUI (that's where I constructed it), but when I copy the exact request and attempt to execute with cURL in the bash command line (cygwin actually), it says:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode>
<faultstring>no SOAPAction header!</faultstring>
<detail/>
</soapenv:Fault>
</soapenv:Body>
The command I'm using is:
curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:" -d "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ebay:apis:eBLBaseComponents"><soapenv:Header><urn:RequesterCredentials><urn:eBayAuthToken>AgA***GO</urn:eBayAuthToken></urn:RequesterCredentials></soapenv:Header><soapenv:Body><urn:GetMyeBaySellingRequest><urn:Version>793</urn:Version><urn:ActiveList><urn:Include>1</urn:Include><urn:IncludeNotes>0</urn:IncludeNotes></urn:ActiveList><urn:OutputSelector>ActiveList.ItemArray.Item.ItemID</urn:OutputSelector><urn:DetailLevel>ReturnAll</urn:DetailLevel><urn:HideVariations>1</urn:HideVariations></urn:GetMyeBaySellingRequest></soapenv:Body></soapenv:Envelope>" -X POST https://api.ebay.com/wsapi?callname=GetMyeBaySelling
I've used this exact syntax on other APIs with no issue, not sure what's different about eBay.
Open your wsdl. search for the operation which you are using to send this "GetMyeBaySellingRequest" request.
Copy the soap action from there and add in you command line
"SOAPAction: add soap action here from bindings or from soapui"
or in SOAP UI click on the operation and see at bottom left corner, you will see "operation properties". From there copy soap action value and put it in your command.

Why can't I get a result from an XPath with namespace in the root element? [duplicate]

This question already has answers here:
Nokogiri/Xpath namespace query
(3 answers)
Closed 8 years ago.
This is probably an XML namespace newbie question but I can't figure out how to get an XPath to work with the following trunctated XML with this particular root element:
<?xml version="1.0" encoding="UTF-8"?>
<CreateOrUpdateEventsRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://dhamma.org" version="3-0-0">
<LanguageKey>
<IsoCode>en</IsoCode>
</LanguageKey>
<Publish>
<Value>true</Value>
</Publish>
<Events>
<Event>
<EventKey>
<LocationKey>
<SubDomain>rasmi</SubDomain>
</LocationKey>
<EventId>10DayPDFStdTag</EventId>
</EventKey>
</Event>
</Events>
</LanguageKey>
</CreateOrUpdateEventsRequest>
Using Ruby and Nokogiri (with a just updated libxml2), it works fine with XPath only if I delete all the extra info in the root element, making it:
<CreateOrUpdateEventsRequest>
Otherwise nothing works:
$> #doc.xpath("//CreateOrUpdateEventsRequest") #=> [] with original header, an array of nodes with modified header
$> #doc.xpath("//LanguageKey") #=> [] with the original header, an array of nodes with modified header
$> #doc.xpath("//xmlns:LanguageKey") #=> undefined namespace prefix with the original
How do I address namespaces like this with XPath?
Many thanks for the help.
The answer seems to be that the XML re-declared XMLNS when it should have declared the namespace with a prefix as in xmlns:myns.
From www.w3.org:
The XML specification reserves all names beginning with the letters 'x', 'm', 'l' in any combination of upper- and lower-case for use by the W3C. To date three such names have been given definitions—although these names are not in the XML namespace, they are listed here as a convenience to readers and users:
xml: See http://www.w3.org/TR/xml/#NT-XMLDecl and http://www.w3.org/TR/xml-names/#xmlReserved
xmlns: See http://www.w3.org/TR/xml-names/#ns-decl
xml-stylesheet: See The xml-stylesheet processing instruction
I don't use Nokogiri nor Ruby,
but you need to register a prefix for namespace http://dhamma.org
When I read http://nokogiri.org/tutorials/searching_a_xml_html_document.html
I understand you must do something like
$> #doc.xpath('//dha:LanguageKey', 'dha' => 'http://dhamma.org')
Here's some code to consider. Starting with code to create a Nokogiri::XML::Document:
require 'nokogiri'
XML = <<EOT
<?xml version="1.0" encoding="UTF-8"?>
<CreateOrUpdateEventsRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://dhamma.org" version="3-0-0">
<LanguageKey>
<IsoCode>en</IsoCode>
</LanguageKey>
<Publish>
<Value>true</Value>
</Publish>
<Events>
<Event>
<EventKey>
<LocationKey>
<SubDomain>rasmi</SubDomain>
</LocationKey>
<EventId>10DayPDFStdTag</EventId>
</EventKey>
</Event>
</Events>
</LanguageKey>
</CreateOrUpdateEventsRequest>
EOT
doc = Nokogiri::XML(XML)
Here's the root node's name:
doc.root.name # => "CreateOrUpdateEventsRequest"
The docs say:
When using CSS, if the namespace is called “xmlns”, you can even omit the namespace name.
doc.at('CreateOrUpdateEventsRequest').name # => "CreateOrUpdateEventsRequest"
doc.at('LanguageKey').to_xml # => "<LanguageKey>\n <IsoCode>en</IsoCode>\n </LanguageKey>"
Using XPath, we can specify the default namespace as:
doc.at('//xmlns:LanguageKey').to_xml # => "<LanguageKey>\n <IsoCode>en</IsoCode>\n </LanguageKey>"
Sometimes, if there are a lot of namespaces it makes sense to use collect_namespaces and pass them in:
name_spaces = doc.collect_namespaces # =>
doc.at('//xmlns:LanguageKey', name_spaces).to_xml # => "<LanguageKey>\n <IsoCode>en</IsoCode>\n </LanguageKey>"
You'll need to look through the documentation for Nokogiri::XML::Node for more information on the various methods.
I recommend using CSS selectors for simplicity and readability over XPath, as a first try. I think XPath has more functionality but it makes my eyes bug out sometimes, so I prefer CSS.

XPATH Error : Unable to evaluate expression

I have an xml like this as mentioned below. I am trying to obtain value for Cardnumber using following expression.
XPATH :
paymentService/ns0:submit/ns0:order/ns0:paymentDetails/ns0:VISA-SSL/cardNumber
But it's giving me error. Can any1 guide me on this?
<?xml version="1.0" encoding="UTF-8"?>
<paymentService version="1.0">
<ns0:submit xmlns:ns0="http://www.tibco.com/ns/no_namespace_schema_location/Payment/PaymentProcessors/WorldPay_CC/SharedResources/Schemas/paymentService_v1.dtd">
<ns0:order>
<description>description</description>
<amount value="500" currencyCode="EUR" exponent="2"/>
<ns0:paymentDetails>
<ns0:VISA-SSL>
<cardNumber>00009875083428500</cardNumber>
<expiryDate>
<date month="02" year="2008"/>
</expiryDate>
<cardHolderName>test</cardHolderName>
</ns0:VISA-SSL>
<session shopperIPAddress="192.165.22.35" id=""/>
</ns0:paymentDetails>
<shopper>
<browser>
<acceptHeader>text/html</acceptHeader>
<userAgentHeader>mozilla 5.0</userAgentHeader>
</browser>
</shopper>
</ns0:order>
</ns0:submit>
</paymentService>
Thanks
Your xmlns:ns0 is misplaced, and (think of this way) because ns0 is defined after <ns0:submit> tag, ns0:submit is "undefined" and thus the parse error.
Edit:
If you need to use this XPath in PHP, you'll either have to declare the namespace before use:
<?xml version="1.0" encoding="UTF-8"?>
<paymentService version="1.0" xmlns:ns0="http://www.tibco.com/ns/no_namespace_schema_location/Payment/PaymentProcessors/WorldPay_CC/SharedResources/Schemas/paymentService_v1.dtd">
<ns0:submit>
Or register the namespace before evaluating your XPath (Thanks to #MiMo for pointing out):
$xml->registerXPathNamespace("ns0","http://www.tibco.com/ns/no_namespace_schema_location/Payment/PaymentProcessors/WorldPay_CC/SharedResources/Schemas/paymentService_v1.dtd");
Also add a slash before your XPATH:
/paymentService/ns0:submit/ns0:order/ns0:paymentDetails/ns0:VISA-SSL/cardNumber
Live demo with declaration first or Live demo with namespace registration (both are demonstrated in PHP).
The problem is the node
<paymentService version="1.0">
Since this is not ended you have to comment it or end it properly.
If you comment that try out with this XPATH
/ns0:submit/ns0:order/ns0:paymentDetails/ns0:VISA-SSL/cardNumber
You need to register the namespace before evaluating the XPath:
$xml->registerXPathNamespace('ns0', 'http://www.tibco.com/ns/no_namespace_schema_location/Payment/PaymentProcessors/WorldPay_CC/SharedResources/Schemas/paymentService_v1.dtd');
where $xml is a SimpleXMLElement variable containing your XML.
Your XPath needs to start with / as per Passerby answer:
/paymentService/ns0:submit/ns0:order/ns0:paymentDetails/ns0:VISA-SSL/cardNumber

Resources