Environment Variables in QTP
Environment variables are similar to Global variables to store values. Environment variables can be accessed at any place in the script and the values will be the same. Also, we can modify the values at any place and the modified values will be retrieved on further use.
Environment variables are very useful when we want to share a variable across actions in a test.
There are two types of Environment variables.
1. Built-In
2. User Defined
1. Built-In:
There are some predefined Environment variables provided by QTP. We can use these environment variables without having assigned any values manually. Built-In environment variables contains values such as test path, OS version, Current Action,Current Action Iteration, User name etc.,
For Ex: If you want to get the path where the test is saved then you can use "TestDir" Environment variable.
How to Read environment variable from QTP Script?
Syntax: Environment.value("Variable Name")
Msgbox Environment.value("OS")
This will print the Operating System of the machine on which QTP is installed.
Below are some other Built-In Environment Varaibles:
1. Action Iteration: Indicates which action iteration is currently running. The value will be displayed or valid only during the test run.
2. Action Name: Displays or indicates which action is currently running. The current value is valid only during test run.
3. ControllerHostName: The name of the computer that serves as the controller. Used when Load runner is running. The current value is valid only during test run under Load.
4. GroupName: This is w.r.t. Load Runner. It is the scenario identification number. The current value is valid only during test run under Load.
5. LocalHostname: Gives the Local Host Name on which QTP is Installed. The current value displayed is WINDOWS XP.
6. OS: Displays the operating system on which QTP is installed. The current value os Microsoft Windows XP Work Station.
7. OS Version: Displays the version of the Operating System.
8. ProductDir: Displays the folder path where the product (QTP) is installed.
9. ProductName: Gives the name of the Product.
10. ProductVersion: Gives the product version.
11. ResultDir: Displays the folder path where the current test results are saved.
12. SceanrioId: This is w.r.t. LoadRunner. Displays the scenario identification number.
13. SystemTempDir: Displays the system temporary directory.
14. TestDir: This is the path of the folder in which the test is located.
15. TestIteration: Indicates which test iteration is currently running.
16. TestName: Displays the name of the test.
17. UpdatingActiveScreen: Indicates whether the active screen images and values are being updated.
18. UpdatingCheckPoints: Indicates whether the checkpoint properties are being updated.
19. UpdatingToDescriptions: Indicates whether test object descriptions are being updated.
20. UserName: Displays the windows login user name.
21. VUserId: This is w.r.t. Load Runner. Indicates the virtual user identification number.
2. User Defined
These are all the environment variables defined by the user. User can store the run time values or any other own values for further access in the script.
There are two types to User Defined Environment variables.
a. Internal
b. External
a. Internal:
Internal Environment variables are the one created by the user with in the test. These variables can be used only with in the test in which it is created. Internal environment variables can be created in two ways.
Method 1:
1. Go to File->setting->environment tab.
2. Select variable type as User defined
3. Click on “+” sign.
4. Add name for e.g qtp
5. Add value for e.g. http://testeverything-qtp.blogspot.com
Click on apply and ok.
Method 2:
Environment.value("<variable name>") = <Value>
Environment.value("qtp") = "http://testeverything-qtp.blogspot.com"
These Environment variables also can be accessed as below
Msgbox Environment.value("qtp")
"http://testeverything-qtp.blogspot.com" will be displayed in the msgbox.
b. External:
External environment variables that you pre-defined in the active external
environment variables file.These external file contains the name & value pair in XML format. You can create as many files as you want and select an appropriate file for each test. Note that external environment
variable values are designated as read-only within the test.
To create an external environment variables file:
1 Open any text editor.
2 Type [Environment] on the first line.
3 Type one variable-value pair on each line in the format—variable=value.
4 Save the file in a location that is accessible from the QuickTest machine. The
file must be a text file, but you can use any file name extension (usually, it will be saved in XML Format).
For example:
[Environment]
MyParam1=10
MyParam2=20
MyParam3=http://testeverything-qtp.blogspot.com
To select the active external environment-variables file:
1 Choose Test > Settings to open the Test Settings dialog box.
2 Click the Environment tab.
3 Select the Load variables and values from external file (reloaded each test run) check box.
4 Use the browse button or enter the full path of the external environment-variables file you want to use with your test.
Loadrunner is a flagship automation load testing product from HP. This products command over 70 % of market share in load and performance testing tools. Nowadays, testing professionals strong in handling Loadrunner automation tool has huge career opportunity.
ReplyDeleteperformance testing training in chennai
hp loadrunner training