2017-08-11 79 views
0

我想用財產轉移爲下面的情形兩個值存儲在相同屬性:肥皂UI適當trasfer

響應:

{ 
    "token_type": "Bearer", 
    "expires_in": "3600", 
    "ext_expires_in": "0", 
    "expires_on": "1502435816", 
    "not_before": "1502431916", 
    "resource": "https://CY17API.toyota.com", "access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlZXVkljMVdEMVRrc2JiMzAxc2FzTTVrT 
} 

我想存儲令牌類型值和訪問令牌值在項目級別的一個屬性中,並將該屬性進一步傳遞給所有測試用例。

爲了在物業轉移中存儲一個值,我使用$.token_type$.access_token但我不知道如何存儲這兩個值。

回答

0

如果Script Assertion用於相同的REST Request測試步驟,則可以在不使用額外的Property Transfer測試步驟的情況下實現。

這裏的想法:

提取所需的值。
將它們存儲在項目級自定義屬性中。
使用property expansion無論哪些值需要在進一步的測試用例中。

腳本斷言:

assert context.response, 'Response is null or empty' 

def json = new groovy.json.JsonSlurper().parseText(context.resposne) 
log.info "Token type: ${json.token_type}" 
log.info "Access token : ${json.access_token}" 

//Check those are not empty in the received response before storing the values 
assert json.token_type, 'Token type is empty or null' 
assert json.access_token, 'Access token is empty or null' 

//Store them at project level 
context.testCase.testSuite.project.setPropertyValue('TOKEN_TYPE', json.token_type) 
context.testCase.testSuite.project.setPropertyValue('ACCESS_TOKEN', json.access_token) 

現在,使用${#Project#TOKEN_TYPE}${#Project#ACCESS_TOKEN}無論你需要的時候,即在進一步測試案例得到的token_type動態值,分別access_token