[英]How to compare responses from http calls in gatling?
I have 2 http calls in 2 different function def and saving json keys from response body in gatling session. 我在2个不同的函数def中有2个http调用,并在加特林会话中从响应主体保存json键。 How can I match them? 我该如何搭配?
def getAppData():HttpRequestBuilder = {
http("get application resource")
.get("host/app")
.header("Authorization", "Bearer "+ token)
.check(status.is(200))
.check(jsonPath("$..${app_info}").saveAs("app_Response"))
}
def getUserData():HttpRequestBuilder = {
http("get user data ")
.get("host/user/data")
.header("Authorization", "Bearer "+ token)
.check(status.is(200))
.check(jsonPath("$..${user_info}").saveAs("userdata_Response"))
}
How do I compare or verify that the json values of app_info and user_info matches ie; 如何比较或验证app_info和user_info的json值是否匹配,即;
app_Response
and userdata_Response
app_Response
和userdata_Response
The values of both of these are arrays . 这两个值都是array。 For instance, in this format: 例如,以这种格式:
"app_info":
[
"name",
"address"
]
same for user_info. 与user_info相同。 I gave a try to use in-built methods of jsonPath().equals() but I believe that's not appropriate way for comparing. 我尝试使用jsonPath()。equals()的内置方法,但我认为这不是比较合适的方法。 If not a way using gatling specific methods then perhaps will find how to perform using scala? 如果不是使用特定方法的方法,那么也许会发现如何使用Scala执行?
Kindly help. 请帮助。
Basically of you use json-spray you should be able to compare both using == operator like described in this other answer here. 基本上,您使用json-spray时,应该可以使用==运算符进行比较,如此处其他答案所述。
Compare json equality in Scala 比较Scala中的json相等性
[Edit] Doing something like this I could compare 2 Json's using spray: [编辑]做这样的事情,我可以比较使用喷雾剂的2个Json:
package example
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import spray.json._
import DefaultJsonProtocol._
class MainSimulation extends Simulation {
val baseUrl = "http://localhost:8080"
val httpProtocol = http
.baseUrl(baseUrl)
.userAgentHeader("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)")
val header = Map("Content-Type" -> "application/json”,”Accept-Charset" -> "utf-8")
val scn = scenario("Scenario")
.exec(http("Get Hello Json")
.get("/hello/Alessandro")
.check(status.is(200))
.check(jsonPath("$").saveAs("activities-1")))
.exec(http("Get Hello Json")
.get("/hello/Ronaldo")
.check(status.is(200))
.check(jsonPath("$").saveAs("activities-2")))
.exec(session => {
println("=======================================================")
val activities_1 = session("activities-1").as[String]
val activities_2 = session("activities-2").as[String]
println(s"Activities 1: ${activities_1.parseJson}")
println(s"Activities 2: ${activities_2.parseJson}")
println(s"Are they equal?: ${activities_1.parseJson == activities_2.parseJson}")
println("=======================================================")
session
})
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
and I can see this in the output: 我可以在输出中看到这一点:
=======================================================
Activities 1: {"activities":["swimming","soccer"],"name":"Alessandro"}
Activities 2: {"activities":["swimming","soccer"],"name":"Alessandro"}
Are they equal?: true
=======================================================
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.