Wednesday, April 30, 2008

Accessing Excel - SilkTest

Few tools are providing built-in functions to read and write the data from Excel. Testers are comfortable with Excel than text file formats.

Silktest does not have any built-in functions to access data from Excel. But you can retrieve the data from Excel by treating Excel as Database. By using below code snippet, you can access the Excel data without pre-defined DSN. For this code snipper, You need to provide Excel filename with full path and worksheet name.

Silktest Excel - Code:

[+] public void ProcessExcelData(STRING sExcelFile, String sExcelSheet) [ ] // Purpose: Drives test suite based on excel sheet(testcase) information. [ ] // Executes for given worksheet. [ ] //SQL declaration [ ] HANDLE hDB [ ] HANDLE hSQL [ ] List of STRING glsData //To get testdata [ ] [ ] Print ("Test data:{sExcelFile} & Worksheet: {sExcelSheet} ") [ ] [-] do [ ] hDB = DB_Connect ("DRIVER=Microsoft Excel Driver (*.xls);DRIVERID=790;FIRSTROWHASNAMES=1;READONLY=FALSE;DBQ={sExcelFile}") [ ] [ ] //execute a SQL statement [ ] hSQL = DB_ExecuteSQL (hDB, "SELECT * from [{sExcelSheet}$]") [ ] //while there are still rows to retrieve [-] while DB_FetchNext (hSQL, glsData) [ ] GetListData (glsData) //Get all data without null [ ] [ ] [ ] //clean up the query [ ] DB_FinishSql (hSQL) [ ] [ ] //disconnect from the database [ ] DB_Disconnect (hDB) [ ] [-] except [ ] ExceptLog() [ ] Print ("Excelsheet {sExcelFile} couldn't be accessed by SilkTest.")

Tuesday, April 29, 2008

Download Virtual TechDays Presentations

Few days back, I have written about Microsoft's Virtual TechDays. Now Microsoft has shared all presentations and webinars (videos). You can get all 32 sessions materials. All sessions are on Microsoft's three new products - Windows Server 2008, SQL Server 2008 and Visual Studio 2008. It is good to see the sessions from experts. You can download from following URL.

Download Page: http://www.microsoft.com/india/virtualtechdays/

Monday, April 28, 2008

Data Driven Approach

Data driven scripts are those application-specific scripts manually coded in the automation tool’s proprietary language and then modified to accommodate variable data. Variables will be used for application under test input and execution of program selections. This allows the script to drive the application with external data supplied by the test engine. Most of the automation tools are having the feature to convert a recorded script into data driven script. The tools such as Silktest, WinRunner and QuickTest Professional are using Excel file as data file format.

Though these methodologies recommended by conspicuous experts are powerful but the utilization of the advantages propounded by these methods in the Test Automation architecture is under question.

Limitations of Data Driven Approach:


  • Multiple data files are essential for this approach and hence the maintenance of these files becomes a nightmare. Each and every Test Case requires inputs and verifications from different files.

  • Testers should carefully enter the data if anything at all changes in all the required files.

  • Script processing errors are common if a proper attention is not given to the file formats.

  • The process of coding and maintaining the tests was tedious and time-consuming. It took a lot of time to create all these tests because there was no modularity and therefore no code reuse.


Due to the ineffective usage of these methods, data driven scripts still contain the hard coded and sometimes very fragile recognition strings for the window components they navigate. When this is the case, the scripts are easily broken when an application change or revision occurs. And when these scripts start breaking (not necessarily just a few). We are sometimes talking about a great many, if not all the scripts, for the entire application.

Saturday, April 26, 2008

Fantasy about Record and Playback

Many testers do not have strong programming skills. With the scripting problems, it leads testers to use record and playback techniques. There indeed are many tools that allow scripts to be recorded and then played back, using screen captures for verification.

Every automated test tool vendor will tell you that their tool is "easy to use" and that your non-technical user-type testers can easily automate all of their tests by simply recording their actions, and then playing back the recorded scripts. This one statement alone is probably the most responsible for the majority of automated test tool software that is gathering dust on shelves in companies around the world. We have seen the vendor’s sample applications. We have seen the tools play nice with those applications. And we try to get the tools to play nice with our applications just as fluently. Inherently, project after project, we do not achieve the same level of success.

The Record / Playback Myth:
The problem that an always crop up is that the layouts are changed, invalidating the screen captures and then the interface controls change making playback fail. Now the scripts must be re-recorded from scratch. Record and playback tools provide an easy way to create throwaway test suites.

You can easily notice that identification of controls and windows is through the co- ordinates of the screen. The scripts will be broken easily when there is a change in resolution of the screen.

The scripts resulting from this method contain hard-coded values, which must change if anything at all changes in the application.

If the tester makes an error entering data, etc., the test must be re-recorded. If the application changes, the test must be re-recorded.

Sometimes this manifesto is hard to explain to people who have not yet performed significant test automation with these capture \ replay tools. But it usually takes less than a week, often less than a day, to hear the most repeated phrase: "It worked when I recorded it, but now it fails when I play it back". But this is true in case of record and play back tool.

Friday, April 25, 2008

Loading a URL - Silktest

Silktest has two methods LoadPage and Navigate to load particular page or URL. Sometimes our project may have modal popups like network authentication or Certificate Security (SSL) popups before loading the page. At that time we can not use LoadPage and Navigate methods. Silktest is used to expect the browser, should be ready. In case of modal dialog box, browser will be active if the modal dialog box is closed.

To solve this problem, we need to type the URL and then hit ENTER key in the browser. Then verify for the possible popups and do appropriate actions. Few people might be using SetTrap and ClearTrap. Trapping can be done for the popups, which are not required any inputs. Below I have given a code snippet.

Code:



[ ] Browser.SetActive ()
[ ] Browser.Maximize()
[ ] Browser.Location.SetText ("{sUrl}")
[ ] Browser.Location.TypeKeys ("")
[ ] Sleep (2)
[+] if (BrowserSecurityInfo.Exists(5))
[ ] BrowserSecurityInfo.SetActive ()
[ ] Print ("BrowserSecurity Info Exists.")
[ ] BrowserSecurityInfo.Continue.Click ()
[+] if (BrowserAuthentication.Exists(5))
[ ] BrowserAuthentication.SetActive ()
[ ] BrowserAuthentication.UserName.SetText (sUsername)
[ ] BrowserAuthentication.Password.SetText (sPassword)
[ ] BrowserAuthentication.OK.Click ()

Thursday, April 24, 2008

Strange behaviour with Service Pack

Recently I installed Windows XP Service Pack3 Rel1 (en_windows_xp_service_pack_3_release_candidate_1_x86_60967.exe) in my PC. I restarted the system. But it is not able to boot at all. All my efforts went to vein. I asked few of my friends. Then I came to know, F8 key is used to select different mode of booting.

Different startup modes:


  1. Safe Mode

  2. Safe Mode with Networking

  3. Safe Mode with Command Prompt

  4. Enable Boot Logging

  5. Enable VGA Mode

  6. Last Known Good configuration

  7. Directory Services Restore

  8. Debugging Mode

  9. Disable Automatic restart on system failure

  10. Start windows normally

  11. Reboot

  12. Return to OS choices Menu


From Directory Services Restore option, I got following information.
"STOP: c0000139 {Entry Point Not Found}
The procedure entry point GdiGetBitmapBitSize could not be located in the dynamic link library GDI32.dll"


Then I searched in the net and I came to know, this problem affects many users. Solution - Original Post . This issue happens with 3311 build of XP SP3. You need to do following steps.
1. Boot from a Windows CD and go for the repair option.
2. Copy gdi32.dll from c:\windows\servicepackfiles\i386\gdi32.dll to c:\windows\system32\gdi32.dll. (Do keep a backup copy of the old gdi32.dll in c:\windows\system32 directory)
3. Reboot normally

I am not an expert in OS installation. It is very hard to follow these steps. I have done after few restarts and now able to work on my system.

Steps involved:

  1. Put your windows XP CD

  2. Restart the system

  3. Press Ctrl+Alt+Del for 5-10 seconds.

  4. CMOS setup will be opened.

  5. Go to Booting priority and set first priority to boot from CD/DVD drive.

  6. Screen will ask to type any key. It means, it is booting from your CD.

  7. Select Windows Repair option

  8. System will load few files from CD and it will ask "Do you want to continue" in command prompt.

  9. Type 1 in the command prompt. If ENTER is pressed, booting will be cancelled.

  10. Type cd System32

  11. Type ren gdi32.dll gdi32.dll.orig

  12. Type cd dllcache

  13. Type ren gdi32.dll gdi32.dll.orig

  14. Type cd \windows\servicepackfiles\i386

  15. Type copy gdi32.dll C:\Windows\System32\

  16. Type Exit



Then System restarts normally. I uninstalled SP3 as first job. Now my system is working fine. Due to this issue, I am unable to use this system for 4 days.

I used to check versions of softwares in our application. We need to specify clearly the version and Service Pack /Fix pack of all required softwares in Software Requirements.

Wednesday, April 23, 2008

Tooltip verification in Browser

SilkTest does not have any built-in function, to get tooltip from browser controls. In browser, there is no ToolTip control, but the few attributes (Alt) are used to simulate a ToolTip.

Using Silktest, we can execute javascript statements in browser at runtime. 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 any browser based objects. QTP is using VBScript. Using QTP also, we can achieve the same like above.

Friday, April 18, 2008

Difference between Application server and Web server

I have explained the difference between Application server and web server. I prepared this table after referring few sites. I hope that it will be very useful to you.

Application server

Web server

Developers can create, test, and execute application components.

It is designed to create and deploy Web site, serving up content more so than applications.

These are typically J2EE-based, running EJBs or other Java components.

It supports JSP,Servlets,ASP and server side Java Script.

It exposes business logic to client applications through various protocols.

It is designed to create and deploy Web site serving.It mainly deals with sending HTML for display in a web browser.

Application Server supports HTTP,TCP/IP and many more protocols.

A Web Server understands and supports only HTTP protocol.

Common Problems in Test Automation

Few years back, I have prepared few documents about automation scripting and concepts. This post will list the common problems faced by software industries in their test automation attempts.

Automation is not cheap
Test Automation is not cheap. Usually it takes between 3 to 10 times as long to create, verify and document the automated test as it takes to create and run once by hand. Test Automation takes lesser time to create than to test each test scripts.

Easy to run test alone is automated
Many test groups automate only the easy to run tests because early in testing, these are easy to design and the program might not be capable of running more complex test cases. Hence harsh test needs to be done by the skilled manual tester.

Duplicate information was kept in multiple repositories
Most of the project teams purchases a test management tool in addition to the already existing automated testing tools. Duplicate information was kept in multiple repositories and was very difficult to maintain. In several instances, the implementation of more tools actually results in less productivity.

Test Scripts duplicates the development effort
Test script development results in an almost complete duplication of the development effort, through overuse of the testing tool’s programming language. In normal case the application itself used a complex algorithm and again the tester recreates these algorithms using the testing tool. Too much time was spent on automating scripts, without much additional value gained. The test team must be careful not to duplicate the development effort; this is a risk when developing elaborate test scripts.

A lack of test development guidelines was noted
One program had several test automation engineers, each using a different style for creating test scripts. Maintaining the scripts is a nightmare. This is due to the non-availability of development guidelines and hence script readability and maintainability becomes complicated.

Reports generated by the tool is futile
More time is spent by the testers in setting up elaborate customized reports, which is part of the automated testing tool. The reports were never used, since the data required for the report is never accumulated in the tool.

Thursday, April 17, 2008

Convert Number to Word

In my first job, I needed to have a function to verify the number to string conversion. The number should be converted to the word. For example, if user enters 8908 and function returns the output as Eight Thousand Nine Hundred and Eight only. I thought that it is very simple. After starting to write it, I faced few issues. Thats why I created four functions. I have given the code below. The current code converts up to crores. This code snippet can be used in Visual Test or Visual Basic. Few changes needs to be done to use in VB Script.

Code: Returns the word to the given number



'---------------------------
' Method : NumberToWord
' Author : T.Palani Selvam
' Purpose : Returns the word to the given number.
' Parameters: sGivenNum - String, contains to be converted number.
'
' Returns : Returns String of corresponding number.
' Caller :
' Calls : - Nil -
'----------------------------
Function NumberToWord(sGivenNum As String) As String
Dim lBeforeDecimal As Long, lAfterDecimal As Long
Dim iDecimalPos As Integer, iIndex As Integer
Dim sBeforeDecimalWord As String, sAfterDecimalWord As String
Dim sResult As String, sChar As String

'sResult = Null
sGivenNum = Trim(Str(Val(sGivenNum)))
If Val(sGivenNum) = 0 Then
NumberToWord = "Zero"
Exit Function
End If
sAfterDecimalWord = ""
sBeforeDecimalWord = ""
iDecimalPos = InStr(sGivenNum, ".")
If iDecimalPos = 0 Then
lBeforeDecimal = Val(sGivenNum)
Else
'sGivenNum = Format(sGivenNum, "#####.00")
lBeforeDecimal = Val(Left(sGivenNum, iDecimalPos - 1))
lAfterDecimal = Val(Mid(sGivenNum, iDecimalPos + 1))
If (lAfterDecimal <> 0) Then
'sAfterDecimalWord = " Paise " + PrimaryConversion(lAfterDecimal)
sAfterDecimalWord = " Point" '+ PrimaryConversion(lAfterDecimal)
For iIndex = 1 To Len(trim(str(lAfterDecimal)))
sChar = Mid$(trim(str(lAfterDecimal)), iIndex, 1)
sAfterDecimalWord = sAfterDecimalWord + " " + PrimaryConversion(val(sChar))
Next iIndex
End IF
If (lBeforeDecimal = 0) Then
NumberToWord = sAfterDecimalWord
Exit Function
End IF
End If

sBeforeDecimalWord = SplitType(10000000, " Crore ", lBeforeDecimal)
sBeforeDecimalWord = sBeforeDecimalWord + SplitType(100000, " Lakh ", lBeforeDecimal)
sBeforeDecimalWord = sBeforeDecimalWord + SplitType(1000, " Thousand ", lBeforeDecimal)
sBeforeDecimalWord = sBeforeDecimalWord + SplitType(100, " Hundred ", lBeforeDecimal)
If sBeforeDecimalWord = "" Then
sBeforeDecimalWord = PrimaryConversion(lBeforeDecimal)
Else
sBeforeDecimalWord = sBeforeDecimalWord + "and " + PrimaryConversion(lBeforeDecimal)
End If
sResult = sBeforeDecimalWord

If sAfterDecimalWord = "" Then
sResult = sBeforeDecimalWord
Else
'sResult = sBeforeDecimalWord + " and" + sAfterDecimalWord
sResult = sBeforeDecimalWord + sAfterDecimalWord
End If

NumberToWord = sResult '+ " Only"
End Function


Code: Set the word according to level


'-------------------------
' Method : SplitType
' Author : T.Palani Selvam
' Purpose : Splits a level to next level.
' Parameters: lNumType - Long, contains like 100, 1000
' sWord - String, contains before conversioned word.
' Returns : Returns String of corresponding number.
'----------------------------
Function SplitType(lNumType As Long, sWord As String,lBeforeDecimal As long ) As String
'Dim lBeforeDecimal As Long
Dim lNumberType As Long

SplitType = ""
lNumberType = lBeforeDecimal \ lNumType
If lNumberType > 0 Then
lBeforeDecimal = lBeforeDecimal - lNumberType * lNumType
SplitType = PrimaryConversion(lNumberType) + sWord
End If
End Function


Code: Parse a string to the given condition


'--------------------------
' Method : GetParsedString
' Author : T.Palani Selvam
' Purpose : Parse a string to the given condition
' Parameters: sData - String, contains full string..
' sSeparate - String, contains separation string
' iOccur - String, contains position of the Split
' Returns : Returns String, Null or other values.
'--------------------------
Function GetParsedString(sData As String, sSeparate As String, iOccur As Integer) As String
Dim iPosition As Integer, iIndex As Integer
Dim sTemp As String

GetParsedString = Null
sTemp = sData

For iIndex =1 To (iOccur -1) Step 1
iPosition = Instr(sTemp,sSeparate)
If (iPosition > 0) Then
sTemp=Mid$(sTemp,len(sSeparate) + iPosition)
Else
Print(sSeparate + " is not occured")
Exit Function
End If
' Print "Original Symbol: " + sTemp, sSeparate
Next iIndex
iPosition = Instr(sTemp,sSeparate)
If (iPosition > 0) Then
sTemp=Left$(sTemp,iPosition - 1)
End If
GetParsedString = sTemp
End Function


Code: Converts primary number to word


'----------------------
' Method : PrimaryConversion
' Author : T.Palani Selvam
' Purpose : It converts primary number to string.
' Parameters: lNumber - Long, contains number
'
' Returns : Returns String of corresponding number.
'-------------------------
Function PrimaryConversion(lNumber As Long) As String
PrimaryConversion = ""
Select Case lNumber
Case 0
Case 1
PrimaryConversion = "One"
Case 2
PrimaryConversion = "Two"
Case 3
PrimaryConversion = "Three"
Case 4
PrimaryConversion = "Four"
Case 5
PrimaryConversion = "Five"
Case 6
PrimaryConversion = "Six"
Case 7
PrimaryConversion = "Seven"
Case 8
PrimaryConversion = "Eight"
Case 9
PrimaryConversion = "Nine"
Case 10
PrimaryConversion = "Ten"
Case 11
PrimaryConversion = "Eleven"
Case 12
PrimaryConversion = "Twelve"
Case 13
PrimaryConversion = "Thirteen"
Case 14
PrimaryConversion = "Fourteen"
Case 15
PrimaryConversion = "Fifteen"
Case 16
PrimaryConversion = "Sixteen"
Case 17
PrimaryConversion = "Seventeen"
Case 18
PrimaryConversion = "Eighteen"
Case 19
PrimaryConversion = "Nineteen"
Case 20
PrimaryConversion = "Twenty"
Case 30
PrimaryConversion = "Thirty"
Case 40
PrimaryConversion = "Forty"
Case 50
PrimaryConversion = "Fifty"
Case 60
PrimaryConversion = "Sixty"
Case 70
PrimaryConversion = "Seventy"
Case 80
PrimaryConversion = "Eighty"
Case 90
PrimaryConversion = "Ninety"
Case Else
PrimaryConversion = PrimaryConversion(lNumber - (lNumber Mod 10)) + " " + PrimaryConversion(lNumber Mod 10)
End Select
End Function

Wednesday, April 16, 2008

Access database without DSN

Developers used to write the code to retrieve the data from database, with the help of DSN (Data Source Name). Developers does not bother about the type of database. DSN is the bridge between database and scripting language.

Assume that your automation scripts are using a DSN. It is difficult to configure DSN, whenever the script runs. But you can set the DSN details dynamically to connect with any database. Below I have given the sample silktest (4test) code to run the script without having physical DSN.

4test code:



[+] void GetAccessDB ()
[ ] STRING CONN_STRING = "Driver=" + Chr(123) + "Microsoft Access Driver (*.mdb)" + Chr(125) + ";Dbq=\\AppServer\build05.mdb;Mode=16;"
[ ] HANDLE dbConn
[ ] HANDLE hSQL
[ ]
[ ] dbConn = DB_Connect(CONN_STRING)
[ ] hSQL=DB_ExecuteSql(dbConn, "Select * from Emp_Master")
[ ]
[ ] DB_FinishSql (hSQL)
[ ] DB_Disconnect (dbConn)

Tuesday, April 15, 2008

Silktest 2008 Release

Much awaited Silktest 2008 was released in this month. This time the trial version of Silktest 2008 is available for 30 days. Now silktest supports Adobe Flex and IBM JRE environment. Silktest is having a new agent to communicate with Adobe Flex and Windows API-based client/server applications.

To get more info about this new release, you can go through following links.



What's New in Silktest 2008:

  1. New SilkTest Open Agent

  2. SilkTest Default Agent

  3. Adobe Flex Support

  4. Adobe Flex Sample Applications

  5. Animated Run Mode (Slow-Motion)

  6. TrueLog Generation Can Be Turned Off or On Using the Run Testcase Dialog

  7. Use ANSI Calls Available from the Agent Options Dialog

  8. DOM Extensions Dialog Includes List Item Option

  9. IBM JRE Support

  10. Two new 4Test keywords - supported_ca & supported_oa

  11. New Functions for the SilkTest Agent

  12. Open Source Libraries - Groovy & XStream

  13. Several icons and dialog boxes look and feel - Revised in Silktest Host

Monday, April 14, 2008

SEO - Search Engine Optimization

After creating my blog, I searched my blog on Google. My blog is not displayed in search results. Then I started to read more about Publicizing the blog. Also I read about Search Engine Optimization (SEO). SEO helps to create high visibility on the leading search engines. It also helps to bring more visitors to your page and indirectly marketing your website.

Brad Callen is one of the search engine optimization experts. He has written a book about SEO. Brad has mentioned two types of optimization. One is OnPage optimization and another one is OffPage optimization. You can download his E-book from docstoc.com.

To know more about SEO, see this Wiki page . Also now You can do Search on my blog.

Saturday, April 12, 2008

HtmlText object not a Parent

Three years ago, we have upgraded Silktest version to 6.5. At that time, Silktest identified HtmlText objects as parent objects. We changed our scripts lot and it was difficult to manage the scripts release by release. Then I found that we need to set a Agent option in Silktest. You can avoid this by two ways.


  • By coding. You need to use this statement after invoking the browser object => BrowserPage.SetUserOption("ShowOverflow", FALSE,USEROPT_DEFAULT)

  • By configuration. Add ShowOverflow=FALSE under [Options] in extend\domex.ini

Friday, April 11, 2008

Microsoft - Virtual TechDays

April 9th and 10th 2008, Microsoft’s Virtual TechDays was held at Bangalore. More than ten thousand engineers would have benefited. To attend this program, user should install Microsoft's Live Meeting in their machine. Totally 32 sessions were there. All sessions are on Microsoft's three new products - Windows Server 2008, SQL Server 2008 and Visual Studio 2008. It is good to see the sessions from experts. I attended SQL Server 2008 and VS 2008 sessions. I missed the BI sessions due to my vacation.

Microsoft has given plenty of information for all sessions. User can get various resources (evaluations, whitepapers, videos) from that site. Below I have given few links and hope that it might be useful to you.


Virtual TechDays - Resources
SQL Server 2008 - Overview
Visual Studio Team System Videos

Thursday, April 10, 2008

Checking Mail Notification

Earlier I have written the code to verify the mails from Microsoft Outlook Express. I used to call CDO(Collaboration Data Objects) object methods. I developed a small VB application to delete all the objects from Inbox. I think, now few methods are deprecated.

Code:



'It is possible, by calling OLE objects from CDO.dll
'Mostly it will be in C:\Program Files\Common Files\System\Mapi\1033\NT\
'-------------------------
' Method : CheckMail
' Author : T.Palani Selvam
' Purpose : Check the mails in the MS Outlook Mail Client for the particular subject & its status.
' Parameters: sDatavalue, String - Contains Username, Password of the MS outlook, Subject & Status of mail.
' Returns : Returns Integer data type(True or False.)
'----------------------------
Function CheckMail(sDataValue As String) As Integer
Dim objSession As Variant
Dim objInbox As Variant
Dim objMessages As Variant
Dim objItem As Variant
Dim intIndex As Integer
Dim intCount As Integer
Dim varReceived As Variant
Dim iStatus As Integer 'To get Current status of the message.
Dim sSubject As String 'Subject of the current message.
Dim sUser As String, sPword As String, sSearch As String, sStatus As String 'Information gets from the Data value
Dim iPosition As Integer, iPosition1 As Integer
Dim sTemp As String
Dim iResult As Integer

iResult = False 'Initializing function
'Error Information Handling
On Local Error GoTo Error_Handler1

'****** Parsing information from Datavalue
sTemp = sDatavalue
intCount = 1
While (Instr(sTemp,"::") <>0 )
iPosition = Instr(sTemp,"::")

Select Case intCount
Case 1
sUser = Left$ (sTemp, iPosition - 1)
Case 2
sPWord = Left$(sTemp, iPosition - 1)
Case 3
sSearch = Left$(sTemp, iPosition - 1)
'Case 4
'sStatus = Left$(sTemp, iPosition)
sStatus = Mid$ (sTemp, iPosition + 2)
Case Else
LogWrite("CheckMail: More information is given in data file.", 1)
End Select
intCount = intCount + 1
sTemp = Mid$ (sTemp, iPosition + 2)
Wend
'**** End Parsing Information

Logwrite("Search Mail Status: " + sStatus + " & Subject String: " + sSearch, 1)
'Set objSession = CreateObject("MAPI.Session")
objSession = OleCreateObject("MAPI.Session") ' Create MAPI session

'objSession.Logon strUser, strPword, False, False, 0
OleDispatch(objSession,"Logon",sUser, sPword,False, False, 0) ' Logon using an existing MAPI session

'Set objInbox = objSession.Inbox
objInbox=OleDispatch(objSession,"Inbox") ' Get inbox folder

'Set objMessages = objInbox.Messages
objMessages=OleDispatch(objInbox,"Messages") 'Get all messages


intCount=OleGetProperty(objMessages,"Count")

LogWrite("Total Messages in Outlook: " + str(intCount) , 1)

sStatus = Trim (sStatus)

For intIndex=1 To intCount Step 1
objItem=OleDispatch(objMessages,"Item",intIndex) 'Get Each message

sSubject = OleGetProperty(objItem,"Subject")
iStatus = OleGetProperty(objItem,"Unread")


If (InStr(UCase(sSubject), UCase(sSearch)) <> 0) Then
If (iStatus AND (Instr(lCase(sStatus),"read") > 1)) Then
iResult = True
Exit For
ElseIf ((Not iStatus) AND (Instr(lCase(sStatus),"read") = 1)) Then
iResult = True
Exit For
End If

End If
Next intIndex

' Logoff from MAPI Session
OleDispatch(objSession,"Logoff")
'Set objSession = Nothing
OleReleaseObject(objSession)

If (iResult) Then
LogWrite("Successfully Mail is checked in the Outlook.",2)
Else
LogWrite("Failure to check Mail in the Outlook.",1)
'giTestResult = giTestResult + 10
End IF
CheckMail = iResult

Exit Sub

Error_Handler1:

If InStr(UCase(Error$), "LOGON") <> 0 And InStr(UCase(Error$), "FAIL") <> 0 Then
LogWrite("CheckMail : Username and password of Outlook information are incorrect. ", 1)
LogWrite("CheckMail : MS Outlook Login status is Failure.", 1)
End If


If Not (objSession = NULL) Then
OleReleaseObject(objSession)
End If

'PRINT "[Failed At] " ERF "(" ERL ") : " ERROR$ 'Actual location.
'PRINT "[Trapped At] " ERF(1) "(" ERL(1) ")" 'Trapped location.
LogWrite("[Failed At] " + ERF(0)+ "("+ str(ERL) +") : "+ ERROR$,1) 'Actual location.
Logwrite("[Trapped At] "+ ERF(1)+ "("+ str(ERL(1))+ ")",1) 'Trapped location.
LogWrite("Error Handling: Failure to check Mail in the Outlook.",1)

glCellRow = glCellRow + 1
setResultDetails("Error: " + Error$ ,glCellRow,3) 'Write into Excel

End Function

Sunday, April 6, 2008

Screen Saver Off

All GUI test suite are not executed if screen saver screen is displayed or machine gets locked. Before running the scripts, automation engineer should confirm not to get the machine lock or screen saver. In few environments, user would not able to control.

Earlier I also faced this problem. Then I used to login as a local user instead of network user or company login id. Later we used VmWare Workstations to run the regression.

You can avoid this situation by few ways.


  1. Using Registry

  2. Using scripting while regression starts

  3. Restart the Machine if system gets locked



Using Registry
It is a simple method. But it should not overriden by your company policy. System Admin may run your company screen savers.
1. Go to HKEY_CURRENT_USER
Path => [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Control Panel\Desktop]
2. Change the following values for following keys.
"ScreenSaveActive"="1"
"ScreenSaveTimeOut"="30000"

Using scripting while regression starts
1. Disable the screen saver. Below code is given for Silktest. Put into ScriptEnter block.
// Declaration
dll "user32.dll"
LONG SystemParametersInfo (LONG uAction, LONG uParam, LONG lpvParam, LONG fuWinIni) alias "SystemParametersInfoA"

// Calling statement
-> SystemParametersInfo (17, 0, 0, 0)

2. Enable the screen saver. Keep below code into ScriptExit function.
// Calling statement
-> SystemParametersInfo (17, 1, 0, 0)

Restart the Machine if system gets locked
User can call any batch script or system restart command. But you need to re-execute the scripts, from where it was stopped. It is a bit complex trick.

Saturday, April 5, 2008

VisualTest - File Handling

Any automation suite must have file handling functions for various scenarios. It may be just text files or any data files. VisualTest also has few methods for file handling. VisualTest code is similar to Visual Basic code. Below I put some of my visual test functions.

Code: Check the given file exists or not



'----------------------------------
' Method : FileExists
' Author : T.Palani Selvam
' Purpose : Check the given file exists or not. PhaseII
' Parameters: sFile, String - Contains a file name.
' Returns : Returns Integer data type(True or False.)
' Caller : SwitchSpecialTags
' Calls : - Nil
'-----------------------------
Function FileExists(sFile As String)As Integer
Dim iPosition As Integer
Dim sDir As String, sTFile As String, sTemp As String

FileExists = False
sTFile = sFile
iPosition = Instr(sFile,"::")
If (iPosition <> 0) Then
sDir = Mid$(sFile,iPosition + 2)
sTemp = Left(sFile, iPosition - 1)
If (Instr(sTemp,":\") <> 0 ) Then
sTFile = sTemp
Else
If (Right$(Trim(sDir),1) <> "\") Then
sDir = Trim(sDir) + "\"
End If
sTFile = sDir + sTemp
End IF
End If
If Exists(sTFile,"-d") Then
FileExists = True
Logwrite( "Successful - Existing file is " + sTFile , 1)
Else
Logwrite( sTFile + " - File doesn't exist.", 1)
End IF

End Function


Code: Check whether the given folder exists or not


'----------------------------
' Method : FolderExists
' Author : T.Palani Selvam
' Purpose : Check the given folder exists or not.(PhaseII)
' Parameters: sFolder, String - Contains a folder name.
' Returns : Returns Integer data type(True or False.)
' Caller : SwitchSpecialTags
' Calls : - Nil
'---------------------------
Function FolderExists(sFolder As String)As Integer
FolderExists = False
If (Right$(Trim(sFolder),1) = "\") Then
sFolder = Trim(sFolder)
sFolder = Left$(sFolder, Len(sFolder) -1 )
End If

If Exists(sFolder,"+d") Then
FolderExists = True
Logwrite( "Successful - Existing Directory is " + sFolder , 1)
Else
Logwrite( sFolder + " - Directory doesn't exist.", 1)
End IF
End Function


Code: Check whether the given string exists in the given file or not.


'-----------------------------
' Method : StringExists
' Author : T.Palani Selvam
' Purpose : 'Check whether the given string exists in the given file or not.
' Parameters: sFile as String, Contains a file name with full path.
' sWord - String , Consists of string to check into the file.
' Returns : Returns Integer value
' Caller : OperationIdentifier()
' Calls : - Nil
'-------------------------
Function StringExists(sFile As String,sWord As String)As Integer
Dim fNumber As Long
Dim sLine As String
Dim iInt As Integer

fNumber=FREEFILE
StringExists=False

iInt =0

OPEN sFile For Input As #fNumber

While not eof(fNumber)
Line Input #fNumber,sLine
sLine = Trim (sLine)

IF (Instr(sWord,sLine)<>0 AND Len(sLine) > 1) Then
PRINT sLine, "String Exists!"
iInt = iInt + 1
If (iInt > 3) Then
StringExists=True
Exit Function
End IF
End If
Wend

CLOSE #fNumber

End Function

Friday, April 4, 2008

Handling HTMLText objects in SilkTest

Silktest is always clicking top-left most point of HtmlText object. For example, Assume that my text object is MyApp.MainFrame.Apply

MyApp.MainFrame.Apply.Click () is equal to MyApp.MainFrame.Apply.Click (1,1,1)

Advanced web technologies are always becoming challenges for Automation. Our enterprise web applications have HtmlText object for navigating purpose. We changed all images to text to support localization. These text objects look like HtmlImages or HtmlPushButtons. Actually those are HtmlText objects.

My problem was, sometimes the click will not happen properly. We cannot use DoClick method for HtmlText objects. I had two tricks to solve this problem. One is Clicking on center of that object or blindly hardcode co-ordinates.

In first way, MyApp.MainFrame.Apply.ClickCenter ()
- Here I have extended the click function.

In the second way, MyApp.MainFrame.Apply.Click (1,6,3)

Thursday, April 3, 2008

Unable to run VBS in Windows XP

Last Year my machine was formatted and windows XP (SP2) was installed. Recently I tried to run few Visual basic scripts (VBS). An error message thrown and unable to run any VB script.

Then I searched and came to know that I need to install Windows Script 5.6 for Windows XP. After installing it, I am able to run the scripts in my PC. Also few links from search results are invalid. Now Windows Script 5.7 is available. Below I have given the links to download script engines. Hope that It will be useful...


  1. Download - Windows Script 5.6 for Windows XP and Windows 2000

  2. Windows Script 5.6 Documentation

  3. Download - Windows Script 5.7 for Windows XP

Wednesday, April 2, 2008

VisualTest - Using Excel Application

Our Automation suite results were in text files. I wanted to create the excel file as results file. You can get to know more about Results Reporting. I used Excel VBA for this. It has simplified my task to prepare the compiled results for entire execution.

Similarly I will write, how to do the same thing by using VB script later....

Code: To check Excel availability in the system



'--------------------------------------
' Method : IsExcelAvailable
' Author : T.Palani Selvam
' Purpose : Checks whether excel application is available or not.
' Parameters: - Nil
' Returns : Returns integer, whether true or false.
' Caller :
' Calls :
'--------------------------------
Function IsExcelAvailable() As Integer
Dim objExcelApp As Variant

ON LOCAL ERROR GOTO Errhandler

IsExcelAvailable = False
objExcelApp = OleCreateObject("Excel.Application")
Sleep 0.5
OleReleaseObject(objExcelApp)
IsExcelAvailable = True
Exit Function

ErrHandler:
'LogWrite("[Failed At] " + ERF(0)+ "("+ str(ERL) +") : "+ ERROR$ + " .Error Number: " + str(Err),1) 'Actual location.
'Logwrite("[Trapped At] "+ ERF(1)+ "("+ str(ERL(1))+ ")",1) 'Trapped location.
Logwrite("Excel Application is not available.", 2)
End Function


Code: To Read Excel data


'---------------------------------------
' Method : ReadExcelCells
' Author : T.Palani Selvam
' Purpose : Read the content from given Excel file
' and checks result automatically, while completing a test case.
' Parameters: - Nil -
' Returns : - Nil -
' Caller :
' Calls :
'
'--------------------------------------
Function ReadExcelCells(sExcelFile as String, sWorkBook as String,sWorkSheet as String,sArrFields() As String) As Integer
DIM objExcelApp As Variant,objExcel As Variant, objCurrentCell As Variant
DIM objWorkBook As Variant,objWorkSheet As Variant

Dim iRows As Integer, iCols As Integer
Dim iRowStatus As Integer, iColStatus As Integer
Dim iRowIndex As integer, iColIndex As integer, iIndex As Integer
Dim sCellValue As String, sValue as String

ReadExcelCells = False

objExcel = OleGetObject (sExcelFile)
objExcelApp = OleDispatch (objExcel,"Application")
'objExcelApp = OleCreateObject ("Excel.Application")
objWorkBook = OleDispatch (objExcelApp,"Workbooks", sWorkBook)
'objWorkBook = OleDispatch (objExcelApp,"Workbooks")
'OleDispatch(objWorkBook,"Add",sWorkBook)
objWorkSheet= OleDispatch (objWorkBook,"Sheets", sWorkSheet)

iIndex = 1
Do While Not (iRowStatus)
objCurrentCell= OleDispatch (objWorkSheet, "Cells", iIndex, 1)
sValue = OleGetProperty (objCurrentCell, "Value")
If (Len(Trim(sValue)) = 0 ) Then
iRowStatus = True
End IF
iIndex = iIndex + 1
Loop
iRows = iIndex - 2 'Rows Count
print "No of rows.." + str(iRows)

iIndex = 1
Do While Not (iColStatus)
objCurrentCell= OleDispatch (objWorkSheet, "Cells", 1, iIndex)
sValue = OleGetProperty (objCurrentCell, "Value")
If (Len(Trim(sValue)) = 0 ) Then
iColStatus = True
End IF
iIndex = iIndex + 1
Loop
iCols = iIndex - 2 'Rows Count
print "No of Columns.." + str(iCols)

ReDim sArrFields(iCols - 1,1) As String
For iIndex=1 To iCols
objCurrentCell= OleDispatch (objWorkSheet, "Cells", 1, iIndex)
sValue = OleGetProperty (objCurrentCell, "Value")
sArrFields(iIndex-1, 0) = sValue
Next iIndex


For iRowIndex = 2 To iRows
For iColIndex = 1 To iCols
objCurrentCell= OleDispatch (objWorkSheet, "Cells", iRowIndex, iColIndex)
sValue = OleGetProperty (objCurrentCell, "Value")
sArrFields(iColIndex-1, 1) = sValue
Next iColIndex
For iIndex = LBOUND(sArrFields,1) TO UBOUND(sArrFields,1)
Print "Field (Name,Value): " + sArrFields(iIndex, 0),sArrFields(iIndex, 1)
'Print "Field Value: " + sArrFields(iIndex, 1)
Next iIndex
Next iRowIndex

OleReleaseObject (objWorkSheet)
OleReleaseObject (objWorkBook)
OleReleaseObject (objExcelApp)
OleReleaseObject (objExcel)

ReadExcelCells = True
End Function


Code: To set Test Results by different colors


'-------------------------------------------------------------------------
' Method : setResultXLDetails
' Author : T.Palani Selvam
' Purpose : Set the standard format for the given Cell Object.
' Parameters: sDetails - String, contains information to be written into Excel cell object
' lRow - Long, contains row number
' lCol - long, contains Column number
' iFontType As Integer
' iFontColor As Integer
' Returns : -Nil
' Caller :
' Calls :
'-------------------------------------------------------------------------
'Default values will be given iFontType =0, iFontColor =0
Sub setResultXLDetails(sDetails As String, lRow As Long, lCol As Long,iFontType As Integer, iFontColor As Integer)
Dim objCell As Variant, objFont As Variant

If Not IsNull(gObjWorkBook) Then
objCell = OleDispatch(gObjWorkSheet,"Cells",lRow,lCol)
objFont = OleDispatch(objCell, "Font")
Select Case iFontType
Case 1
OleSetProperty(objFont,"Bold",True)
Case 2
OleSetProperty(objFont,"Italic",True)
Case 3
OleSetProperty(objFont,"Bold",True)
OleSetProperty(objFont,"Italic",True)
Case Else
End Select

Select Case iFontColor
Case Is < 1
Case Is < 26
OleSetProperty(objFont,"ColorIndex",iFontColor)
Case Else
End Select

OleSetProperty(objCell,"Value", sDetails)
OleReleaseObject(objFont)
OleReleaseObject(objCell)
End IF
End Sub


Code: To set value into given cell


'-------------------------------------------------------------------------
' Method : setResultDetails
' Author : T.Palani Selvam
' Purpose : Set the standard format for the given Cell Object.
' Parameters: sDetails - String, contains information to be written into Excel cell object
' lRow - Long, contains row number
' lCol - long, contains Column number
' Returns : -Nil
' Caller :
' Calls :
'-------------------------------------------------------------------------
Sub setResultDetails(sDetails As String, lRow As Long, lCol As Long)
Dim objCell As Variant
If Not IsNull(gObjWorkBook) Then
objCell = OleDispatch(gObjWorkSheet,"Cells",lRow,lCol)
OleSetProperty(objCell,"Value", sDetails)
OleReleaseObject(objCell)
End IF
End Sub

Tuesday, April 1, 2008

SilkTest - Convert .jou to results file

Journal (*.jou) file is created, While SilkTest scripts are running. Results are stored temporarily in this. Journal file is converted to a .res file, when the script finishes running.

You re-run that particular script/plan/suite file for a testcase and then stopped manually within 5-10 minutes. In the results file, You can see the results for previous run Or select the previous results. There you can see the results of previous execution.

Remove the jou file, if SilkTest reports the error "Could not open results file."