我是一家小公司的系统管理员,我正在尝试为我们的一个 Web 应用程序设置第一个带有 gatling 的测试。我知道一点 C 和 Java 语法以及正则表达式,但不知道 Scala。
我正在尝试测试的应用程序在 URL 中有 jsessionid(包括 jvmRoute),而不是在 cookie 中设置。根据 Stéphane Landelle在这里所写的内容,Gatling 应该自动记录每个用户会话的 jsessionid 并重放它,但这似乎只有在 jsessionid 设置为 Cookie 时才有效。
我从测试用例的 URL 中删除了实际记录的 jsessionid,理由是它在以后的任何尝试中都无效。当我运行测试时,Appserver 会生成一个新的 jsessionid,它不会包含在以后的任何调用中。
因此,我试图从初始重定向中抓取 jsessionid 并将其包含在任何未来的 URL 中。第一个响应中有一个 Location Header,如下所示:
Location https://URL/welcome.do;jsessionid=F97250BDC1576B5766CEFA56645EA3F4.node1
目前的代码如下所示:
.exec(http("Open Page")
.get("""/?code=abcdef""")
.headers(headers_0)
// Test extract jsessionid from URL
.check(headerRegex("Location", "jsessionid=(.*)")).saveAs("jsess")
.exec(http("welcome.do")
.post("""/welcome.do;jsessionid=${jsess}""")
...它不编译。
12:15:14.198 [ERROR] i.g.a.ZincCompiler$ - FirstTest.scala:53: value saveAs is not a member of io.gatling.http.request.builder.HttpRequestBuilder
12:15:14.199 [ERROR] i.g.a.ZincCompiler$ - .check(headerRegex("Location", "jsessionid=(.*)")).saveAs("jsess")
12:15:14.200 [ERROR] i.g.a.ZincCompiler$ - ^
12:15:14.261 [ERROR] i.g.a.ZincCompiler$ - one error found
如果我将一个右括号移到末尾:
.check(headerRegex("Location", "jsessionid=(.*)").saveAs("jsess"))
它编译但不执行所需的操作:
---- Errors --------------------------------------------------------------------
> No attribute named 'jsess' is defined 11 (78.57%)
> status.in(200,304,201,202,203,204,205,206,207,208,209), but ac 2 (14.29%)
tually found 404
> headerRegex((Location,jsessionid=(.*))).exists, found nothing 1 ( 7.14%)
================================================================================
那么,我如何记录 jsessionid 以便重用它?还是我在这里做错了?任何帮助表示赞赏。