Forum Discussion

susmi_shailu's avatar
12 years ago

Webservice testing

I am trying to generate soap request using the PrepareRequest method given in TestComplete Webservices api.

But some of elements in the serviceRequestXML is not present when returned by the prepareRequest method. I have verified the requestObject before passing to the method and the values are present in it. Please find the attached WSDL and the script.



In the serviceXML the <lead/> object is getting empty. LeadData is Any type object and the value is set with an xml read from a file. PrepareRequest method doesn't include the xml set on LeadData and also it doesn't throw any errors when the method is called.



Is this a bug in the TestComplete or am I missing anything? Please advice me.



here is the wsdl: https://qaleads2.autobase.net/DMXIntegrations/DMXIntegrations.asmx

The Code below:



Sub WebServiceMethodTest

  Dim MethodName

  Dim ServiceInfo, RequestObj, RequestXml,URL, ServiceName, SoapVersion

  Dim ArrayObj

  Dim Root, HeaderNode, CredentialsNode, UserIDNode, PasswordNode

  Dim HeaderElement, CredentialsElement, UserIDElement, PasswordElement

  Dim UserIDValue, PasswordValue

  Dim XmlHttpRequest



  ' Specify the name of the web service method to be tested

  MethodName = "AddOEMNewLead"

 

  'Specifies the URL address of the web service's WSDL document

  URL = "https://qaleads2.autobase.net/DMXIntegrations/DMXIntegrations.asmx?WSDL"

  ' Specifies the web service's name

  ServiceName = "DMXIntegrations"

  ' Specifies the protocol version to be used

  SoapVersion = WebServices.svSoap11



  ' Obtains the WebServiceInfo object

  Set ServiceInfo = WebServices.CreateWebServiceInfo(URL, ServiceName, SoapVersion)    

 

   Dim TypeFactory

  'Get the type factory for the web service

  Set TypeFactory = WebServices.TestWebService.TypeFactory

  Set LeadEntity = TypeFactory.TestLeadEntity

  LeadEntity.OemType = "Ford"

  LeadEntity.Type = "QA"

  'Set TestLeadEntity.LeadData = TypeFactory.LeadDataType

  Set obj1 = TypeFactory.LeadDataType  

  Set obj = CreateXMLObj("C:\Leads\FordLead.xml")

  Set obj1.Any = obj                                    

  Set LeadEntity.LeadData = obj1        

 

  'Create an object with the method's input parameters

  Set RequestObj = ServiceInfo.PrepareRequestObject(MethodName)

 

  RequestObj.passkey = "Susmitha"

  Set RequestObj.lead = LeadEntity



  ' Make an XML document for the SOAP request

  Set RequestXml = ServiceInfo.PrepareRequest(MethodName, RequestObj)

  Log.message RequestXml.XML

  ' Modify the XML data and add a SOAP header with credentials



  Set Root = RequestXml.documentElement  



  'Create an XMLHTTP object for sending the SOAP request

  Set XmlHttpRequest = CreateObject("MSXML2.XMLHTTP.3.0")

 

  ' Send the created SOAP request to the web service

  Call XmlHttpRequest.open("POST", "https://qaleads2.autobase.net/DMXIntegrations/DMXIntegrations.asmx", False)

  Call XmlHttpRequest.send(RequestXml)

 

  Set ResponseXML = XmlHttpRequest.responseXML

  Log.Message ResponseXML.XML

End Sub



Thanks,

Shell

 

2 Replies

  • AlexKaras's avatar
    AlexKaras
    Community Hero
    Hi Shell,



    Website on the address provided requires certificate for identification... :(



    Update: Nevermind, wsdl is accessible without identification. I'll try to get a look...



    Update2: According to my experience, VBScript is the worst choice for WebServices tests in TestComplete. The reason is that when you do negative testing (i.e. provide WebService with wrong data), an exception is usually returned from the call. You can handle it in VBScript using On Error Resume Next and On Error GoTo 0 statements, but they are really inconvenient and clutter test code a lot.

    So, unless you have some good reasons as for VBScript, I would recommend to consider either DelphiScript or JScript.
  • AlexKaras's avatar
    AlexKaras
    Community Hero
    Hi Shell,



    I tried to create a sample test using TestComplete's means (i.e. using its services provided for WebServices testing but not preparing request manually via PrepareRequest()), but failed to execute it because of the authentication error.

    I tried the same using SoapUI, but it also failed with the same 'peer not authenticated' error.



    Anyway, these lines of your code are not clear to me:

      Set obj1 = TypeFactory.LeadDataType  

      Set obj = CreateXMLObj("C:\Leads\FordLead.xml")

      Set obj1.Any = obj                                    

      Set LeadEntity.LeadData = obj1 



    a) Neither TestComplete, nor SoapUI indicated that LeadDataType object is required for the AddOEMNewLead() method call. Lead.LeadType is of string type.



    b) Even if you need to assign the value to the obj1.Any you should not assign obj object to it because obj is a COM object, while obj1.Any is a serialized text representation. So I think that instead of Set obj1.Any = obj something like obj1.any = obj.xml should be used (but I would like to check this in debugger).