Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...