4

The response data in my test has this line:

<head><title>
    My Title
</title><meta charset

I checked this regex in the inbuilt regex tester in Jmeter and it found the title.

(?m)(?is)<title>\n\tMy Title\n</title>

However, when I use it as a response assertion, the assertion always fails.

I have tried all settings in "Apply to" section. "Text Response" is selected for "Response Field to Test". I selected "Contains" for "Pattern Matching Rules".

I have a very similar issue with a regular expression extractor as well - the selected expression passes in the tester, but fails with regular expression extractor.

I believe it may have something to do with the multi-line nature of the response.

Any pointers?

Anand
  • 193
  • 2
  • 9

3 Answers3

4

try use:

(?<=<title>\s*)(\S.+\S)(?=\s*</title>) for find any title

(?<=<title>\s*)(My Title)(?=\s*</title>) for find 'My title'

burning_LEGION
  • 13,246
  • 8
  • 40
  • 52
  • I get this error: `Assertion failure message: Bad test configuration org.apache.oro.text.MalformedCachePatternException: Invalid expression: (?<=\s*)(\S.+\S)(?=\s*) Sequence (?<...) not recognized` – Anand Jul 01 '12 at 11:16
  • try without (?<=) and (?=) `\s*(My Title)\s*` – burning_LEGION Jul 01 '12 at 11:19
2

Try the following:

Regular Expression: <title>(.+?)</title>
Template: $1$
Match: 1
Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
Diaes
  • 371
  • 4
  • 9
0

Try to use xpath instead.

Use expression like //title/text() along with XPath Extractor - to extract title value, - and expression like //title[text()='My Title'] along with XPath Assertion.

In both the cases you have to ensure that that Use Tidy (tolerant parser) option is CHECKED - since you are parsing HTML (not XML!..) response.

Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
  • xpath assertion is more resource consuming in comparison to response assertion – Tarun Aug 31 '15 at 11:00
  • ...as well as using regular expressions to parse xhtml may appear less generic, reliable and handy way to do things and create sustained and maintainable tests: http://stackoverflow.com/a/1732454/993246. Anyway it depends only on the situation and your choice. – Aliaksandr Belik Aug 31 '15 at 13:57