Forum Discussion

gunnettmd's avatar
gunnettmd
Contributor
13 years ago

Retrieving JSON object

Hi all,



I am writing some tests against a web page that, when a parameter is changed, receives a  JSON object from the server. The developers are also writing these JSON objects out to the browser console log.



My question is, can I retrieve this kind of infomration from a GUI script? I have done some reading but came up with no solutions. Possibly using a callback function?



Any help would be appreciated!

Thanks.

Mike
  • chicks's avatar
    chicks
    Regular Contributor
    Hi Mike,



    Can you clarify why you want this in a GUI object.?



    I automated some web services using the http request object .  See these threads:



    http://smartbear.com/forums/f81/fp19/t65754/testing-curl-webservices



    http://smartbear.com/forums/f74/t50150/How-can-i-do-a-HTTP-post-from-testcomplete



    http://smartbear.com/forums/f81/fp7/t75732/TestComplete-web-service-communication





    I used the eval statement so that I could parse the JSON  object.



    var reply = get_xml_string_representing_JSON();



    eval ("replyObject = " + reply)



    Log.Message( replyObject.value1):;   etc. etc. etc.



    I vastly preferred NOT using GUI objects to test this as it was much much faster.



    Regards,  Curt





  • Hi Curt,



    Thanks for the reply. Here is my situation:



    The web app displays some default results. These results can be modified by the user by specifying new/different criteria. Changing the criteria spawns a JSON object that is passed to the service, which returns another JSON object containing the results. We want to automate the validation of both the JSON object that is spawned by interacting with the GUI and the results being returned.



    Right now, we are updating a hidden DIV with the values because reading the browser console was not happening.
  • chicks's avatar
    chicks
    Regular Contributor
    So, you currently have a workaround, correct?  Did those threads help or are you still looking for a better way?



    Regards,  Curt