How to Work With Environment Variable in UFT?

0
27
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

How to Work With Environment Variable in UFT?
How to Work With Environment Variable in UFT?

How to Work With Environment Variable in UFT?

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 processand 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.

Till now you have learnt that environment is kind of Global variable. Now think about Global variable in any programming language. The scope of the global variable is inside the test while the test or the program is running. If you look at machine view architecture it is nothing but a memory allocation to store some value. So when program ends the memory allocation is also released.Now say you have used many global variable inside your test. You will be doing some operations on that Environment variable comes to rescue us.

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:

UFT – Component 1
1. File –> Settings –> Parameters. Add output parameter
2. In Expert View: Parameter(“yourOutputParameter”) = something
UFT 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

Types of Environment Variables in UFT:

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. we can create them and these variables are used only a test where they were created. Once you created that variable you can not modify the name of variable and u can modify the value. If u want to use these variable in many tests you can export them in XML file. There you can modify the name of the variable.

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.The variables which are Imported from XML file are called External variables. These are read only variables. u can modify name and value of these variables. If u want to modify them..go to XML file which  are stored and right click on that file click n edit. The script will open, there you can edit name and value.
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.
Exp–


Environment.Value("name")= "abc"
//'calling that veriable-- 
msgbox Environment.Value("name")
 

Steps to add user defined environment variables in the script:

  1. Go to File 
  2. Go to settings
  3. Go to  Environment 
  4. Select variable type as user defined 
  5. Click add icon (+) 
  6. Enter variable name
  7. Enter variable Value
  8. Click ok

We can create any number of variables we want.

How to save environment variables in XML?

Steps:
  1. Click export
  2. Provide path
  3. Provide file name
  4. Save with .xml extension
  5. Click ok.

Built-in: 

You have done Built In Variables are activated at runtime only. By using these variables we can know test execution or platform information. Variables that represent information about the test and the computer on which the test is run, such as Test path and Operating system. In other words they are system variables. These variables are accessible from all tests, but read-only It is activated during runtime.Test execution information can be retrieved through this variable
Exp–


Environment.Value("OSVersion") 
 

There are so many in the list.commonly used Environment variable in UFT to track the iterations.

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.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here