简体   繁体   English

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

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

Iam testing a web service in UFT using Microsoft XML DOM and HTTP IAM使用Microsoft XML DOM和HTTP在UFT中测试Web服务

When i trigger the request XML, i get response in two ways 当我触发请求XML时,我通过两种方式获得响应

Way 1 when it success 方式一成功

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

Way 2 when it fails 失败时的方法2

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

Iam capturing the <MessageStatus>SUCCESS</MessageStatus> by using the xpath 我通过使用xpath捕获<MessageStatus>SUCCESS</MessageStatus>

set ObjXml = Createobject("Microsoft.XMLDOM")

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

ResultText=ObjNode.text

when it is success it works damn good and when it fails and response appears as shown in way 2, i get a error like Object Required and it wont continue further. 当成功时,它会很好地工作;当失败时,响应会出现,如方法2所示,我得到了像Object Required这样的错误,它将不会继续下去。

is there any way so that if object not found it should not come out of function and it should return Status as failed and continue further 有什么方法可以使如果找不到对象,它就不应退出功能,并且应该返回Status作为失败并继续

VB scipt iam using is 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"

But it is failing in Step 1 it self :( can we handle this ? 但是它在步骤1中失败了:(我们可以处理这个问题吗?

I doubt you are getting the error on the SelectSingleNode, perhaps that's just a typo in your question? 我怀疑您在SelectSingleNode上遇到错误,也许这只是您输入的错误?

I suspect you are really getting the failure when trying to access ObjNode.Text . 我怀疑您尝试访问ObjNode.Text时确实遇到了失败。 This is because SelectSingleNode will return Nothing if it can't find the node requested. 这是因为SelectSingleNode如果找不到所请求的节点,将不返回Nothing内容。 So you just need to check the return value before deciding whether to access .Text. 因此,您只需要在确定是否访问.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

Oh, and you can probably shorten your XPath to //MessageStatus if that element never appears elsewhere in the document. 哦,如果该元素从未出现在文档的其他位置,则可以将XPath缩短为//MessageStatus

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

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