UFT Tutorial:UFT Parameterization–Best Guide for UFT 14.x

Testing is now an important phase of the software development life cycle to secure the product’s quality. Also, without having testing, we can’t ensure the fulfillment of all the requirements. Here automation is playing an essential role in the testing cycle to reduce the efforts and time. In the market, there are multiple testing tools available to automate the testing process. The most used automation testing tool is UFT.  

In this UFT Tutorial article, we are going to learn about the different types of UFT Parameterization such as UFT Environment Variables, UFT DataTable Parameters, UFT Action Parameters, Random Number Parameters with practical implementation.

UFT Tutorial – Table of Content

UFT Tutorial #1: UFT Overview

UFT Tutorial #2: UFT Setup – Download, Install, License Configuration and ALM Connection

UFT Tutorial #3: UFT Object Repository

UFT Tutorial #4: UFT Actions & Function Library 

UFT Tutorial #5: UFT Parameterization 

UFT Tutorial #6: VB Scripting in UFT

UFT Tutorial #7: Step by Step Guide to Create Test Case in UFT

UFT Tutorial #8: Exception Handling in UFT

UFT Tutorial #9: Recording in UFT with Checkpoints & Dictionary Object 

UFT Tutorial #10: UFT Interview Questions and Answers 

UFT Tutorial #4: UFT Parameterization

Overview of UFT Parameterization:

UFT Parameterization is an approach to feed test data into the test steps through parameter during the run time. It will help us to increase the reusability of test case modules to use in different data criteria. UFT Parameterization is the key to any advanced test framework.

Purposes of UFT Parameterization:

  • UFT Parameterization allows feeding the test data into test cases at run time
  • Easy to maintenance.
  • Increase the script reusability to execute the same steps for multiple sets of test data.
  • In the case of data change, test script modification is not required.
  • We can avoid hard coding in the test cases through UFT Parameterization.

UFT Environment Variables:

UFT Environment variables are used to store the global test data, which can be used across the test suites. Primarily, test suite configuration, test environment-related data are stored here, which are applicable for all the test scripts. Such as Application URL, Report Path, Test Environment name, etc., are stored in the environment variable. 

The syntax for reading/ edit environment variables is “Environment.Value(“ParamName”).” We can view the variables from the Environment tab of the “Test Settings” wizard. 

Classification: Two types of environment variables are available –

Built-in: These are the UFT defined environment variables related to UFT and Test Case information details. Such as TestName, OS, OS Version, etc. This is the read-only variable and accessible from entire test suites.

User-Defined: These types of environment variables are defined by the tester based on the requirements. Again user-defined environment variables are classified into two parts –

·        Internal – It is defined in the specific test case for reading or writing purposes. From the wizard, we can add, edit, or delete user-defined internal environment variables. Also, it can be created during the execution as well by assigning any value to Environment.Value(“ParamName”), the variable will be auto-created. The scope of these variables is restricted to a particular test case.

·        External – It is defined in an external XML file that can be associated with UFT through Load Variable options from the same wizard. These variables can be accessed only for reading purposes. The scope of these variables is the entire suite.

UFT Parameterization - UFT Environment Variable
UFT Parameterization – UFT Environment Variable

Create Internal Environment Variable:

Step1# Open Test Setting from navigation “File->Settings.”

Step2# Click on Environment link from the left navigation to open Environment Section. Also, Select variable type as User-defined.

Step3# Click on the plus icon to add the internal environment variable.

UFT Parameterization - UFT Environment Variable - Internal 1
UFT Parameterization – UFT Environment Variable – Internal 1

Step4# Internal Environment Variable is now created. We can edit or delete the same variable from this screen as well.

UFT Parameterization - UFT Environment Variable - Internal 2
UFT Parameterization – UFT Environment Variable – Internal 2

Step5# From the test, we can read the value using the code –     Environment.Value(“envTestEnvironmnet”)

Create External Environment Variable:

Step1# Create an external XML file as per the below structure. The variables can be defined under the “Name” tag. 

UFT Parameterization - UFT Environment Variable - External XML
UFT Parameterization – UFT Environment Variable – External XML

Step2# Open Test Setting from navigation “File->Settings.”

Step3# Click on Environment link from the left navigation to open Environment Section. Also, Select variable type as User-defined.

Step4# Select the check box “Load variables and ..” and provide the path for the previously created external XML file.

Step5# The external environment variable will be created with a blue font. 

UFT Parameterization - UFT Environment Variable - External
UFT Parameterization – UFT Environment Variable – External

Step6# From the test, we can read the value using the code – Environment.Value(“externalEnvVariable”)

UFT DataTable Parameters:

UFT DataTable is used to store test data, which can be used in the test cases during the run time. Structure wise, UFT DataTable Parameters are looked like Microsoft Excel sheet. Every column of the datatable sheet is referred to as the UFT datatable parameter. We can store different data sets in datatable, which can drive the test execution. UFT Datatable parameters are an essential part of the data-driven test framework. UFT Datatable Parameters are store as default.xlsx file in the UFT Test case folder.

To run a test case for different global datatable rows, we can configure the same in the Test Settings dialog, that can be accessed from menu navigation “File -> Settings -> Run(Tab)” as shown below:

UFT Parameterization - Run Setting
UFT Parameterization – Run Setting

UFT DataTable Classification: 

There are two types of datatable available –

  • Local datatable – Every action has one default datatable, which is referred to as local datatable. It can be accessed across actions. Syntax to access the local datatable –

DataTable.Value(“Param1”,dtLocalSheet) or DataTable.Value(“Param1”,”SheetName”)

Here dtLocalSheet can only be used from the container action of that datatable.

  • Global datatable – Every test case has one default global datatable, which can be accessed across different actions. Syntax to access the local datatable–

DataTable.Value(“Param1”,dtGlobalSheet) or DataTable.Value(“Param1”,”Global”)

Purposes:

  • Test Data parameterization.
  • Easy to implement and maintain the UFT Datatable Parameters.
  • Easy to work with bulk test data.
  • This is the primary component of Automation Data-Driven Test Frameworks.
  • Easily isolate the test data from the code area.
  • This can be updated easily by any nontechnical test user.

DataTable Operations (Mostly used):

DataTable - UFT Interview Questions and Answers
Sample UFT DataTable

Read-Write Operation – 

In the above figure, if we want to access value from the second row of local action, named mainAction, the script will look like –

//Copy data from Param1 to Param2 column.

DataTable.GetSheet(“mainAction”).SetRowCount(2)

tempVariable = DataTable.value(“Param1”,“mainAction”) // Read from dataTable

DataTable.value(“Param2”,“mainAction”) = tempVariable // Update datatable

Add Sheet and Parameter –  

DataTable.AddSheet(“NewSheet”) //Add sheet with name NewSheet

DataTable.GetSheet(“NewSheet”).AddParameter “param_name”,”Default_Value” //Add Parameter

Get sheet count – DataTable.GetSheetCount

Get number of rows – DataTable.GetSheet(“NewSheet”).GetRowCount

Get number of parameters – DataTable.GetSheet(“NewSheet”).GetParameterCount

Delete sheet – DataTable.DeleteSheet(“NewSheet”)

Get current selected row – DataTable.GetSheet(“NewSheet”).GetCurrentRow

Select/Set specific row – DataTable.GetSheet(“NewSheet”).SetCurrentRow(row_number)

Import the Excel sheet into datatable – 

DataTable.ImportSheet fileName, source_sheet, destination_sheet

fileName – External excel file name with path.

source_sheet – sheetname of the external excel source.

destination_sheet – destination tadatable sheet name.

Export Datatable into Excel sheet – 

DataTable.ExportSheet fileName, source_sheet, destination_sheet

fileName – External excel file name with path.

source_sheet – source datatable name.

destination_sheet(Optional) – destination external excel data sheet name.

UFT Action Parameters:

Action parameters are used to define the variables that are accessible in the contained actions. It’s mainly used to pass the test data into called actions and return as output. The parameter can be created from the action properties section.

There are two types of action parameters available –

Input Parameter – Pass value to actions.

Output Parameter – return value from actions.

Action Parameters - UFT Interview Questions and Answers
UFT Action Parameters

Input Parameters: 

We can pass the value as an input parameter as arguments when calling the action. Example –

RunAction “childAction”, oneIteration,inputValu1,inputValu2, outputValue

Here we are passing the value of variables inputValu1 and inputValu2 as an action parameter. Same value can be read from childAction using Parameter(“inputParam1”) and Parameter(“inputParam2”).

Output Parameters:  

We can read the value as an output parameter variable as arguments when calling the action. Example –

function “childAction”, one iteration,inputValu1,inputValu2, outputValue

Here outputValue is the variable that stores the output parameter of the childAction.

Create Action Parameter:

Step1# Open Action Properties section from “View->Properties” navigation.

UFT Parameterization - Create Action Parameter 1
UFT Parameterization – Create Action Parameter 1

Step2# Click on the Add button from the Parameter tab and click on the “Add Input Parameter” or “Add Output Parameter” link.

Step3#: Enter the required details to create parameters.

UFT Parameterization - Create Action Parameter 2
UFT Parameterization – Create Action Parameter 2

UFT Random Number Parameters:

The UFT Random Number parameter helps us to generate random numbers through this specific parameter. The following example returns a random number using the random number settings defined in the p_Text parameter.

RandomNumber(“p_Text”)

UFT Parameterization – Assign Parameters into UFT test step:

Step1# Change the action layout from editor view to keyword view through the menu option “View->Keyword View.”

UFT Parameterization - Assign Parameters 1
UFT Parameterization – Assign Parameters 1

Step2# Click on the value column for any step and click the <#P> icon.

UFT Parameterization - Assign Parameters 2
UFT Parameterization – Assign Parameters 2

Step3# Based on the configuration/ data setup, we can select either of the below four types of the parameter from the corresponding tabs –

  • Test/Action Parameter
  • DataTable
  • Environment
  • Random Number
UFT Parameterization - Assign Parameters 3
UFT Parameterization – Assign Parameters 3

Conclusion:

In this uft tutorial, we have learned about UFT Parameterization such as UFT Environment Variables, UFT DataTable Parameters, UFT Action Parameters with practical implementation. Click here to understand more from the Microfocus support portal. Also, if you want to prepare for UFT Interview Questions, please click here.

Leave a Comment