4
votes

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?

3

3 Answers

4
votes

try use:

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

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

2
votes

Try the following:

Regular Expression: <title>(.+?)</title>
Template: $1$
Match: 1
0
votes

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.