【问题标题】:How to pass a List (session (String attribute)) in a loop to Create a Bulk Json Request in Gatling Scala如何在循环中传递列表(会话(字符串属性))以在 Gatling Scala 中创建批量 Json 请求
【发布时间】:2022-10-17 04:30:08
【问题描述】:

如何将列表(会话(字符串属性))传递给逻辑以在 Gatling Scala 中创建批量 Json 请求

从这种请求的响应中,我正在保存会话属性,这些属性是列表(字符串 1...字符串)

    .exec(http("Find Perftest")
      .get("/Perftest")
      .queryParam("PerftestId", PerftestId)
      .check(jsonPath("$.results[*].name").findAll.saveAs("PerfName"))
      .check(jsonPath("$.results[*].id").findAll.saveAs("PerfID"))
      .check(jsonPath("$.results[*].type.id").findAll.saveAs("TypeID"))
      .check(status.is(200)))

我正在尝试从保存的会话属性(列表)构建动态批量 Json 请求

    .exec { session =>
      val PerfNamex = session("PerfName").as[List[String]]
      val PerfIDx = session("PerfID").as[List[String]]
      val TypeIDx = session("PerfID").as[List[String]]
      val i =0
      val data1 = (i  to 2)
        .map { r =>
          Json.toJson(Map(
            "name" -> Json.toJson(s"${PerfName(i)}"),
            "assetId" -> Json.toJson(s"${PerfIDx(i)}"),
            "typeId" -> Json.toJson(s"${TypeIDx(i)}"))   }

      val data2 = Json.toJson(data1)
      session
    }

将创建的 Bulk Json 传递给以下请求

    .exec(http("exec Bulk Perftest")
      .post("/Perftest/bulk")
      .body(StringBody(session =>
        s"""${session("data2")}""".stripMargin)).asJson)

Error Bulk Json Request:

body:StringRequestBody{charset=UTF-8, content=SessionAttribute(Session(Bulkperftestexe,1,HashMap(gatling.http.cache.baseUrl -> http://ppppp/pp, TestID -> Vector(ed811977, bd34bc09), gatling.http.cache.dns -> io.gatling.http.resolver.ShufflingNameResolver@53184a5c, gatling.http.ssl.sslContexts -> io.gatling.http.util.SslContexts@226d7a8c, gatling.http.referer -> http://PPPP/PP, TypeID -> Vector(00002600, 00000089), gatling.http.cookies -> CookieJar(Map(CookieKey(jsessionid,**,/) -> StoredCookie(JSESSIONID=yffgfffgdfgjhfghjfghfghfgjhfsss, path=/, HTTPOnly,true,false,1665496888776),data2)}```

预期的

[
{"name": "PerfTest1445", "id" : 13424, "typeid": 4566}, // values should be from list session attributes
{"name": "PerfTest4344", "id" : 10011, "typeid": 3423},
{"name": "PerfTest0055", "id" : 45633, "typeid": 5456}
]

请提出一个解决方案,从以前的响应中保存的 Session 属性(Lists String)创建 Bulk Json 请求

【问题讨论】:

    标签: json scala performance-testing gatling scala-gatling


    【解决方案1】:

    您需要设置会话值

    session.set("data2", data2)
    

    并将data2 转换为字符串

    .body(StringBody(session =>
        s"""${session("data2").as[String]}""".stripMargin)).asJson)
    

    【讨论】:

      猜你喜欢
      • 2021-09-11
      • 2019-11-18
      • 1970-01-01
      • 1970-01-01
      • 2019-12-21
      • 2016-02-11
      • 2021-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多