【问题标题】:Query Match in SoapUI doesn't work for a proper XpathSoapUI 中的查询匹配不适用于正确的 Xpath
【发布时间】:2019-12-17 13:09:42
【问题描述】:

所以我得到了这个 XML:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">http://http://someurl.de/test/schema/function</a:Action>
      <a:MessageID>urn:uuid:4f318e88-c586-42c4-a2e8-2d9fdd18daca</a:MessageID>
      <a:ReplyTo>
         <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
      </a:ReplyTo>
      <a:To s:mustUnderstand="1">http://localhost:8088/mockMessageServiceViaWsHttpX509TokenWithoutSct</a:To>
   </s:Header>
   <s:Body>
      <ReceiveMessages xmlns="http://someurl.de/test/schema">
         <request xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <ServiceNameIdentifier>single</ServiceNameIdentifier>
            <ServiceNameQualifier/>
         </request>
      </ReceiveMessages>
   </s:Body>
</s:Envelope>

到目前为止,我使用了几个 XPath 表达式,如下所示:

count(//ServiceNameIdentifier[.='single'])

或者这个

count(//ReceiveMessages/request/ServiceNameIdentifier[.='single'])

我正在检查结果是否为 1。

我检查了这个:

//ReceiveMessages/request/ServiceNameIdentifier/text()

并测试结果是否为“单一”但也无济于事......

https://www.freeformatter.com/ 网站上,它起作用了。在 SoapUI 中它没有,我不知道我做错了什么......

【问题讨论】:

  • 这能回答你的问题吗? Default namespaces in soapUI XPath assertions
  • 并非如此。我设置了 3 个不同的端点,每 2 个或 3 个响应。对于前两个它有效,但不适用于第三个,我不知道为什么......
  • 这是来自重复标志的自动消息。请注意 ReceiveMessagesrequestServiceNameIdentifier 元素位于 http://someurl.de/test/schema 命名空间 URI 下。

标签: xpath soapui


【解决方案1】:

命名空间总是让我头疼,所以我尽量绕过它们。以下 XPath 使用 local-name() 忽略元素的命名空间,并使用 contains 函数测试内容:

count(//*[local-name() = 'ServiceNameIdentifier'][contains(.,'single')])

对于您的有效负载,这将返回 1:

【讨论】:

  • 你,先生,太棒了!这完美!非常感谢!
【解决方案2】:

【讨论】:

  • 我确实喜欢这个declare namespace s="http://www.w3.org/2003/05/soap-envelope" declare namespace a="http://www.w3.org/2005/08/addressing" count(//s:Envelope/s:Body/ReceiveMessage/request/ServiceNameIdentifier[.='single']) &gt; 0 但它不起作用......
  • @Kazoooka 您缺少“someurl.de/test/schema”的命名空间(如果您按“声明”soapui 将为您生成它们)。然后你会得到类似//s:Envelope/s:Body/d:ReceiveMessage/i:request/i:ServiceNameIdentifier[.='single']
  • 我现在这样做了:``` 声明命名空间 s="w3.org/2003/05/soap-envelope" 声明命名空间 a="w3.org/2005/08/addressing" 声明命名空间 i="w3.org/2001/XMLSchema-instance" 声明命名空间 ns="@987654326 @" count(//s:Envelope/s:Body/ns:ReceiveMessage/i:request/i:ServiceNameIdentifier[.='single']) > 0 ``` 但遗憾的是它仍然不起作用......还有我没有找到“声明”按钮。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-20
  • 1970-01-01
  • 2021-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多