Working With Passwords Within an Edit Control in Desktop Windows Applications

Applies to TestComplete 15.45, last modified on December 01, 2022

Note: To learn how to simulate user actions over text edit box controls in web applications, see Working With Text Edit Controls in Web Applications.

While testing edit controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

Masking Characters

If the current edit control is a password dialog box, it displays placeholder characters instead of symbols typed by the user. Symbols that are displayed instead of the user's input are specified by the application. The standard symbol that replaces the characters is an asterisk (*). You can use the wPasswordChar property to find out which symbol is used to replace password characters. Here is an example:

JavaScript, JScript

// Post a password character to the log
Log.Message (Edit.wPasswordChar);

VBScript

' Post a password character to the log
Log.Message Edit.wPasswordChar

DelphiScript

// Post a password character to the log
Log.Message(Edit.wPasswordChar);

C++Script, C#Script

// Post a password character to the log
Log["Message"](Edit["wPasswordChar"]);

Note: This property is used with single-line edit controls only.

Password Variables

TestComplete provides a special Password variable type. The values specified for variables of this type are encrypted. You can use variables of this type to enter data in the edit control by using the SetText or Keys action. The value you enter is not posted to the log, and the image in the log does not contain the entered text.

JavaScript, JScript

// Enter the password
Sys.Keys(Project.Variables.Var1);

VBScript

' Enter the password
Sys.Keys(Project.Variables.Var1)

DelphiScript

// Enter the password
Sys.Keys(Project.Variables.Var1);

C++Script, C#Script

// Enter the password
Sys["Keys"](Project["Variables"]["Var1"])

If you record password input to edit controls, the password values are automatically saved into password variables and masked in recorded tests. It helps you keep your passwords secure when testing.

If your passwords are recorded as text stings and are not masked in tests, make sure the Tools > Options > Engines > Recording > Record text input into simple editors as option is set to SetText (the default value).

Enter Passwords Into Edit Controls

A password is entered in the same way text is entered in an edit control (for detailed information, see Entering Text into an Edit Control in Desktop Windows Applications). The following example demonstrates how you can enter a password in an edit control:

JavaScript, JScript

// Enter the password
Sys.Keys("MyPassword");

VBScript

' Enter the password
Sys.Keys "MyPassword"

DelphiScript

// Enter the password
Sys.Keys('MyPassword');

C++Script, C#Script

// Enter the password
Sys["Keys"]("MyPassword");

The length of the password can be limited (see Determining Maximum Text Length in an Edit Control in Desktop Windows Applications). If the length is limited, you can enter, for example, only 5 symbols and further input is impossible.

Note: If you use an edit control in password mode, you may not want to store the password in a test. You can use the BuiltIn.InputBox routine or create a custom user form (for detailed information, see Entering Passwords) to avoid security problems.

See Also

Working With Edit Controls in Desktop Windows Applications
Entering Passwords
wPasswordChar Property (Edit Controls)
Determining Maximum Text Length in an Edit Control in Desktop Windows Applications
Working With Text Edit Controls in Web Applications

Highlight search results