Question

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)

The JMeter command line might look like this:

JMeter -t "DrupalAssertions.jmx" -Jurl=http://my.dot.com -Jdrupal=true

where I provide the URL to test and an additional property "drupal" indicating my best guess on whether the site is Drupal-based.

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 (?i)(drupal) for a sadly lacking pattern) to see if it's contained in the response.

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.

I want to try to use an expression like this:

(?i)(drupal) == ${__P(drupal)} 

in a pattern, but that doesn't work. The name of the Compare Assertion looks promising, but I don't see how to incorporate the property into a comparison.

Update: The approach suggested by PMD UBIK-INGENIERIE does work. I used a Regular Expression Extractor like this:

<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Extract Drupal in Response" enabled="true">
  <stringProp name="RegexExtractor.useHeaders">false</stringProp>
  <stringProp name="RegexExtractor.refname">drupalInResponse</stringProp>
  <stringProp name="RegexExtractor.regex">(.*drupal.*)</stringProp>
  <stringProp name="RegexExtractor.template">$0$</stringProp>
  <stringProp name="RegexExtractor.default">__false__</stringProp>
  <stringProp name="RegexExtractor.match_number">1</stringProp>
</RegexExtractor>

followed by this BeanShell Assertion:

// 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"; 
}

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.

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" :)

Was it helpful?

Solution

You can use a regexp extractir with your first pattern

Then use a Beanshell assertion which will use your variable and compare it to drupal property.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top