[英]Check string in gatling simulation
試圖檢查身體上是否存在字符串。 類似於檢查狀態是.check(status.is(200))
。 我也想檢查字符串。 嘗試.check(bodyString.is("greeting"))
但出現錯誤:
val scn = scenario("GreetingPages")
.during(testTimeSecs) {
exec(
http ("greeting")
.get("/greeting")
.check(status.is(200))
.check(bodyString.is("Greeting"))
).pause(minWaitMs,maxWaitMs)
.exec(
http("greeting1")
.get("/greeting1")
.check(status.is(200))
.check(bodyString.is("Greeting1"))
).pause(minWaitMs,maxWaitMs)
.exec(
http("Third page")
.get("/greeting2")
.check(status.is(200))
.check(bodyString.is("Greeting2"))
).pause(minWaitMs,maxWaitMs)
}
---- 錯誤 --------------------------------------------- ----------------------
bodyString.find.is(Greeting),但實際找到 {"message":"G 9 (47.37%) reeting"} bodyString.find.is(Greeting1),但實際找到 {"message":"5 (26.32%) Greeting1"} bodyString.find.is(Greeting2),但實際找到 {"message":"5 (26.32%) Greeting2"}
原因是bodyString
返回完整的響應正文,如文檔中所述。
您可以in
matcher 中使用(您可以在此處查看實現 - 查找 InMatcher[A] ,但它不起作用,因為您需要將expected.contains(actualValue)
與expected.contains(expected)
切換
我建議你實現自己的MyOwnInMatcher
:
class MyOwnInMatcher[A](expected: Seq[A]) extends Matcher[A] {
def name: String = "customIn"
protected def doMatch(actual: Option[A]): Validation[Option[A]] = actual match {
case Some(actualValue) =>
if (expected.contains(actualValue))
actual.success
else
s"found $actualValue".failure
case _ => Validator.FoundNothingFailure
}
}
並使用它:
.check(jsonPath("$.message").validate(customIn("Greeting"))))
,檢查 json 響應正文的message
屬性中是否存在“Greeting”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.