Web script Examples

QTP Web Testing
————————————–
‘How to Verify links in a specified web page
Option explicit
Dim objDesc,objColl,i,LinkName
Dim ExpUrl,ActUrl
Set objDesc=Description.Create
objDesc.Add “micclass”,”Link”
set objColl=Browser(“Google”).Page(“Google”).ChildObjects(objDesc)
For i=0 to objColl.count-1 step 1
 LinkName=Browser(“Google”).Page(“Google”).link(“index:=”&i).getroproperty(“name”)
ExpUrl=Browser(“Google”).Page(“Google”).link(“index:=”&i).getroproperty(“url”)
Browser(“Google”).Page(“Google”).link(“index:=”&i).click
wait(4)
ActUrl=Browser(“Google”).getroproperty(“url”)
If  instr(1,ActUrl,ExpUrl,1)>0 Then
Reporter.ReportEvent micPass,”Link validation done”,”Test is Pass”

Else
Reporter.ReportEvent  micFail,”Link validtaion Fail”,”Test is Fail”

End If
Browser(“Google”).Back
Next

Web Functions (User defined functions)

————————————————-
1) Write a function for Launching the Application
Function App_Launch()
SystemUtil.Run “C:Program FilesInternet Exploreriexplore.exe”,”http://www.dealsdirect.com.au/”
Wait (10)
Browser_Name = Browser(“Online Shopping | Australia”).GetROProperty(“title”)

If Browser_Name =”Online Shopping | Australia Online Shopping | Deals Direct”  Then
App_Launch=”Application Launched”
Msgbox App_Launch
Else
App_Launch=”Application Not Launched”
Msgbox App_Launch
End If
End Function
———————————————————-
2) ‘Write a function to Count Links in Dealsdirect.com.au Application
Function Links_Count()
Dim oLink, Links, i
Set oLink=Description.Create
oLink(“micclass”).Value=”Link”
Set Links=Browser(“Online Shopping | Australia”).Page(“Online Shopping | Australia”).ChildObjects(oLink)
Msgbox Links.Count
End Function
————————————————————-
3) ‘Write a function to Count Links in any opened  web Page
Function Links_Count()
Dim oLink, Links, i
Set oLink=Description.Create
oLink(“micclass”).Value=”Link”
Set Links=Browser(“title:=.*”).Page(“title:=.*”).ChildObjects(oLink)
Msgbox Links.Count
End Function
———————————————————–

QTP Training Guidelines

In QTP we have 2 types of features

1) QTP Tool Features
2) VB Script Features
Try to learn and practice VB Script features more, but QTP Tool features also important.

 

Comments