2015-06-11 23 views
0

我有一個用下面的迴應REST請求:了SoapUI相關(產權調換)

{ 
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlQwWE8xNnAtMmZzMWxremV5", 
    "expires_in": 2592000, 
    "token_type": "Bearer" 
} 

我想利用access_token值,將其存儲在一個屬性,它重新用於隨後的兩個請求。

遵循一些教程here,運行獲得access_token請求時,我得到一個:

錯誤解析目標屬性:錯誤意想不到的元素CDATA

但是,爲什麼?

在我的原始響應中沒有CDATA。

+0

「遵循一些教程」還不夠好!你究竟做了什麼? – SiKing

回答

0

如果您在使用transfer properties step從響應中獲取JSON值時遇到問題,可以使用groovy test step來實現您的目標。在其他testSteps(REST或SOAP

import groovy.json.JsonSlurper 

// get response using the name of your test step 
def response = context.expand('${REST Test Request#Response}') 
// parse response 
def jsonResp = new JsonSlurper().parseText(response) 
// get the token an set as a property in the testCase 
testRunner.testCase.setPropertyValue('access_token',jsonResp.access_token) 

然後:

因此,創建一個groovy test step與後續的代碼來解析您的回覆,讓你的價值,並將其設置爲(在testCase級爲例)屬性......),你可以使用如下代碼來獲取access_token價值,你在testCase設置:

${#TestCase#access_token} 

希望這有助於