【问题标题】:Conditionals based on Gatling scenarios基于加特林场景的条件
【发布时间】:2016-07-13 11:05:35
【问题描述】:

我想知道加特林是否可以使用条件(基于场景)。

我在 Gatling 2.1.7 中有一个登录帖子,如下所示:

.exec(http("User login")
            .post("/api/user_login")
            .headers(Headers.headers_1))

还有几个场景:

val user1 = scenario("user1").exec(
    Action.login,
    Action.addDocument,
    Action.logout
)
val user2 = scenario("user2").exec(
    Action.login,
    Action.deleteDocument,
    Action.logout
)

setUp(
    user1.inject(atOnceUsers(1))
    user2.inject(atOnceUsers(1))
).protocols(httpProtocol)

每个用户都有单独的登录凭据(在标题中),并且只能以特定方式与应用交互。

那么(在伪代码中)加特林支持这样的东西吗?

.exec(http("User login")
            .post("/api/user_login")
            .doIf(scenario == "users1") {
                .headers(Headers.headers_1) // login info for user1
            }
            .doIf(scenario == "users2") {
                .headers(Headers.headers_2) // login info for user2
            })

【问题讨论】:

    标签: scala gatling


    【解决方案1】:

    可以从io.gatling.core.session.Session获取scenarioName

    http("User login")
        .post("/api/user_login")
        .headers(if(session.scenarioName.equals("user1")) Headers.headers_1 else Headers.headers_2) 
      session
    

    但你可以选择使用参数actions

    def login(header: Map[String, String]) = {
      http("User login")
        .post("/api/user_login")
        .headers(header)
    }
    //...
    Action.login(Headers.headers_1),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多