Forum Discussion

NisHera's avatar
NisHera
Valued Contributor
7 years ago
Solved

Reading array of objects in web api

I'm having a response of web_api with array of objects.

It seems "ParseResponse" couldn't read end objects any help would appreciate.

 

Below is my inspection on parsed response variable...

 

There should be 2 contact_phone details objects include in response (as per SoapUI test)

 

method parameters are as below

  • Hi,

     

    Check sample project from the <Users>\Public\Documents\TestComplete 12 Samples\Common\Web Service Testing\Functional Testing\ folder. It contains example of processing array returned as a result.

    Does it help?

3 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Check sample project from the <Users>\Public\Documents\TestComplete 12 Samples\Common\Web Service Testing\Functional Testing\ folder. It contains example of processing array returned as a result.

    Does it help?

    • NisHera's avatar
      NisHera
      Valued Contributor

      thanks AlexKaras 

      it is not straight forward.  But could decipher after an hour and half.

      If anybody comes across same problem  below is the code 

       

      function test123(){
        
        var wsCall, CnPhDetArray ;
        
        WebServices.XXXwsSoap.getContactPhone(28);
        wsCall = WebServices.CreateWebServiceInfoFromItem('XXXwsSoap');
        var CnPhDetArray = wsCall.ParseResponse("getContactPhone",WebServices.XXXwsSoap.LastResponse);
      
        for(var i = 0; i <= VarArrayHighBound(CnPhDetArray.list.Contact_PhoneDetail, 1); i++)
          Log.Message("Array[" + aqConvert.IntToStr(i) + "] = " + CnPhDetArray.list.Contact_PhoneDetail(i).Phone_Number );
      }

       

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        Hm... I expected it to be more user-friendly... I did not provide code sample as I did not have TestComplete with Web Services project at hand at that moment, but I would try something like this:

        -- As your service has more than one output parameter, call it as per https://support.smartbear.com/testcomplete/docs/app-testing/web/services/out-parameters-methods.html recommendations;

        -- Assuming that returned data are in the Contact_PhoneDetail parameter (which is an array), I would expect this code:

          Contact_PhoneDetail[i].Phone_Number;

        (Though the above should be verified in debugger|code evaluation window)