scala gatling - 在测试期间提取 cookie 值字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22262595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 06:05:57  来源:igfitidea点击:

gatling - extract cookie value string during test

scalagatling

提问by locoMotion

My tests run fine but now I need multiple sessions running at once. I've tried getting the cookie value using headerRegex("Set-Cookie", "HOME_SESSID=(.*)").saveAs("homeSessid")but when I print this out its returning a value of com.excilys.ebi.gatling.http.check.HttpMultipleCheckBuilder@6075598

我的测试运行良好,但现在我需要同时运行多个会话。我已经尝试使用获取 cookie 值headerRegex("Set-Cookie", "HOME_SESSID=(.*)").saveAs("homeSessid")但是当我打印出来它返回一个值com.excilys.ebi.gatling.http.check.HttpMultipleCheckBuilder@6075598

I have no idea where this is coming from. My question is: what is going on?

我不知道这是从哪里来的。我的问题是:发生了什么?

Thanks.

谢谢。

edit: forgot to mention that the value its returning is not a session id and no matter what I use for the cookie name I get the same value.

编辑:忘了提到它返回的值不是会话 ID,无论我使用什么 cookie 名称,我都会得到相同的值。

edit (solution):

编辑(解决方案):

1) In the first .exec: .check( headerRegex("Set-Cookie", """HOME_SESSID=(.*dll/(\d+))""").saveAs("homeSessid") )

1) 在第一个 .exec 中: .check( headerRegex("Set-Cookie", """HOME_SESSID=(.*dll/(\d+))""").saveAs("homeSessid") )

2) Then to retrieve homeSessidin later http requests I did, for example: .post( session=>{session}.getAttribute("homeSessid").toString + "/some/relative/url" )

2)然后homeSessid在以后的http请求中检索我所做的,例如: .post( session=>{session}.getAttribute("homeSessid").toString + "/some/relative/url" )

回答by locoMotion

1) In the first .exec:

1) 在第一个 .exec 中:

.check( headerRegex("Set-Cookie", """HOME_SESSID=(.*dll/(\d+))""").saveAs("homeSessid") )

.check( headerRegex("Set-Cookie", """HOME_SESSID=(.*dll/(\d+))""").saveAs("homeSessid") )

2) Then to retrieve homeSessid in later http requests I did, for example:
.post( session=>{session}.getAttribute("homeSessid").toString + "/some/relative/url" )

2)然后在后来的http请求中检索homeSessid,例如:
.post( session=>{session}.getAttribute("homeSessid").toString + "/some/relative/url" )

回答by Stephane Landelle

Please properly read the Check documentation. Checks save data into the Session, so that's where you have to read. Here, you're just trying to print the extractor.

请正确阅读检查文档。检查将数据保存到会话中,因此您必须在那里阅读。在这里,您只是想打印提取器。

For example, after performing your check, you could add a exec(function), like:

例如,在执行检查后,您可以添加一个exec(function),例如:

.exec(session => {
  println(session("homeSessid").as[String]) // Gatling 2 API
  session
})