分配JSON响应中的子节点到项目变量,每次在SoapUI中发送请求时。

huangapple go评论57阅读模式
英文:

Assign child node from a JSON response to project variable everytime a request is sent in SoapUI

问题

是的,您可以从JSON响应中提取数据并将其分配给项目变量,然后可以在另一个请求中进一步使用它。在您的情况下,您希望提取身份验证令牌。希望这可以帮助您。

英文:

I am new to soapUI and still figuring it out.
Is it possible to extract data from a JSON response and assign it to a project variable which can further be used in another request. In my case it's an authentication token.

Appreciate all your responses.

Found nothing specific on internet regarding this.

答案1

得分: 0

使用属性传递完成了。

添加一个属性传递步骤,选择前一个REST请求的响应,并使用Xquery获取子节点,然后将其分配给项目变量。

例如:

{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Save", "onclick": "SaveDoc()"}
    ]
  }
}}

使用Xquery,"$.menu.popup.menuitem.value",来访问相应的子节点。

英文:

I did it using property transfer.

Add a property transfer step, and select the response of the previous REST request, and use Xquery to get the child node, and assign it to the project variable.

For eg:

{"menu": {  
  "id": "file",  
  "value": "File",  
  "popup": {  
    "menuitem": [  
      {"value": "New", "onclick": "CreateDoc()"},  
      {"value": "Open", "onclick": "OpenDoc()"},  
      {"value": "Save", "onclick": "SaveDoc()"}  
    ]  
  }  
}}

Use the Xquery, "$.menu.popup.menuitem.value", to access the respective child node.

huangapple
  • 本文由 发表于 2023年3月3日 21:56:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627987.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定