title: JMeter - Verify a Specific Cookie Value was Used?
body: <p>So in my Test Plan I have a Cookie Manager setup inside my Thread Group which sets a specific Cookie value for 1 Cookie. Let's call it, <strong><em>MYID</em></strong>. I'm trying to figure out a way to verify that this specific Cookie's value was used to complete this one HTTP Request, because if I set my MYID to a specific value *(<em>which actually tells which web server to go to)</em>, say to <em>"Server1"</em>, but <em>Server1</em> is down, unavailable, etc... HAProxy should change this and send you to <em>Server2</em>.</p>
  
  <p>So basically I want to try and make sure that Cookie <strong><em>MYID</em></strong> was equal to <strong><em>"Server1"</em></strong> all the way through the HTTP Request.</p>
  
  <p>I am trying to use a BeanShell PostProcessor to verify the Cookie's value after the request is ran, but when I tried using some code I have inside a PreProcessor that sets a cookie in a different Test Plan of mine I get an error saying:</p>
  
  <p><strong>Error Message:</strong></p>
  
  <blockquote>
    <p>Typed variable declaration : Attempt to resolve method: getCookieManager() on undefined variable or class name: sampler</p>
  </blockquote>
  
  <p><br>
  And below here is the Code slightly modified from a BeanShell PreProcessor in another Test Plan I have...</p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>import org.apache.jmeter.protocol.http.control.Cookie;
  import org.apache.jmeter.protocol.http.control.CookieManager;
  
  CookieManager manager = sampler.getCookieManager();
  
  for (int i = 0; i &lt; manager.getCookieCount(); i++) {
      Cookie cookie = manager.get(i);
      if (cookie.getName().equals("MYID"))    {
          if (cookie.getValue().equals("Server1")) {
              log.info("OK: The Cookie contained the Correct Server Number...");
          } else {
              log.info("ERROR: The Cookie did NOT contain the Correct Server Number...");
          }
          break;
      }
  }
  </code></pre>
  
  <p>For the error, I was thinking the "sampler" object was no longer available since the Request was already run, or something along those lines, but I'm not sure...</p>
  
  <p>Or, is there another JMeter object I should be using instead of the "BeanShell PostProcessor" in order to verify the Cookie's value was correct..?</p>
  
  <p>Any thoughts or suggestion would be greatly appreciated!</p>
  
  <p>Thanks in Advance,<br>
  Matt</p>