QTP sample Scripts

by admin on June 22, 2011

QTP sample Scripts

Script to display the count of WebTable/Link/Image in the browser

Set b = Description.Create

b(“micclass”).value = “WebTable” ‘insert “Link” or “Image” in place of “WebTable”

Set ls = Browser(“Database/SQL Server Interview”). Page(“Database/SQL Server Interview”).ChildObjects(b)

Msgbox ls.count

Set b = Nothing

Set ls = Nothing

================================================

Script to display the count of Links

Set a = Description.Create

a(“micclass”).value = “Link”

Set ls = Browser(“name:=Data.*”). Page(“title:=Data.*”).ChildObjects(a)

Msgbox ls.count

Set a = Nothing

Set ls = Nothing

=============================================================================

To click a hyper link

Set a = Description.Create

a(“micclass”).value = “Link”

a(“text”).value = “Interview Tips”

Browser(“name:=Data.*”). Page(“title:=Data.*”).link(a).click

Set a = Nothing

===============================================================================

To pass custom step to test results

Set a = Description.Create

a(“micclass”).value = “Link”

a(“text”).value = “Interview Tips”

Set ls = Browser(“name:=Data.*”). Page(“title:=Data.*”)

ls.link(a).click

Reporter.ReportEvent micPass, “Custom Step”, “The user-defined step Passed.”

Set a = Nothing

Set ls = Nothing

================================================================================

Clicking the link(“Interview tips”) with Descriptive programming

Set aTitle = Description.Create

aTitle(“micclass”).value = “Browser”

Set aPage = Description.Create

aPage(“micclass”).value = “Page”

Set aLink = Description.Create

aLink(“micclass”).value = “Link”

aLink(“text”).value = “Interview Tips”

Browser(aTitle).page(aPage).Link(aLink).Click

=====================================================================================

To display the browser names

Set aBrowser = Description.Create

aBrowser(“micclass”).value = “Browser”

Set aTemp = Desktop.ChildObjects(aBrowser)

msgbox aTemp.count

For i = 0 to aTemp.count-1

c = aTemp(i).getroproperty(“name”)

msgbox c

Next

=====================================================================================

When in case of multiple browsers opened, use the 3rd line statement to identify the exact browser to perform the operation

Set aTitle = Description.Create

aTitle(“micclass”).value = “Browser”

aTitle(“name”).value = “Database/SQL Server Interview Questions”

Set aPage = Description.Create

aPage(“micclass”).value = “Page”

Set aLink = Description.Create

aLink(“micclass”).value = “Link”

aLink(“text”).value = “Interview Tips”

Browser(aTitle).page(aPage).Link(aLink).Click

=====================================================================================

#SQASolutionShare on FacebookShare on Google+Share on LinkedInTweet about this on TwitterEmail this to someone

Previous post:

Next post: