Saturday, June 26, 2010

Resizing Bitmap using Dotnet Factory

Set oImage=DotNetFactory.CreateInstance("System.Drawing.Image","System.Drawing")
vstPath="C:\Sample Pictures\Water lilies.jpg" 'path of the bitmap to be resized.
Set oBitmap=DotNetFactory.CreateInstance("System.Drawing.Bitmap","System.Drawing",oImage.FromFile(vstPath),30,40)
vStResizedPath="C:\Sample Pictures\Water lilies1.jpg"
oBitmap.Save(vStResizedPath)'Save the resized bitmap.
Set oBitmap=Nothing
Set oImage=Nothing

Thursday, June 3, 2010

Reuse Your QTP Code

In this article, I am going to explain you how can we reuse the code which is written for web application.
In the below class, I have written function fnc_set to set value in a WebEdit.

Class FirstClass
Private VarBrowserObj
Private VarWebEditObj
Private VarSetValue
'**********Let Property*****************************************
Public Property Let fnc_VarSetValue(val)
End Property
'**********Set Property****************************************
Public Property Set fnc_VarBrowserObj(val)
Set VarBrowserObj=val
End Property

Public Property Set fnc_VarWebEditObj(val)
Set VarWebEditObj=val
End Property
'**************Funtions and Procedures**********************
Public Function fnc_set
Browser(VarBrowserObj).WebEdit(VarWebEditObj).Set VarSetValue
End Function
End Class

Here, I am creating an object for the above class and setting up values and objects for class properties.

Public objClass
'Creating object for class
Set objClass=new FirstClass

'Calling Let to assign value for VarSetValue property

'Calling Set property method for Browser object
Dim objBrowser:Set objBrowser=Description.Create()
Set objClass.fnc_VarBrowserObj=objBrowser

'Calling Set property method for WebEdit object
Dim objWebEdit:Set objWebEdit=Description.Create()
Set objClass.fnc_VarWebEditObj=objWebEdit

'Calling fnc_set function for Web operation

You may think that the above class can be used only for web application. But we are able to use for other application also.

'Calling Let to assign value for VarSetValue property

'Calling Set property method for Dialog object
Dim objDialog:Set objDialog=Description.Create()
objDialog("micclass").Value="Dialog"'Here is the trick, you need to inlcude micclass property along with main property.
Set objClass.fnc_VarBrowserObj=objDialog

'Calling Set property method for WinEdit object
Dim objWinEdit:Set objWinEdit=Description.Create()
objWinEdit("attached text").Value="Agent Name:"
Set objClass.fnc_VarWebEditObj=objWinEdit

objClass.fnc_set 'Setting value in winedit with same function.