WebExt Performance Demo
One of the benefits of using Web Extensibility Add-ins is that you get a performance gain in running tests vs using the old WebElement method. For a demonstration, I wrote a basic WebExt add-in that only has one class defined: Div. Div is any object whose tagName is "DIV", so it is the equivalent of WebElement("tagName:=DIV"). You can download it here. All you have to do to use it in your QTP 9.5 environment is extract that zip file into "C:\progfiles\hp\QuickTest Professional\dat\Extensibility\Web" and restart QTP. Make sure to check the "rawElements" add-in on QTP's splash screen.
Create a new test that uses the rawelements add-in and run this script:
-
Set oBrowser = openNewBrowser ("http://news.google.com")
-
oBrowser.WaitProperty "attribute/readyState", "complete"
-
'oBrowser.sync
-
timeThis "oBrowser.Div(""className:=lh"", ""index:=0"").exist"
-
timeThis "oBrowser.Div(""className:=lh"", ""index:=1"").exist"
-
timeThis "oBrowser.WebElement(""tagName:=DIV"", ""className:=lh"", ""index:=0"").exist"
-
timeThis "oBrowser.WebElement(""tagName:=DIV"", ""className:=lh"", ""index:=1"").exist"
-
-
function timeThis (sEval)
-
Set oTimer = MercuryTimers.Timer("timer1")
-
oTimer.Start
-
sReturn = eval(sEval)
-
oTimer.Stop
-
print "executed: " & sEval
-
print "returned: " & sReturn
-
print "took: " & oTimer.ElapsedTime / 1000 & " seconds"
-
timeThis = sReturn
-
end function
If you aren't using SIFL, change the first line to your preferred means of opening a browser and navigating to news.google.com.
This will open news.google.com and get the first two headline divs using the Div add-in and WebElement and show you how long it takes to execute. For me, the first two times using the Div method took 2.12 and 0.86 seconds. The second two checks using the WebElement method took 4.08 and 4.05 seconds.
The reason the first time using the WebExt takes longer is it has to attach the javascript for the Div class to IE. After it does that, future executions are much speedier.
In conclusion, this is the long, boring way to say that WebElement is slow and Web Extensibility objects can be much faster.
Tags: qtp, QTP-9.5, QuickTest-Pro-9.5, Web-Extensibility, WebExt


Leave a Reply