Sin*_*zak 7 performance-testing gatling scala-gatling
我尝试了在 Gatling.io 上找到的不同方法,但我的问题仍然存在。当我发送 GET 请求时,有一个 API 以 JSON 格式返回一个简短的响应。
获取请求:
http://localhost:some_port/api/endpoint1?parameter1=1234¶meter2=5678
回复:
{“交易”:“6d638b9b-f131-41b1-bd07-0d1c6a1d4bcc”,“参考”:“some_text”}
我需要从响应中获取事务值并在另一个请求中使用它。
下一个请求:
http://localhost:some_port/api/endpoint2?transaction= $transactionValue¶meter=8
到目前为止,我已经尝试使用 regex、jsonPath 和 Int 或 String 值,但结果是 0 或 None。
到目前为止,这是我的场景代码:
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class class1 extends Simulation {
    val httpProtocol = http
        .baseURL("http://localhost:port")
        .inferHtmlResources()
        .acceptHeader("text/html,application/json")
        .acceptEncodingHeader("gzip, deflate")
        .acceptLanguageHeader("en-US,en;q=0.9,hr;q=0.8,sr;q=0.7,bs;q=0.6")
        .userAgentHeader("Mozilla/5.0 (X11; Fedora; Linux x86_64)")
    val headers = Map(
        "Content-Type" -> "application/json")
    val uri1 = "http://localhost:port/api/endpoint1"
    val uri2 = "http://localhost:port/api/endpoint2"
    val scn = scenario("getEndpoint1")
        .exec(http("endpoint1")
            .get("/api/endpoint1?parameter1=1234¶meter2=5678")
            .headers(headers)
      .check(jsonPath("$.transaction").findAll.saveAs("transaction")))
    .pause(3)
    .exec(session => {
      val transaction = session("transaction").asOption[String]
      session
    }).exec(http("endpoint2").get(uri2 +s"/transaction=${"transaction"}¶meter=8").headers(headers))
    setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
如果您有任何建议或看到我做错了什么,将不胜感激。