March 16, 2011
Calling dll functions using Silktest
[ ] // Here is the function that kills any window using Windows API(mainly win32 dlls).
[ ]
[ ] use 'msw32.inc'
[ ]
[+] dll "kernel32.dll"
[ ] BOOL TerminateProcess( HWND hProcess, UINT uExitCode)
[ ] HWND OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId)
[ ] BOOL GetExitCodeProcess( HWND hProcess, out DWORD lpExitCode)
[ ] const LONG PROCESS_ALL_ACCESS = 0x000F0000 | 0x00100000 | 0xFFF
[ ]
[-] main ()
[ ] // Usage
[ ] TerminateAnyWin (Browser) // kills the active browser
[ ]
[ ]
[ ] //Function definition
[ ] ======================
[ ]
[-] boolean TerminateAnyWin (window wWindow)
[ ]
[ ] HWND hProcess
[ ] DWORD iExitCode
[ ]
[ ] boolean bSuccessful
[ ] integer iProcessID
[ ]
[ ] wWindow.SetActive ()
[ ] iProcessID = wWindow.GetAppID ()
[ ]
[ ] hProcess = OpenProcess (PROCESS_ALL_ACCESS, 0, iProcessID)
[ ]
[ ] GetExitCodeProcess (hProcess, iExitCode)
[ ]
[ ] bSuccessful = TerminateProcess (hProcess, iExitCode)
[ ]
[ ] return bSuccessful
[ ]
March 11, 2011
Allowing popup windows from a website using registry functions
[+] void AllowPopups (string sHTTPServer)
[ ]
[ ] Reg_CreateKey (HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\New Windows\Allow")
[ ] Reg_CreateValue (HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\New Windows\Allow", sHTTPServer, "REG_BINARY: 0x0000")
// Example: AllowPopups ("http://www.yahoo.com")
Deleting browser cookies and temporary internet files using command prompt
// Silk Test code to delete cookies using command line.
[+] void DeleteCookies()
[ ] // Close All Browsers
[ ]
[ ] SYS_Execute("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2")
Here are the different options for various tasks:
================================================
echo Clear Temporary Internet Files:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
echo Clear Cookies:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
echo Clear History:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
echo Clear Form Data:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16
echo Clear Saved Passwords:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32
echo Delete All:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255
echo Delete All w/Clear Add-ons Settings:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 435
For more details click here.
March 07, 2011
Capturing screenshot and window declarations when an error occurrs in the testcase execution.
// To achieve this you need to override the recovery system, you need to write your own TestCaseExit function as below.
[-] void TestCaseExit (boolean bException)
[ ]
[ ] List of string lsErrorPageDeclarations
[ ] string sExceptionBitmapFile = "AbsoluteBitmapFilePath"
[ ]
[-] if bException == True
[ ] // Test case failed
[ ]
[ ] // Delete any bitmaps from a previous Exception.
[-] if SYS_FileExists(sExceptionBitmapFile)
[ ]
[ ] SYS_RemoveFile(sExceptionBitmapFile)
[ ]
[ ] // Go to the top of the form.
[ ] BrowserPage.Click(1,1,1)
[ ] BrowserPage.TypeKeys("
[ ]
[ ] Desktop.CaptureBitmap (sExceptionBitmapFile)
[ ] lsErrorPageDeclarations = BrowserPage.GenerateDecl ()
[ ]
[ ] Print("---------------------------------------------------------------------------")
[ ] ResOpenList ("The declarations for the current BrowserChild are:")
[ ] Print("---------------------------------------------------------------------------")
[ ]
[ ] ListPrint (lsErrorPageDeclarations)
[ ]
[ ] ResCloseList()
March 03, 2011
Basic API for BorderLess table
Here is basic API for Borderless tables:
=====================================
boolean Exists (number nTimeOut optional) // Tells the presence of table at the declared boderless level (0 to 1)
list of list of string GetTableData (boolean bIncludeEmptyCells optional) // equal to GetRowRangeText
integer GetRowCount ( )
boolean DoesKeyExists (String sKey, int iSearchColIndex, list of list of string
llsTableData optional) // Tells presence of a text in the table
List of String GetRowText (TABLEROW Row, boolean bShowSpannedCell optional)
integer GetRowIndex (String sKey, int iSearchColIndex, list of list of string llsTableData optional)
Declaration of Table Object:
=====================
[+] BorderlessTable tblBalanceDetails
[ ] tag "$balanceDetails"
[ ] real rLevelOfRecognition = 0.76 // This is a mandatory datamember, tells at which level table is visible.
Usage
========================
[ ] boolean bFound =Page.tblBorderLess.DoesKeyExists ("abc ", 1) // searches for the presence of text "abc" in the column1 of the table
[ ] Verify(bFound, true, "Verifying that key exists in the column1")
// no need to explicitly set the borderless table setting before calling the method.
Definition of Functions:
========================
[+] winclass BorderlessTable : HtmlTable
[ ] // ***************************************************************
[ ] // Data-Member Section
[ ] setting DontInheritClassTag = True // Prevent Recorder and GetChildren from Overriding Standard Class with this extended Class
[ ]
[ ] real rLevelOfRecognition = null
[ ] const real rDefaultLevelofrecognition = 0.76
[+] boolean Exists (number nTimeOut optional)
[ ] boolean bExists
[ ] //Reading the option level that is present, end of the function it resets back to this level.
[ ] real rPreviousLevel = BrowserPage.GetUserOption ('ShowBorderlessTables')
[ ]
[+] if rLevelOfRecognition == null
[ ] //assigning default recognition level
[ ] rLevelOfRecognition = rDefaultLevelofrecognition
[+] else
[ ] //Validating the range.
[+] if rLevelOfRecognition < 0 || rLevelOfRecognition > 1
[ ] RaiseError (INVALID_PARAMETER,"Value of parameter 'rLevelOfRecognition' should be in the range of ZERO to ONE")
[+] do
[+] if rPreviousLevel != rLevelOfRecognition
[ ] BrowserPage.SetUserOption ('ShowBorderlessTables', rLevelOfRecognition)
[ ] bExists = derived :: Exists (nTimeOut)
[+] if rPreviousLevel != rLevelOfRecognition
[ ] BrowserPage.SetUserOption ('ShowBorderlessTables', rPreviousLevel)
[ ]
[+] except
[+] if rPreviousLevel != rLevelOfRecognition
[ ] BrowserPage.SetUserOption ('ShowBorderlessTables', rPreviousLevel)
[ ]
[ ] reraise
[ ] return bExists
[+] list of list of string GetTableData (boolean bIncludeEmptyCells optional)
[ ] list of list of string llsData = {}
[ ] int iRow, iCol
[ ] list of string lsRowData
[+] if rLevelOfRecognition == null
[ ] //assigning default recognition level
[ ] rLevelOfRecognition = rDefaultLevelofrecognition
[+] else
[ ] //Validating the range.
[+] if rLevelOfRecognition < 0 || rLevelOfRecognition > 1
[ ] RaiseError (INVALID_PARAMETER,"Value of parameter 'rLevelOfRecognition' should be in the range of ZERO to ONE")
[ ] //setting default value of bIncludeEmptyCells as true
[+] if bIncludeEmptyCells == null
[ ] bIncludeEmptyCells = true
[ ] //Reading the option level that is present, end of the function it resets back to this level.
[ ] real rPreviousLevel = BrowserPage.GetUserOption ('ShowBorderlessTables')
[+] do
[+] if rPreviousLevel != rLevelOfRecognition
[ ] BrowserPage.SetUserOption('ShowBorderlessTables', rLevelOfRecognition)
[ ] BrowserPage.SetUserOption("RowTextIncludesEmptyCells", bIncludeEmptyCells)
[ ] // Checking for the presence of Table
[+] if !this.Exists()
[ ] RaiseError(GENERAL_SCRIPT_ERROR, "Cannot find table object {this}")
[ ] llsData = this.GetRowRangeText(1)
[ ]
[+] if rPreviousLevel != rLevelOfRecognition
[ ] BrowserPage.SetUserOption('ShowBorderlessTables', rPreviousLevel)
[ ] BrowserPage.SetUserOption("RowTextIncludesEmptyCells", false)
[+] except
[+] if rPreviousLevel != rLevelOfRecognition
[ ]
[ ] BrowserPage.SetUserOption('ShowBorderlessTables', rPreviousLevel)
[ ]
[ ] BrowserPage.SetUserOption("RowTextIncludesEmptyCells", false)
[ ] reraise
[ ]
[+] if llsData == {}
[ ] RaiseError (GENERAL_SCRIPT_ERROR, "Unable to get Table Data.")
[ ] //Trimming the all cell values in the table.
[+] for iRow=1 to listcount(llsData)
[ ] lsRowData=llsData[iRow]
[ ]
[+] for iCol=1 to listcount(lsRowData)
[ ] llsData[iRow][iCol]=Trim(llsData[iRow][iCol])
[ ]
[ ] return llsData
[ ]Returns presence of Key text in the table.
[+] boolean DoesKeyExists (String sKey, int iSearchColIndex, list of list of string llsTableData optional)
[ ]
[ ] boolean bFound = false
[ ] int i
[ ]
[-] if llsTableData==null
[ ] llsTableData = this.GetTableData ()
[ ]
[-] for i=1 to ListCount (llsTableData)
[ ]
[-] if CaseSensitiveMatchString (sKey,llsTableData[i][iSearchColIndex])
[ ]
[ ] bFound = true
[ ] break
[ ]
[ ] return bFound
[+] integer GetRowCount ( )
[ ] real rPreviousBLTLevel
[ ] integer iRows = 0
[ ]
[-] if rLevelOfRecognition == null
[ ] //assigning default recognition level
[ ] rLevelOfRecognition = rDefaultLevelofrecognition
[ ]
[ ] rPreviousBLTLevel = BrowserOptions.SetBorderLessTableLevel ( rLevelOfRecognition )
[-] do
[ ] iRows = derived :: GetRowCount ()
[ ] BrowserOptions.SetBorderLessTableLevel ( rPreviousBLTLevel )
[-] except
[ ] BrowserOptions.SetBorderLessTableLevel ( rPreviousBLTLevel )
[ ] reraise
[ ]
[-] if iRows == 0
[ ] RaiseError (GENERAL_SCRIPT_ERROR, "Table is empty")
[ ] return iRows
[ ]
[+] List of String GetRowText (TABLEROW Row, boolean bShowSpannedCell optional)
[ ]
[ ] List of STRING lsRowData = {}
[ ] real rPreviousBLTLevel
[ ] int iCol
[ ]
[+] if rLevelOfRecognition == null
[ ] //assigning default recognition level
[ ] rLevelOfRecognition = rDefaultLevelofrecognition
[ ]
[ ] rPreviousBLTLevel = BrowserOptions.SetBorderLessTableLevel ( rLevelOfRecognition )
[+] do
[ ] lsRowData = derived :: GetRowText (Row, bShowSpannedCell)
[ ] BrowserOptions.SetBorderLessTableLevel ( rPreviousBLTLevel )
[+] except
[ ] BrowserOptions.SetBorderLessTableLevel ( rPreviousBLTLevel )
[ ] reraise
[ ]
[ ] //Trimming all the cell values in the row
[+] for iCol =1 to listcount(lsRowData)
[ ] lsRowData[iCol] = Trim ( lsRowData[iCol] )
[ ]
[ ] return lsRowData
[+] integer GetRowIndex (String sKey, int iSearchColIndex, list of list of string llsTableData optional)
[+] //HELP:
[ ] // Returns the rowindex of given key, on presence of Key it returns Non-Zero value, [else] zero.
[ ] // sRowValue can be AccountNumbers/status etc
[ ] // iSearchColIndex is the table Coloumn index in which it searches for Key.Default Value is 1 i.e the first column
[ ]
[ ] integer i, iIndex = 0
[-] if llsTableData==null
[ ] llsTableData = this.GetTableData ()
[-] for i=1 to ListCount (llsTableData)
[+] if CaseSensitiveMatchString (sKey,llsTableData[i][iSearchColIndex])
[ ] iIndex = i
[ ] break
[-] if iIndex == 0
[ ]
[ ] RaiseError (GENERAL_SCRIPT_ERROR, "Unable to find {sKey} in {iSearchColIndex} Column.")
[ ]
[ ] return iIndex