Header Ads

environment variable in QTP

Environment Variable comes into picture when you try to parameterize data.In all Unix and Unix-like systems, each process has its own private set of environment variables. By default, when a process is created it inherits a duplicate environment of its parent process, except for explicit changes made by the parent when it creates the child. At API level, these changes must be done between fork and exec. Alternatively, from shells such as bash, you can change environment variables for a particular command invocation by indirectly invoking it via env or using the ENVIRONMENT_VARIABLE=VALUE notation. All Unix operating system flavors as well as DOS and

Microsoft Windows have environment variables; however, they do not all use the same variable names.
Running programs can access the values of environment variables for configuration purposes. Examples of environment variables include:

PATH - lists directories the shell searches, for the commands the user may type without having to provide the full path.
HOME (Unix-like) and userprofile (Microsoft Windows) - indicate where a user's home directory is located in the file system.
TERM (Unix-like) - specifies the type of computer terminal or terminal emulator being used (e.g., vt100 or dumb).
PS1 (Unix-like) - specifies how the prompt is displayed in the Bourne shell and variants.
MAIL (Unix-like) - used to indicate where a user's mail is to be found.

Shell scripts and batch files use environment variables to communicate data and preferences to child processes.

They can also be used to store temporary values for reference later in the script, although in Unix other variables are usually used for this.

In Unix, an environment variable that is changed in a script or compiled program will only affect that process
and possibly child processes. The parent process and any unrelated processes will not be affected. In DOS changing a variable's value (or removing it) inside a BATCH file will change the variable for the duration of command.com's existence.
In Unix, the environment variables are normally initialized during system startup by the system init scripts,
and hence inherited by all other processes in the system. Users can, and often do, augment them in the profile
script for the shell they are using. In Microsoft Windows, environment variables defaults are stored in the
windows registry or set in autoexec.bat.

Environment parameters are useful for localization testing, when we want to test an application where the user
interface strings change, depending on the selected language. Environment parameters can be used for testing the same application on different browsers. We can also vary the input values for each language by selecting a different Data Table file each time we run the test.
The BPT components are like independent scripts. That is why you need to use Input/Output parameters or
External data storage (Excel/Flat/XML files).
How to create output parameters for BPT components:
QTP - Component 1
1. File --> Settings --> Parameters. Add output parameter
2. In Expert View: Parameter("yourOutputParameter") = something
QTP Component 2
1. File --> Settings --> Parameters. Add input parameter
2. In Expert View: yourVar = Parameter("yourInputParameter")
QC -> Test Plan view
1. Create a script with by drag and drop your components
2. Component 2: Click on inputs
3. Table with input parameters will appear
4. Click on "Output from Previous Component" Checkbox
5. Select the Output parameter from Component 1
User-defined internal: Variables that we define within the test.we can create them and these variables are used only a test where they were created. Once we created that variable, we can not modify the name of
variable and u can modify the value. They are saved with the test and accessible only within the test in which
they were defined.
User-defined external: Variables that you predefined in the active external environment variables file. The variables which are Imported from XML file are called External variables.These variables are read-only in this context.We can create a list of variable-value pairs in an external file in .xml format.We can then select the file as the active external environment variable file for a test and use the variables from the file as parameters.
We can set up your environment variable files manually, or we can define the variables in the Environment tab of the Test Settings dialog box and use the Export button to create the file with the correct structure.
Environment.Value("name")= "abc"
calling that veriable-- msgbox Environment.Value("name")
Go to Test settings--->Environment
Built-in: Variables that represent information about the test and the computer on which the test is run, such as Test path and Operating system. These variables are accessible from all tests, and are designated as read-only It is activated during runtime.Test execution information can be retrieved through this variable

There are so many in the list.commonly used Environment variable in QTP to track the iteration
Why TestIteration?
A good use of "TestIteration" built in environment variable would be if you want to execute a specific section of Sceipt based on the number of Iteration. For example, if the test runs the first iteration we want to execute Function A and 2nd iteration Function B.

How to read the runtime Test Iteration?

TestIteration is a built-in environment variable in Quick Test Professional, so we can read it using the Environment keyword. The syntax is bellow:

tIteration = Environment(?TestIteration?)

Example of TestIteration use:

?Using If-Else statment
tIteration = Environment(?TestIteration?)
If tIteration = 1 Then
Call FunctionABC()
ElseIf tIteration = 3 Then
Call FunctionXYZ()
End If

Note: Quick Test Pro (QTP) also have ?ActionIteration? environment variable to read action iteration.

How can I check if a environment variable exist or not?

When we use Environment("Param1").value then QTP expects the environment variable to be already defined. But when we use Environment.value("Param1") then QTP will create a new internal environment variable if it does not exists already. So to be sure that variable exist in the environment try using Environment("Param1").value
Powered by Blogger.