2014-05-09 16 views
1

蔭測試使用的是Microsoft XML DOM在UFT Web服務和HTTP如何處理對象所需的失敗在QTP/UFT

當我觸發請求XML,我得到的反應有兩種方式

路1當它成功

<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反應似乎,我得到這樣對象一個錯誤需要和它不會繼續進一步。

有沒有什麼辦法,這樣,如果沒有找到對象不應該出來的功能,併爲失敗它應該返回狀態,並繼續進一步

VB素文字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步是自我:(我們可以處理這個問題?

回答

2

我懷疑你是對的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如果該元素從來沒有在文檔中的其他地方出現。

+0

那是工作謝謝小福:) –