Cannot use currentLocationRegex (in Java)

Hello,

Actually I want to get the location from header response, so I’m using currentLocationRegex as mentioned in Gatling - HTTP Checks

But it seems Eclipse doesn’t accept it, it can’t recognize the function(even the package is already imported).

Here it’s the code that I’m using :

.exec(
http(“/auth/realms/bhs-ca/login-actions/authenticate?session_code=”+sessionUrl)
.post(authURL+“/auth/realms/bhs-ca/login-actions/authenticate?session_code=”+sessionUrl)
.formParam(“username”, “********”)
.formParam(“password”, “*******”)
.formParam(“reponse_type”, “code”)
.headers(headers_3)
.check(status().is(200))
.check(currentLocationRegex(“session_state=(.*)&code=(.*)”).captureGroups(2).saveAs(code))
)

I’ve used before regex to check a value in response body and it worked well!
Anyone has a solution for that?
Thank you

What doesn’t work exactly? Beware that as you have 2 capture groups, the extracted result is an array of Strings of length 2, so if you want to use Gatling EL to access the values, you’ll have to access by index, see Gatling - Expression Language

Also, .saveAs(code)) is wrong. It should be .saveAs("code"))

Do you have all the required imports?

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

Note that currentLocationRegex is a (static) method present in io.gatling.javaapi.http.HttpDsl.HttpDsl class.

Hello

Yeah the reason was the missing static package .

Thank you for the reply!