Environment Variables

How to load environment variables during runtime?

Questions by sagirinaveen

Showing Answers 1 - 3 of 3 Answers

ram4u

  • Jun 20th, 2009
 

User-Defined Internal, User-Defined External, Built-in are the types of environment variables available in QTP.

Built-in variables as the name suggests are predefined by QTP. Examples of such variables are OS, OSVersion, ActionName which are for Operating System, Operating System Version and name of the action which is currently running, respectively.

Lets look at an example of this:

1. Open a new Test.

2.Go to File (Menu)->Settings, a Test Settings window opens.

3. Go to Environment Tab. By default Built-in variable type is selected and you will be able to see Name and Description of Built-in variables below Variable type dropdown box.

4. You can click on any of those variables to see their current value.

5. I just did the above four steps in order to show you from where you can access Built-in variables.

6. Now close this Test Settings window and go to test.

7. In the Expert View type:

a = environment("ActionName") & " is running on " & environment("OS")
msgbox (a)

8. And Run the test.

It is just a simple way to show how a Built-in environment variable works.

User Defined Internal variables are the variables defined by you (the user) within the test and which are saved within the test and also accessible from within the test.

Lets look at an example of this:

1. Open a new Test.

2. Go to File (Menu)->Settings, a Test Settings window opens.

3. Go to Environment Tab. From Variable type dropdown select User-defined.

4. Click on the '+' which is on the right of Variable type dropdown.

5. 'Add New Environment Parameter' window opens up, type the name and value of the variable e.g. in Name type 'a' and in Value type 'hello' (without quotes, I have added quotes just for clarity) and click on OK. It will add the variable with its type as 'internal'.

6. Click Apply and OK to come out of Test Settings window.

7. Go to expert view and type:
msgbox(environment("a"))

8. Now Run the test. It will show you the value of variable 'a' in the message box.

User-Defined external variables are the variables which are defined in the file outside of test. These act as read only for the test. You can create as many files for environment variables as you want and choose them for your test.

Now lets look at an example of this:

Open a new text file and type the following lines in it and save it with .xml extension. ( I saved it in 'tests' folder in the 'QuickTest Professional' folder under C:Program files.)

QTp environment variables

1. Open a new Test.

2. Go to File (Menu)->Settings, a Test Settingswindow opens.

3. Go to Environment Tab. From Variable type dropdown select User-defined.

4. Click on "Load variables and values from external file" check box and import that external xml file that we created above. As soon as it is imported the complete path of that file will be shown in the File text box and the variable in it will show under Name, Value and Type heading (in our case it will show Address under Name, 25 yellow Road under Value and External under Type).

5. Click on Apply and Ok to come out of it.

6. Go to expert view and type:
msgbox(environment("Address"))

7. Now run the test. It will show you the value of variable 'Address' in the message box.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions