繁体   English   中英

如何处理QTP / UFT中的对象必需的故障

[英]How to Handle Objects required failures in QTP/UFT

IAM使用Microsoft XML DOM和HTTP在UFT中测试Web服务

当我触发请求XML时,我通过两种方式获得响应

方式一成功

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <SearchResourceResponse xmlns="http://www.ICLNBI.com/ICLNBI.xsd">
         <MessageElements xmlns="">
            <MessageStatus>SUCCESS</MessageStatus>
            <MessageAddressing>
               <from>ICL</from>
               <to>QPortal</to>
               <messageId>1234</messageId>
               <action>SearchResource</action>
               <timestamp>2013-07-29T17:05:17.860Z</timestamp>
               <ServiceName>SearchResource</ServiceName>
               <ServiceVersion>2.0</ServiceVersion>
            </MessageAddressing>
       </SearchResourceResponse>
   </soap:Body>
</soap:Envelope>

失败时的方法2

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body/>
</soap:Envelope>

我通过使用xpath捕获<MessageStatus>SUCCESS</MessageStatus>

set ObjXml = Createobject("Microsoft.XMLDOM")

Set ObjNode= ObjXml.SelectSingleNode("/soap:Envelope/soap:Body/*/MessageElements/MessageStatus")

ResultText=ObjNode.text

当成功时,它会很好地工作;当失败时,响应会出现,如方法2所示,我得到了像Object Required这样的错误,它将不会继续下去。

有什么方法可以使如果找不到对象,它就不应退出功能,并且应该返回Status作为失败并继续

VB Scipt IAM使用是

Set ObjNode= ObjXml.SelectSingleNode("/soap:Envelope/soap:Body/*/MessageElements/messageStatus")
ResultText=ObjNode.text

If ResultText="SUCCESS" or ResultText="Success" Then 

TcStatus = "Passed"

Else if 

ResultText="FAIL" or ResultText= "FAILURE" Then

TcStatus = "Passed"

但是它在步骤1中失败了:(我们可以处理这个问题吗?

我怀疑您在SelectSingleNode上遇到错误,也许这只是您输入的错误?

我怀疑您尝试访问ObjNode.Text时确实遇到了失败。 这是因为SelectSingleNode如果找不到所请求的节点,将不返回Nothing内容。 因此,您只需要在确定是否访问.Text之前检查返回值即可。

Set ObjXml = Createobject("Microsoft.XMLDOM")

'Presumably you have a step to load the XML here.

Set ObjNode = ObjXml.SelectSingleNode("/soap:Envelope/soap:Body/*/MessageElements/MessageStatus")
If ObjNode Is Nothing Then
    MsgBox "Oh no! Failure!"
Else
    ResultText = ObjNode.text
End If

哦,如果该元素从未出现在文档的其他位置,则可以将XPath缩短为//MessageStatus

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM