Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Using Parameterization for data driven testing in QTP/ UFT

UFT/ QTP enables us to configure the values for properties and other items by defining a value as a constant or a parameter. We can also use regular expressions for some values to increase the flexibility and adaptability of our tests. A parameter is value that is defined or generated externally and is retrieved during a run session. A parameter for example can take value from an external source like excel sheet or UFT data tables.

The major advantage or need of using parameters in test is to create data driven tests. 

Let me explain this with an example. Suppose there are two edit controls in the Page Username and Password and user clicks on login button to login.

Suppose the requirement is to create test which will validate different users are able to login into application successfully. If we use constant value for Username and Password and have to validate for 100 Users, we will need to create 100 tests, Maintaining 100 tests is a tedious task and time consuming activity. 

Let me explain this with an example, suppose there is change in identification property of the Username edit box. E.g. Name of Username field is changed to E-Mail and the user using constants is using the local object repository for each test. We need to make change in each of the tests. Maintenance is also difficult because of rework for minor change in script. Also keeping the test executor understand the difference between the tests and which test is for which purpose is difficult task with growth in size of test suite.

Using Parameters in the test solves the above problem, we can iterate the same test steps execution using multiple data set and can compare the expected result with the pre-defined data stored in the data source. 

For e.g for successful login or incorrect password, parameterization using data table object, the code is like:

Parameterization

Browser("qaautomationqtp").page("qaautomationqtp").WebEdit("UserName").Set DataTable("UserName", dtGlobalSheet)

Browser("qaautomationqtp").page("qaautomationqtp").WebEdit("Password").Set DataTable("Password", dtGlobalSheet)

Browser("qaautomationqtp").page("qaautomationqtp").Webbutton("SignIn").Click

In the above example we use the global sheet to drive the data. We can upload data from external excel file or database to datatables in QTP and also extract back the information from data tables to excel using data table import/export methods. Once we have data in the local sheet or global sheet in data table, we can use data as shown in above code in QTP.

By data driven testing using parameterization, we need to create only a single test for 100 of tests using hardcoded approach and also the data is managed at a single place, hence improving the maintenance of the test.

Next question is what all we can parameterize in QTP, we can parameterize :

  • Checkpoints properties

  • Object properties for a selected step.

  • Operation arguments defined for a selected step.

  • Object properties in Object Repository.



The different ways in which data can be parameterized in QTP/UFT are as follows:


  • Test parameters enable us to use values passed in the test.
  • Action parameters enable us to pass values from other actions in the test.
  • Using Random Number, we can parameterize the value where any random numeric value can be provided.

  • Environment variable can be used for parameterization in QTP

    • Using datatables in QTP/UFT, we can parameterize the data. Before running the test we need to specify in Test Setting or action settings in QTP, how many iteration the test needs to be executed


    This article "Working with data tables" explains how to work with data tables in details.

    This article Environment variable explains how to work with environment variable in QTP.


    No comments:

    Post a Comment