Showing posts with label qtp. Show all posts
Showing posts with label qtp. Show all posts

Sunday, April 8, 2012

QTP New Version?

QTP did not release any updates for almost two years. Any guess, whether HP is going to come with any different release altogether or coming up with new tool...

See the release history below...

11.0 - Released in 2010
10.0 - Released in 2009
9.5 - Released in 2008
9.2 - Released in 2007
9.1 - Released in 2007
9.0 - Released in 2006
8.2 - Released in 2005
8.0 - Released in 2004
source: Wikipedia - QuickTest Professional

Friday, August 8, 2008

VBScript - Numbers as CmdLine Arguments

While I was preparing code for Excel Automation , I decided to pass the few integer values. Always the script got failed, if I pass the integer values through arguments. But the script went through fine, if I directly pass the parameters in that function call. While debugging the code, I was not able to find the reason for failure. I did Google search and unable to get the right solution.

Later I analyzed the code and put the simple conversion, while getting the arguments. The code worked as expected.


  1. To Convert String to Integer --> iStartRow = CInt (WScript.Arguments.Item(1))

  2. To Convert String to Double --> dExpVal = CDbl (WScript.Arguments.Item(2))

  3. To Convert String to Number --> nRowRange = Val (WScript.Arguments.Item (3))

To know more about the Command Line Arguments to VBScript, go through this post - Passing Command Line Arguments .

If you are unable to run any VBScript, See my old post - Unable to run VBScript / WScript / CScript in Windows XP .

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

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

Wednesday, June 25, 2008

Comparison between SilkTest and QuickTest Professional

Two months back, I thought to write a post about SilkTest and QTP comparison. Both the tools are market-leading testing tools. The latest versions of both tools have Vista and Flex support. I did not give any detailed description for each feature or item.

Product page
Here I have listed the product pages for both.
Silktest Product Page
Quick Test Professional Product page

Wiki pages
Silktest on Wiki
QuickTestProfessional (QTP) on Wiki

Code samples for both tools
Sample 4test code snippets for SilkTest
Sample QTP and VB Script code snippets

References:


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

  2. WinRunner vs. QuickTest Pro Quick Comparison - By Shawn LoPorto, Senior Test Automation Architect

  3. AUTOMATION TEST TOOLS - By Ray Robinson, 2001

  4. Comparision of Web testing tools



Comparison Table: SilkTest Vs QuickTest Professional


Features

SilkTest

QuickTest Professional

Recording ScriptRecorder available with different set of features.Recorder available with different set of features.
OS Windows upto Vista, Unix (SilkBean)Windows upto Vista, Unix (Xrunner)
Browsers supportInternet Explorer, Netscape, FireFox, AOLInternet Explorer, Netscape, FireFox, AOL
Database testsWith the help of DSN (ODBC32 Interface)With the help of DSN (ODBC32 Interface) plus VB Scripting
Data functionsGoodGood. Having extensive support for SpreadSheet (Excel).
TestsTermed as Testcase. Each Testcase has block of coding statements.Termed as Actions. Each Action has block of coding statements.
Test ScriptScript is a single file.Actually Script is a folder and have set of supporting files.
Code ViewClassic 4Test, Visual 4TestKeyword View, Expert View
Objects RepositoryOfficial term is Window declarations. They can be edited directly from the Editor.Maintained as separate file. With the help of utility, objects are modified. Two types as per QTP setting. They are 'Per Action Repository' and 'Shared Repository'. File extensions will be varied for each type.
Dynamic objectsObject properties can be passed dynamically. Variety of methods available to handle them.Object properties can be passed dynamically. Another term is known as Descriptive Programming.
Class MappingClass Mapping is available.Class Mapping is available.
Custom ClassesRecorderClass and Extension Kit are available.Virutal Object Wizards available.
Image testingBitmap Capture and Verification functions.Bitmap Capture and Verification functions.
Test/Error RecoveryPowerful Recovery system available.Recovery Manager
VerificationProvided Verify and Verify Properties functions.Provided check points for different purposes.
Results ReportingResults are stored into *.res binary files. It can be converted into differnt formats. Multiple versions can be stored into single file.QTP results are stroed as XML files and can be converted to HTML files. Result folder contain many files. One result folder can store results for only one run.
Test Management Tool IntegrationIntegrated with SilkCentral Test Manager.Integrated with Quality Center.
Distributed TestingRemote Agent.Having Remote COM Agent.
DLL support Only Standard DLLs. It does not support the COM/ActiveX DLLs, which are created by VB/.NET.Both COM and Standard DLLs are supported.
Java SupportYesYes
Flex Support Available to certain extent.Available to certain extent.
DotNet SupportYesYes
Internatioalization (i18N) Support YesYes
Timer functionsHaving rich set of functions to calculate time taken for block of statements or testcases. Help: TimersHaving limited functions to calculate time taken for block of statements or actions. Help: Measuring Transactions
Environment support Can access OS level variables.Can access OS level variables.
Batch RunSuite (*.s) and Test plan (*.pln) are available.Test Batch Runner utility.
Coding 4Test Language. Similar to Visual Basic
Ability to run multiple scripts consistantly and continuously.YesShould run from Quality Center.
Coding Style 4Test Language. Similar to C++Visual Basic Script
Integration with External librariesNO VB Script libraries.
Code Samples Few samples from vendor. Few samples from vendor. But many VB Script samples available on Internet.
OOPs SupportYes. Oops concepts are supported for certain extent. User can extend standard classes.NO
Data types Set of data types are available. User can create their own data types also. Set of data types are available. User cannot create their own data types
Interactive DebuggingDebugging features available.Debugging steps available.
Ease of use Just record and playback, won't help. Medium. Record and playback used to help. Very Simple. Easy to learn.
DocumentationHLP file available. PDF docs are only for beginners.Both CHM and PDF files are available. Enough info.
Tool Updates Continuing process. Continuing process.
Cost~$9KMore than $10K
Script Templates Manual. No Ways to create automatic templates. Manual. No Ways to create automatic templates.
EditorGood. Simple one. Having Project explorer similar to MS Visual Studio.Better one with nice look. But using tabs to show more than one script.
Tool Support Tool support is available for only latest versions (from silktest 8.0 ) Tool support is available for only latest versions.
Latest VersionSilktest 2008QuickTest Professional 9.5
Strengths Good Development language, good online community, recovery system, Good cross browser support, Code MaintenanceThe most popular test tool by great user base, plenty of jobs, good online community, Good cross browser support.
WeaknessesHelpdesk, Slightly expensive, Skilled resourcesHelpdesk (Getting bad now), Expensive tool.
Vendor Borland. Initially developed by Segue. Borland acquired Segue on 2006. HP (Hewlett-Packard). Initially developed by Mercury Interactive. HP acquired Mercury on 2006.
Product Name Changes Initially QA Partner. Later changed to SilkTest.Initially Astra QuickTest. Later changed to QuickTest Professional.



Note:In case, if you want to add or modify any feature, please drop a mail to palani.selvam@gmail.com

Monday, June 23, 2008

QTP - Descriptive Programming

QuickTestProfessional help refers Descriptive Programming as Programmatic description. Below given few info about Descriptive Programming.

Using Object Repository
When you record an operation on an object, QuickTest adds the appropriate test object to the Object Repository. Once the object exists in the Object Repository, you can add statements in the Expert View to perform additional methods on that object. To add these statements, you usually enter the logical name of each of the objects in the object's hierarchy as the object description, and then add the appropriate method.

Descriptive Programming (Programmatic Description) Usage
Programmatic description can be very useful if you want to perform an operation on an object that is not stored in the Object Repository. You can also use programmatic descriptions in order to perform the same operation on several objects with certain identical properties, or in order to perform an operation on an object whose properties match a description that you determine dynamically during the test run.

There are two types of programmatic descriptions:

  1. Static . You list the set of properties and values that describe the object directly in a VBScript statement.
  2. Dynamic . You add a collection of properties and values to a Description object, and then enter the Description object name in the statement.

Using the Static type to enter programmatic descriptions directly into your statements may be easier for basic object description needs. However, in most cases, using the Dynamic type provides more power, efficiency, and flexibility.

Useful Links :
Descriptive Programming by QTP Expert Tarun Lalwani

Sample QTP code for Descriptive Programming - Dynamic

Sample QTP code for Descriptive Programming - Static

Thursday, June 5, 2008

QTP - Handling Dynamic objects

Most of the QTP (Quick Test Professional) users are using playback methods to develop the scripts. Here I have given a code snippet to handle dynamic objects. You can put the object physical description directly. You can develop the script with Object Repository.

Code: Login for Mercury Flight

Dialog("nativeclass:=#32770","text:=Login").Activate Dialog("nativeclass:=#32770","text:=Login").WinEdit("nativeclass:=Edit","attached text:=Agent Name:").Set "tester1" Dialog("nativeclass:=#32770","text:=Login").WinEdit("nativeclass:=Edit","attached text:=Password:").Set "mercury" Call wait(2) Dialog("nativeclass:=#32770","text:=Login").WinButton("nativeclass:=Button","text:=OK").Click

Code: Browser certification dialog
If Browser("name:=Certificate Error: Navigation Blocked").Page("title:=Certificate Error: Navigation Blocked").Exist(0) Then ' To DO End If

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

Sunday, March 23, 2008

Class Mapping in QuickTestPro

Class Mapping concept is explained in Custom Objects . QuickTest Professional (QTP) also provides class mapping. The Object Mapping enables you to map an object of an unidentified or custom class to a Standard Windows class.

You can do by Object Identification dialog box from tools menu. For more information, you can refer help for Mapping User-Defined Test Object Classes.

Thursday, March 20, 2008

QTP - Getting INPUT objects

I wrote a qtp (Quicktest Professional) code for listing INPUT element's objects. Descriptive Programming is a feature in QTP. It is used to handle dynamic objects. I will write later about Descriptive Programming. Here below function returns particular type of objects in a web page.

Function:



'Calling function to list editboxes
Set ObjEditAll = ListAllWebObjects (Browser("My APP").Page("First Form"),"text")

Function ListAllWebObjects (ObjContainer,sControlType)
' Getting all type of INPUT objects
Dim MyDescription,objEditBoxes,NoOfChildObjs,Counter,strReport
Dim sTemp, objEdit

'Initialization
'ListAllWebObjects = Nothing
Set MyDescription = Description.Create()
MyDescription("html tag").Value = "INPUT"
MyDescription("type").Value = sControlType

Set objEditBoxes = ObjContainer.ChildObjects(MyDescription)
NoOfChildObjs = objEditBoxes.Count

strReport = ObjContainer.ToString() & " contains the following child object(s):"
For Counter=0 to NoOfChildObjs-1
strReport = strReport & vbNewLine & objEditBoxes.Item(i).ToString()
set objEdit = objEditBoxes(Counter)

sTemp = objEdit.GetROProperty ("name")
Reporter.ReportEvent micDone, objEdit.ToString() & " - name property", sTemp

sTemp = objEdit.GetROProperty ("class")
'sTemp = objEdit.object.ClassName
Reporter.ReportEvent micDone, objEdit.ToString() & " - class property", sTemp

sTemp = objEdit.GetROProperty ("index")
Reporter.ReportEvent micDone, objEdit.ToString() & " - index property", sTemp

sTemp = objEdit.GetROProperty ("location")
Reporter.ReportEvent micDone, objEdit.ToString() & " - location property", sTemp

sTemp = objEdit.GetROProperty ("html id")
Reporter.ReportEvent micDone, objEdit.ToString() & " - html id property", sTemp

sTemp = objEdit.GetROProperty ("innerhtml")
Reporter.ReportEvent micDone, objEdit.ToString() & " - innerhtml property", sTemp

sTemp = objEdit.GetROProperty ("outerhtml")
Reporter.ReportEvent micDone, objEdit.ToString() & " - outerhtml property", sTemp

sTemp = objEdit.GetROProperty ("innertext")
Reporter.ReportEvent micDone, objEdit.ToString() & " - innertext property", sTemp

sTemp = objEdit.GetROProperty ("outertext")
Reporter.ReportEvent micDone, objEdit.ToString() & " - outertext property", sTemp

Next

set ListAllWebObjects = objEditBoxes

Reporter.ReportEvent micDone, ObjContainer.ToString() & " child objects", strReport
End Function

Tuesday, March 18, 2008

MS XML Parser by Visual Basic

I love to use XML Parser. It is very easy to do by Visual basic. You can get the equivalent visual test code here - Visual Test - MS XML Parser. I'm thinking to use it in Quick Test Professional (QTP). Below code snippets are simple and easy to use.

Case1: To load any XML content



'-----------------------------------------
' Method : XMLParserLoadXML
' Author : T.Palani Selvam
' Purpose : Creates XML Parsing object according to the given XML String.
' Parameters: sXML - String, contains data in XML Format.
' Returns : Returns a Object, which contains XML Parsing object.
' Caller : - Nil
' Calls : - Nil -
'------------------------------------------
Function XMLParserLoadXML(sXML As String) As Variant
Dim objXML As Variant

XMLParserLoadXML = Null

Set objXML = CreateObject("Microsoft.XMLDOM") 'Declare a Object
objXML.async = False
objXML.loadXML (sXML) 'Load xmlformat String

'OleSetProperty(objXML,"preserveWhiteSpace") = False

If (objXML.parseError <> 0) Then
LogWrite ("Parsing Error in the File :" + sXMLFile)
Exit Function
End If

'Top Node of given file
Set XMLParserLoadXML = objXML.documentElement
End Function



Case2: It parsed the given tag in given content and returns the node.


'-----------------------------------------
' Method : XMLParser
' Author : T.Palani Selvam
' Purpose : Creates XML Parsing object according to the given XML Format File and Element.
' Parameters: sXMLFile - String, contains a file name, which is in XML Format.
' sTag - String, contains element name from which Tag or element based object to be returned.
' Returns : Returns a Object, which contains XML Parsing object.
' Caller : - Nil
' Calls : - Nil -
'-----------------------------------------
Function XMLParser(sXMLFile As String, sTag As String) As Variant
Dim objXML As Variant, objNode As Variant, objTemp As Variant, objRoot As Variant
'Dim varTest As Variant
Dim iIndex As Integer, iTemp As Integer
'Dim objRoot As node

XMLParser = Null
sTag = Trim(sTag)
Set objXML = CreateObject("Microsoft.XMLDOM") 'Declare a Object
objXML.async = False
objXML.Load (sXMLFile) 'Load xmlformat file

If (objXML.parseError <> 0) Then
LogWrite ("Parsing Error in the File :" + sXMLFile)
MsgBox ("Parsing Error in the File :" + sXMLFile)
Exit Function
End If

'Top Node of given file
Set objRoot = objXML.documentElement
'Print "XML File is : " & sXMLFile
'Print objRoot.nodeName & " Name of the node.."

If ((sTag = "") Or (sTag = objRoot.nodeName)) Then
'XMLParser = CVar(objRoot)
Set XMLParser = objRoot
'Set varTest = objRoot
'XMLParser = objRoot
Exit Function
End If

If objRoot.hasChildNodes <> 0 Then
objTemp = objRoot.childNodes
iTemp = objTemp.length

For iIndex = 0 To iTemp - 1
objNode = objTemp.Item(iIndex)
If (UCase(Trim(objNode.nodeName)) = UCase(sTag)) Then
XMLParser = objNode
Exit Function
Else
Set objNode = Nothing
End If
Next iIndex
End If

objTemp = objXML.getElementsByTagName(sTag) 'Search whole file with sTag
iTemp = objTemp.length
If (iTemp > 0) Then
objNode = objTemp.Item(0)
XMLParser = objNode
End If

End Function

Friday, February 22, 2008

Automation Tool support

In my first job, I used to automate by using VisualTest. There is no updates, after IBM acquired Rational. In this year, the yahoogroups also removed. VisualTest is a simple and powerful tool. Similarly Segue was acquired by Borland. Initially Borland took much time to set the updates on Silktest and Silkperformer. Later it announced that older versions of Silktest and silkperformer will not have support. Now its time for HP-Mercury.

Yesterday I got a mail from my friend. It said that HP is going to stop support for Winrunner. PDF is available here. There is a solution to migrate winrunner scripts to QuickTestProfessional. It is available at win-quick I donot know how much painful task it is for each company.


The frequent acquisitions are making many questions among to automation engineers.

1. Whether this product will be promoted?
2. Whether the updates will be added frequently as per changing technology?
3. What will happen to future if the product is ended?
4. How will be job market for this particular tool?