场景中的加特林交换协议

问题描述 投票:7回答:1

我正在尝试创建一个加特林场景,该场景需要在测试过程中将协议切换到其他主机。用户旅程为

https://example.com/page1
https://example.com/page2
https://accounts.example.com/signin
https://example.com/page3

因此,作为一个单一场景的一部分,我需要以太网切换场景设置中定义的protocol,或切换协议中定义的baseUrl,但我不知道该怎么做。

基本情况可能看起来像

package protocolexample

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class Example extends Simulation {
  val exampleHttp = http.baseURL("https://example.com/")
  val exampleAccountsHttp = http.baseURL("https://accounts.example.com/")

  val scn = scenario("Signin")
    .exec(
      http("Page 1").get("/page1")
    )
    .exec(
      http("Page 2").get("/page2")
    )
    .exec(
      // This needs to be done against accounts.example.com
      http("Signin").get("/signin")
    )
    .exec(
      // Back to example.com
      http("Page 3").get("/page3")
    )

  setUp(
    scn.inject(
      atOnceUsers(3)
    ).protocols(exampleHttp)
  )
}

我只需要弄清楚如何进行第三步的以太交换主机或协议。我知道我可以创建多个场景,但这需要跨多个主机的单个用户流。

我已经尝试使用其他协议直接进行

exec(
  // This needs to be done against accounts.example.com
  exampleAccountsHttp("Signin").get("/signin")
)

导致]

protocolexample/example.scala:19: type mismatch;
 found   : String("Signin")
 required: io.gatling.core.session.Session
       exampleAccountsHttp("Signin").get("/signin")

并且还更改请求的基本URL

exec(
  // This needs to be done against accounts.example.com
  http("Signin").baseUrl("https://accounts.example.com/").get("/signin")
)

导致]

protocolexample/example.scala:19: value baseUrl is not a member of io.gatling.http.request.builder.Http

我正在尝试创建一个加特林场景,该场景需要在测试过程中将协议切换到其他主机。用户旅程为https://example.com/page1 https://example.com/page2 https:// ...

gatling
1个回答
11
投票

您可以使用绝对URI(包含协议)作为Http.getHttp.post等的参数。

class Example extends Simulation {
  val exampleHttp = http.baseURL("https://example.com/")
  val scn = scenario("Signin")
    .exec(http("Page 1").get("/page1"))
    .exec(http("Page 2").get("/page2"))
    .exec(http("Signin").get("https://accounts.example.com/signin"))
    .exec(http("Page 3").get("/page3"))
  setUp(scn.inject(atOnceUsers(3))
    .protocols(exampleHttp))
}
© www.soinside.com 2019 - 2024. All rights reserved.