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.


    How to send e-mail using outlook object in QTP

    This post explain how to send e-mail using microsoft outlook object with or without any attachments. In the next article we will explain how to read information from an e-mail message.

    ''Function Description - This function sends a mail to end user
    '' Arguments - SendtoUser - Mail will be send to user mentioned in send to
    ''Subject - Subject of the mail
    ''Body - Text of the mail
    ''Attachment - Path of attachment to send e-mail

    SendMailUsingOutlook "SendToUser@test.com; testZ@test.com"," Subject", "Body", ""

    Function SendMailUsingOutlook(SendToUser, Subject, Body, Attachment) 

    '' create an object of outlook application and creating a new e-mail object
        Set objOutlook=CreateObject("Outlook.Application") 
        Set objMail=objOutlook.CreateItem(0) 

    '' Provide details of the mail object
        objMail.to=SendToUser
        objMail.Subject=Subject 
        objMail.Body=Body 

    '' attach a file with the e-mail, provide path of the attachment in the folder
        If (Attachment <> "") Then 
            objMail.Attachments.Add(Attachment) 
        End If 
    '' Send the e-mail
        objMail.Send 
    '' close the instance of Outlook application object
        objOutlook.Quit 

    ''release the object created    Set objMail = Nothing 
        Set objOutlook = Nothing 
    End Function 

    Tutorial about Array in VBScript for QTP

    Array is a data type used to describe a collection of elements. An array can be one-dimensional or multidimensional array. In VBScript, array can be represented as follows:


    Dim arrayOned(6) - represent a dimension array which can store 7 elements. Index starts from 0.
    Dim arraytwod(6)(4) - represents a two dimensional array which can store 7*5 =35 element
    Dim(6)(4)(5) - Represents a three dimensional array. We can describe  n-dimension array in similar ways.

    The above arrays are example of fixed array. Once we specify an array with dim and providing size of array, it is created as fixed dimension array. We cannot change the size of the array.
    We can also create dynamic array in VBScript as shown below:

    dim arraydynam() - create a variable without providing the size of array.Redim arraydynam(10) - we can then assign a size to the array by using redim. We can resize the array size as when required. 


    On reducing the size of the array, loss of information can take place, so care should be taken while reducing the size of array in dynamic array.


    There are some useful inbuilt functions in VBScript used to work with arrays. Let us discuss on the same.


    Split Function - Split can be used to split a string into array based on the delimiter provided. Syntax for Split function is:

    Split (expression [, delimiter [, count [, compare]]]) - here expression denotes the string which will be splitted based on the delimiter provided. 
    Count and compare are optional with default value as -1 (repeats all substring) and binary compare. Default delimiter used is space.

    Ubound function - Ubound returns largest subscript for the provided dimension of an array. In Case of argument for dimension not provided, it gives the ubound for first dimension

    UBound(array, dimension))

    Lbound function - Lbound returns smallest subscript for the provided dimension of an array. In Case of argument for dimension not provided, it gives the lbound for first dimension

    UBound(array, dimension))

    Join Function - Join function does opposite of what Split function does. It joins all the elements in the array using the delimiter. Syntax of function is:Join(array, delimiter)

    In case of join also, the default delimiter if not provided is space character.

    Filter Function - Filter is used to create a sub array from array matching the particular condition.
    Filter(array, value, include, compare) - In the function, include and compare are optional parameters, include can have value true or false, true for searching for element with particular value matching and false to return elements which do not have match the condition

    Array function - This function creates an array based on array element provided in the argument.

    e.g. : a = array ("testing ", "array", "by" ,"creating", "array", "using array functions)

    IsArray function returns true/false that indicates whether a specified variable is an array or not


    ''A simple code explaining the various functions for array manipulation

    dim arr, strjoin
    arr = split("this,is, wonderfrul, test",",") ' create an array using split function
    ilowbound = lbound(arr) 'get lowerbound and upperbound for array
    iupperbnd = ubound(arr)
    for i=ilowboud to iupperbnd Step 1 '' Loop the array element
    msgbox arr(i)
    Next
    b= filter(arr, "t")
    msgbox b(1)
    strjoin = join(arr, ";")
    msgbox strjoin
    msgbox Isarray(arr)