UFT11.50 - Service Test - How can I obtain the data from the response body

℡╲_俬逩灬. 提交于 2019-12-06 12:33:06

问题


{
    "Id": 456,
    "Type": null,
    "Name": "Store112",
    "Root": "\\\\server\\ShareFolder",
    "Username": "alm",
    "Password": null
}

This is a JSON file response body from a HTTP Request, how can I get the value of 'ID' property? Does UFT or QTP has a function to support this?


回答1:


In order to use a specific JSON property from the response you should do the following.

  1. Select the HTTP tab in the properties pane
  2. In the Response Body section select JSON from the drop down list
  3. Load a sample of the expected JSON response

Then in the activity you want to use the value, click the link icon for the input parameter, select the HTTP tab and select the Id property from the Output section.




回答2:


With QTP10 it is not possible to do this natively, but depending on how much data you want from the JSON file (only ID or do you want to parse the whole thing) and how complicated the JSON file is (multiple childs objects etc.) you can use the following tactics:

  1. Most generic: Try to find a VBScript JSON parser like these guys.
  2. Most hackery: Create an Internet Explorer application instance, attach a (java)script element to the empty document and eval the response body inside this element to a variable. Import this variable to QTP as an object by reading out the DOM. Now you can get the ID by id = ImportedObject.ID
  3. Simplest: Use a regular expression to get the ID with a pattern like ""ID"": *([^,]*) on the response body.

I would opt for 3 unless you want to get much more information from the JSON file.



来源:https://stackoverflow.com/questions/15151600/uft11-50-service-test-how-can-i-obtain-the-data-from-the-response-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!