Monday, 19 August 2013

Prompt Dialog For Password Entry In QTP with help of DotNetFactory

The following code popup a dialog with a edit box for a password entry when it run from the QTP
Set objForm = DotNetFactory.CreateInstance(“System.Windows.Forms.Form”, “System.Windows.Forms”)
Set objBtn1 = DotNetFactory.CreateInstance(“System.Windows.Forms.Button”, “System.Windows.Forms”)
Set objEdit1 = DotNetFactory.CreateInstance(“System.Windows.Forms.TextBox”, “System.Windows.Forms”)
x=80
y=40
Set p1 = DotNetFactory.CreateInstance(“System.Drawing.Point”,”System.Drawing”,x,y) ‘This will provide the locations(X,Y) for the controls
Set lbl= DotNetFactory.CreateInstance(“System.Windows.Forms.Label”,”System.Windows.Forms”)
lbl.Text=”Enter Password”
lbl.Location=p1
objForm.Controls.Add(lbl)
p1.Y=CInt(lbl.Height)+40
objEdit1.Location=p1
objForm.Controls.Add(lbl)
objEdit1.UseSystemPasswordChar=true’To set the password character From system
objForm.Controls.Add(objEdit1)
objBtn1.Text=”OK”
p1.Y=Cint(p1.Y)+CInt(objEdit1.Height)+20
objBtn1.Location=p1
objForm.CancelButton=objBtn1
objForm.Controls.Add(objBtn1)
objForm.StartPosition=CenterScreen
objForm.Text=”Mohan kakarla”
objForm.ShowDialog
msgbox “The Password You have Entered Is: “&objEdit1.Text

No comments:

Post a Comment