首页 > 解决方案 > getCookieValue 返回一个对象

问题描述

我已经使用 getCookieValue() 方法从会话中获取 cookie 值,它返回一个对象 io.gatling.http.action.cookie.GetCookieValueBuilder@2012cf26

.exec{session => {
       val cookie = getCookieValue(CookieKey("CookieKey"))
          println("Session cookie is :::::::::::::::::::::::::" + cookie.toString)
         session
     }}

应该获取 cookie 值而不是 io.gatling.http.action.cookie.GetCookieValueBuilder@2012cf26

标签: gatlingscala-gatling

解决方案


查看文档,getCookieValue 是一个 DSL 操作(正如您所发现的),它返回一个构建器,因此您需要在“执行”块中执行它 - 它旨在获取命名 cookie 并将其放入会话中。

所以如果你这样做了

.exec(getCookieValue(CookieKey("CookieKey")))

名为“CookieKey”的 cookie 的值将放在会话中的键“CookieKey”下。

您不能在会话函数中调用 DSL 方法 - 返回的构建器永远不会被调用


推荐阅读