问题描述
当我使用 gatling(3.4.2) 进行负载测试时,我试图将 cookie 添加到对服务器的调用之一
我有 2 个服务器调用。第一个设置 cookie,我需要将它传递给下一个调用。我不知道它是否会自动通过,但在我的情况下,我没有看到 cookie 值在第二次调用中到达服务器。
当我打印会话时,我会看到此信息
Session(
My test scenario message,2,Map(
gatling.http.ssl.sslContexts -> io.gatling.http.util.SslContexts@786b59ec,gatling.http.cache.dns -> io.gatling.http.resolver.ShufflingNameResolver@209aa7d3,gatling.http.cache.baseUrl -> http://localhost:<port>,gatling.http.cookies -> CookieJar(Map(CookieKey(mycookiename,localhost,/) -> StoredCookie(MyCookieName=Q10nIQhHfIeZZ.kybQNzXg,domain=localhost,path=/,secure,HTTPOnly,SameSite=None,false,1616889603472)))),KO,List(),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$7409/1860226084@4f59ec6b,io.netty.channel.nio.NioEventLoop@40811b47
)
在 session.attributes
地图内的“gatling.http.cookies”键下,我看到 mycookiename
的 cookie 值
我尝试按照 gatling 文档中建议的方式进行设置 - https://gatling.io/docs/current/http/http_helpers/#getting-a-cookie-value 但以下方法均无效。
.exec {
getCookieValue(CookieKey(name = "mycookiename"))
}
.exec {
getCookieValue(CookieKey(name = "MyCookieName"))
}
.exec {
getCookieValue(CookieKey(name = "mycookiename").withDomain("localhost").withPath("/"))
}
.exec {
getCookieValue(CookieKey(name = "MyCookieName").withDomain("localhost").withPath("/"))
}
我可以看到,当我尝试输入一些任意值时,该值会在后续调用中到达服务器
.exec(addCookie(Cookie("MyCookieName","3EB3LA47Bi1V3Y20YHxVqg")))
这意味着,如果我使用 addCookie
设置 cookie,它会到达服务器,但不知何故我无法使用 getCookieValue
设置它。此外,由于 CookieJar
和所有相关类都设为私有,因此我无法从 session.attributes.get("gatling.http.cookies")
手动执行此操作。有人可以建议我如何继续吗?
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)