February 13, 2008
SilkTest Tip18 - Tooltip verification in web pages
SilkTest does not have built-in function, to get tooltip from browser controls. In a browser there is no actual ToolTip control, but the alt tag is sometimes used to simulate a ToolTip.
Silktest can execute javascript statements. By using that, we can get tooltip from web objects. In the following example sAltProp variable gets the tooltip of AutoImage object.
STRING sAltProp = MyApp.AutoImage.ExecMethod('getAttribute("alt")')
Similarly we can use javascript to get more info from that object. I will write another tip for javascript execution.
SilkTest Tip17 - How to recover .Jou file and convert to .res
While SilkTest is running a script, it temporarily stores results in a journal file (.jou) which is converted to a .res file when the script finishes running.
You re-ran that particular script/plan/suite file for a testcase and then stopped manually. In the results file, select the previous results. There you can see the results of previous execution.
Remove the jou file, if SilkTest reports the error "Can't open results file."
February 12, 2008
Tip16 - To get child objects from any container object
This function is useful, if user tries to get all children of particular CLASS object. I have used recursive technique here.
Code:
[-] public LIST OF WINDOW GetChildObjects(Window wContainer, DATACLASS dcObject)
[ ] // To get All child objects.
[ ] // Used recursive method.
[ ] LIST OF WINDOW lwndObjects, lwTemp1, lwTemp2
[ ] LIST OF WINDOW lwndChildren = {...}
[ ] WINDOW wParent, wChild, wTemp
[ ]
[-] do
[-] if (wContainer.Exists (10))
[ ] lwndChildren = wContainer.GetChildren (TRUE, FALSE)
[ ]
[-] for each wChild in lwndChildren
[-] if wChild.IsOfClass(dcObject)
[ ] ListAppend (lwndObjects,wChild)
[-] else
[ ] lwTemp1 = wChild.GetChildren(TRUE, FALSE)
[-] if (ListCount(lwTemp1) > 1)
[ ] lwTemp2 = GetChildObjects(wChild,dcObject)
//To get particular objects
[-] if (ListCount(lwTemp2) > 0)
[ ] ListMerge (lwndObjects, lwTemp2)
[-] else
[ ] Print ("Container {[STRING]wContainer} is not available.")
[+] except
[ ] ExceptLog ()
[ ]
[ ] return lwndChildren
Tip15 - Set tag dynamically
Sometimes user may want to assign the tag dynamically at runtime. Replace the tag with a function call. See the Example.
Two dialogs have the same label or caption, but do not have identical contents. For example, one Open dialog has a Name text field and the other Open dialog has a Search pushbutton. See the Tip9.
For more Info, Pls see the Silktest help-> Index-> Multitag statement ->Multitag statement
Example:
[-] HtmlTable GridTable
[ ] tag "{GetTableTags()}"
[ ]
[-] String GetTableTags()
[ ] return (sGridTableTag)
February 11, 2008
Tip14 - Getting IP address of a machine
Below code snippet is useful to find IP address of a system. It is based on Sys_execute command.
[+] public String GetIpAddress(String sMachineName)
[ ] //To get IP Address for the particular machine in Network
[ ] List of String lsOutput
[ ] String sCommand
[ ] String sTemp, sItem
[ ] String sResult = NULL
[ ] Boolean bResult = FALSE
[ ] Integer iPos1, iPos2
[ ]
[ ] sCommand = "ping -a {sMachineName}"
[ ] Sys_Execute (sCommand,lsOutput)
[ ]
[ ] //ListPrint (lsOutput)
[-] for each sItem in lsOutput
[-] if (MatchStr("*pinging*", sItem))
[ ] bResult = TRUE
[ ] break
[ ]
[-] if (bResult)
[ ] iPos1 = StrPos ("[", sItem)
[ ] iPos2 = StrPos ("]", sItem)
[-] if ((iPos1 > 0) && (iPos2 > 0))
[ ] sResult = SubStr(sItem,iPos1+1, iPos2-iPos1-1)
[ ] Print ("Found IP Address: {sResult}")
[ ] return sResult
Tip13 - Reference Operator @
The reference operator (@expression) lets you refer to functions and variables indirectly, by name. It uses the value of its operand to refer to variable, the fields in a record, function, method, property or child window.
Example
1. Used to refer a window object
wLeftframe.@(sModuleName).Click(1,16,10)
2. Used to refer method or function
wLeftframe.Links.@(sPropReload)( )
3. To refer a member of record type
adAlert.@sComments = "My Comments"
February 10, 2008
Tip12 - To match a string against list of string
In Silktest, we do not have a built-in function to match a item by wild cards with a List of items. In this scenario, you can use following code snippet. Here I have declared as string and if you want to use different data types, declare as ANYTYPE.
[-] public Integer MatchList(String sPattern, LIST OF STRING lsInput)
[ ] //To match one string with any item in list of strings
[ ] //Returns the item value(integer)
[ ] Integer iCount, iItem
[ ] String sData, sTemp
[ ] Integer iReturn = 0
[ ]
[ ] iCount = ListCount(lsInput)
[-] for iItem=1 to iCount
[-] if (MatchStr(sPattern,lsInput[iItem]))
[ ] iReturn = iItem
[ ] break
[ ]
[ ] return iReturn
Tip11 - To click on center position of a object
Sometimes script is required to click center of the objects. It depends upon the control classes. In few scenarios, silktest will return negative co-ordinates for particular objects. At that time, we can set the statement to click on center of the object. The code snippet is given below.
[+] public void ClickCenter(window wObjectName , boolean bIsRightClick optional)
[ ] // Clicking on Center point of any Object [Html Image , Text Etc.]
[ ]
[ ] RECT rWindowShape
[ ]
[ ] rWindowShape = wObjectName.GetRect (TRUE)
[ ]
[+] if ((bIsRightClick==NULL) || bIsRightClick==TRUE) // if Left click .?
[ ]
[ ] wObjectName.Click(2,rWindowShape.xSize/2,rWindowShape.ySize/2)
[ ]
[+] else
[ ]
[ ] wObjectName.Click(1,rWindowShape.xSize/2,rWindowShape.ySize/2)
[ ]