2017-03-09 56 views
2

我需要在jmeter中驗證API模式。 我的API響應數據我們如何驗證jmeter中的響應數據模式(僅列值)?

[{ 
    "snid": "1", 
    "subject": "Automation", 
    "state": null, 
    "country": null, 
    "contact_name": "John", 
    "email": "[email protected]", 
    "phone": "402-221-9999" 
}, { 
    "snid": "2", 
    "subject": "Testing", 
    "state": null, 
    "country": null, 
    "contact_name": "Smith", 
    "email": "[email protected]", 
    "phone": "402-111-2222" 
}] 

,所以我想,以驗證它包含響應消息

{ 
    "snid": "", 
    "subject": "", 
    "state": , 
    "country": , 
    "contact_name": "", 
    "email": "", 
    "phone": "" 
} 

我只是需要驗證的列名和字段進行排序。 我已經使用response assertions包含但它不驗證的順序,也JSON path assertion驗證對象值不是參數(或它驗證完整的消息),但在我的情況下,我需要驗證確切的架構。

請幫

回答

0

我發現身邊工作,你 第一解析對象JSON slurper

def slurper = new groovy.json.JsonSlurper(); 

def response = slurper.parseText(prev.getResponseDataAsString()); 

def testdata = response[0].keySet() as List; 

這將TESTDATA保存爲

[ 「SNID」, 「主題」,「狀態「,」country「,」contact_name「,」email「,」phone「]

1

您可以使用map.keySet(),它會給你從地圖上的所有鍵。

[ "snid", 
    "subject", 
    "state", 
    "country", 
    "contact_name", 
    "email", 
    "phone" 
] 
相關問題