withDefault Check Transforming feature


As per the documentation, “withDefault” set the value to the default value if nothing matches. If there’s a match, then I am expecting the matched value to be used.

But, I see extract statements always save the default value even if extracts capture the intended value.

                    .formParam("emailInput", "XYZ")
                    .formParam("passwordInput", "***")
                    .formParam("loginButton", "Log In")
                    .check(regex("HTTP/1.1 (.*?) OK").withDefault("confirm").optional().saveAs("Response_Code"))

Sample Response:

HTTP/1.1 200 OK
Date: Mon, 01 Aug 2022 15:48:55 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 8445
Connection: keep-alive
Cache-Control: no-cache
Pragma: no-cache

Expected Response_Code value: 200 ( regex matches the response )
Actual Response_Code value : confirm ?? Why it is saving default value

I think this is the reason:

So when you looking in Debug on Gatling, Response looks like:

HTTP response:
        200 OK
        Content-Type: application/json
        Matched-Stub-Id: 33ec48b6-7167-47dc-b7a7-d141086558f3
        Vary: Accept-Encoding, User-Agent
        Transfer-Encoding: chunked


so Status Code isn’t part of body.

I don’t know what you want to do but if you need Status Code you can do:


Thanks @GeMi , yes I was able to capture the status using .check(status().saveAs(“Response_Code”))

But, unfortunately request under below doIfEquals is not getting executed.

Response Code captured =200 and I am expecting below statement to pass and do the stuff. But neither the flow enters this block nor do I see any failure related to doIfEquals in the logs.

.doIfEquals("#{Response_Code}","200").then( "do stuff"

Okay Status in int I believe and below code is working

.doIfEquals("#{Response_Code}",200).then( "do stuff"
1 Like

Just an opinion … conditions pass/fail status should be shown the in Trace logs.