I apologize in advance for this poorly worded question.
I'm re-writing an older E2E test that performs a POST of an XML document to an internal site using vbScript. With WinHttpRequest and Microsoft.XMLDOM the data is accepted and appears as expected in the website. However, when I perform the "same" operation using Cypress I obtain different results.
My question: Is there difference in the way these two technologies perform the POST operation or am I missing something in the Cypress code?
Thanks in advance for any advice!
VBS
Dim xmlhttp, oXML
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "POST", "https://InternalWebSite.com/Orders/CXMLOrder.aspx", False
xmlhttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded; charset=UTF-8"
xmlhttp.setRequestHeader "Content-length", "1000"
xmlhttp.setRequestHeader "Connection", "close"
xmlhttp.setRequestHeader "soapAction", ""
Set oXML = CreateObject("Microsoft.XMLDOM")
oXML.async = False
oXML.load(localPath & "\MyOrderFile.xml")
xmlhttp.send(oXML)
CYPRESS
it('Post Order File to Site', () => {
const myOrderFile = 'C:\\Automation\\MyOrderFile.xml'
cy
.readFile(myOrderFile)
.then(function (text) {
cy.log(text)
postXML(text)
})
})
function postXML(text) {
return cy.request({
url: 'https://InternalWebSite.com/Orders/CXMLOrder.aspx',
method: 'POST',
body: text,
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'content-length': '1000',
'connection': 'close',
'soapAction': ''
}
}
)}
The solution ended up being quite simple.
In the original VBS code the "content-length" was set to 1000 - my assumption was that if it worked for VBS it would also work for Cypress. As it turns out setting "content-length" based on the actual XML payload length was the trick.
From: 'content-length': '1000',
To: 'content-length': text.length,