簡體   English   中英

在soapUI中使用Groovy提取JSON字段以用於后續步驟

[英]Using Groovy in soapUI to extract a JSON field for use in subsequent steps

我是soapUI中Groovy腳本的新手。 我試圖在Groovy中檢索響應,並以字符串形式獲取內容,並從響應正文中獲取trans id ,並使用它在request2中進行設置。

以下是響應正文。

{"trans response" : {
   "status" : "pending request",
   "trans id " : 1000078
  }
}

以下代碼段提取trans id的值(包括尾隨空間)並設置測試用例屬性:

import groovy.json.JsonSlurper

def response = new groovy.json.JsonSlurper().parseText(context.expand('${RESTRequest1#Response}'))
def String transId = response.'trans response'.'trans id '

// Set as a test case property
testRunner.testCase.setPropertyValue("transId", transId)

然后,您可以在后續步驟中使用transId屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM