2016-08-25 128 views
1

有沒有一種方法可以使用無頭瀏覽器在UFT中運行我們的自動化腳本,類似於我們使用硒?使用UFT進行無頭UI自動測試

我現在運行的腳本消耗了大量的時間,速度非常慢。

我對UFT比較陌生,在網上進行了一些使用UFT進行無頭測試的研究,但是找不到任何東西。

任何指針或建議,將不勝感激。

回答

0

你看起來像下面的代碼?

Public Function GetAllLinksInthePage() 
    Dim oIE 
    Set oIE = CreateObject("InternetExplorer.Application") 
    oIE.Visible = False 
    oIE.Navigate2 "http://newtours.demoaut.com/" 
    Wait 4 
    Set oIEDocument = oIE.Document 
    Set oLinkCollection = oIEDocument.getElementsByTagName("A") 
    iLinkCount = oLinkCollection.Length 
    If iLinkCount > 0 Then 
     For iCount = 0 To iLinkCount - 1 
      Print oLinkCollection(iCount).Text 
     Next 
    End If 
    Set oIE = Nothing 
End Function 
0

如果您的應用程序以REST或SOA的形式提供豐富的API集,則可以使用XMLHTTP對象。它獨立於QTP/UFT。這是純粹的VBSscript,可以在任何地方使用。可悲的是,你必須從頭開始編寫大量代碼,但這很容易。

dim xmlhttp, fso, f1, serverURL 
 
Set xmlhttp = Createobject("Microsoft.XMLHTTP") 
 
serverURL = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Atlanta+GA+USA&destinations=Dallas+TX+USA&units=imperial&sensor=false" 
 
xmlhttp.Open "POST", serverURL, false 
 
xmlhttp.Send 
 
Set fso = CreateObject("Scripting.FileSystemObject") 
 
Set f1 = fso.CreateTextFile("D:\Sample VB Scripts\testfile.xml", True) 
 
f1.write xmlhttp.ResponseText 
 
f1.close

Sample XMLHTTP code

相關問題