JMeter响应断言失败模式

时间:2017-03-28 12:33:39

标签: regex xml jmeter

适用于:主要样本和子样本 要测试的响应字段:文本响应 模式匹配规则:包含

要测试的模式:

<?xml version="1.0" encoding="ISO-8859-5" standalone="yes"?>
<CIT_REQUEST>
    <SYSTEM>
        <CIT_Version Value="1.0"/>
        <ERR Value=""/>
        <FORMAT Value="XML"/>
        <INTERFACE_RET Value=""/>
        <MAIN_ID Value="37407427745"/>
        <MSG_ID Value=".*"/> - regexp not working
        <SYNC Value="N"/>
        <Version Value="002"/>
    </SYSTEM>
    <DATA>
        <PACKAGE_B64>
    PE1zZ0NsaWVudEFkZFJzIHhtbG5zPSJ1cm46c2NoZW1hcy1wc2l0LXJ1OmdwIj48
UnFVSUQ+Mzc0MDc0Mjc3NDU8L1JxVUlEPjxScVJlc3VsdD48U3RhdHVzPk9rPC9T
dGF0dXM+PENvbW1lbnQ+TmV3PC9Db21tZW50PgoJCQk8L1JxUmVzdWx0PjxSZXN1
bHQ+PENsaWVudElkPjc3MzY0NTgyPC9DbGllbnRJZD48SW50ZXJuYWxfQ2xpZW50
SWQ+MjY3PC9JbnRlcm5hbF9DbGllbnRJZD4KCQkJPC9SZXN1bHQ+CgkJPC9Nc2dD
bGllbnRBZGRScz4=

</PACKAGE_B64>
    </DATA>
</CIT_REQUEST>

响应:

<?xml version="1.0" encoding="ISO-8859-5" standalone="yes"?>
<CIT_REQUEST>
    <SYSTEM>
        <CIT_Version Value="1.0"/>
        <ERR Value=""/>
        <FORMAT Value="XML"/>
        <INTERFACE_RET Value=""/>
        <MAIN_ID Value="37407427745"/>
        <MSG_ID Value="F3C826680F5E45C3AA97DEE4DA51F54B"/> - MSG_ID Value changes for each request
        <SYNC Value="N"/>
        <Version Value="002"/>
    </SYSTEM>
    <DATA>
        <PACKAGE_B64>
    PE1zZ0NsaWVudEFkZFJzIHhtbG5zPSJ1cm46c2NoZW1hcy1wc2l0LXJ1OmdwIj48
UnFVSUQ+Mzc0MDc0Mjc3NDU8L1JxVUlEPjxScVJlc3VsdD48U3RhdHVzPk9rPC9T
dGF0dXM+PENvbW1lbnQ+TmV3PC9Db21tZW50PgoJCQk8L1JxUmVzdWx0PjxSZXN1
bHQ+PENsaWVudElkPjc3MzY0NTgyPC9DbGllbnRJZD48SW50ZXJuYWxfQ2xpZW50
SWQ+MjY3PC9JbnRlcm5hbF9DbGllbnRJZD4KCQkJPC9SZXN1bHQ+CgkJPC9Nc2dD
bGllbnRBZGRScz4=

</PACKAGE_B64>
    </DATA>
</CIT_REQUEST>

断言失败消息:

Assertion error: false
Assertion failure: true
Assertion failure message: Test failed: text expected to contain /<?xml version="1.0" encoding="ISO-8859-5" standalone="yes"?>
<CIT_REQUEST>
    <SYSTEM>
        <CIT_Version Value="1.0"/>
        <ERR Value=""/>
        <FORMAT Value="XML"/>
        <INTERFACE_RET Value=""/>
        <MAIN_ID Value="37407427745"/>
        <MSG_ID Value=".*"/>
        <SYNC Value="N"/>
        <Version Value="002"/>
    </SYSTEM>
    <DATA>
        <PACKAGE_B64>
    PE1zZ0NsaWVudEFkZFJzIHhtbG5zPSJ1cm46c2NoZW1hcy1wc2l0LXJ1OmdwIj48
UnFVSUQ+Mzc0MDc0Mjc3NDU8L1JxVUlEPjxScVJlc3VsdD48U3RhdHVzPk9rPC9T
dGF0dXM+PENvbW1lbnQ+TmV3PC9Db21tZW50PgoJCQk8L1JxUmVzdWx0PjxSZXN1
bHQ+PENsaWVudElkPjc3MzY0NTgyPC9DbGllbnRJZD48SW50ZXJuYWxfQ2xpZW50
SWQ+MjY3PC9JbnRlcm5hbF9DbGllbnRJZD4KCQkJPC9SZXN1bHQ+CgkJPC9Nc2dD
bGllbnRBZGRScz4=

</PACKAGE_B64>
    </DATA>
</CIT_REQUEST>/

请帮助regexp或其他方法。

3 个答案:

答案 0 :(得分:1)

根据How to Use JMeter Assertions in Three Easy Steps文章

的“回应断言”章节
  

模式可以是:

     
      
  1. “等于”或“子串”子句的“字符串”
  2.   
  3. “包含”或“匹配”子句的“Perl5风格”正则表达式
  4.   

所以你有两个选择:

  1. 如果您仍想使用“包含”模式匹配规则need to escape

      字符类之外的
    • .^$*+?()[{\|字符
    • 字符类中的
    • ^-]\个字符
  2. 更简单的选项是将模式匹配规则更改为“等于”或“子串”

答案 1 :(得分:0)

答案 2 :(得分:0)

对于XML断言最好的方法是使用jmeter提供的XML断言,这将检查XML的整个语法