[英]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.