Sunday, May 24, 2009

Script for Highlighting the Objects

Hi All,

Hope most of you people might be knowing how to highlight an Object in Object Repository using "Highlight in Application" button.
Here i am providing a way of Highlighting the Objects of specific Class programmatically(thru script).

' script :
systemutil.Run "http://www.qtpking.blogspot.com/"
Dim obj Set obj=Description.Create
obj("micclass").value="Link"
Set x=browser("QTP for you ...").Page("QTP for you ...").ChildObjects(obj)
For i=0 to x.count-1
x(i).highlight
Next


'Note: Add 'Page' object into Obj.Repo. before execution
Just execute the above script & watch the output.....:)

Msgbox Vs Print Dialog

Hi All,

You might be familiar with usage of 'Msgbox' in the scripts for displaying the information,Variables,Values.
But from QTP 9.x series HP has introduced a new feature Called "Print" Statement.
The purpose of the Print Statement is similar to Msgbox , see below to have clear picture.
Msgbox:
Msgbox VBScript function is used to display information during the run session.
Note: The run session pauses until the message box is closed.
So while runnings batch testing,Driver scripts we have to make sure that we have not used "Msgbox" in our scripts. The run session pauses until the message box is closed & we cannot expect the test results until run session is completed.
Print :
Print Utility statement is used in our scripts to display information in the QuickTest Print Log window while still continuing the run session.
Note: The run session wouldn't pauses inspite of the display of QuickTest Print Log window.
So while runnings batch testing,Driver scripts if at all we have used 'Print' statements it would not effect the test script execution(Run session) & we would get the test results.
See the below Example
' Using Print Statement:
print "ASCII value of A : "&Asc("A")
print "ASCII value of a : "&Asc("a")
print "ASCII value of B : "&asc("B")
print "ASCII value of b : "&asc("b")

Output:




















Output:

Saturday, May 23, 2009

Function for Excel Cell Colors

Hi All,
Hope all of you are doing well....:)
Here i am providing an Userdefined Function for displaying the cell colors of Excel document.

' Function Defination:
Function ExcelCellColors_display(FilePath)
Dim xl
Set xl=CreateObject("Excel.Application")
xl.visible=True
xl.WorkBooks.Open FilePath
' Retrieving the rowcount used
rc=xl.Activesheet.usedrange.rows.count

' Clearing the existing Data in excel (If any)
For j=1 to rc
xl.Cells(j,1).interior.colorindex=null
xl.Cells(j,1).value=Null
xl.Cells(j,2).value=Null
xl.Cells(j,2).interior.colorindex=null
Next
xl.cells(1,1).value="Color"
xl.cells(1,2).value="Color Index"

' Filling the colors & colorindex values
For i=2 to 56
xl.Cells(i,1).interior.colorindex=i-1
xl.Cells(i,2).value=xl.Cells(i,1).interior.colorindex
Next
xl.ActiveworkBook.Save
wait(1)
xl.Application.quit
Set xl=nothing
End Function

'Function Declaration/Calling:
Call ExcelCellColors_display( "D:\Documents and Settings\Sree\Desktop\Excel_colors.xls")

Output: