2016-08-12 60 views
0

我使用JSON有效負載進行了很多HTTP請求,並且正在爲每個請求讀取一個文件以獲取JSON有效負載,如下所示。Gatling: - 從單個文件中讀取多個JSON有效負載

postPayload1 = val postPayload = ElFileBody("Test_case1.json") 

    val TC1 = feed(accountNumberFeeder1) 
    .exec(http(testCase1).post(appendPathToUrl).headers(common_header).body(postPayload).asJSON 
    .check(status.is(200) 
    ) 

但是,它現在變成我的資源目錄中的很多JSON文件。因此,我可以將所有JSON合併到一個文件中,如下所示。

{"testCase1":{ 
    "activationSource": "HH", 
    "accountStatus": null, 
} 
} 

{"testCase2":{ 
    "activationSource": "HH", 
    "accountStatus": null, 
} 
} 

並使用我的密鑰「testCase1」,「testCase2」等訪問它?

val postPayload = ElFileBody("Test_case.json") 

回答

0

來自官方的加特林文檔,我發現http://gatling.io/docs/2.2.1/session/feeder.html

JSON饋線 有些人可能想以JSON格式而不是CSV使用數據:

val jsonFileFeeder = jsonFile("foo.json") 
val jsonUrlFeeder = jsonUrl("http://me.com/foo.json") 

例如,下面的JSON :

[ 
    { 
    "id":19434, 
    "foo":1 
    }, 
    { 
    "id":19435, 
    "foo":2 
    } 
] 

將變成:

record1: Map("id" -> 19434, "foo" -> 1) 
record2: Map("id" -> 19435, "foo" -> 2) 

請注意,根元素當然是一個數組。

相關問題