title: JMeter Response Assertion: incorporating property into pattern test
body: <p>I'd like to setup a JMeter test plan to suggest whether a web site (URL) is Drupal-based (based completely on the HTTP response from the site) and compare it with existing data that I have on the environment. (I realize that using an HTTP approach, as opposed to say examining the site's file system, is "iffy" but I'm curious how useful the approach is)</p>
  
  <p>The JMeter command line might look like this:</p>
  
  <pre><code>JMeter -t "DrupalAssertions.jmx" -Jurl=http://my.dot.com -Jdrupal=true
  </code></pre>
  
  <p>where I provide the URL to test and an additional property "drupal" indicating my best guess on whether the site is Drupal-based.</p>
  
  <p>In my test plan, I add an HTTP Request to return the HTML content of the page for the URL. I'm then able to successfully add a Response Assertion that tests a pattern (say <code>(?i)(drupal)</code> for a sadly lacking pattern) to see if it's contained in the response.</p>
  
  <p>That much works fine, or as expected, but what I'd like to do is to compare the value of the "drupal" property against the result of that pattern test in that same Response Assertion. I know I'm missing something simple here, but I'm not seeing how to do that. </p>
  
  <p>I want to try to use an expression like this: </p>
  
  <pre><code>(?i)(drupal) == ${__P(drupal)} 
  </code></pre>
  
  <p>in a pattern, but that doesn't work. The name of the <a href="http://jmeter.apache.org/usermanual/component_reference.html#Compare_Assertion" rel="nofollow">Compare Assertion</a> looks promising, but I don't see how to incorporate the property into a comparison.</p>
  
  <p><strong>Update</strong>: The approach suggested by PMD UBIK-INGENIERIE does work. I used a Regular Expression Extractor like this:</p>
  
  <pre><code>&lt;RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Extract Drupal in Response" enabled="true"&gt;
    &lt;stringProp name="RegexExtractor.useHeaders"&gt;false&lt;/stringProp&gt;
    &lt;stringProp name="RegexExtractor.refname"&gt;drupalInResponse&lt;/stringProp&gt;
    &lt;stringProp name="RegexExtractor.regex"&gt;(.*drupal.*)&lt;/stringProp&gt;
    &lt;stringProp name="RegexExtractor.template"&gt;$0$&lt;/stringProp&gt;
    &lt;stringProp name="RegexExtractor.default"&gt;__false__&lt;/stringProp&gt;
    &lt;stringProp name="RegexExtractor.match_number"&gt;1&lt;/stringProp&gt;
  &lt;/RegexExtractor&gt;
  </code></pre>
  
  <p>followed by this BeanShell Assertion:</p>
  
  <pre><code>// Variable "drupalInResponse" is "__false__" by default
  if ( !(vars.get("drupalInResponse").equals("__false__") ) ) {
    vars.put("drupalInResponse","true");
  }
  else {
    vars.put("drupalInResponse","false");
  }
  
  print("\n\nThe value of property 'drupal' is: " + props.get("drupal") + "\n");
  print("\n\nThe value of variable 'drupalInResponse' is: " + vars.get("drupalInResponse") + "\n");
  
  if (vars.get("drupalInResponse").equals( props.get("drupal") ) ) { 
    print("Site Drupalness is consistent with your beliefs"); 
  } 
  else { 
    print("You're wrong about the site's Drupalness"); 
    Failure = true; 
    FailureMessage = "Incorrect Drupal assumption"; 
  }
  </code></pre>
  
  <p>In the Regular Expression Extractor, I'd set a default value that I felt wouldn't be matched by my pattern of interest, then did an ugly verbose Java comparison with the "drupal" property in the BeanShell Assertion.</p>
  
  <p>Wish somehow that the assertion could be made in a single component rather than it having two parts, but you can't argue with "working" :) </p>