gpt4 book ai didi

场景期间的加特林交换机协议(protocol)

转载 作者:行者123 更新时间:2023-12-04 10:48:20 24 4
gpt4 key购买 nike

我正在尝试创建一个 Gatling 场景,该场景需要在测试期间将协议(protocol)切换到不同的主机。用户旅程是

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

所以作为单一场景的一部分,我需要切换 protocol在场景设置中定义,或切换 baseUrl在协议(protocol)上定义,但我不知道如何做到这一点。

一个基本的场景可能看起来像

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)
)
}

我只需要弄清楚如何为第三步切换主机或协议(protocol)。我知道我可以创建多个场景,但这需要是跨多个主机的单个用户流。

我试过直接使用其他协议(protocol)

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

最佳答案

您可以使用绝对 URI(包含协议(protocol))作为 Http.get 的参数, Http.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))
}

见: https://gatling.io/docs/current/cheat-sheet/#http-protocol-urls-baseUrl

baseURL: Sets the base URL of all relative URLs of the scenario on which the configuration is applied.

关于场景期间的加特林交换机协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36403068/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com