SoapUI 断言 - XPath 或包含断言都可以

SoapUI Assertions - either XPath or Contains Assertion would be fine

以下回复示例。我想检查以下响应中是否存在特定错误代码 (860)。从技术上讲,为了避免在参考编号中意外发现错误,我需要检查它是否位于标记为 860 的位中(插入空格以便显示)。

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:activatePortResponse xmlns:ns2="http://transferobjects.abc.abc.org">
         <return som="6001365" state="Approved">
            <errors>
               <error>
                  <code>860</code>
                  <description>The Port cannot be activated outside the ready for service dateTime window (grace period taken into account).</description>
                  <mnemonic>RFS_WINDOW</mnemonic>
               </error>
               <name>som</name>
            </errors>
            <success>false</success>
         </return>
      </ns2:activatePortResponse>
   </soap:Body>
</soap:Envelope>

我试图构建一组具有预期错误结果的调用,以检查错误响应是否按应有的方式返回。浏览所有对我来说毫无意义的常见垃圾消息,我只是不断调整。

原来我可以使用 Contains 方法并粘贴更多,而不仅仅是 860 甚至 860 我只需要像这样粘贴更大的块:

       <error>
          <code>860</code>
          <description>The Port cannot be activated outside the ready for service dateTime window (grace period taken into account).</description>
          <mnemonic>RFS_WINDOW</mnemonic>
       </error>

所以我有一个解决方案,但如果有人想告诉我如何用 XPath 以一种不那么笨拙的方式来做,那就太棒了。

您可以使用以下表达式 //error/code 执行 XPath 匹配断言,它在上面的响应消息中会找到 860。这样你就知道这个 860 是在 XML 层次结构中的特定位置找到的。