All the example code and files are available in compressed format here for download.
Please note that I have changed the test case parameter ConvertTempResult to #ConvertTempResult in order to mark up output parameters.
Here is the function for response validation:
Function validateXMLResponse (objDictionary)
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
'loadXML
xmlDoc.loadXML(objDictionary.Item("XMLResponse"))
'Check XML syntax
If (xmlDoc.parseError.errorCode <> 0) Then
Set myErr = xmlDoc.parseError
objDictionary.Item("XMLResponseResult") = "Failed"
objDictionary.Item("XMLResponseResultDetails") = "ERROR: " & myErr.reason
Set validateXMLResponse = objDictionary
Exit Function
End If
Set root = xmlDoc.documentElement
'Put all test parameters in array
arrAllKeys = objDictionary.Keys
arrAllValues = objDictionary.Items
'Update values
For i = 0 to Ubound(arrAllKeys)
'Only process #-type parameters
If Left(arrAllKeys(i),1) = "#" Then
strParameterElementName = arrAllKeys(i)
strParameterElementName = Right(strParameterElementName,Len(strParameterElementName)-1)
strParameterElementValueExpected = arrAllValues(i)
'Get element and value
Set node = root.getElementsByTagName(strParameterElementName)
If node.Length > 0 Then
For n = 0 to node.Length-1
'Return actual value in [element]_Out
objDictionary.Item(strParameterElementName & "_Out") = node.Item(n).Text
strParameterElementValueActual = node.Item(n).Text
'Set result
If strParameterElementValueExpected = strParameterElementValueActual AND _
objDictionary.Item("XMLResponseResult") <> "Failed" Then
objDictionary.Item("XMLResponseResult") = "Passed"
Else
objDictionary.Item("XMLResponseResult") = "Failed"
objDictionary.Item("XMLResponseResultDetails") = objDictionary.Item("XMLResponseResultDetails") & _
strParameterElementName & " = " & strParameterElementValueActual & " , expected value " & _
strParameterElementValueExpected & " ;" 'use ; as separator
End If
Next
End If
Set node = Nothing
End If
Next
'Return
Set validateXMLResponse = objDictionary
'Clean up
Set root = Nothing
Set xmlDoc = Nothing
End Function
So finally we have these steps all together:
' Example of XML/Web Service automation in VBScript using WinHttp, XML DOM and ADO
' by Stefan Thelenius march 2008
'Set test case id and data source file
intTestCaseID = 1
strMyDataFile = "c:\MyTestData.xls"
'Get test case parameters
Set objMyTestParameters = getTestParametersIntoDictionary (strMyDataFile, _
"TestCase", "TestCaseID", intTestCaseID)
'Get global parameters
Set objMyGlobalParameters = getTestParametersIntoDictionary (strMyDataFile, _
"Global", "GlobalID", objMyTestParameters.Item("GlobalID"))
'Merge parameters
Set objMyTestParameters = mergeDictionaries (objMyGlobalParameters, objMyTestParameters)
'Create request from template
objMyTestParameters.Item("XMLRequest") = getXMLTemplate (objMyTestParameters.Item("XMLTemplateFile"), _
objMyTestParameters.Item("XMLTemplate"))
'Insert test parameters
objMyTestParameters.Item("XMLRequest") = setTestParametersInXMLRequest (objMyTestParameters)
'Send request
objMyTestParameters.Item("XMLResponse") = sendXMLRequest (objMyTestParameters)
'Validate response
Set objMyTestParameters = validateXMLResponse (objMyTestParameters)
'Display output
Msgbox objMyTestParameters.Item("XMLResponse")
Msgbox objMyTestParameters.Item("XMLResponseResult")
Msgbox objMyTestParameters.Item("XMLResponseResultDetails")
Msgbox objMyTestParameters.Item("ConvertTempResult_Out")
14 comments:
Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Smartphone, I hope you enjoy. The address is http://smartphone-brasil.blogspot.com. A hug.
Thanks! I checked your blog but I am not that good in reading Portuguese. I like the concept of smartphones but I'm more into smaller cell-phones like my Nokia 6500 Classic
This code really rocks. Good Work...
Hello Stefan your code is really good :) It realle helped me testing web services, I just have a question regarding the size of the response I am having problem when the response is too big, do you suggest any solution to this. Lets say the response is 35879 characters. I saw this text in the http info "This property can only be invoked after the Send method has been called.
When using this property in synchronous mode, the limit to the number of characters it returns is approximately 2,169,895."
Any idea?
Hi,
I have not encountered a response out of range...yet
What kind of problem do you get?
The XML gets truncated.
I am receiving this error directly from WinHttpReq.ResponseText. There is not error just XML gets truncated so later will fail on validation since format is not correct.
I have not found the reason, the only thing I know is that the response is way bigger than other request that I have done and have worked.
OK,
So you get a part of your response...have many characters do you get in the response before truncation? Is it below 2,169,895 ?
The number os characters is 2055, below than 2,169,895.
Hi
I am trying to send a SOAP request using vbscript. I am getting this error
No credentials were found and the authenticate action was configured to fail in this situation.
Can you please help me on this
Hi,
Have you provided credetials (WinHttpReq.SetCredentials)?
/Stefan
Hi
Thanks for your reply.
I have sent a mail with my request and response.
Please help me on this.
Hi,
Can you please let me know how to use UsernameToken credentials ?
Thanks
Mani
Wow, there is really much worthwhile info here!
Post a Comment