加特林如何从文件中只读取 body 的一部分?
Gatling how to read only a part of body from file?
我想将 Gatling 与 GraphQL 结合使用,但找不到合适的方法来处理 GraphQL 查询。 Gatling 是否支持直接从文件读取到 Gatling EL 变量?
下面是我想要实现的示例 - JSON 字段 query
的值是从文件 init-query.graphql
中读取的。
http("getInit")
.post("/api/graphql")
.body(StringBody(
"""
|{
| "query": "${init-query.graphql}",
| "variables": null
|}
""".stripMargin))
.asJson
我也尝试过不同的馈线但是 none 它们可以将文件的内容放入 Gatling EL 变量中(或者更确切地说我不能这样做)所以它可以像变量一样使用${init-query-content}
好的,知道怎么做了:
.exec(session => {
val bodyExpr = ElFileBody("init-query.graphql")
val bodyStr = bodyExpr(session).toOption.get.filter(_ >= ' ') // remove control characters
session.set("queryContent", bodyStr)
})
.exec(http("getInit")
.post("/api/graphql")
.body(StringBody(
"""
|{
| "query": "${queryContent}",
| "variables": null
|}
""".stripMargin))
.asJson
)
我想将 Gatling 与 GraphQL 结合使用,但找不到合适的方法来处理 GraphQL 查询。 Gatling 是否支持直接从文件读取到 Gatling EL 变量?
下面是我想要实现的示例 - JSON 字段 query
的值是从文件 init-query.graphql
中读取的。
http("getInit")
.post("/api/graphql")
.body(StringBody(
"""
|{
| "query": "${init-query.graphql}",
| "variables": null
|}
""".stripMargin))
.asJson
我也尝试过不同的馈线但是 none 它们可以将文件的内容放入 Gatling EL 变量中(或者更确切地说我不能这样做)所以它可以像变量一样使用${init-query-content}
好的,知道怎么做了:
.exec(session => {
val bodyExpr = ElFileBody("init-query.graphql")
val bodyStr = bodyExpr(session).toOption.get.filter(_ >= ' ') // remove control characters
session.set("queryContent", bodyStr)
})
.exec(http("getInit")
.post("/api/graphql")
.body(StringBody(
"""
|{
| "query": "${queryContent}",
| "variables": null
|}
""".stripMargin))
.asJson
)