Sharing cookie values between thread groups in JMeter

前端 未结 8 2152
暗喜
暗喜 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:09

    I should have been a little more clear in my question, but we got this fixed. Here is our solution:

    Http Cookie Manager
    Thread A - 1 Thread - 1 Loop Count
      - Login Page
          - BeanShell PostProcessor
                - props.put("MyCookie","${COOKIE_}");
    Thread B - 50 Threads - Infinite Loop Count
      - 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("",props.get("MyCookie"),"","",false,0);
            manager.add(cookie);
      - Page to hit
      - Another page to hit, repeat as needed
    

    Then there is a configuration change for JMeter needed:

    Open up the jmeter.properties file and go to the line "CookieManager.save.cookies=false" and make it = true.

    This will allow the login cookie in the first thread to be used in the second thread.

提交回复
热议问题