Search code examples
testingcookiesjmetersingle-sign-onperformance-testing

Passing Cookie as a Request Header - SSO JMeter


I'm doing load testing for an application using JMeter for which I need to perform SSO authentication. I have to send a cookie as request header like I it is done below:

enter image description here

I have the value that I need to send, which I have extracted using Regular Expression Extractor on a previous Request. How can I achieve this?

I am using JMeter 3.1


Solution

    1. Add a cookie manager to your Test Plan
    2. Extract cookie with your Regular Expression Extractor to some variable (e.g. my_cookie)
    3. Add JSR223 Sampler and use this code

      import org.apache.jmeter.protocol.http.control.CookieManager; import org.apache.jmeter.protocol.http.control.Cookie;
      CookieManager manager = sampler.getCookieManager(); Cookie cookie = new Cookie("SESSION_COOKIE_NAME", "${my_cookie}", "${servername}", "/", false, 0); manager.add(cookie);

    More info for CookieManager class here