Friday, May 30, 2008

Silktest - String Match against a List

Silktest has MatchStr function to compare one string with another. Here you can use pattern. But Silktest does not have a built-in function to match a item by a pattern with a List of items. I have used this scenario in many places of the code. Code snippet is given below.

4Test Code: To Match a string against List

[-] 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

Thursday, May 29, 2008

Silktest - Classic 4Test and Visual 4Test

I think that many of the silktest automation engineers do not know, Silkest has two outline editors. Visual 4Test, enabled by default, is similar to Visual C++ and contains colors.

Classic 4Test is one of the two outline editors you can use with SilkTest. Classic 4Test is similar to C and does not contain colors.

Below I have given the samples for both type of modes. To change editor modes, click Edit Menu -> "Visual 4Test" to select or clear the check mark. You can also specify your editor mode on the General Options dialog.

Sample Classic 4Test - Silktest 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} window is not available.");
}
}
except
{
ExceptLog ();
}

return lwndChildren;
}


Sample Visual 4Test - Silktest 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} window is not available.")
[+] except
[ ] ExceptLog ()
[ ]
[ ] return lwndChildren

Wednesday, May 28, 2008

QTP - Tooltip verification in Browser

In Silktest, I have done tooltip verification by using Javascript. Post Silktest - Tooltip verification in Browser

How will you verify tooltip in Quick Test Professional (QTP)? Dmitry Motevich clearly explained it in his blog. He is using FireEvent("onmouseover") to simulate mouse placing over the link and picking the value from Windows Class. I hope that we can use outerhtml to get the tooltip value from ALT attribute.

Dmitry Motevich's Post : How to capture ToolTip by QTP

Tuesday, May 27, 2008

Silktest - Record Class

Yesterday I was going through Silktest Knowledge base in Borland support. Silktest has a feature "Record Class" for custom controls. This feature can list out external methods (public). It is an informative article.

Below quote is from Borland Support - Silktest KnowledgeBase .

Recording Class will let the built-in methods that any object has, be available to use in 4Test. These will be held in your include file in the form of a Winclass.

It can also be used if you are testing a component in SilkTest that is seen as a CustomWin, then you can Record Class against it.

Alternatively, it can be used on objects that are being recognised correctly by SilkTest but which may have their own built-in methods (only public methods) which would be more appropriate to your needs. If this is the case, then record class will be suitable for you to make these methods (as well as properties) available to be used.

Monday, May 26, 2008

Test Development

Today Software Testing is not a low end task. Testers are doing variety of testing. Sometimes developers are moved to Test Automation and Performance Testing. I am sure that Code development skills improves Tester's ability. Many test expertises have said about it. I found one interesting article at Testy's blog. He has analyzed in depth. Link ==> Do testers need programming skills?

The below quote content is from I.M.Testy's blog

The debate over whether testers need to at least understand programming concepts is still raging within the discipline. To me this debate is puzzling because it seems to suggest that as a professional, I don't have to really understand or be completely proficient in critical aspects of my trade. Even Cem Kaner noted, "I think that the next generation of testers will have to have programming skills." Actually, there was a time not so long ago when testers had to have programming skills, so it is nice that Cem now acknowledges that skill as useful in testing.

Unfortunately, occasionally even within Microsoft a few people still want to differentiate between STE and SDET by blindly assuming that STE meant non-programming testers. The fact is, that the old STE ladder level guidelines clearly stated skills such as debugging production code, and design and develop effective automation as required skills for Microsoft testers. Unfortunately, some managers chose to selectively ignore these skill requirements and some groups chose to differentiate between GUI testers and any tester who could write code by labeling them as STE and SDET respectively. (This was a horrible abomination of job titles in my opinion.) The new SDET competencies at Microsoft are designed, and supposed to be implemented in a manner, to reinforce the essential skills we expect from our testers so a tester at a certain level in their career stage in one business unit essentially has equitable skills of any other tester at the same level in their career stage in any group in the company.

Friday, May 23, 2008

Free Training on Windows Vista

Microsoft has come up a free training in Vista. You can learn the tips and tricks of deploying and optimizing Windows Vista by attending Windows Vista Live - a two day online event. Equip yourself with actionable insights into key security features, application compatibility issues, performance optimization, tools and guidance for Windows Vista deployment. This session provides a deep dive opportunity to help you seamlessly roll out Windows Vista.

Register Page1
Register Page2

Optimize Windows Vista - June 5, 2008 | 1400 - 1530 hrs

Topics covered:


  1. Addressing application comparibility

  2. Key security features

  3. Troubleshooting and optimizing performance


Deploy Windows Vista - June 6, 2008 | 1400 - 1530 hrs

Topics covered:

  1. Tools and guidance for deploying

  2. Best practices

Thursday, May 22, 2008

Advanced Peer-to-Peer Networking (APPN)

In my first job, I used to store few tech terms as texts. One such thing is given below.

Advanced Peer-to-Peer Networking (APPN), part of IBM's Systems Network Architecture (SNA), is a group of protocols for setting up or configuring program-to-program communication within an IBM SNA network. Using APPN, a group of computers can be automatically configured by one of the computers acting as a network controller so that peer programs in various computers will be able to communicate with other using specified network routing.
APPN features include:

Better distributed network control; because the organization is peer-to-peer rather than solely hierarchical, terminal failures can be isolated Dynamic peer-to-peer exchange of information about network topology, which enables easier connections, reconfigurations, and routing Dynamic definition of available network resources, Automation of resouce registration and directory lookup

Wednesday, May 21, 2008

Winrunner - Handling Dynamic objects

Most of the Winrunner users are using playback methods to develop the scripts. Here I have given two code snippets to handle dynamic objects.

Code: To find Image

public function SetToSearchPage() { web_sync(200); set_window("{class: window, MSW_class: html_frame,active:1}",60); web_image_click("{class: object,MSW_class: html_rect,html_name: \"search_gnav.gif\"}", 0, 0); web_sync(250); } #End of SetToSearchPage()

Code: To find correct Window, after clicking a link
public function SetTitle() { set_window("{class: window, MSW_class: html_frame,active:1}",20); win_get_info("{class: window, MSW_class: html_frame,active:1}","html_name", sWinTitle); #report_msg("RE Source Page Title is " & sWinTitle); if (index(sWinTitle, "Users") != 0) { set_window("My Users",40); #report_msg("My Users page has been identified"); } else if (index(sWinTitle, "Group") != 0) { set_window("Group",20); #report_msg("Group page has been identified"); } else if (index(sWinTitle, "View Agenda") != 0) { set_window("View Agenda",30); #report_msg("View Agenda page has been identified"); }else { report_msg("Couldn't find the window in GUI MAP is " & sWinTitle); } }

Tuesday, May 20, 2008

Winrunner - File Handling

Winrunner code is similar to 'C' code. Any automation suite must have file handling functions for various scenarios. It may be just text files or any data files. Winrunner also has few methods for file handling. Below few sample code snippets are given..

Code: To read a file

#--------------------------------- # Method : fileRead # Author : T.Palani Selvam # Purpose : Read all contents of a file. # Parameters: String, contains file name. # # Returns : - Nil - # Caller : # Calls : - Nil - #---------------------------------- public function fileRead(in m_sFile) { auto iLine; auto sEachLine; auto sFileContent; printf("fileRead is going to process for " & m_sFile); file_open(m_sFile,FO_MODE_READ); iLine = 0; while(file_getline(m_sFile, sEachLine) == 0) { sFileContent = sFileContent & sEachLine; iLine++; printf(sEachLine); } #report_msg(sFileContent); #Line is too length file_close(m_sFile); } #end of fileRead(in m_sFile)


Code: To write info to a file
#------------------------------ # Method : fileWrite # Author : T.Palani Selvam # Purpose : Write Given inputs to a file. # Parameters: String, contains file name. # # Returns : - Nil - # Caller : # Calls : - Nil - #----------------------------- public function fileWrite(inout m_sFile) { auto iLine; auto sEachLine; auto iBool; auto null=""; printf("fileWrite is going to process for " & m_sFile); file_open(m_sFile, FO_MODE_WRITE); iLine = 0; do { sEachLine = create_input_dialog("Enter Input to write in " & m_sFile); if (sEachLine == null ) { #equals to NULL iBool = 0; } else { iBool = 1; iLine = iLine + 1; file_printf(m_sFile,"%s",sEachLine & "\r\n"); printf(sEachLine); } } while(iBool == 1); file_close(m_sFile); #Closing file } #end of fileWrite(in m_sFile)


Code: To Append info to a file
#----------------------------------- # Method : fileAppend # Author : T.Palani Selvam # Purpose : Write Given inputs to a file. # Parameters: String, contains file name. # # Returns : - Nil - # Caller : # Calls : - Nil - #---------------------------------- public function fileAppend(inout m_sFile) { auto iLine; auto sEachLine; auto iBool; auto null=""; printf("fileAppend is going to process for " & m_sFile); file_open(m_sFile, FO_MODE_APPEND); iLine = 0; do { sEachLine = create_input_dialog("Enter value to append in " & m_sFile); if (sEachLine == null ) { #equals to NULL iBool =0; } else { iBool = 1; iLine = iLine + 1; file_printf(m_sFile,"%s",sEachLine & "\r\n"); printf(sEachLine); } } while(iBool == 1); file_close(m_sFile); } #end of fileAppend(in m_sFile)

Monday, May 19, 2008

Silktest - Reference Operator '@'

Silktest uses '@' symbol for different purposes. This reference operator (@) can be used to refer 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. You can use reference operator in following ways:

Case 1:
1. Used to refer a window object
wLeftframe.@(sModuleName).Click(1,16,10)

Case 2:
2. Used to refer method or function
wLeftframe.Links.@(sPropReload)( )

Case 3:
3. To refer a member of record type
adAlert.@sComments = "My Comments"

Friday, May 16, 2008

SilkTest - TimeStamp for Current time

In Previous post, I have given the code to get TimeStamps from TSL (Winrunner) code. Now the same feature is given in Silktest (4Test) Code. It will be useful to create unique files and set the DateTime info whenever needed. Below I have given the 4Test ( Silktest scripting ) code snippet for timestamps.

4Test Code: TimeStamp for Current time



[+] public void GetCurrentDateTime(out String sDate optional, out String sTime optional,String sDateFormat null optional,String sTimeFormat null optional)
[ ] // Purpose: Current date and time are taken from the system.
[ ] DateTime dtmCurrent
[ ]
[+] if (IsNull(sDateFormat))
[ ] sDateFormat = "mm/dd/yyyy"
[+] if (IsNull (sTimeFormat))
[ ] sTimeFormat = "hh:nn:ss AM/PM"
[ ] dtmCurrent = GetDateTime ( )
[ ] sTime=FormatDateTime (dtmCurrent, sTimeFormat)
[ ] sDate=FormatDateTime (dtmCurrent, sDateFormat)
[+] String GetTimeStamp()
[ ] //Purpose: To get current time stamp in the given format
[ ] String sDate, sTime
[ ] String sTcFile
[ ] STRING sPrefix
[ ]
[ ] GetCurrentDateTime (sDate, sTime,"yyyymmdd","hhnnss" )
[ ] sPrefix = "{sDate}{sTime}"
[ ] return sPrefix

Thursday, May 15, 2008

Winrunner - Code for TimeStamp

I used to develop a function to have timestamps in all the testing tools. I have written same in Winrunner also. It will be useful to create unique files and set the dateTime info whenever needed. Below I have given the TSL (Test Script Language) code snippet for timestamps.

TSL Code: TimeStamp for Current time



#This function returns the current system time like this --> "24Jan2003_11hh_20mm_45ss"
public function GetTime() {
# w - in terms of Word
auto sDate, sTime, sDayW, sDayN, sMonthW, sMonthN, sYear, sHour, sMinute, sSecond;
auto sCurDate, sCurTime;
auto sArrDate[], sArrTime[];
auto sReturn;

sCurTime = get_time();
sCurDate = time_str(sCurTime); #returns like Mon Dec 16 16:09:56 2002

split (sCurDate, sArrDate, " ");
sDayW = sArrDate[1];
sMonthW = sArrDate[2];
sDayN = sArrDate[3];
sTime = sArrDate[4];
sYear = sArrDate[5];

split(sTime, sArrTime, ":");
sHour = sArrTime[1];
sMinute = sArrTime[2];
sSecond = sArrTime[3];

sReturn = sDayN & sMonthW & sYear & "_" & sHour & "hh_" & sMinute & "mm_" & sSecond & "ss";

return sReturn;

} #end of GetTime()

Wednesday, May 14, 2008

Repair Internet Explorer 6.x

Sometimes Internet Explorer 6.x DLLs may get corrupted due to silktest or some other third party tools. By this, silktest may not able to get browser objects properly. To repair IE, You can do following things.

Re-Install
Start > Run rundll32 setupwbv.dll,IE6Maintenance "C:\Program Files\Internet Explorer\Setup\SETUP.EXE" /g
or
Start > Run rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 C:\windows\inf\ie.inf

and select to repair IE if this does not help.... then another possibility would be to run the LSP fix in Internet Explorer, see http://inetexplorer.mvps.org/data/lsp_fix.htm

Re-Register DLLs
Another way is, copy below info into a batch file and run it.



REM Ie6_cure.bat
regsvr32 Shdocvw.dll
regsvr32 Shell32.dll
regsvr32 Oleaut32.dll
regsvr32 Actxprxy.dll
regsvr32 Mshtml.dll
regsvr32 Urlmon.dll

Tuesday, May 13, 2008

Silktest - Unable to start Internet Explorer

Most of the silktest engineers would have faced this problem. I have got the same problem couple of times and rectified. Thats why, I thought to put into blog.

Sometimes, we may get like below, while trying to enable extensions for browser.

---------------------------
Extension Settings
---------------------------
SilkTest detected a Client/Server application.
The required Extension has been enabled.
---------------------------

Problem Description
Few Silktest DLLs might have corrupted for that profile (Say network userid). Thats why it is throwing that error.

Solution
In that same machine, login as other user and run the same scripts.
If it works fine, delete your primary user profile -> restart the machine-> login as the same primary user. Then the scripts will work.
If it doesn't work, you have to check your Browser. Try to reinstall IE and run the scripts. Otherwise repair IE.

For IE7, You may need to reinstall Silktest again.

Monday, May 12, 2008

Dynamic GUI Identifier

In real time, mostly user needs to select the data or click links dynamically. Sometimes user may want to assign the tag dynamically at runtime. In Silktest, user can replace the tag with a function call. See the Example.

Example:

[-] HtmlTable GridTable
[ ] tag "{GetTableTags( )}"
[ ]
[-] String GetTableTags( )
[ ] return (sGridTableTag)


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 Handle Same titled windows .

For more Info, Please see the Silktest Help-> Index Tab-> Multitag statement -> Multitag statement

Saturday, May 10, 2008

Handle Same titled windows

Many projects are having same title for the windows or dialog boxes. Assume that two window objects are unique and children of them are different. In this situation, look for unique child objects and re-define your frame like below. It will be useful mainly for installers and web applications. Often the browser title will be same for many screens.

Below I have given for Silktest. Assume that X & Y are two different windows and having same tag. Both windows are differentiated by their unique child objects.

Window X
tag "TestWindow/[TextField]Name/.."

Window Y
tag "TestWindow/[Pushbutton]Search/.."

Friday, May 9, 2008

Deleting temporary files

It is a better practice to compile all your scripts, before running for a build. I have written a simple DOS batch script, which deletes the given temporary files. I have done this for Silktest.

You can put following code into a batch (*.bat) file and put under your scripts directory. Also You can modify as per your requirements.




rem ******************************
echo on

rem *****************************************
rem * Delete Silktest temporary files*
rem *****************************************

cd ../
del *.ino /S /Q
del *.in_ /S /Q
del *.res /S /Q
del *.to /S /Q
del *.t_ /S /Q
del *.s_ /S /Q
del *.bak /S /Q
rem del *.xls /S /Q
Rem del *.bmp /S /Q
del *.gif /S /Q

rem "All temporary files are deleted."
pause
rem ******************************

Thursday, May 8, 2008

SilkTest - Handling Popups

Sometimes AUT popups are not closed properly or any unexpected popups may be displayed, while running GUI Automation suite. At that time, scripts should close those popups automatically. Otherwise scripts can not be executed as unattended. In this case, You can consider any/all of the following points.

1. While running your scripts, you can close all other applications except Silktest and AUT. Even you can stop sending messages, while running the scripts.

2. You can use SetTrap and ClearTrap methods for expected dialogs. It can be used for security dialog boxes.

3. Develop a common function(s), it should close all the popups related to AUT and call into TestcaseExit or ScriptExit functions.

Wednesday, May 7, 2008

Borland WebCasts and Whitepapers

Now a days, many companies are ready to share their white papers, webcasts, podcasts and other presentations. Microsoft has shared all its' Virtual TechDays sessions' presentations. Recently Borland has conducted a webcast " The New SilkTest - Discover the open paradigm in functional test automation". Now Borland has shared its LifeCycle Quality Management whitepapers and webcasts. They are available at below links:

Borland WebCasts
Borland Whitepapers

Tuesday, May 6, 2008

VBScript - Passing CmdLine Arguments

I was searching on net, how to pass the command line arguments. It is possible. We can pass the command line arguments in VBScript. If you have worked with command-line tools, you are already familiar with the concept of arguments. Arguments can be divided as Named Arguments and UnNamed Arguments.

Named arguments
Named arguments are arguments that consist of two parts: a name and a value. The name must be prefaced with a forward slash, and a colon must separate the name from the value. The slash prefix and the colon separator are fixed and cannot be changed. See below Example.

RemoteServer.vbs /Host:AppSrv1 /App:Symantec /TimeLimit:2000
Item : Value
Host:AppSrv1
App:Symantec
TimeLimit:2000


UnNamed arguments
The WshUnnamed filtered collection contains the one unnamed argument. The WshUnnamed Count method and Length property return the number of filtered arguments in the WshUnnamed collection. Example is given below.

FormatMask.vbs "D:\VB\FormatMask\Complex.xls" 30 12
Item : Value
0 : D:\VB\FormatMask\Complex.xls
1 : 30
2 : 12


Source: Working with Command-Line Arguments

Code: Example of UnNamed arguments



If WScript.Arguments.Count = 3 Then
ServerName = WScript.Arguments.Item(0)
EventLog = WScript.Arguments.Item(1)
EventID = WScript.Arguments.Item(2)
Else
Wscript.Echo "Usage: GetEvents.vbs ServerName EventLog EventID"
Wscript.Quit
End If


Code: Named arguments


Set colNamedArguments = WScript.Arguments.Named

strServer = colNamedArguments.Item("Server")
strPacketSize = colNamedArguments.Item("PacketSize")
strTimeout = colNamedArguments.Item("Timeout")
Wscript.Echo "Server Name: " & strServer
Wscript.Echo "Packet Size: " & strPacketSize
Wscript.Echo "Timeout (ms): " & strTimeout

Saturday, May 3, 2008

QTP - TextBox Length

I was going through EMOS Framework. I think that this framework has been developed in QuickTest Professional 6.5 There I have seen a function to find the text box length. Below I have given that code snippet, which is very simple.

Code:

Public Sub BrowserWebEdit (strWebEdit,strInValue) If strInValue <> "" Then 'Get Length of strInValue InLenCount = Len(strInValue) 'Get Max Length for input LenCount = Browser(strBrowser).Page(strPage).WebEdit(strWebEdit).GetROProperty ("max length") If InLenCount > LenCount Then If LenCount <> -1 Then 'Trim Length of input Reporter.ReportEvent micWarning, strInValue , InLenCount & ": Length exceeds field input value trimed to: " & LenCount strInValue = Left(strInValue, LenCount) End If End If Browser(strBrowser).page(strPage).Sync Browser(strBrowser).Page(strPage).WebEdit(strWebEdit).Set strInValue End If End Sub

Friday, May 2, 2008

VBScript - File Read and Write

I have developed few projects using Visual Basic. But I do not have much scripting in Visual Basic Script (VBS). In VB, the file handling functions are different than VBScript. We need to use FileSystemObject for file handling. Below I have given two code snippets to read and write into text files. This code can be used into Quick Test Professional also.

Reading a Text file



Const ForReading = 1, ForWriting = 2

FileName = "D:\VBs\Mysamples\1create.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(FileName) Then

Set objTextFile = objFSO.OpenTextFile(FileName, ForReading)

Do while Not objTextFile.AtEndOfStream
sLine = objTextFile.ReadLine
Wscript.Echo sLine
loop

End If

objTextFile.Close

Set objFile = Nothing
Set objFSO = Nothing


Writing to a Text file


Const ForAppending = 8
FileName = "D:\VB\Mysamples\1create.txt"

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

For iIndex=1 to 10
objTextFile.WriteLine(iIndex)
Next

objTextFile.Close

Set objTextFile = Nothing
Set objFSO = Nothing