我想执行两个应该一个接一个地执行的场景,并且第一个场景“生成”的数据应该用作第二个场景的基础。
因此,例如可以清算信用卡。第一种情况是在卡上授权/保留一定金额:
val auths = scenario("auths").during(durationInMinutes minutes) {
feed(credentials)
.feed(firstNames)
.feed(lastNames)
.feed(cards)
.feed(amounts)
.exec(http("send auth requests")
.post(...)
.check(...))}
第二个是从信用卡中获取/获取金额:
val caps = scenario("caps").during(durationInMinutes minutes) {
feed(credentials)
.feed(RESPONSE_IDS_FROM_PREVIOUS_SCENARIO)
.exec(http("send auth requests")
.post(...)
.check(...))}
我最初考虑过在检查时使用saveAs(...)选项,但我发现保存的字段仅对给定的会话有效。
所以基本上我想保留我从auths场景中获得的ID并在大写场景中使用它们。
我无法在一个场景中执行这两个步骤(saveAs可以为此工作),因为我对两个场景都有不同的要求。
答案 0 :(得分:0)
引用文档:“目前我们的模拟是一个很大的单一场景。首先让我们将它分解为可组合的业务流程,类似于使用Selenium的PageObject模式。这样,您将能够轻松地重用某些部分和在不牺牲维护的情况下建立复杂的行为。“在gatling.io/Advanced Tutorial
因此,您不存在场景之间通信的内置机制(AFAIK)。建议以您可以随后将调用与URI结合的方式构建代码。在你的情况下(除了实现细节)你应该有这样的东西:
val auths = feed(credentials)
.feed(firstNames)
.feed(lastNames)
.feed(cards)
.feed(amounts)
.exec(http("send auth requests")
.post(...)
.check(...) // extract and store RESPONSE_ID to session
)
val caps = exec(http("send auth requests")
.post(...) // use of RESPONSE_ID from session
.check(...))
然后你的场景看起来像这样:
val scn = scenario("auth with caps").exec(auths, caps) // rest omitted
构建代码的更好方法可能就是使用对象。请参阅提到的教程链接。
更多说明性示例(编译,但我没有运行它,而域名是foo.com):
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class ExampleSimulation extends Simulation {
import scala.util.Random
import scala.concurrent.duration._
val httpConf = http.baseURL(s"http://foo.com")
val emails = Iterator.continually(Map("email" -> (Random.alphanumeric.take(20).mkString + "@foo.com")))
val names = Iterator.continually(Map("name" -> Random.alphanumeric.take(20).mkString))
val getIdByEmail = feed(emails)
.exec(
http("Get By Email")
.get("/email/$email")
.check(
jsonPath("userId").saveAs("anId")
)
)
val getIdByName = feed(names)
.exec(
http("Get By Name")
.get("/name/$name")
.check(
jsonPath("userId").is(session =>
session("anId").as[String]
)
)
)
val scn = scenario("Get and check user id").exec(getIdByEmail, getIdByName).inject(constantUsersPerSec(5) during (5.minutes))
setUp(scn).protocols(httpConf)
}
希望这是你正在寻找的。 p>