Handling Passwords in QTP Scripts

Most of the applications/websites will require a password for getting into them.

So, automation tools such QTP should be able to handle the passwords. But anyway, it is not a good practice to keep the password as it is in the scripts.

By default QTP will encrypt the password while recording. The recorded step will look like the below statement.
Dialog(“Login”).WinEdit(“Password:”).SetSecure “49ff257067d53a774881c348da151ccf9282c2109b60”

SetSecure method will be specifically used for handling passwords.
This recording approach will be useful only when you are going to use one or few passwords in your script.

If you want to use many number of different passwords for executing many iterations, this recording approach won’t be much useful.In this case we can use password encoder utility provided by QTP.
It can be accessed from start menu (e.g Programs->Quick Test Professional->Tools->Password Encoder)
It will look like below screenshot.

We need to enter the password text, and clicking “Generate” button will provide the encoded password string.
We can put this string in the Datatable for executing multiple iterations with different passwords.
It will be useful not only for automating the testing, but also in below scenario.
– you want to allow a person available in a remote place to get into your application/site for doing some testing or for some other purpose, and you don’t want to share the password with him. In this case you can just create a QTP script to log into the application.

Some people may not be willing to store the password in the QTP script even in the encrypted form also.In this case, we can create a simple HTML form and call it from QTP script to show as a pop-up window for getting password from user while executing the Script.

It is possible to see the encrypted password in plain text format. So, don’t store your important passwords in encrypted format also. Instead of storing the password, you can create a simple HTML form and call it from QTP script to show as a pop-up window for getting password from user while executing the Script.

Below lines of code were created while recording the login window of the sample flight application using QTP.

Dialog(“Login”).WinEdit(“Agent Name:”).Set “quality”  

Dialog(“Login”).WinEdit(“Password:”).SetSecure “4ce5631fdebb5762c2878e6f8f735a9d0511b0b7”  

Dialog(“Login”).WinEdit(“Agent Name:”).Set “quality”

Dialog(“Login”).WinEdit(“Password:”).SetSecure “4ce5631fdebb5762c2878e6f8f735a9d0511b0b7”
Here we can see the encrypted value “4ce5631fdebb5762c2878e6f8f735a9d0511b0b7” for the password “mercury”
But, when I run the QTP script after just changing the code like below, I was able to see the plain text password “mercury” in the Agent Name field.

Dialog(“Login”).WinEdit(“Agent Name:”).SetSecure “4ce5631fdebb5762c2878e6f8f735a9d0511b0b7”  

Leave a Reply