[英]Gatling - Check if response body string key is certain value
我在 Gatling 中有一個場景,我想檢查響應正文值是否映射到錯誤字符串。 響應是 400:
{"error": "ERROR_1"}
檢查失敗,出現編譯錯誤:
http("Some Request")
.put("/endpoint")
.asJson
.check(jsonPath("$.error") == "ERROR_1")
.check(status.is(400))
還嘗試將錯誤保存為變量
.check(jsonPath("$.error").saveAs("error"))
.check("${error}" == "ERROR_1")
並意識到.check("${error}".is("ERROR_1"))
也不起作用,因為 .is 僅適用於整數。 加特林文檔也沒有過多解釋表達式https://gatling.io/docs/current/http/http_check#validating
有任何想法嗎?
您關於 .is 僅適用於整數的聲明是不正確的 - 這就是您應該如何構建此檢查。
這是一個通過檢查的工作示例
def test : ScenarioBuilder = scenario("test")
.exec(
http("test call")
.post("http://httpbin.org/anything")
.body(StringBody("""{"error": "ERROR_1"}"""))
.check(jsonPath("$..error").is("ERROR_1"))
)
您不能使用==
作為加特林檢查需要一個或多個 HttpChecks 並且==
返回一個布爾值。
嘗試這個:
.check(
status.is(400),
jsonPath("$.error").is("ERROR_1")
)
感謝所有的答案! 似乎我錯過了 . 在 .error 中,所以這對我有用:
http("Some Request")
.put("/endpoint")
.asJson
.check(jsonPath("$.error").is("ERROR_1"))
.check(status.is(400))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.