[英]Gatling> Json response map with Json File
Hi I want to validate my Json File saved in resources with the Json response via Get method. 嗨,我想通过Get方法通过Json响应来验证保存在资源中的Json文件。 My Saved Json File looks like this, which is in an array [{ "id":"123" }]
我保存的Json文件如下所示,它位于数组[{“ id”:“ 123”}]中
I am unable to map the File with Response. 我无法使用响应映射文件。
object Products {
val jsonFetchProductIDs = ElFileBody("abc.json")
val fetchProductIds: HttpRequestBuilder = http("fetch")
.get("endpoint")
.body(jsonFetch)
val products = http("Products")
.get("endpoint")
}
class ProductsTest extends Simulation {
val productIdInfo = exec(
Products.products
.check(status.is(200), jsonPath("$.id").ofType[Map[String,Any]].findAll.saveAs("productsID"))
)
val productIdResult = exec(session => {
val id = session.get("id").asOption[String]
foreach("${productsID}", "id") {
exec(session => {
val idMap = session("id").as[Map[String, Any]]
val allId = idMap(" allId")
session.set("allId", allId)
})
}
session
})
val getproductidscenario1 = scenario("Products ID")
.exec(Login.login)
.exec(EventBus.openSSE)
.exec(Accounts.fetchInitialAccounts)
.pause(10)
.exec(productIdInfo)
.exec(productIdResult)
setUp (
getproductidscenario1.inject(atOnceUsers(1)).protocols(HttpConf.httpConf)
)
}
You can use the command below to compare the result against file content 您可以使用下面的命令将结果与文件内容进行比较
bodyString.is(ElFileBody("expected_response.json"))
bodyString.is(ElFileBody(“ expected_response.json”))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.