1
votes

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

2
Are you trying to send additional cookie values apart from the ones already existing, manually?M Navneet Krishna

2 Answers

1
votes
  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

0
votes

You basically don't need to extract anything, just add HTTP Cookie Manager to your Test Plan and it will automatically handle cookies.

If you need certain cookie value to use it somewhere else you can add the next line to user.properties file (lives in JMeter's "bin" folder)

CookieManager.save.cookies=true

and restart JMeter to pick the property up. Once done you will be able to refer cookie value as ${COOKIE_mc} where required.

See Using the HTTP Cookie Manager in JMeter for more information.