简体   繁体   English

Gatling:从 foreach 循环中保存的“findAll”列表访问变量

[英]Gatling: Access variables from saved “findAll” list in foreach loop

I'm new to Gatling and Scala, and I had a hopefully quick and basic question about how to access the elements that are saved as from a findAll in the previous request.我是 Gatling 和 Scala 的新手,我有一个关于如何访问上一个请求中从findAll中保存的元素的快速而基本的问题。

The regex in the below code matches multiple button values.以下代码中的正则表达式匹配多个按钮值。 I eventually want to find the "max" button value (by something I'll come up with later), and based on that use that button in subsequent requests.我最终想找到“最大”按钮值(我稍后会想出的东西),并基于此在后续请求中使用该按钮。 However, I'm unable to actually access the values in button_list .但是,我无法实际访问button_list中的值。 In the terminal when I try to print the values, the values don't get substituted and literally print like this for each button:在终端中,当我尝试打印值时,这些值不会被替换,并且对于每个按钮都像这样打印:

Button ${count}: ${button}
Button ${count}: ${button}

Here's the snippet producing this:这是产生这个的片段:

...
        .exec(http("click_ok")
            .post("www.foo.com")
            .headers(headers_0)
            .formParam("_flowExecutionKey", "${flow_execution_key}")
            .formParam("_eventId_submit", "${_eventId_submit}")
            .check(regex("""foo(.*?)bar""").findAll.saveAs("button_list"))).exitHereIfFailed
        .pause(1)
        .foreach("${button_list}", "button", "count") {
            exec(session => {
                println("Button ${count}: ${button}")
            session})
        }
...

When I see the session print out in the logs, I can see that the buttons have matched and the session contains a list like the following, so I know there are successful matches:当我在日志中看到session打印出来时,我可以看到按钮已经匹配,并且 session 包含如下列表,所以我知道匹配成功:

button_list -> List(c11/98/280, c11/98/390)

Anyone have an example or know what I'm doing wrong?任何人都有一个例子或知道我做错了什么? Thanks!谢谢!

As explained in the official documentation , Gatling Expression Language is not something that magically works anywhere.正如官方文档中解释的那样,加特林表达式语言并不是在任何地方都能神奇地工作的东西。 It only works when passing such String to a Gatling DSL method, not in your own code.它仅在将此类 String 传递给 Gatling DSL 方法时才有效,而不是在您自己的代码中。 You must use the Gatling Session API .您必须使用加特林 Session API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM