03-23-2011, 12:04 AM
(This post was last modified: 03-23-2011, 12:11 AM by cdesserich.)
The best way I know how is to use .NET components. These functions can be added to a function library or just included in the test you are running.
Then to use it with your code, you simply call the EncryptedPassword function for your SetSecure call. It will prompt with a password masked box.
EDIT: I should point out that those functions really shouldn't be included in the test itself, they will run MUCH faster if included in a function library.
Code:
Public Function EncryptedPassword()
Dim dialogForm, dialogTextBox, dialogAcceptButton, dialogStartPosition, dialogBorderStyle, ResultEnum
Set dialogForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set dialogTextBox = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")
Set dialogAcceptButton = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set dialogStartPosition = DotNetFactory.CreateInstance("System.Windows.Forms.FormStartPosition", "System.Windows.Forms")
Set dialogBorderStyle = DotNetFactory.CreateInstance("System.Windows.Forms.FormBorderStyle", "System.Windows.Forms")
Set ResultEnum = DotNetFactory.CreateInstance("System.Windows.Forms.DialogResult", "System.Windows.Forms")
dialogForm.Text = "Enter Password"
dialogForm.Width = 250
dialogForm.Height = 100
dialogForm.MinimizeBox = False
dialogForm.MaximizeBox = False
dialogForm.StartPosition = dialogStartPosition.CenterScreen
dialogForm.FormBorderStyle = dialogBorderStyle.FixedDialog
dialogTextBox.UseSystemPasswordChar = True
dialogTextBox.Width = 220
dialogTextBox.Top = 15
dialogTextBox.Left = 15
dialogAcceptButton.Text = "OK"
dialogAcceptButton.Top = 45
dialogAcceptButton.Left = 90
dialogForm.AcceptButton = dialogAcceptButton
dialogForm.AcceptButton.DialogResult = ResultEnum.OK
dialogForm.Controls.Add dialogTextBox
dialogForm.Controls.Add dialogAcceptButton
Do
dialogForm.ShowDialog(GetQtpNativeWindow)
dialogForm.Text = "Enter Password - CANNOT BE BLANK"
Loop While dialogTextBox.Text = ""
EncryptedPassword = Crypt.Encrypt(dialogTextBox.Text)
'MsgBox dialogTextBox.Text
dialogAcceptButton.Dispose
dialogTextBox.Dispose
dialogForm.Dispose
Set dialogBorderStyle = Nothing
Set dialogStartPosition = Nothing
Set dialogAcceptButton = Nothing
Set dialogTextBox = Nothing
Set dialogForm = Nothing
End Function
Private Function GetQtpNativeWindow
Dim hWnd, qtpWnd
Set hWnd = DotNetFactory.CreateInstance("System.IntPtr", "Mscorlib", Window("RegExpWndTitle:=QuickTest Professional.*").GetROProperty("hWnd"))
Set qtpWnd = DotNetFactory.CreateInstance("System.Windows.Forms.NativeWindow", "System.Windows.Forms")
qtpWnd.AssignHandle hWnd
Set GetQtpNativeWindow = qtpWnd
Set hWnd = Nothing
Set qtpWnd = Nothing
End Function
Then to use it with your code, you simply call the EncryptedPassword function for your SetSecure call. It will prompt with a password masked box.
Code:
Browser("micclass:=Browser").Page("micClass:Page").WebEdit("pwd").SetSecure EncryptedPassword
EDIT: I should point out that those functions really shouldn't be included in the test itself, they will run MUCH faster if included in a function library.