Jmeter - HTTP Cookie Manager and HTTP Header Manager conflict

Viewed 113

Hello everyone.

I am working with JMeter and I found one conflict between HTTP Cookie Manager and HTTP Header Manager. I am not sure how to process it.

What should be done:

I need to add extra data into the "Cookie Data:" section from the "Request Body".

I found this solution:

  1. Add "HTTP Header Manager".
  2. Add name: "Cookie" with needed value. enter image description here
  3. As you can see from the screenshot - I am adding "Cookie" values in the "HTTP Header Manager". As a result, I get this: enter image description here
  4. As you can see from the screenshot - I was able to add data into the "Cookie Data:" request from the "Request Body".

What's the problem:

  1. I use "HTTP Cookie Manager" too.
  2. When I execute a sample with data that came from the "HTTP Cookie Manager" and data came from the "HTTP Header Manager" - JMeter doesn't add data from the "HTTP Header Manager". enter image description here
  3. As you can see from the screenshot - I add the "Cookie" header into the "HTTP Header Manager".
  4. As a result, I am expecting to get this data into the "Cookie Data" area of the request. But... I see only the data came from the "HTTP Cookie Manager". enter image description here
  5. As you can see from the screenshot - added data from the "HTTP Header Manager" is missing in this "Cookie Data" section from the request.

I researched in google and try a lot of things - but without result.

2 Answers

Headers will be available through the Request Header tab in the Request area.

enter image description here

If you want to add custom cookies, you can add them through a Cookie Manager

enter image description here

You can view the cookies through the Request tab in the View Result Tree

enter image description here

I don't think you can use both, you have 2 options:

  1. Completely remove HTTP Cookie Manager and perform manual correlation of cookies by extracting the Set-Cookie header value, perform the necessary amendments, construct the needed cookie and use HTTP Header Manager to set the desired Cookie header value

  2. Use JSR223 PreProcessor and modify the cookie value using Groovy code on the fly. Something like:

    def manager = sampler.getCookieManager()
    
    0.upto(manager.getCookieCount(), { index ->
        def cookie = manager.get(index)
        if (cookie.getName() == 'cookie_you_are_looking_for') {
            cookie.setValue(cookie.getValue() + 'foo')
        }
    })
    
    sampler.setCookieManager(manager)
    

    More information: Modifying Cookies in JMeter with Groovy

Related