I am trying to automate test for soap/xml messages with request library. If have tried other libraries but there I run into problems (mainly lacking the possibility of accessing the WSDL with an URL). I have succes with request library in the sennse that I manage to send in a message and get the response message back. So far so good, but there is one problem with the response I get in my logging. One of the tags in the response has a <[!CDATA[]] part, which is not correctly formatted in the response. This makes it very cumbersome to retrieve the content of the response, if not impossible. I tried to see if parsing into xml would work, but I get just the same. I hope someone has a good suggestion to get the response back in a correct format. See below for my robot script and the expected and actual response I get in robot (everything is edited as to not share any sensitive data).
Robot script:
*** Settings ***
Library RequestsLibrary
Library Collections
Library SeleniumLibrary
Library String
Library OperatingSystem
Library XML use_lxml=${TRUE}
Library SoapLibrary
Resource ../Resources/Inputs/cardscan240xml.robot
*** Variables ***
omitted
*** testcases ***
create session CardScan ${base_url}
#Create Request Headers
${request_header}= create dictionary SOAPAction="document/http://xxxx.com/CustomUI:xxxxxxxxxxMember" Content-Type=text;charset=utf-8
#Send the XML request body
${SAVE_Response}= Post Request CardScan ${channel_url} headers=${request_header} data=${CARDSCAN}
#Log Response and Status Code Details
log to console ${SAVE_Response.status_code}
log ${SAVE_Response.headers}
log ${SAVE_Response.text}
This is how I get it in robot framework
The response I should get back (this is how I got it from soapui.):
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns:xxxxxxxxxxxLoyaltyMember_Output xmlns:ns="http://xxxx.com/xxxUI">
<ns:MessageType>0250</ns:MessageType>
<ns:MessageXML><![CDATA[<?xml version="1.0" encoding="UTF-8"?><PrivateData><LoyaltyMessageNumber2><Customer xxxxID="5563" xxxID="1" xxxID="1254" xxxType="2" BusinessDate="2005/02/16"><LoyaltyInfo FirstName="Chris" CardID="2600787879882" HomeStore="" CardStatus="00" ServerDate="2021/07/07" CardIDType="P" LastName="xxxxkoren"><EligibleOffers></EligibleOffers><Segments><xxxxID="4"></Seg><xxxx="4"></Seg></Segments><Accounts><xxxxID="1000" Value="181"></Acc></Accounts><Email>c.xxxxxxxxx22@eu.xxxxxx.com</Email><EmailValidFlag>Y</EmailValidFlag><EReceiptFlag></EReceiptFlag></LoyaltyInfo></Customer></LoyaltyMessageNumber2><xxxxxxxCustomerInfo FreeCustomerInfo3="" FreeCustomerInfo4="" FreeCustomerInfo1="" FreeCustomerInfo5="" FreeCustomerInfo2=""></xxxxxCustomerInfo><xxxxxxInvoiceData Address2="" Address5="" CustomerName="Chris Tester" VatNr="" CustomerNumber="111111111" Address1="" Address4="" CompanyName="" Address3=""></xxxxxInvoiceData></PrivateData>]]></ns:MessageXML>
<ns:ResponseCode>00</ns:ResponseCode>
</ns:xxxxxxxxLoyaltyMember_Output>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is how I get it in Robot framework:
POST Response : url=https://xxxxxxvsbl.nl.xxxxxx.net:8113/xxi_anxx_xxu/xxxxxxt.swe?SWEExtSource=AnonWebService&SWEExtCmd=Execute
status=200, reason=
body=<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-
ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body>
<ns:xxxxxInboundLoyaltyMember_Output xmlns:ns="http://xxxxx.com/xxxxxUI">
<ns:xxxxxxType>0250</ns:xxxxxType><ns:MessageXML><?xml version="1.0"
encoding="UTF-8"?><PrivateData><xxxxxxNumber2><Customer
xxxxxID="124" xxxxxD="1" xxxxxID="124"xxxxxType="2"
BusinessDate="2005/02/16"><LoyaltyInfo FirstName="Chris"
CardID="211111111879882" HomeStore="" CardStatus="00"
ServerDate="2021/07/07" CardIDType="P"LastName="xxxxxelkoren"><EligibleOffers></EligibleOffers><Segments>&
lt;Seg ID="4"></Seg><Seg ID="4"></Seg></Segments><Accounts><Acc ID="1000" Value="181"></Acc></Accounts><Email>c.xxxxxkoren22@eu.xxxxxx.com</Email><EmailValidFlag>Y</EmailValidFlag><EReceiptFlag></EReceiptFlag></LoyaltyInfo></Customer></xxxxxxMessageNumber2><xxxxxxCustomerInfo FreeCustomerInfo3="" FreeCustomerInfo4="" FreeCustomerInfo1="" FreeCustomerInfo5="" FreeCustomerInfo2=""></xxxxxxCustomerInfo><xxxxxxxInvoiceData Address2="" Address5="" CustomerName="Chris Tester" VatNr="" CustomerNumber="2600787879882" Address1="" Address4="" CompanyName="" Address3=""></xxxxxxxxInvoiceData></PrivateData>
</ns:MessageXML>
<ns:ResponseCode>00</ns:ResponseCode>
</ns:xxxxxxInboundLoyaltyMember_Output>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
Sorry, I struggle to get the robot response very readable, but I do hope that it is clear that the regular tags pose no problem. But that the CDATA tag and the double quotes within the cdata part are not readable. I hope someone has a suggestion to fix this.
With the xml library, the CDATA is automatically deleted and the corresponding part is encoded, cf https://www.freeformatter.com/xml-escape.html
' is replaced with '
" is replaced with "
& is replaced with &
< is replaced with <
> is replaced with >
If you want to make it nicer, you can treat the xml as a string and then replace these tags with :
.replace("<","<").replace(">",">").replace("&","&") etc...
Otherwise, i think some method exists : https://wiki.python.org/moin/EscapingXml