【问题标题】:gatling - extract cookie value string during testgatling - 在测试期间提取 cookie 值字符串
【发布时间】:2014-03-07 23:18:47
【问题描述】:

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

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

谢谢。

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

编辑(解决方案):

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

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

【问题讨论】:

    标签: scala gatling


    【解决方案1】:

    1) 在第一个 .exec 中:

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

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

    【讨论】:

    • 2) 下面会更简单:.post("${homeSessid}/some/relative/url")
    • @Stephane。谢谢,我之前试过这个,但它没有被评估为会话值,而只是打印字符串文字。但它现在似乎正在工作。不知道为什么。谢谢:)
    • 我还有一个问题 - 我在 url 的参数列表中有一个“/”,我不想编码为“%2F”,因为它代表一个目录。有什么办法可以强制 scala/gatling 不对其进行编码?
    【解决方案2】:

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

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

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

    【讨论】:

    • 您好,感谢您的回答。我想在未来的 http 请求中使用会话值。我该怎么办?
    • 您确实必须阅读文档,您所问问题的所有答案都在那里。
    • 我的检查语句正在运行:.check( headerRegex("Set-Cookie", "HOME_SESSID=(.*)").saveAs("homeSessid") ),当我执行它时它就可以了。但是,当我添加您描述的 exec 函数时,我在编译时遇到“类型不匹配”错误:found : java.lang.String("homeSessid") required: com.excilys.ebi.gatling.core.Predef.Session
    • 我的检查语句:.check( headerRegex("Set-Cookie", "HOME_SESSID=(.*)").saveAs("homeSessid") ) 当我尝试使用"$(homeSessid)" 打印出homeSessid 时,它只会打印字符串文字
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    相关资源
    最近更新 更多