正则表达式在响应断言和正则表达式提取器Jmeter中失败

时间:2022-06-01 20:17:59

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.

我在Jmeter的内置正则表达式测试器中检查了这个正则表达式,它找到了标题。

(?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 个解决方案

#1


4  

try use:

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

(?<=

\ s *)(\ S。+ \ S)(?= \ s * </ title>)查找任何标题</p>

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

(?<=

\ s *)(我的标题)(?= \ s * </ title>)用于查找“我的标题”</p>

#2


2  

Try the following:

请尝试以下方法:

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

#3


0  

Try to use xpath instead.

尝试使用xpath代替。

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

使用像// title / text()和XPath Extractor这样的表达式来提取标题值,以及像// title [text()='My Title']这样的表达式以及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.

在这两种情况下,您必须确保使用Tidy(容错解析器)选项是CHECKED - 因为您正在解析HTML(而不是XML!..)响应。

#1


4  

try use:

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

(?<=

\ s *)(\ S。+ \ S)(?= \ s * </ title>)查找任何标题</p>

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

(?<=

\ s *)(我的标题)(?= \ s * </ title>)用于查找“我的标题”</p>

#2


2  

Try the following:

请尝试以下方法:

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

#3


0  

Try to use xpath instead.

尝试使用xpath代替。

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

使用像// title / text()和XPath Extractor这样的表达式来提取标题值,以及像// title [text()='My Title']这样的表达式以及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.

在这两种情况下,您必须确保使用Tidy(容错解析器)选项是CHECKED - 因为您正在解析HTML(而不是XML!..)响应。