情景期间的 Gatling 开关协议
Gatling switch protocols during scenario
我正在尝试创建一个 Gatling 场景,它需要在测试期间将协议切换到不同的主机。用户旅程是
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)
)
}
我只需要弄清楚如何在第 3 步中切换主机或协议。我知道我可以创建多个场景,但这需要是跨多个主机的单个用户流。
我试过直接使用其他协议
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(包含协议)作为 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.
我正在尝试创建一个 Gatling 场景,它需要在测试期间将协议切换到不同的主机。用户旅程是
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)
)
}
我只需要弄清楚如何在第 3 步中切换主机或协议。我知道我可以创建多个场景,但这需要是跨多个主机的单个用户流。
我试过直接使用其他协议
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(包含协议)作为 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.