preload

TestComplete – “UserName/Password” Form

Posted by Albert Gareev on Apr 16, 2012 | Categories: How toRoutinesSource codeTestComplete

Parent page: Using GUI Forms in TestComplete

Even though automation scripts are intended to drive the application under test there are cases when communication with tester is required. With TestComplete, we have a vast arsenal of predefined GUI controls for that (and those, acquainted with Delphi, will be pleasantly surprised by the way it’s organized).

Today’s post provides an example of creating and using ‘Username/Password’ dialog.
But, first, a couple of words why automation scripts would need one.

No, this is not an authorization to run the scripts. This is for the scripts.
Maybe you need to connect to the database. Or run the scripts with administrator’s permission. Or it’s just a security requirement from your stakeholders.

Whatever it is, you better not store such sensitive data in a file or the source code. Make them exist only during run-time.

Preparing Modal Form

We begin with a sample form.

Add Edit Controls, Buttons, and Labels

Set Object Properties

Form
  • Name – object name to use in the code; ‘Security’ in my example
  • Caption – title of the window when the form is displayed
Label controls
  • Caption – displayed text
Edit Box Controls
  • Name – object name to use in the code; ‘EditUsername’/’EditPassword’ in my example
  • EditPassword.Properties.EchoMode = eemPassword – to mask password characters
Buttons
  • Caption – displayed text; ‘OK’/’Cancel’ in my example
  • Cancel = True – for ‘Cancel’ button
  • ModalResult = mrCancel – for ‘Cancel’ button
  • Default = True – for ‘OK’ button
  • ModalResult = mrOK – for ‘OK’ button

Example

  Dim objDlg
  Dim sUsername, sPassword
  Dim Result

  'Get object's instance
  Set objDlg = UserForms.Security

  'Execute
  Result = objDlg.ShowModal

  If Result = mrOK Then
    'retrieve the input
    sUsername = objDlg.EditUsername.Text
    sPassword = objDlg.EditPassword.Text
  Else
    'Respond
    MsgBox "Execution cancelled", vbOKOnly
    'exit function or finalize execution
  End If

  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.