UFT Tutorial 14

UFT Class 14
(Parameterization Part 2 - Parameterization using Data Table Parameters)


3) Using Data Table Parameters


What is Data Table?


It is an integrated spread sheet for Data related operations

How to launch:


View -> Data

> Data Table has 2 types of sheets

a) Global sheet

b) Actions sheets (Local sheets)

> Data Table located in 2 areas

a) In UFT tool main window (Design-time Data Table)

b) UFT tool Result window (Run-time Data Table)

> It attaches one Data Table for every new Test

Usage of Data Table:


a) Enter Test data directly into Data Table and connect to the Test.

b) Import data from external files (text or excel) and into Data Table and connect to the Test.

c) Import data from a Database and into Data Table and connect to the Test.

d) Using Data table methods and programmatic statements

Steps for Data Driven Testing using Data Table:


a) Generate the basic Test and run it once

b) Launch Data table and Enter or Import test data.

c) Connect test data to the Test

                Using Editor View
                Or
                Using Keyword view
                or
                Using Data Driver
d) Run the Test
-------------------------------
Syntax for connecting Test Data to the Test using Editor view


DataTable("Column Name"/Column Id, Sheet Name / Sheet Id)

Ex:

SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set DataTable(1, 1) 
Dialog("Login").WinEdit("Password:").Set DataTable(2, 1)
Wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
---------------------------------------
Import Test Data from External files (Text or Excel)


i) Text file

> Data Table considers Text file first line as Column headers

> In between two columns Tab space is the delimiter
---------------
ii) Excel File

> Data Table considers Excel sheet first row as Column headers
------------------------------------------------------------------
c) Import data from a Database and into Data Table and connect to the Test.

Steps:

> Create a Database

> Create Tables

> Enter Data
---------
> Create DSN (Data Source Name)

Note: If you want to connect to a Database then Connection string (DSN) is required

> Connect Test Data
------------------------------
Creating DSN:

> Launch Data Table

> Place mouse pointer on Data Table and Right Click

> Sheet > Import > From Database

> Select "Specify SQL statement manually" option

> Click Next

> Click Create

> Click New

> Select Driver for our Database and Click Next

> Browse path to store DSN

> Click Next > Click Finish

> Click Select

> Browse database and select

> Click OK > Click OK

> Enter SQL statement

> Click Finish
-------------------------------------
d) Using Data table methods and programmatic statements


Note: We insert programmatic statements in order to overcome some limitations of Tool features.

Ex:

'Create a new sheet in Run-time Data Table
DataTable.AddSheet "Login"

'Import Test data from an external file
Datatable.ImportSheet "C:\Users\G C Reddy\Desktop\abcd.xls", 1, "Login"

RowsCount = DataTable.GetSheet("Login").GetRowCount

For i = 1 To RowsCount Step 1
DataTable.SetCurrentRow(i)
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set DataTable("Agent", "Login")
Dialog("Login").WinEdit("Password:").Set DataTable(2, 3)
wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
Next
-------------------------------------------------
'Data Driven Testing using Data Table parameters and programmatic statements

DataTable.AddSheet "Login"
DataTable.ImportSheet "C:\Users\G C Reddy\Desktop\abcd.xls", 1, 3

RowCount = DataTable.GetSheet("Login").GetRowCount
For i = 1 To RowCount Step 1
                Datatable.SetCurrentRow(i)
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set DataTable(1, 3)
Dialog("Login").WinEdit("Password:").Set DataTable(2, 3)
wait 2
Dialog("Login").WinButton("OK").Click
If Window("Flight Reservation").Exist(12) Then
Window("Flight Reservation").Close      
DataTable(3, 3) = "Login Successful -Passed"
Else
SystemUtil.CloseDescendentProcesses
DataTable(3, 3) = "Login Unsuccessful -Failed"
End If
DataTable.ExportSheet "C:\Users\G C Reddy\Desktop\Result1.xls", "Login"
Next
------------------------------------
'Read Data from external file and write Result and error messages

Dim RowCount, OrderNumber
'Data Driven Testing using Data Table parameters and programmatic statements
DataTable.AddSheet "Login"
DataTable.ImportSheet "C:\Users\G C Reddy\Desktop\abcd.xls", 1, 3

RowCount = DataTable.GetSheet("Login").GetRowCount
For OrderNumber = 1 To RowCount Step 1
                Datatable.SetCurrentRow(OrderNumber)
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set DataTable(1, 3)
Dialog("Login").WinEdit("Password:").Set DataTable(2, 3)
wait 2
Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").Exist(12) Then
Window("Flight Reservation").Close      
DataTable(3, 3) = "Login Successful -Passed"
Else
DataTable(4, 3) = Dialog("Login").Dialog("Flight Reservations").Static("Agent name must be at").GetROProperty("text")
SystemUtil.CloseDescendentProcesses
DataTable(3, 3) = "Login Unsuccessful -Failed"
End If
DataTable.ExportSheet "C:\Users\G C Reddy\Desktop\Result1.xls", "Login"
Next
-------------------------------------------------

0 comments:

Post a Comment