[英]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.