带有特殊字符的Jmeter响应消息断言 [英] Jmeter response message assertion with special characters

查看:680
本文介绍了带有特殊字符的Jmeter响应消息断言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对包含特殊字符的响应执行响应消息断言.

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

我看了这个问题:

但是当它包含特殊字符时,我仍然无法使其与断言相匹配.我已经尝试过文本响应/包含,子字符串"和响应消息/包含,子字符串",但是都不匹配.

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.

我要测试的模式是:

由于验证错误,v1.Accounts.Accounts.UpdateAccount失败:[MobileNumber]字段MobileNumber必须是最大长度为'20'的字符串或数组类型."

"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'."

推荐答案

按照如何在三个简单步骤中使用JMeter断言文章:

模式可以是:

  • 等于"或子字符串"子句的字符串"
  • 包含"或匹配"子句的"Perl5样式"正则表达式

对于 Substring ,它应该非常简单:只需将整个模式"原样放在要测试的模式"字段中,如果响应包含该模式,则断言将通过.

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.

对于包含的情况,JMeter使用

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'.

以防万一,当涉及到与Perl兼容的正则表达式时,您需要进行转义以下字符:

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

还请记住,正则表达式非常脆弱,因此任何多余的空格,换行符,制表符,任何会破坏它们的内容,因此,如果以上建议对您没有帮助,请至少使用部分(较好的)答复来更新您的问题,并指定您需要检查其中的哪一部分,这可能是最好的选择 XPath断言

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

这篇关于带有特殊字符的Jmeter响应消息断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆