Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Friday 24 July 2015

CheckPoints

Checkpoints are  verification points takes expected results from the user, compares with Actual result during execution and provides test results.

Types of Checkpoints:
  1. Standared Checkpoint: it takes object property values
  2. Text Checkpoints
  3. Text area checkpoints
  4. Bitmap checkpoints
  5. Database checkpoints
  6. Accessibility checkpoints
  7. XML checkpoints(from application)
  8. XML checkpoints (from Resources)
  9. File Content checkpoints(NEW)
  10. Page checkpoints
  11. Image checkpoints
  12. Table Check Points
Note: From 10 12 checkpoints are hidden checkpoints, can be inserted using standard checkpoint. From 6 to 12 except file content checkpoint are only for web. Database, xml(from resource and file content checkpoint are back end checkpoints)



Thursday 23 July 2015

We can capture index property at run time.

make the index value as a variable and pass a range of values to that variable for the object description.

for intIndex=0 to 3
    Browser().Page().Button("name:=some name","index:="&intIndex).click
    If Browser().Page("CustPage").Exist Then
       Exit For
    End If
Next


this logic to find the required webtable with actual column count etc ...


so your code click to all the buttons and check the page title ...now you know the which index takes you to what screen.

so once you capture these values dynamically ...can use to automate the functionality to these 4 pages ...have a common function to any environment to capture index values first then use them to navigate to required screen .. 

Monday 20 July 2015

Files and Folder in Vb-Scripts

FSO is a UFT object model, through which UFT/ VB Scripting allows users to process / manipulate system drives, folders and files

What can FSO do: FSO deals with files (text files) / Folders & Drives (system folders/ drives)

FSO is useful forTo create files / add data / remove data / copy files / delete files / save files and so on.

Example:

'Create a filesystemObject
Set fso=createobject("Scripting.FileSystemObject")
'Create a non existing file "qtptest.txt "  with overwrite option as True
Set qfile1=fso.CreateTextFile("C:\qtptest.txt",True,False)
'Close the files
qfile1.Close
'Release the allocated objects
Set qfile1=nothing

'Output --> New File "qtptest.txt " is created

Example-2 :  

'Create a filesystemObject
Set fso=CreateObject("Scripting.FileSystemObject")
'Create a   file "qtptest.txt "  in C Drive .
'Then  run the below statement with overwrite option as False
Set qfile2=fso.CreateTextFile("C:\qtptest.txt",False,False)
Set fso=nothing

'Output --> Error message "File already exists" is displayed

Methods:

CopyFile: Copies one or more files from one location to a new location

Syntax: fso.CopyFile (source, destination[, overwrite])

Arguments:

FSO: (Required) The name of a FileSystemObject object previously instantiated.

Source: (Required) A character string file specification, which   can include wildcard characters, for one or more files to be copied.

Destination: (Required) Character string destination where the file or files from source are to be copied.Wildcard characters are not allowed in the destination string.

Overwrite: (Optional) Boolean value that indicates if existing files are to be overwritten. If True, files are overwritten; if False, they are not. The default is True. 
Note that CopyFile will fail if destination has the   read-only attribute set, regardless of the value of overwrite.

Example: 

Set fso=createobject("Scripting.FileSystemObject")
'File to be copied Sourcefile="C:\copy.txt"'Dest folder where the file has to be copied
Destination="D:\final1\"
'If the destination doesnot exist then create the destination folder
If fso.FolderExists(Destination) = false Then
   fso.CreateFolder (Destination)
End If
'Copy the file
fso.CopyFile Sourcefile,Destination,True
Set fso=nothing


DeleteFile: Deletes a specified file.

Syntax: fso.DeleteFile (filename[, force])

Arguments:

Fso: (Required) The name of a FileSystemObject object previously instantiated

Filename: (Required) The name of the file to delete. The filename can contain wildcard characters in the last path component.

Force: (Optional) Boolean value that is True of files with the read-only attribute set are to be deleted;False if they are not. False is the default.

Example:   

Set fso=createobject("Scripting.FileSystemObject")
'File to be  deleted.  Sourcefile="C:\copy.txt"  
'Delete the file
fso.DeleteFile Sourcefile
Set fso=nothing


CreateFolder: Creates a new folder in the specified location.

Syntax: fso.CreateFolder(foldername)

Arguments:

Fso: (Required) The name of a FileSystemObject object previously instantiated.

FolderName: (Required) A character string expression that identifies the folder to create

Example:    

Set fso=createobject("Scripting.FileSystemObject")
'Folder to be created Foldername="D:\Folder_create" 
'If the folder doenot exst then create the folder
If fso.FolderExists(Foldername) = false Then
   fso.CreateFolder (Foldername)
End If
Set fso=nothing

CopyFolder: Copies a folder to a new location.

Syntax: fso.CopyFolder (source, destination[, overwrite])

Arguments:

Fso: (Required) The name of a FileSystemObject object previously instantiated.

Source:(Required) A character string folder specification, which can include wildcard characters, for one or more folders to be copied. Wildcard characters can only be used in the last path component of the source argument.

Destination: (Required) Character string destination where the folder and subfolders from source are to be copied. Wildcard characters are not allowed in the destination string.

Overwrite: (Optional) Boolean value that indicates if existing folders are to be overwritten. If True, files are overwritten; if False, they are not. The default is True.

Example:   

Set fso=createobject("Scripting.FileSystemObject")
'Folder to be created SourcePath="D:\Folder_create" DestinationPath="D:\Destination\" 
'If the folder doesnot exst then create the folder
If fso.FolderExists(DestinationPath) = false Then
   fso.CreateFolder (DestinationPath)
End If
fso.CopyFolder  SourcePath,DestinationPath,True
Set fso=nothing

MoveFolder: Moves one or more folders from one location to another.

Syntax: fso.MoveFolder (source, destination)

Arguments:

Fso: (Required) The name of a FileSystemObject object previously instantiated.

Source:(Required) The path to the folder or folders to be moved. The source argument string can contain wildcard charactersin the last path component only.

Destination: (Required) The path where the folder or folders are to be moved. The destination argument can't contain wildcard characters.

Example:    

Set fso=createobject("Scripting.FileSystemObject")
'Folder to be created SourcePath="D:\Folder_move" DestinationPath="D:\Destination\"

'If the folder doesnot exst then create the folder
If fso.FolderExists(DestinationPath) = false Then
   fso.CreateFolder (DestinationPath)
End If
fso.MoveFolder  SourcePath,DestinationPath
Set fso=nothing


DeleteFolder: Deletes the specified folder and its contents.

Syntax: fso.DeleteFolder (folderspec[, force])

Arguments:

Fso: (Required) The name of a FileSystemObject object previously instantiated
Folderspec: (Required) The name of the folder to delete. The folderspec can contain wildcard characters in the last path component.
Force:        (Optional) Boolean value that is True of folders with the read-only attribute set are to be deleted;False if they are not. False is the default.

Example:  

Set fso=createobject("Scripting.FileSystemObject")
'Folder to be  deleted.  FolderDel="D:\final1"  'Delete the folder
fso.DeleteFolder(FolderDel)
Set fso=nothing

DriveExists:  Determines whether or not a specified drive exists.

Syntax: fso.DriveExists (drivespec)

Arguments:

Fso: (Required) The name of a FileSystemObject object previously instantiated.
Drivespec: (Required) A drive letter or a complete path specification.

Example:  

Set fso=createobject("Scripting.FileSystemObject")
'The drive to check the existence
drivepath="D:\"
If fso.DriveExists(drivepath) then
     msgbox  "Drive Exists"  
Else    
    Msgbox "Drive doesnot Exist"
End If
Set fso=nothing


FileExists: Determines whether or not a specified file exists.

Syntax: fso.FileExists (filespec)

Arguments:

Fso: (Required) The name of a FileSystemObject object previously instantiated.
Filespec: (Required) The name of the file whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the file isn't expected to exist in the current folder.

Example:  

Set fso=createobject("Scripting.FileSystemObject")
'The file to check the existence
filepath="D:\qtptest.txt"
If fso.FileExists(filepath) then
  msgbox  "File Exists"
Else
  Msgbox "File doesnot Exist"
End If
Set fso=nothing

FolderExists:  Determines whether or not a specified folder exists.

Syntax: fso.FolderExists (folderspec)

Arguments:

Fso: (Required) The name of a FileSystemObject object previously instantiated.
Folderspec: (Required) The name of the folder whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the folder isn't expected to exist in the current folder.

Example:   

Set fso=createobject("Scripting.FileSystemObject")
'The Folder to check the existence
folderpath="D:\qtp"
If fso.FolderExists(folderpath)  then
 msgbox  "Folder Exists"
Else
 Msgbox "Folder doesnot Exist"
End If
Set fso=nothing

GetDrive:  Returns a Drive object corresponding to the drive for a specified path.

Syntax: objDrv = fso.GetDrive(drivespec)

Arguments:

Fso:  (Required) The name of a FileSystemObject object previously instantiated.
Drivespec: (Required) The drivespec argument can be a drive letter (c), a drive letter with a colon appended (c:), a drive letter with a colon and path separator appended (c:\), or any network share specification (file://computer2/share1

Example: 

Set fso=createobject("Scripting.FileSystemObject")
'Drive for  getting details  Sourcefile="C:\"  
Set get_drv=fso.GetDrive(Sourcefile)
'Some of the following details can be retrieved from a drive
msgbox  get_drv.AvailableSpace
Msgbox  get_drv.DriveLetter
msgbox  get_drv.DriveType
msgbox  get_drv.FileSystem
msgbox  get_drv.FreeSpace
msgbox  get_drv.Path
Msgbox  get_drv.RootFolder
Msgbox  get_drv.SerialNumber
Msgbox  get_drv.TotalSize
Set fso=nothing


GetFolder:  Returns a Folder object corresponding to the folder in a specified path

Syntax: objFolder = fso.GetFolder(folderSpec)

Arguments:

Fso: (Required) The name of a FileSystemObject object previously instantiated.
FolderSpec: (Required) The folderspec is the path (absolute or relative) to a specific folder.

Example:    

Set fso=createobject("Scripting.FileSystemObject")
'Folder  for  getting details 
Sourcefolder="D:\QTP" 
Set get_folder=fso.GetFolder(Sourcefolder)
'get the subfolders count in a folder
Set  get_subfolder=get_folder.SubFolders
For  each  sfile  in get_subfolder
  'Get the name of each folder
   Msgbox  sfile.name
Next
Set fso=nothing


GetFile: Returns a File object corresponding to the file in the specified path. The file object methods and properties can be accessed. See File Object for the file object’s methods and properties.

Syntax: objFile = fso.GetFile(fileSpec)

Arguments:

Fso: (Required) The name of a FileSystemObject object previously instantiated.
FileSpec: (Required) The filespec is the path (absolute or relative) to a specific file.

Example:    

Set fso=createobject("Scripting.FileSystemObject")
'File for  getting details  Sourcefile="D:\qtptest.txt"
Set get_file=fso.GetFile(Sourcefile)
'Some of  the following details can be retrieved from a file
msgbox  get_file.DateCreated
msgbox  get_file.DateLastAccessed
msgbox  get_file.DateLastModified
msgbox  get_file.ParentFolder
msgbox  get_file.Path
Set fso=nothing   


Wednesday 15 July 2015

Excel Operations In Vb-script

Microsoft has developed the Excel application with hierarchy of object model.We can do excel operations using excel object model.

Simple object model Example: 

Excel Application --> Workbooks--> Worksheet--> cells

Syntax:

Set variable = CreateObject("Class value") 

Excel objects
1) Excel Application Object
It is Used to perform operations on Excel Application
Set variable = CreateObject("Excel.Application")
2) Excel Workbook Object
It is used to work with Excel files/Workbooks
Set variable = ExcelApplicationObject.Workbooks.Add/Open("File Path")
3) Excel Worksheet Object
It is used to work with Excel Sheets/Worksheets
Set variable = ExcelWorkbookObject.Worksheets(Sheet Id Or "Sheet Name")
Excel Application Object is always only one, We can create one or more Excel Workbook objects, We can create one or more Excel Worksheet objects for every workbook object
Difference between FileSystemObject model and Excel object model in case of Sub Objects.
> In FileSystemObject model creating Text stream object (sub object) is mandatory to perform Text(Read, write etc…) related operations

> In Excel object model creating sub objects is optional, but if you want work with multiple files and multiple sheets then sub objects are required.
Create an Excel file

Dim objExcel
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True ‘To view the Operation during execution
objExcel.Workbooks.Add ‘To create new file
objExcel.ActiveWorkbook.SaveAs “C:\Users\Desktop\raju.xlsx”
objExcel.Quit ‘To close the Excel Application
Set objExcel = Nothing


Getting value from an existing excel sheet

Dim oExcel, oWB, oSheet, getVal
Set oExcel=CreateObject("Excel.Application")
Set oWB=oExcel.Workbooks.Open("C:\raju.xls")
Set oSheet=oWB.WorkSheets("Sheet1")
oExcel.Visible=TRUE
getVal=oSheet.Cells(1,1).Value
print getVal
oWB.Close
Set oExcel=Nothing


Inserting value to an existing excel sheet

Dim oExcel, oWB, oSheet, setVal
Set oExcel=CreateObject("Excel.Application")
Set oWB=oExcel.Workbooks.Open("C:\raju.xls")
Set oSheet=oWB.WorkSheets("Sheet1")
oExcel.Visible=TRUE
setVal="ValueInserted"
oSheet.Cells(4,1).Value=setVal

oWB.Save
oWB.Close
Set oExcel=Nothing


Create excel file and enter some data save it......  

'Create Excel Object    
Set excel=createobject("excel.application")  
'Make it Visible    
excel.Visible=True  
'Add New Workbook    
Set workbooks=excel.Workbooks.Add()  
'Set the value in First row first column    
excel.Cells(1,1).value="testing"  
'Save Work Book    
workbooks.saveas"D:\raju.xls"  
'Close Work Book    
workbooks.Close  
'Quit from Excel Application    
excel.Quit  
'Release Variables    
Set workbooks=Nothing  
Set excel=Nothing


Deleting Rows from Excel Sheet ...... 

'Create Excel Object    
Set excel=createobject("excel.application")  
'Make it Visible    
excel.Visible=True  
'Open the Excel File  
Set workbook=excel.Workbooks.Open("D:\raju.xls")
'Get the Control on Specific Sheet  
Set worksheet1=excel.Worksheets.Item("Sheet1")
'Delete Row1  
worksheet1.Rows("1:1").delete
'Save Excel  
workbook.SaveAs("D:\raju.xls")
'Close Work Book    
workbook.Close  
'Quit from Excel Application    
excel.Quit  
'Release Variables    
Set worksheet1=Nothing
Set workbook=Nothing
Set excel=Nothing  


Count number of rows in Excel without opening it - using vbscipt in UFT.

Set objExcel=CreateObject("Excel.Application")
Set objWB=objExcel.WorkBooks.Open("C:\abc.xls")
Set objSheet=objWB.WorkSheets(1)
msgbox objSheet.usedrange.rows.count
Set objExcel=Nothing


Add new sheet....

'This code demonstrate how to add new sheet to existing excel file and rename it at runtime

Dim oExcel, oWB, oSheet, getVal
Set oExcel=CreateObject("Excel.Application")
oExcel.visible=True
oExcel.DisplayAlerts = False   'this will not allow alerts to be displayed
Set oWB=oExcel.Workbooks.Open("C:\raju.xls")
Set oSheet1=oWB.Sheets.Add  'a new sheet is added with default name i.e. Sheet4 etc.

oSheet1.Name="UFT"  'rename newly added sheet
oSheet1.cells(1,1).value="Welcome"  'enter value
oWB.Save
oWB.Close
Set oExcel=Nothing



Using excel sheet as database table


Excel sheet can be used as a database for the  parameterization purpose. Following code demonstrate how to connect and consider excel sheet as database table.

This might be usefull while working with databases. You can export database 
table into excel (one time) and then work on excel as database

Dim objCon, objRecordSet, strExlFile, colCount, row,i
Set objCon = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

strExlFile = "D:\TestScript.xlsx"
objCon.Open "DRIVER={Microsoft Excel Driver(*.xls)};DBQ="&strExlFile&"; Readonly=True"

strSQLStatement = "SELECT * FROM [Sheet1$]"
objRecordSet.Open strSQLStatement, objCon 'create recordset
colCount = objRecordSet.Fields.count    'No of columns in the table

While objRecordSet.EOF=false
    row=""
    For i=0 to colCount-1
        row=row &"    "& objRecordSet.fields(i)
    Next 
    Print row
    objRecordSet.moveNext
Wend
Set objRecordSet = Nothing
objCon.Close
Set objCon = Nothing