【问题标题】:Retrieve cookie value with Gatling使用 Gatling 检索 cookie 值
【发布时间】:2021-06-02 22:18:54
【问题描述】:

我对 Gatling 有点陌生,我想从 cookie 中获取价值。我尝试了很多方法来做到这一点,但我可能会误解一些东西。

首先,我正在向我的身份验证 API 发出一个发布请求,该 API 创建了我想要的 cookie。

然后我试过了:

   .exec {
      session => println(session)
      println(session.attributes)

      // return a Some object whose value is of type CookieJar (with apparently private access)
      println(session.attributes.get("gatling.http.cookies"))

      /*
      // Doesn't compile due to CookieJar being private
      val value: CookieJar = session.attributes.get("gatling.http.cookies") match {
        case None => None
        case Some(cj: CookieJar) => cj
      }
      print(value)
      */

      // return a GetCookieBuilder which doesn't seem really useful
      println(getCookieValue(CookieKey("COOKIE_NAME")))

      session
    }

你有什么想法吗?

【问题讨论】:

    标签: scala http gatling


    【解决方案1】:

    getCookieValue 是 DSL 组件,不是您可以在自己的函数中调用的方法。

    它被用作场景步骤,从内部 CookieJar 中提取 cookie 值并将其作为专用属性复制到 Session 中。

    exec(getCookieValue(CookieKey("COOKIE_NAME")))
    .exec { session =>
      println(session("COOKIE_NAME").as[String])
      session
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 2016-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多