简体   繁体   中英

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.

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 . 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:

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. You must use the Gatling Session API .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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