Thursday, September 20, 2012

DotNetFactory in QTP

*******************************************************************************************
DotNetFactory :
*******************************************************************************************

DotNetFactory is a new utility object of QTP , which enables QTP scripting to directly access methods and properties of a .NET object by creating an instance of this object.

To use DotNetFactory, you will first need to create the object instance. To create the object instance use ‘CreateInstance’ method.



Syntax : DotNetFactory.CreateInstance (TypeName [,Assembly] [,args])


********************************************************************************************
Below is the example to create the simple userfrom using  DotNetFactory:
********************************************************************************************

function UserLoginForm()

Set objForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set objBtn1 = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set objLbl = DotNetFactory.CreateInstance("System.Windows.Forms.Label", "System.Windows.Forms")
Set objPassword = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")
Set objLbl2 = DotNetFactory.CreateInstance("System.Windows.Forms.Label", "System.Windows.Forms")
Set objUserName = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")
Set objRegion = DotNetFactory.CreateInstance("System.Windows.Forms.ComboBox", "System.Windows.Forms")
objForm.Left=500
objForm.Top=250
objForm.Height=275
objUserName.Top=40
objUserName.Left=100
objPassword.Top=70
objPassword.Left=100
objPassword.UseSystemPasswordChar=True
objForm.CancelButton = objBtn1
objLbl.text = "User Name"
objLbl.Top=40
objLbl.Width=80
objLbl.left=20
objLbl2.text="Password"
objLbl2.Top=70
objLbl2.Left=20
objLbl2.Width=80
objRegion.Items.add "DEV"
objRegion.Items.add "QA"
objRegion.Items.add "PROD"
objBtn1.text = "OK"
objBtn1.Top=170
objBtn1.Left=95
objBtn1.Width=120
objBtn1.Height=30
objUserName.TabIndex=1
objPassword.TabIndex=2
objRegion.TabIndex=3
objBtn1.TabIndex=4
objForm.controls.add(objLbl)
objForm.controls.add(objLbl2)
objForm.controls.add(objUserName)
objForm.controls.add(objBtn1)
objForm.controls.add(objPassword)
objForm.controls.add(objRegion)

objForm.StartPosition = CenterScreen

objForm.Text = "Regression Testing"
objForm.showDialog

Environment.Value("vUserName") =objUserName.text
Environment.Value("vPassword")=objUserName.text
Environment.Value("vRegion")=objRegion.Text

end function

No comments:

Post a Comment