Sharing cookie values between thread groups in JMeter

前端 未结 8 2129
暗喜
暗喜 2020-12-08 11:32

I have the following setup:

Thread A
  - Http Cookie Manager
  - Login Page
Thread B
  - Http Cookie Manager
  - Page to hit
  - Another page to hit
         


        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 12:12

    CookieManager does not share cookies between threads. For some reason @ClarenceKlopfstein's method didn't work for me (jmeter 3.0). For some reason "${COOKIE_}" didn't seemed to evaluate the string passed.

    So, here's another solution to do a Login, and then pass the .ASPXAUTH cookie. It should work without any configuration changes: In a setUp Thread Group (important):

    BeanShell PostProcessor:
     import org.apache.jmeter.protocol.http.control.CookieManager;
     import org.apache.jmeter.protocol.http.control.Cookie;
    
     CookieManager manager = ctx.getCurrentSampler().getCookieManager();
     Cookie cookie = manager.get(3); //Find the '.ASPXAUTH' cookie
     log.info("Cookie:" + cookie);
     props.put("MyCookie",cookie.getValue());
    

    Then in a normal Thread Group:

    BeanShell PreProcessor:
     import org.apache.jmeter.protocol.http.control.CookieManager;
     import org.apache.jmeter.protocol.http.control.Cookie;
     CookieManager manager = sampler.getCookieManager();
     Cookie cookie = new Cookie(".ASPXAUTH",props.get("MyCookie"),"","/",false,0);
     manager.add(cookie);
    

提交回复
热议问题