I have lately been working with Apache JMeter to generate reports based on the data returned from a series of web service calls (details on how to do this will be in a later posting).
Apache JMeter is an Apache project that is predominately used as a load testing tool for analyzing and measuring the performance of a variety of services. Its main focus is web applications.
I have been struggling for quite some time at how to extract the response of an HTTP Sampler into a variable for later use. In cases where the response is xml, I would just use an XPath Extractor but in this case, the response from the service is HTML HTML is not guaranteed to be well formed xml (XML does not permit end-tag minimization (missing
, etc), unquoted attribute values, and a number of other SGML shortcuts) so an XPath Extractor would periodically throw errors.
The problem I have been struggling with is how to use a Regular Expression Extractor to save the entire HTTP Sampler response to a variable in JMeter. The documentation for the Regular Expression Extractor states that it allows the user to extract values from a server response using a Perl-type regular expression.
After much trial and error, here is the expression that I came up with:
() – grouping
? – Enables the embedded pattern-,attach modifiers. ?i enables case insensitivity, ?m enables multiline treatment of the input, ?s enables single line treatment of the input (it affects how the ‘.’ meta-character is interpreted), and ?x enables extended whitespace comments. We are using ?s to allow the use of ‘.’ to match a newline character.
s – Allows use of . to match a newline character
^ – matches the beginning of a string or line
. – matches everything. Usually this would exclude \n but since we have prefaced our expression with ?s it includes even these.
Here is how I configured my Regular Expression Extractor