Data Driven Approach - QTP Automation

Data Driven Approach: In Automation testing

Data driven approach advocates externalizing the test data from the test automation tool (usually into an Excel sheet; Databases, XML files or other data sources may be used as well), to improve the maintainability of test data. It is aimed at helping business users to manipulate the test data without having to modify the actual scripts. It is also helpful when we need to drive a test script with multiple sets of input data. For example: running the same script for different roles/user id’s.
Pros:
·         Avoids hard-coding of test data in the scripts
·         Non-technical users can easily change the test data using the Excel sheets, without modifying the scripts in any way
·         The same script can easily be executed with multiple rows of test data
·         Reasonably simple to implement

Cons:
·         Provide features for non technical business users to interact with the framework

Demonstration on parameterizing data using QTP Datasheet

Step 1 - Go to Automation à Record and Run Settings, and open the ch1blogs site in a new IE Browser.



Step 2 - Click on Automation à Record/F3/ Record from the Tool bar. 

Based on Step 1 perform the following operations  –
·         An IE browser opens up with the URL https:\\ch1blogs
·         A User Authentication window pops up asking the user to enter the User Id and Password
·         Enter the details and the user is navigated to Blogs Home Page.
·         Click on Explore à View My Blog which navigates the user to the Blog Site page.

When you see the same in the script, (QTP – Explore View), the operations are recorded with hardcoded values for User Id and Password.

User name is the User Id entered and Password is the encrypted version of the Password entered during recording.




If we hard code these values, we cannot run the same script on several sets of data.  Hence we need to parameterize these values.

Data Drive the values using QTP Datasheet

Step 1 – Go to Tools à Data Driver

 The following window will be displayed with all hard coded values.


In my case User Id and Password are the hardcoded values and hence the value of “Constants” is 1(since it is a Constant Value) and the value of “Parameterized” is 0, since the value is not Parameterized yet.

Step 2 - Click Parameterize…  Select Parameterization Type window appears as below. 

Step 3

·         Step by Step Parameterization is selected by default, to perform a Step by Step Parameterization of the objects.

·         Parameterize All, parameterizes all the objects at a stretch.

·         Select Step by Step Parameterization and Click on Next.



Step 4 –

·         Parameterize the Selected Step appears with the hierarchy of the operations performed displayed in the left.

·         Select the hardcoded value – UserName in our case and click on the icon next to the Parameter – called Parameter Options


Step 5 –

·         When clicked on the Parameter Options, Parameter Options is displayed.

·         Since we are parameterizing through QTP data table, we select Data Table option under Parameter Types

·         Edit the Name to any Logical Name, to be the column name in the Data Table.
(The left screen below gives the Name, generated by the tool and LoginId (name in the right screen) is the name given by the user.

         


Step 6

·         Select the location where the column LoginId should exist in the Data Table.  By default the option is Global sheet. 

·         It can be Global or Local based on the usage of the value.

·         If the variable has to be used multiple times for various iterations, it is put in Local, if it has to be used once it is normally put in Global.


Step 7 – Click OK

Step 8

·         The user is back in “Parameterize the Selected Step”.

·         Click FINISH.

Step 9

·         Now the user is back in “Data Driver”

·         Now the User Name value is no more a Constant and it is Parameterized.

·         Hence the value for Constant becomes 0 and the value for Parameterized becomes 1.



Step 10 – Click OK

Step 11

·         Now the QTP script has changed from hardcoded 132218 to the Parameterized value.

·         The hardcoded value “132218” is replaced by DataTable(“LoginId”,dtGlobalSheet)

·         LoginId is the column name given to the Parameterized value and dtGlobalSheet is the location, the LoginId column is available in the Data Sheet.

·         In the Data Table(left bottom), you can view the Input Parameter LoginId, with the value, and in the Active Screen to the right the User name column is highlighted.





·         The advantage of using the Data Driver is the value need not be hardcoded and any number of LoginIds can be passed to work on multiple logins.

·         Several iterations can be performed with same or different sets of data.

·         The test data can be changed as and when needed without touching the script.

Post a Comment

Previous Post Next Post