Thursday, July 31, 2008

VisualTest - Browser related functions

VisualTest has different set of functions for browser related operations. Below I have given few code snippets.

VistualTest code - To Invoke Internet Explorer

'--------------------------- ' Method : WebStart ' Author : T.Palani Selvam ' Purpose : To Start a IE. ' Parameters: sURL As String. ' ' Returns : - Nil - ' Caller : - Nil ' Calls : - Nil - '----------------------------- Sub WebStart(sURL As String) gsContext = WebExplore(sURL) WSetActWnd(val(gsContext)) If Not wIsMaximized(val(gsContext)) Then wMaxWnd(val(gsContext)) Sleep giPageLoad Logwrite("IE is started. URL : " + sURL , 1) End Sub

Vistual Test code - Navigate to given URL
'------------------------ ' Method : WebNavigation ' Author : T.Palani Selvam ' Purpose : To Start a IE. ' Parameters: sURL As String. ' ' Returns : - Nil - ' Caller : - Nil ' Calls : - Nil - '--------------------------- Sub WebNavigation(sURL As String) If ( Not WebBrowserExists(gsContext)) Then WebStart(sURL) Else WebNavigate(gsContext, sURL) Sleep giPageLoad WSetActWnd(val(gsContext)) If Not wIsMaximized(val(gsContext)) Then wMaxWnd(val(gsContext)) Logwrite("Navigated URL : " + sURL , 1) End If End Sub

Vistual Test code - To click Back Button in Browser
'-------------------------- ' Method : WebBackHistory ' Author : T.Palani Selvam ' Purpose : Back history from IE. ' Parameters: sValue As String. ' ' Returns : - Nil - ' Caller : - Nil ' Calls : - Nil - '----------------------------- Sub WebBackHistory(sValue As String) Dim iTimes As Integer iTimes = Val(sValue) If ( Not WebBrowserExists(gsContext)) Then LogWrite("Main Browser doesn't exist.Couldn't be gone to back", 1) Else If (iTimes = 0) Then iTimes = 1 WebBack(gsContext, iTimes) Sleep giPageLoad WSetActWnd(val(gsContext)) If Not wIsMaximized(val(gsContext)) Then wMaxWnd(val(gsContext)) Logwrite("Going back number of items in History is " + str(iTimes) , 1) End If End Sub

Vistual Test code - To click Forward Button in Browser
'--------------------------- ' Method : WebForwardHistory ' Author : T.Palani Selvam ' Purpose : Forward history from IE. ' Parameters: sValue As String. ' ' Returns : - Nil - ' Caller : - Nil ' Calls : - Nil - '--------------------------------- Sub WebForwardHistory(sValue As String) Dim iTimes As Integer iTimes = Val(sValue) If ( Not WebBrowserExists(gsContext)) Then LogWrite("Main Browser doesn't exist.Couldn't be gone to Forward", 1) Else If (iTimes = 0) Then iTimes = 1 WebForward(gsContext, iTimes) Sleep giPageLoad WSetActWnd(val(gsContext)) If Not wIsMaximized(val(gsContext)) Then wMaxWnd(val(gsContext)) Logwrite("Going Forward number of items in History is " + str(iTimes) , 1) End If End Sub

Friday, July 25, 2008

Silktest - TestPlan solutions

TestPlan is one of the good features in Silktest. You can query to execute certain testcases from Testplan. Also you can mark only failures from the silktest results. Below I have given the two test plan issues and solutions for them.

1. How to pass Dollar ($) sign in TestPlan?
TestPlan is using $ symbol to represent the variables. Silktest will through the error, if any testdata contains dollar ($) character explicitly.
Solution:
Replace symbol $ by {Chr(36)}


2. Running Main() from TestPlan
Few weeks back, I wanted to run the Main() function from Testplan. It is very old suite ( 10 years old). I thought, Silktest does not have any provision to call Main () function. I put the query into Borland forum and I got the answer.
Solution:
We have to represent the Main() as testcase. We should not change the hierarchy/indentation for script and testcase statements. See the sample plan below.



[-] SilkTest Issues
[ ] Developer: Palani Selvam
[ ] script: silkIssues.t
[ ] testcase: main()
[ ]



By this way, we can run the functions too..


[-] SilkTest Issues
[ ] Developer: Palani Selvam
[ ] script: silkIssues.t
[ ] // testcase: main()
[ ] testcase: MyTestCalls5 ()


Tuesday, July 22, 2008

VisualTest - Pressing Shortcut Key

Each GUI testing tool contains a way to press shortcut keys. Visual Test also has the feature to invoke shortcuts. It is similar to SendKeys in Windows Host Script. Below code I have written around eight years ago.

Visual Test code - To invoke Shortcut key



'---------------------
' Method : ShortcutKeys
' Author : T.Palani Selvam
' Purpose : Play shortcut keys.
' Parameters: sDatavalue, String - Contains a file name.
' Returns : Returns Integer data type(True or False.)
' Caller : SwitchSpecialTags
' Calls : - Nil
'----------------------
Function ShortcutKeys(sDataValue As String) As Integer
Dim iPosition As Integer
Dim sFirst As String
Dim sLast As String

ShortcutKeys = False

While (Instr(LCase(sDataValue),"+")<> 0 )
iPosition = Instr(LCase(sDataValue),"+")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 1)
sDataValue = sFirst + sLast
Wend


If (Instr(LCase(sDataValue),"ctrl")<> 0 ) Then
iPosition = Instr(LCase(sDataValue),"ctrl")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 4)
sDataValue = sFirst + "^" + sLast
End IF

If (Instr(LCase(sDataValue),"shift")<> 0 ) Then
iPosition = Instr(LCase(sDataValue),"shift")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 5)
sDataValue = sFirst + "+" + sLast
End IF

If (Instr(LCase(sDataValue),"alt")<> 0 ) Then
iPosition = Instr(LCase(sDataValue),"alt")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 3)
sDataValue = sFirst + "%" + sLast
End IF

If (Instr(LCase(sDataValue),"tab")<> 0 ) Then
iPosition = Instr(LCase(sDataValue),"tab")
sFirst = Left(sDataValue, iPosition - 1)
sLast = Mid$(sDataValue, iPosition + 3)
sDataValue = sFirst + "{TAB}" + sLast
End IF

If (Instr(UCase(sDataValue),"DELETE")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"DELETE")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 6)
sDataValue = sFirst + "{DEL}" + sLast
ElseIf (Instr(UCase(sDataValue),"DEL")<> 0 ) Then
iPosition = Instr(UCase(sDataValue),"DEL")
sFirst = Left(sDataValue, iPosition - 1)
sLast = Mid$(sDataValue, iPosition + 3)
sDataValue = sFirst + "{DEL}" + sLast
End IF


If (Instr(LCase(sDataValue),"enter")<> 0 ) Then
iPosition = Instr(LCase(sDataValue),"enter")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 5)
'sDataValue = sFirst + "{ENTER}" + sLast
sDataValue = sFirst + "~" + sLast
End IF

If (Instr(LCase(sDataValue),"right")<> 0 ) Then
iPosition = Instr(LCase(sDataValue),"right")
sFirst = Left(sDataValue, iPosition - 1)
sLast = Mid$(sDataValue, iPosition + 5)
sDataValue = sFirst + "{RIGHT}" + sLast
End IF

If (Instr(LCase(sDataValue),"left")<> 0 ) Then
iPosition = Instr(LCase(sDataValue),"Left")
sFirst = Left(sDataValue, iPosition - 1)
sLast = Mid$(sDataValue, iPosition + 4)
sDataValue = sFirst + "{LEFT}" + sLast
End IF

If (Instr(LCase(sDataValue),"down")<> 0 ) Then
iPosition = Instr(LCase(sDataValue),"down")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 4)
sDataValue = sFirst + "{DOWN}" + sLast
End IF

If (Instr(LCase(sDataValue),"up")<> 0 ) Then
iPosition = Instr(LCase(sDataValue),"up")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 2)
sDataValue = sFirst + "{UP}" + sLast
End IF

If (Instr(UCase(sDataValue),"ESCAPE")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"ESCAPE")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 6)
sDataValue = sFirst + "{ESC}" + sLast
ElseIf (Instr(UCase(sDataValue),"ESC")<> 0 ) Then
iPosition = Instr(UCase(sDataValue),"ESC")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 3)
sDataValue = sFirst + "{ESC}" + sLast
End IF

If (Instr(UCase(sDataValue),"INSERT")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"INSERT")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 6)
sDataValue = sFirst + "{INS}" + sLast
ElseIf (Instr(UCase(sDataValue),"INS")<> 0 ) Then
iPosition = Instr(UCase(sDataValue),"INS")
sFirst = Left(sDataValue, iPosition - 1)
sLast = Mid$(sDataValue, iPosition + 3)
sDataValue = sFirst + "{INS}" + sLast
End IF

If (Instr(UCase(sDataValue),"BREAK")<> 0 ) Then
iPosition = Instr(UCase(sDataValue),"BREAK")
sFirst = Left(sDataValue, iPosition - 1)
sLast = Mid$(sDataValue, iPosition + 5)
sDataValue = sFirst + "{BREAK}" + sLast
End IF

If (Instr(LCase(sDataValue),"f1")<> 0 ) Then
iPosition = Instr(LCase(sDataValue),"f1")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 2)
sDataValue = sFirst + "{F1}" + sLast
End IF

If (Instr(uCase(sDataValue),"F2")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F2")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 2)
sDataValue = sFirst + "{F2}" + sLast
End IF

If (Instr(uCase(sDataValue),"F3")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F3")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 2)
sDataValue = sFirst + "{F3}" + sLast
End IF

If (Instr(uCase(sDataValue),"F4")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F4")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 2)
sDataValue = sFirst + "{F4}" + sLast
End IF

If (Instr(uCase(sDataValue),"F5")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F5")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 2)
sDataValue = sFirst + "{F5}" + sLast
End IF

If (Instr(uCase(sDataValue),"F6")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F6")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 2)
sDataValue = sFirst + "{F6}" + sLast
End IF

If (Instr(uCase(sDataValue),"F7")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F7")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 2)
sDataValue = sFirst + "{F7}" + sLast
End IF

If (Instr(uCase(sDataValue),"F8")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F8")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 2)
sDataValue = sFirst + "{F8}" + sLast
End IF

If (Instr(uCase(sDataValue),"F9")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F9")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 2)
sDataValue = sFirst + "{F9}" + sLast
End IF

If (Instr(uCase(sDataValue),"F10")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F10")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 3)
sDataValue = sFirst + "{F10}" + sLast
End IF

If (Instr(uCase(sDataValue),"F11")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F11")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 3)
sDataValue = sFirst + "{F11}" + sLast
End IF

If (Instr(uCase(sDataValue),"F12")<> 0 ) Then
iPosition = Instr(uCase(sDataValue),"F12")
sFirst = Left(sDataValue, iPosition -1)
sLast = Mid$(sDataValue, iPosition + 3)
sDataValue = sFirst + "{F12}" + sLast
End IF

Logwrite ("Shortcut key processed: " + sDataValue, 1)

sDataValue = Trim(lCase(sDataValue)) 'Because some times, shortcut keys are not functioned in Upper case.

Play sDataValue

ShortcutKeys = True

End Function

Saturday, July 19, 2008

Excel Automation Using VBScript

Using VBScript, we can automate most of the Excel verification activities. In one project we can export reports to Excel. I have to verify the cell value, font color and Background color. It is difficult task to verify each cell property by any GUI testing tool. All tools are used to identify Excel Grid (Workbook) as Custom Object. I am using VBScript to read the excel contents. Another advantage, you can use the VBScript against different versions of Excel such as 2002, 2003 and 2007. But you need to change the code for Excel 2003 and 2007, if you have done by using GUI objects.

Below I put one Visual Basic script code. It reads the given excel file and put the details of each cell into a log file. Copy all contents from below textbox and save it as MyExcel.vbs and try to run this VBS file. You can run this script by using any GUI Testing tool. Command line call should be cscript MyExcel.vbs sExcelFile iStartRow iStartCol iEndRow iEndCol iSheetIndex

To Know more about this VBA Help, download help from this link Microsoft Office 2003 Editions: Excel VBA Language Reference

If you are unable to run any VBScript, See my earlier post Unable to run VBS or CScript in Windows XP .

VB Script to Read Excel Contents



' USAGE: MyExcel.vbs "D:\VB\Complex.xls" iStartRow iStartCol iEndRow iEndCol iSheetIndex
'cscript MyExcel.vbs "D:\VB\Complex.xls" 1 1 30 12 2

'******** Variables Declaration
' Files section
'XLS File name
gsFile="D:\VB\Complex.xls" 'File with macros
gsLogFile="D:\VB\Results_vbs.log"

Dim gsExcelFile, giStartRow, giStartCol, giEndRow, giEndCol, giSheetIndex
Dim gsResultsFile 'Text file name
gsDirSeparator = "\" 'Directory separator character


If WScript.Arguments.Count = 6 Then
gsExcelFile = WScript.Arguments.Item(0)
giStartRow = CInt (WScript.Arguments.Item(1))
giStartCol = CInt (WScript.Arguments.Item(2))
giEndRow = CInt (WScript.Arguments.Item (3))
giEndCol = CInt (WScript.Arguments.Item (4))
giSheetIndex = CInt (WScript.Arguments.Item (5))
'To Read the Excel file
'ReadExcel gsFile, 1, 1, 30, 12, 2
'WScript.Echo "ReadExcel " , gsExcelFile, giStartRow, giStartCol, giEndRow, giEndCol, giSheetIndex
ReadExcel gsExcelFile, giStartRow, giStartCol, giEndRow, giEndCol, giSheetIndex

Else
'WScript.Echo "Usage: MyExcel.vbs sExcelFile iStartRow iStartCol iEndRow iEndCol iSheetIndex"
'WScript.Quit
ReadExcel gsFile, 1, 1, 30, 12, 2
End If

'ReadExcel gsFile, 1, 1, 30, 12, 2

'---------------------------------
' Method : ReadExcel
' Author : T. Palani Selvam
' Purpose : Reading Excel contents.
' Parameters: - Nil
' Returns : - Nil
' Caller : - Nil
' Calls : - Nil

' Revision History:
'
' [No] da-mon-year Name: Action:
' [ 1] 07-Nov-2007 Palani Created first version
'---------------------------------
Sub ReadExcel(sExcelFile, iStartRow, iStartCol, iEndRow, iEndCol, iSheetIndex)

'WScript.Echo "ReadExcel " , sExcelFile, iStartRow, iStartCol, iEndRow, iEndCol, iSheetIndex
'ReadExcel(sExcelFile As Variant, iStartRow As Integer, iStartCol As Integer, iEndRow As Integer, iEndCol As Integer,iSheetIndex As Integer)

' Purpose: For Excel verification
' To Read the Excel and write into a file
' Each cell content
' Each cell - Foreground color, font name, font style, font size and Background color.


Dim sExcelPath 'As Variant 'Excel file

'********** Excel object declaration **********'
' Excel Application object
Dim objExcel 'As Excel.Application
Dim objXLWorkbooks 'As Excel.Workbooks
Dim objXLWorkbook 'As Excel.Workbook

Dim WorkSheetCount 'As Variant 'Work sheets count in a excel
Dim CurrentWorkSheet 'As Excel.Worksheet ' Current worksheet
Dim objCells 'As Excel.Range
Dim objCurrentCell 'As Variant
Dim objFont 'As Variant

' Result contents
Dim sCellValue 'As Variant
Dim sShowCellValue 'As Variant
Dim sFontName 'As Variant
Dim sFontStyle 'As Variant
Dim iFontSize 'As Variant
Dim iBackColorIndex 'As Variant
Dim iForeColorIndex 'As Variant
Dim iBackColorIndex2 'As Variant
Dim iForeColorIndex2 'As Variant
Dim sResult 'As Variant


' Row and Col integer variables
Dim iUsedRowsCount 'As Integer
Dim iUsedColsCount 'As Integer
Dim iTop, iLeft 'As Integer
Dim iRow 'As Integer 'Row item
Dim iCol 'As Integer 'Col item
Dim iCurRow 'As Integer
Dim iCurCol 'As Integer


If (sExcelFile = "") Then
sExcelPath = "D:\VB\Contacts.xls"
Else
sExcelPath = sExcelFile
End If

if (iSheetIndex = "") Then
iSheetIndex =1
End If


FileDeleteAndCreate (gsLogFile)

'XL file check
If (FileExists (sExcelPath) <> 0) Then
LogWrite ("The Excel file " & Chr(34) & sExcelPath & Chr(34) & " does not exit!")
'WScript.Echo "The Excel file, " & Chr(34) & sExcelPath & Chr(34) & " does not exit!"
'WScript.Quit
Else
LogWrite ("The XL file " & sExcelPath & " exists.")
End If

Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open sExcelPath, False, True
'WScript.Echo "Reading data from " & sExcelPath
' objExcel.ExecuteExcel4Macro

'On Error GoTo ErrorHandler1
On Error Resume Next


WorkSheetCount = objExcel.Worksheets.Count
'WScript.Echo "We have " & WorkSheetCount & " worksheets."
'Set objXLWorkbook = objExcel.Workbooks(1)
Set objXLWorkbook = objExcel.ActiveWorkbook
'objXLWorkbook.RunAutoMacros

Set CurrentWorkSheet = objExcel.ActiveWorkbook.Worksheets(iSheetIndex) 'iSheetIndex worksheet
'Set CurrentWorkSheet = objExcel.ActiveWorkbook.Worksheets(1) 'First worksheet
' CurrentWorkSheet = objExcel.Worksheets(1) 'First worksheet


iUsedRowsCount = iEndRow 'CurrentWorkSheet.UsedRange.Rows.Count
iUsedColsCount = iEndCol 'CurrentWorkSheet.UsedRange.Columns.Count
iTop = iStartRow 'CurrentWorkSheet.UsedRange.Row
iLeft = iStartCol 'CurrentWorkSheet.UsedRange.Column

' Cells object
CurrentWorkSheet.Cells.Activate

For iRow = iTop To iUsedRowsCount '(iUsedRowsCount - 1)
'Read All rows
For iCol = iLeft To iUsedColsCount '(iUsedColsCount - 1)
'Read all Columns

sResult = ""

Set objCurrentCell = CurrentWorkSheet.Cells(iRow, iCol)
sCellValue = objCurrentCell.Value

'If ((sCellValue = empty) Or (sCellValue = "empty")) Then
If ((sCellValue = empty)) Then
sCellValue = "empty"
Else
Set objFont = objCurrentCell.Font
sFontName = objFont.Name

sFontStyle = objFont.FontStyle
iFontSize = objFont.Size
iForeColorIndex = objFont.Color
iForeColorIndex2 = objFont.ColorIndex

If (sFontName = Empty) Then
sFontName = "empty"
End If
If (sFontStyle = Empty) Then
sFontStyle = "empty"
End If
If (iFontSize = Empty) Then
iFontSize = "-99999999"
End If
If (iForeColorIndex = Empty) Then
iForeColorIndex = "99999999"
End If
If (iForeColorIndex2 = Empty) Then
iForeColorIndex2 = "99999999"
End If
sResult = "Reading Cell {" & CStr(iRow) & "," & CStr(iCol) & "}," & sCellValue & "," & sFontName & "," & CStr(sFontStyle) & "," & CStr(iFontSize) & "," & CStr(iForeColorIndex) & "," & CStr(iForeColorIndex2)

LogWrite (sResult)

End If
Set objCurrentCell = Nothing

Next

Next

' This will prevent Excel from prompting us to save the workbook.
objExcel.ActiveWorkbook.Saved = True
Set CurrentWorkSheet = Nothing

'objExcel.Worksbooks.Close
objExcel.Quit

''Set CurrentWorkSheet = Nothing
Set objExcel = Nothing


MsgBox "Read COmpleted.", vbOKOnly, "Exec Over"
Exit Sub

ErrorHandler1:
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description
Err.Clear ' Clear the error.

End Sub

'---------------------------------
' Method : Logwrite
' Author : T. Palani Selvam
' Purpose : Append the given message into Log file.
' Parameters: sMsg - String, Contains logging message.
' Returns : - Nil
' Caller : - Nil
' Calls : - Nil

' Revision History:
'
' [No] da-mon-year Name: Action:
' [ 1] 07-Nov-2007 Palani Created first version
'---------------------------------
Sub LogWrite(sMsg)
Const ForAppending = 8
'FileName = "D:\VBs\Mysamples\1create.txt"

Set objFSO = CreateObject("scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (gsLogFile, ForAppending, True)

objTextFile.WriteLine date & " " & time & ": " & sMsg
objTextFile.Close

Set objTextFile = Nothing
Set objFSO = Nothing
End Sub

'---------------------------------
' Method : FileExists
' Author : T. Palani Selvam
' Purpose : Checks the given file is avialable or not.
' Parameters: - Nil
' Returns : - Returns As Boolean
' Caller : - Nil
' Calls : - Nil
'---------------------------------
Function FileExists(strPathName)
'return 0 if a file exists else -1
Dim ObjFSO

Set ObjFSO = CreateObject("Scripting.FileSystemObject")

if ObjFSO.FileExists(strPathName) = False then
FileExists = -1
else
FileExists = 0
end If

Set ObjFSO = Nothing
End Function

'---------------------------------
' Method : FileDeleteAndCreate
' Author : T. Palani Selvam
' Purpose : To delete the file if exists..
' Parameters: - Nil
' Returns : - Returns As Boolean
' Caller : - Nil
' Calls : - Nil
'---------------------------------
Function FileDeleteAndCreate(strFileName)
' delete
Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next
Set objTextFile = objFSO.GetFile(strFileName)
objTextFile.Delete

Set objTextFile = objFSO.CreateTextFile(strFileName)

objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing

End Function

'---------------------------------
' Method : Initialize
' Author : T. Palani Selvam
' Purpose : Initial actions & arrangements will be completed.
' Parameters: - Nil
' Returns : - Nil
' Caller : - Nil
' Calls : - Nil
'---------------------------------
Sub Initialize()
'CHECKING INPUT FILES ARE AVAILABLE OR NOT
gsLogFile = App.Path & "\Results.log"
End Sub

Wednesday, July 16, 2008

Winrunner - Version History

I was going through Wilsonmar site few months back. He has listed winrunner product version history. Already you know that Winrunner product line will be ended soon. Source: Wilsonmar Page

Winrunner - Product Version History


  • Version 8.2 became available Aug 15, 2005.

  • Version 8.0 became available Jan 2005

  • Version 7.6 is a point release available Jan 2004.

  • Version 7.5 was a major release out March 2002.

  • Version 7.01 is the release sent to maintenance licensees on August 2001.

  • Version 6.02 is needed for Windows 2000.

  • Version 6.0 SP1 (2.23 MB Web.z and info.ini files) created 11/29/99.

Tuesday, July 15, 2008

Silktest - File Download window

Sometimes Silktest is not identifying FileDownload objects properly. To save it, we need to use TypeKeys. I used following code snippet to save a file from Browser.

Sample 4Test code



[+] Boolean SaveFile (String sFile)
[ ] Boolean bResult = FALSE
[+] do
[+] if (FileDownload.Exists(1))
[ ] Print ("FileDownload exists.")
[ ] FileDownload.SetActive ()
[ ] Sleep (1)
[ ] FileDownload.Save.Click (1,10,3)
[ ] Sleep (3)
[ ]
[ ] Window wActive = Desktop.GetActive ()
[ ] Print ("Window: {wActive}")
[ ] // DialogBox("File Download").DialogBox("Save As")
[ ] wActive.TypeKeys (sFile)
[ ] wActive.TypeKeys ("", 1)
[ ] wActive.TypeKeys ("", 1)
[ ] wActive.TypeKeys ("S",1)
[ ]
[ ] bResult = TRUE

[+] else
[ ] Print ("BrowserFileDownload does not exist.")
[+] except
[ ] ExceptLog ()
[ ]
[ ] return bResult
[ ]

Saturday, July 12, 2008

Winrunner - Expert Questions

Earlier I had prepared set of questions to ask for WinRunner interview. I have given few of them below:

Expert Questions - WinRunner


  1. Scope of public, static, extern, auto variables.

  2. Differnce between Compiled Module and Main script

  3. What's the purpose of the wrun.ini file?

  4. What is the difference between "set_window" and "win_activate"?

  5. What is a checkpoint and what are different types of checkpoints?

  6. What are the virtual objects and how do you learn them?

  7. How can you merge GUI maps & tell me the possible ways?

  8. What is meant by GUI mapping? What is the concept behind that?

  9. What are the difference between calling a script and compiled module?

  10. What is the difference between loading a script and calling a script?

  11. Why do we go for eval to call a script?

  12. What is the difference between treturn, texit, return?

  13. What is the usage of tl_step?

  14. Tell about Match statement in WinRunner?

  15. What is function generator? How to use this in Winrunner?

  16. What is the difference between GUI_close_all and GUI_unload_all() ?

  17. Tell me about substr, index, split?

  18. What is synchronization point and tell me the usage of that?

  19. What is the difference between writing a function and writing a script?

  20. How do you handle unexpected events and errors?

Tuesday, July 8, 2008

Comparison of SilkTest and Winrunner

Last month, I have posted Comparison of SilkTest and QuickTest Professional . Then I thought to put one more comparison with Winrunner. This time I have compared in low level. It means comparing functions and file structure level. Hope it will be useful for automation newbies.

Wiki pages
Silktest on Wiki
Winrunner on Wiki

Code samples for both tools
Sample 4test code snippets for SilkTest
Sample TSL code snippets for Winrunner

References:


  1. SILKTEST AND WINRUNNER FEATURE DESCRIPTIONS - By Horwath/Green/Lawler

  2. Comparison of SilkTest and QuickTest Professional



Comparison Table: SilkTest Vs Winrunner

Features

SilkTest

WinRunner

Project fileSilktest has two types of extensions to represent projects. One is vtp file, which is usual one. Another one is stp file, which is zipped version of silktest project. <ProjectName>.ini or partner.ini has silktest settings.No project file.
Tool Configuration<ProjectName>.ini or partner.ini has silktest settings for particular project. Silktest has options set (*.opt) to configure the project level settings.Initial startup configurations are stored in wrun.ini file.
Test Environment vaiablesSetOption and GetOption methods are used to set various silktest settings. GetTestCaseName, GetTestCaseErrorCount, GetTestCaseState and GetTestCaseWarningCount functions are used to get information about testcases.setvar and getvar functions available to set or get test variables. Few options are : cs_run_delay, cs_fail, delay_msec, rec_item_name, rec_owner_drawn, searchpath, silent_mode, single_prop_check_fail, synchronization_timeout, tempdir and speed
Script RecorderOnly one mode for different activities.Record Testcase, Application State, Actions.Two modes. 1. Context sensitive mode 2. Analog mode.
Code ViewClassic 4Test, Visual 4TestOnly one view
Test ScriptScript is a single file. Extension is *.t. One script can contain many testcases.Actually Script is a folder and have set of supporting files.There will a file 'script'. That contains actual script.
  1. a db folder for asc data
  2. an exp folder for expected results.
  3. a debug folder for using during debug runs.
TestsTermed as Testcase. Each Testcase has block of coding statements.No separate terms.
Objects RepositoryOfficial term is frame file. They can be edited directly from the Editor. File extension is (*.inc). Objects are called as Window declarations. User can declare variables and functions inside frame file.Termed as GUI Map. Maintained as separate file. With the help of utility, objects can be modified. Two types as per Winrunner setting. They are 'GuiMap file per Test' and 'Global GUI Map'. File extension is same for both types as (*.gui). User can not declare variables and functions inside GUI Map file.
Physical descBased on Caption, Prior text, Index, Window ID, Location and Attribute.Wildcards can be used.Wildcards can be used.Identifying based on obligatory properties. An optional property is used only if the obligatory properties do not provideunique identification of an object. In cases where the obligatory and optional properties do not uniquely identify an object, WinRunner uses a selector. For example, if there are twoOK buttons with the same MSW_id in a single window, WinRunner would use a selector to differentiate between them. Two types of selectors are available:
  1. A location selector uses the spatial position of objects.
  2. An index selector uses a unique number to identify the object in a window.
Logical name - used to identify the objectCalled as Test Identifier. It is similar to variable. It should not have space or any other special characters. It is not similar to variable. It can have space and few special characters.
Object Representation
Based on true object hierarchy. Dynamic representation sample is given below:
Syntax: class("tag").class("tag").class("tag")
Example: MainWin("Text Editor - *").DialogBox("Find").TextField("Find What")
Based on Flat list. There will be only two levels. Top level will be window and leaf level will be child objects. Dynamic representation sample
Syntax: "{class: <class>, MSW_class: <WR class>,<property>:<propertyvalue>}"
Example: set_window("{class: window, MSW_class: html_frame,active:1}",20);
Function library Termed as Include (*.inc) file. Compile modules. Again it is similar to Test Script. Test Library/API calls use "frame.inc". You have to use in the beginning of script. Termed as Compiled module. GUI_load and GUI_open functions are used to load GUI Maps. You can call above functions anywhere from the script. You can call comipiled modules like below:
  1. reload( "C:\\MyAppFolder\\" & "flt_lib" );
  2. load( "C:\\MyAppFolder\\" & "flt_lib" );
CheckPoint Provided Verify and Verify Properties functions. Provided various check points for different purposes.
Results Reporting Results are stored into *.res binary files. It can be converted into differnt formats. Multiple versions can be stored into single file.Winrunner results are stored in separate folder for each run. Result folder contain two files:
  1. _t_rep.hdr -> Header file, which contains test run info
  2. _t_rep.eve -> results file, which contains info about each execution.
Library Browser Library Browser Function Generator
User Message Print(), Printf() functions report_msg() function.
Result Function Verify (), raise () and Reraise () functions tl_step () function
Exception Handling <do-except> block is available and few supporting functions. Winrunner does not have explicitly similar to do-except or try-catch block. But it has different wizards to handle different type of exceptions such as Pop-up exceptions, TSL exceptions, Object exceptions and Web exceptions.
Test/Error Recovery Powerful Default recovery system is set based on extension and MainWindow. It can be extended by using BaseState. Recovery Scenarios, which is available from Winrunner 7.5. Lower versions do not have this feature.
Wait statements Sleep (10) ' 10 seconds to wait Wait (10) ' 10 seconds to wait
Halt Execution temporarily Agent.DisplayMessage () - temporarily stopping execution with a message.pause() - pauses test execution and displays a message
To activate a windowMyWin.SetActive () set_window ("Shell_TrayWnd", 2);
Accessing DLLsOnly Standard DLLs. It does not support the COM/ActiveX DLLs, which are created by VB/.NET Both COM and Standard DLLs are supported. COM DLL support is available from Winrunner 7.5
Database Verification Having built-in functions to extract information from Databases through ODBC32 Interface (DSNs)Having built-in functions to extract information from Databases through ODBC32 Interface (DSNs). WinRunner also provides a visual recorder to create a Database Checkpoint used to validate the selected contents of an ODBC compliant database within a testcase.
Data functions Good Good. Having extensive support for SpreadSheet (Excel).
Scripting Language 4Test scripting language. It is a object oriented scripting language. Similar to C++ TSL - Test Script Language. It is based on the C programming language.
Data types Set of data types like integer, string and number are available. User can create their own data types also.No data types
Mostly using - Compound Data type LIST data type. ARRAY. Subscript can be integer or string.

Monday, July 7, 2008

Winrunner -Scope of Variables

Winrunner has four different types of variables. They are used inside the funciton, outside the function and calling from different tests.

auto : An auto variable can only be declared within a function and is local to that function.
It exists only while the function is running. A new copy of the variable is created each time the function is called.

static : A static variable is local to the function, test, or compiled module in which it is declared. The variable retains its value until the test is terminated by a Stop command.

public : A public variable can only be declared within a test or module, and is available for all functions, tests, and compiled modules.

extern : An extern declaration indicates a reference to a public variable declared outside of the current test or module.

For more info, See the Winrunner Help.

Friday, July 4, 2008

Winrunner - Tooltip verification

Winrunner does not have any built-in function, to get tooltip. Jerry McGowan has written TSL code to verify the tooltip. I was searching my old winrunner scripts. At that time, I found this sample code.

Already I have written a post for tooltip verification by QTP. Post QTP - Tooltip verification in Browser

Winrunner (TSL) code - To verify Tooltip

############################################################ # Function: # check_tootip() # # Description: # Moves the mouse to a specified location within an object # to activate the object popup text message. The expected # popup message is then compared to the actual text, and # the function returns E_OK if the text is found. # # Parameters: # object - Name of the object # tip - The expected tip text that should popup when # the mouse is moved over the object. # x - The x position within the object to move the mouse # y - The y position within the object to move the mouse # # Returns: # "E_OK" if the tip is found, "E_NOT_FOUND" otherwise. # # Syntax: # rc = check_tooltip(object,tip,x,y); # # Example: # check_tooltip("ToolbarWindow32","Create Order",5,5); # ############################################################ function check_tooltip(in object, in tip, in x, in y) { auto parent, text; # Move to the first button of the toolbar obj_mouse_move (object, x,y); # Wait until the tip is displayed. wait(1); # Get the text for the window. obj_get_info(object,"parent",parent); win_get_text(parent, text); # You can then search the contents of text to see if # the expected tip is displayed. if (index (text, tip) > 0) { tl_step ("Tool tip", PASS, tip); return (E_OK); } else { tl_step ("Tool tip", FAIL, tip); return (E_NOT_FOUND); } }; ############################################################ # End of script ############################################################

Thursday, July 3, 2008

Winrunner - SET_WINDOW and WIN_ACTIVATE

This is one of my favorite and Expert questions in Winrunner.

  1. What is the difference between "set_window" and "win_activate"?
  2. When would you use "set_window" and when would you use "win_activate"?

win_activate has the syntax win_activate(window);. The win_activate function
makes the specified window the active window by bringing it into focus and
raising it to the top of the display. (It is the equivalent to clicking on the
window banner)

Set_window has the following syntax: set_window(window,[time]);
The set_window function directs input to the right application window. This
directs the GUI map to this window. It also sets the scope for object
identification in the GUI map.

The most important difference is that set_window has a timing option.
WinRunner will wait a maximum of the number used in the function, PLUS the system set timeout, to wait for the window to appear. Win_activate assumes the window is already on the desktop and has no timing option.

Tuesday, July 1, 2008

QTP - Smart Identification

Sometimes back, I was in a QTP interview panel. Most of the candidates do not know about smart identification. That's why, I thought to write to this post.

Need of Smart Identification
Smart identification is a technique in QuickTest Professional. It is used to identify the objects, even though few mandatory properties are changed at run time.

Smart Identification Overview
The Smart Identification dialog box enables you to create and modify the Smart Identification definition that QuickTest Professional uses for a selected test object class. When the recorded definition for an object does not enable QTP to identify an option, QuickTest Professional uses the smart identification definition (if defined and enabled) to identify the object.

Smart Identification uses two types of properties:


  1. Base filter properties: The most fundamental properties of a particular test object class; those whose values cannot be changed without changing the essence of the original object. For example, if a Web link's tag was changed from <A> to any other value, you could no longer call it the same object.

  2. Optional filter properties: Other properties that can help identify objects of a particular class as they are unlikely to change on a regular basis, but which can be ignored if they are no longer applicable.


To know more about Smart Identification, You can see the QuickTest Professional Help for following topics:

  1. About Configuring Smart Identification

  2. Understanding the Smart Identification Process

  3. Reviewing Smart Identification Information in the Test Results

  4. Walking Through a Smart Identification Example

  5. Step-by-Step Instructions for Configuring a Smart Identification Definition