Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

Jmeter response message assertion with special characters

I'm trying to perform a response message assertion on a response which contains special characters.

I looked at this issue:

Adding / at the start and end of the asserted string in Response Assertion in JMeter

But I still can't get it to match the assertion when it contains special characters. I've tried Text Response/Contains,Substring and Response Message/Contains,Substring, but none of them match.

My pattern to test is:

"v1.Accounts.Accounts.UpdateAccount failed due to validation errors:[MobileNumber] The field MobileNumber must be a string or array type with a maximum length of '20'."

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As per How to Use JMeter Assertions in Three Easy Steps article:

The Pattern can be either be:

  • a “string” for “Equals” or “Substring” clauses
  • a “Perl5-style” Regular Expression for “Contains” or “Matches” clauses

In case of Substring it should be pretty simple: just put the whole "pattern" into the "Patterns to test" field as it is and if response contains the pattern - the assertion will pass.

In case of Contains JMeter uses Perl5Matcher.contains() method under the hood so treats the "Pattern" as a regular expression. Therefore you will need to escape the special characters with the back slash like:

v1.Accounts.Accounts.UpdateAccount failed due to validation errors:[MobileNumber] The field MobileNumber must be a string or array type with a maximum length of '20'.

Just in case, when it comes to Perl-Compatible Regular Expressions you need to escape the following characters:

  • .^$*+?()[{| characters outside character classes
  • ^-] characters inside character classes

Also keep in mind that Regular Expressions are very fragile so any extra space, new line, tabulation, whatever will break them so if above recommendations won't help please update your question with at least partial (better full) response and specify what part of it you need to check, it might be the case it is much better to go for XPath Assertion


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...