abstracta / jmeter-java-dsl

Simple JMeter performance tests API
https://abstracta.github.io/jmeter-java-dsl/
Apache License 2.0
477 stars 59 forks source link

Add support to add custom cookies in the cookie manager #178

Open andy-tarr opened 1 year ago

andy-tarr commented 1 year ago

Add support to the cookie manager to create custom cookies

rabelenda commented 1 year ago

Thank you Andy, that is a standing feature.

What do you think something like this:

testPlan(
        threadGroup(1, 1,
            httpCookies()
               .add(new Cookie("MyCookie", "val")
                 .domain("myservice.com")
                 .path("/users")
                 .secure(true)
                 .expires(Instant.now().plusSeconds(30))
               )
            httpSampler("http://myservice.com"),
        )
    ).run();

We could internally implement it with a jsr 223 sampler, and would have the advantage, over JMeter cookies manager way of setting cookies, that you can directly control at what point in test plan you actually want the cookies to be set. This would avoid cookies being set in requests which shouldn't (and may make the test plan behave in unexpected way) or require some workaround, like adding a controller, to limit the scope of the cookie manager to get a similar effect.

We could even in the future use same approach add methods to remove some particular cookie, or explicitly clear all cookies.

andy-tarr commented 1 year ago

I think this approach looks great