Data Table Parametrization
Chapter X
Implementing parametrization by using Data Table
Data Table: - It is used to hold the Test Date
Navigation: - View MenuData Table
--> It is looks like MS-Excel Spread Sheet
--> It contains 65536 Rows and 256 Columns
--> By default it contains Global and Action1 Sheet
--> Every action of the scripts contains the same sheet in the Data Table
Types of Data Table: -
1. Design Data Table
2. Run Time Data Table
Design Data Table: - Table which is displaying in test pane is called as Design Data Table
Run Time Data Table: - The table which is displaying result window called as Runtime Data Table
Note: - Run time Data Table is copy of Design Data Table
Note: - Any modifications to data table during runtime it performs the operations in Run Time Data Table
not in Design Data Table
Note: -Test script execution iterations depends on Global Sheet number of Rows
Example: -
Global Action1 Action No. of Iterations
- - - 1
- 5 10 1
5 10 15 5
10 5 1 10
Rename the column Names of Data Table: -
Navigation: - Select the required sheet Design Data Table -->Double click on required column -->Enter
new column name -->Click OK Button.
By Scripting: -
Syntax: - DataTable.GetSheet (“”).AddParameter””, “”
Example: - Adding User_Name Column in Global Sheet
DataTable.GetSheet(“Global”).AddParameter”User_Name”,”Sreekar”
Example: - Adding Val1 Column in Action1 Sheet
DataTable.GetSheet(“Action1”).AddParameter”Val1”,”Sreekar”
ScriptNo17: - Write a script to find given sheet existence in data table
sExpSht = "Action"
iFlag = 0
iShtCnt = DataTable.GetSheetCount
'MsgBox iShtCnt
For index = 1 To iShtCnt
sActSht = DataTable.GetSheet(index).Name
If sExpSht = sActSht Then
Print "Sheet is Found"
iFlag = 1
Exit For
End If
Next
If iFlag = 0 Then
Print "Sheet is not Found"
End If
Retrieving data From Data Table: -
--> It retrieves from Run Time Data Table not from Design Table
1. MsgBox DataTable("User_Name")
MsgBox DataTable("User_Name",1)
MsgBox DataTable("User_Name","Global")
MsgBox DataTable. Value("User_Name",1)
-->It retrieves User_Name Column value from Global Sheet
2. MsgBox DataTable("User_Name","Action1")
-->It retries User_Name Column Value from Action1 Sheet
3. MsgBox DataTable.GetSheet("Global").GetParameter("User_Name").ValueByRow(4)
-->It retrieves 4th of User_Name column value from Global Sheet
4. MsgBox DataTable.GetSheet("Action1").GetParameter("User_Name").ValueByRow(4)
-->It retrieves 4th row of User_Name column value from Action1 Sheet
Entering Data into Data Table: -
1. DataTable("val","Global")="QTP"
It Enters "QTP" in val column of Global Sheet
2. DataTable("val","Action1")="QTP"
It Enters "QTP" in val column of Action1 Sheet
3. DataTable.GetSheet("Global").GetParameter("val").ValueByRow(3)="QTP"
It Enters "QTP" in 3rd Row of val column in Global Sheet
4. DataTable.GetSheet("Action1").GetParameter("val").ValueByRow(3)="QTP"
It Enters "QTP" in 3rd Row of val column in Action1Sheet
Methods for Data Table: -By using this method we can perform required operations to the Run Time
Data Table
1. AddSheet: - It is used to add a required sheet to the Run time Data Table (RDT)
Syntax: - DataTable. AddSheet””
Ex: - DataTable.AddSheet"MySheet"
-->If we have data in multiple rows in Global Sheet then it over rights the sheet do not creates
new sheet like MYSheet1
2. DeleteSheet: - It is used to Delete a required sheet from RDT
Syntax: - DataTable. DeleteSheet""
Ex: DataTable.DeleteSheet"Global"
DataTable.AddSheet"MySheet"
DataTable.DeleteSheet"Action1"
-->At least one is default in Data Table
3. Export: - It is used to save a RDT in given path
Syntax: - DataTable.Export”Path”
Ex: - DataTable.Export"E:\01 My Scripts\test.xls"
4. ExportSheet: - It is used to Save a required sheet of RDT in required path
Syntax: - DataTable.ExportSheet"Path",””
Ex: DataTable.AddSheet"MySheet"
DataTable.GetSheet("MySheet").AddParameter"User_Name","Sreekar"
DataTable.ExportSheet"E:\01 My Scripts\test.xls","MySheet"
5. GetCurrentRow: - It is used to retrieve the current Active Row from the required sheet of
RDT.
Ex: - --> Retrieving from Global Sheet
MsgBox DataTable.GetCurrentRow (or)
MsgBox DataTable.GetSheet("Global").GetCurrentRow
Retrieving from Action1 Sheet
MsgBox DataTable.GetSheet("Action1").GetCurrentRow
6. GetRowCount: - By using this we can retrieve number of rows from required sheet of RDT
Ex: -->Retrieving from Global Sheet
MsgBox DataTable.GetRowCount (or)
MsgBox DataTable.GetSheet("Global").GetRowCount
-->Retrieving from Action1 Sheet
MsgBox DataTable.GetSheet("Action1").GetRowCount
7. GetSheet: - It is used to Activate required sheet from RDT
Syntax: - DataTable.GetSheet("")
Example: -DataTable.GetSheet("Global")
DataTable.GetSheet("Action1")
8. GetSheetCount: - It is used to retrieve number of sheets from RDT
Ex: - MsgBox DataTable.GetSheetCount
9. Import: - It is used to save a excel file in RDT [How many sheets we have in RDT it imports
only that number of sheets from Excel]
Ex: - DataTable.AddSheet"MySheet"
DataTable.Import"E:\01 My Scripts\test.xls"
10. ImportSheet: - It is used to save a required sheet of MS-Excel to required sheet of RDT
Syntax: - DataTable.ImportSheet”Path”,Ms-Excle Sheet ID, RDT Sheet ID
Ex: - DataTable.ImportSheet"E:\01 My Scripts\test.xls",3,2
11. SetCurrentRow: - It is used to activate required row in required sheet of RDT
Ex: - -->Activating row in Global Sheet
DataTable.SetCurrentRow(1) [or]
DataTable.GetSheet ("Global").SetCurrentRow(2)
-->Activating row in Action1Sheet
DataTable.GetSheet ("Action1").SetCurrentRow(2)
12. SetNextRow: - It activates the Next row of current active row
Ex: ---> Activating Global Sheet
DataTable. SetNextRow (or)
DataTable.GetSheet("Global").SetNextRow
-->Activating Action1 Sheet
DataTable.GetSheet("Action1").SetNextRow
13. SetPrevRow: -It activates previous row of current active row
Ex: - -->Activating Global Sheet
DataTable. SetPrevRow
DataTable.GetSheet("Global").SetPrevRow
-->Activating Action1 Sheet
DataTable.GetSheet("Action1").SetPrevRow
Ex: - MsgBox DataTable. GetCurrentRow
DataTable.GetSheet ("Action1").SetPrevRow
DataTable ("val1","Action1")
ScriptNo18: - Write a script to find mathematical operation to given values, maintain data in Excel File.
On Error Resume Next
Dim iRowCnt,iRowNum,iVal1,iVal2
DataTable.ImportSheet"E:\01 My Scripts\cal.xls", 1, 2
iRowCnt = DataTable.GetSheet("Action1").GetRowCount
For iRowNum = 1 To iRowCnt
iVal1 = CInt (DataTable("val1","Action1"))
iVal2 = CInt (DataTable("val2","Action1"))
DataTable("add","Action1") = iVal1 + iVal2
DataTable("sub","Action1") = iVal1 - iVal2
DataTable("mul","Action1") = iVal1 * iVal2
DataTable("div","Action1") = iVal1 / iVal2
If Err.Number <> 0 Then
DataTable("comments","Action1") = Err.Description
Err.Clear
End If
DataTable.GetSheet("Action1").SetNextRow
Next
DataTable.Export"E:\01 My Scripts\calresult.xls"
sPassword
mercury
sUserName
suresh
Chapter X
Implementing parametrization by using Data Table
Data Table: - It is used to hold the Test Date
Navigation: - View MenuData Table
--> It is looks like MS-Excel Spread Sheet
--> It contains 65536 Rows and 256 Columns
--> By default it contains Global and Action1 Sheet
--> Every action of the scripts contains the same sheet in the Data Table
Types of Data Table: -
1. Design Data Table
2. Run Time Data Table
Design Data Table: - Table which is displaying in test pane is called as Design Data Table
Run Time Data Table: - The table which is displaying result window called as Runtime Data Table
Note: - Run time Data Table is copy of Design Data Table
Note: - Any modifications to data table during runtime it performs the operations in Run Time Data Table
not in Design Data Table
Note: -Test script execution iterations depends on Global Sheet number of Rows
Example: -
Global Action1 Action No. of Iterations
- - - 1
- 5 10 1
5 10 15 5
10 5 1 10
Rename the column Names of Data Table: -
Navigation: - Select the required sheet Design Data Table -->Double click on required column -->Enter
new column name -->Click OK Button.
By Scripting: -
Syntax: - DataTable.GetSheet (“
Example: - Adding User_Name Column in Global Sheet
DataTable.GetSheet(“Global”).AddParameter”User_Name”,”Sreekar”
Example: - Adding Val1 Column in Action1 Sheet
DataTable.GetSheet(“Action1”).AddParameter”Val1”,”Sreekar”
ScriptNo17: - Write a script to find given sheet existence in data table
sExpSht = "Action"
iFlag = 0
iShtCnt = DataTable.GetSheetCount
'MsgBox iShtCnt
For index = 1 To iShtCnt
sActSht = DataTable.GetSheet(index).Name
If sExpSht = sActSht Then
Print "Sheet is Found"
iFlag = 1
Exit For
End If
Next
If iFlag = 0 Then
Print "Sheet is not Found"
End If
Retrieving data From Data Table: -
--> It retrieves from Run Time Data Table not from Design Table
1. MsgBox DataTable("User_Name")
MsgBox DataTable("User_Name",1)
MsgBox DataTable("User_Name","Global")
MsgBox DataTable. Value("User_Name",1)
-->It retrieves User_Name Column value from Global Sheet
2. MsgBox DataTable("User_Name","Action1")
-->It retries User_Name Column Value from Action1 Sheet
3. MsgBox DataTable.GetSheet("Global").GetParameter("User_Name").ValueByRow(4)
-->It retrieves 4th of User_Name column value from Global Sheet
4. MsgBox DataTable.GetSheet("Action1").GetParameter("User_Name").ValueByRow(4)
-->It retrieves 4th row of User_Name column value from Action1 Sheet
Entering Data into Data Table: -
1. DataTable("val","Global")="QTP"
It Enters "QTP" in val column of Global Sheet
2. DataTable("val","Action1")="QTP"
It Enters "QTP" in val column of Action1 Sheet
3. DataTable.GetSheet("Global").GetParameter("val").ValueByRow(3)="QTP"
It Enters "QTP" in 3rd Row of val column in Global Sheet
4. DataTable.GetSheet("Action1").GetParameter("val").ValueByRow(3)="QTP"
It Enters "QTP" in 3rd Row of val column in Action1Sheet
Methods for Data Table: -By using this method we can perform required operations to the Run Time
Data Table
1. AddSheet: - It is used to add a required sheet to the Run time Data Table (RDT)
Syntax: - DataTable. AddSheet”
Ex: - DataTable.AddSheet"MySheet"
-->If we have data in multiple rows in Global Sheet then it over rights the sheet do not creates
new sheet like MYSheet1
2. DeleteSheet: - It is used to Delete a required sheet from RDT
Syntax: - DataTable. DeleteSheet"
Ex: DataTable.DeleteSheet"Global"
DataTable.AddSheet"MySheet"
DataTable.DeleteSheet"Action1"
-->At least one is default in Data Table
3. Export: - It is used to save a RDT in given path
Syntax: - DataTable.Export”Path”
Ex: - DataTable.Export"E:\01 My Scripts\test.xls"
4. ExportSheet: - It is used to Save a required sheet of RDT in required path
Syntax: - DataTable.ExportSheet"Path",”
Ex: DataTable.AddSheet"MySheet"
DataTable.GetSheet("MySheet").AddParameter"User_Name","Sreekar"
DataTable.ExportSheet"E:\01 My Scripts\test.xls","MySheet"
5. GetCurrentRow: - It is used to retrieve the current Active Row from the required sheet of
RDT.
Ex: - --> Retrieving from Global Sheet
MsgBox DataTable.GetCurrentRow (or)
MsgBox DataTable.GetSheet("Global").GetCurrentRow
Retrieving from Action1 Sheet
MsgBox DataTable.GetSheet("Action1").GetCurrentRow
6. GetRowCount: - By using this we can retrieve number of rows from required sheet of RDT
Ex: -->Retrieving from Global Sheet
MsgBox DataTable.GetRowCount (or)
MsgBox DataTable.GetSheet("Global").GetRowCount
-->Retrieving from Action1 Sheet
MsgBox DataTable.GetSheet("Action1").GetRowCount
7. GetSheet: - It is used to Activate required sheet from RDT
Syntax: - DataTable.GetSheet("
Example: -DataTable.GetSheet("Global")
DataTable.GetSheet("Action1")
8. GetSheetCount: - It is used to retrieve number of sheets from RDT
Ex: - MsgBox DataTable.GetSheetCount
9. Import: - It is used to save a excel file in RDT [How many sheets we have in RDT it imports
only that number of sheets from Excel]
Ex: - DataTable.AddSheet"MySheet"
DataTable.Import"E:\01 My Scripts\test.xls"
10. ImportSheet: - It is used to save a required sheet of MS-Excel to required sheet of RDT
Syntax: - DataTable.ImportSheet”Path”,Ms-Excle Sheet ID, RDT Sheet ID
Ex: - DataTable.ImportSheet"E:\01 My Scripts\test.xls",3,2
11. SetCurrentRow: - It is used to activate required row in required sheet of RDT
Ex: - -->Activating row in Global Sheet
DataTable.SetCurrentRow(1) [or]
DataTable.GetSheet ("Global").SetCurrentRow(2)
-->Activating row in Action1Sheet
DataTable.GetSheet ("Action1").SetCurrentRow(2)
12. SetNextRow: - It activates the Next row of current active row
Ex: ---> Activating Global Sheet
DataTable. SetNextRow (or)
DataTable.GetSheet("Global").SetNextRow
-->Activating Action1 Sheet
DataTable.GetSheet("Action1").SetNextRow
13. SetPrevRow: -It activates previous row of current active row
Ex: - -->Activating Global Sheet
DataTable. SetPrevRow
DataTable.GetSheet("Global").SetPrevRow
-->Activating Action1 Sheet
DataTable.GetSheet("Action1").SetPrevRow
Ex: - MsgBox DataTable. GetCurrentRow
DataTable.GetSheet ("Action1").SetPrevRow
DataTable ("val1","Action1")
ScriptNo18: - Write a script to find mathematical operation to given values, maintain data in Excel File.
On Error Resume Next
Dim iRowCnt,iRowNum,iVal1,iVal2
DataTable.ImportSheet"E:\01 My Scripts\cal.xls", 1, 2
iRowCnt = DataTable.GetSheet("Action1").GetRowCount
For iRowNum = 1 To iRowCnt
iVal1 = CInt (DataTable("val1","Action1"))
iVal2 = CInt (DataTable("val2","Action1"))
DataTable("add","Action1") = iVal1 + iVal2
DataTable("sub","Action1") = iVal1 - iVal2
DataTable("mul","Action1") = iVal1 * iVal2
DataTable("div","Action1") = iVal1 / iVal2
If Err.Number <> 0 Then
DataTable("comments","Action1") = Err.Description
Err.Clear
End If
DataTable.GetSheet("Action1").SetNextRow
Next
DataTable.Export"E:\01 My Scripts\calresult.xls"
ScriptNo19: - Write a script for Login functionality for Multiple Users -->Maintain DATA in MS-Excel
DataTable.ImportSheet"E:\01 My Scripts\datatable-user.xls",1,2
For i = 1 To iRowCnt
sUname = DataTable("Username","Action1")
sPwd = DataTable("Password","Action1")
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
If Dialog("Login").Exist Then
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set sUname
Dialog("Login").WinEdit("Password:").Set sPwd
Dialog("Login").WinButton("OK").Click
If Dialog("Login").Dialog("Flight Reservations").Exist(5) Then
Dialog("Login").Dialog("Flight Reservations").Activate
sError = Dialog("Login").Dialog("Flight Reservations").Static("Please enter agent
name").GetROProperty("text")
Dialog("Login").Dialog("Flight Reservations").Close
Dialog("Login").Close
DataTable("Results","Action1") = sError
Else
If Window("Flight Reservation").Exist Then
DataTable("Results","Action1") = "Valid User"
Window("Flight Reservation").Activate
Window("Flight Reservation").Close
Else
DataTable("Results","Action1") = "User is valid but not opened the application"
End If
End If
Else
DataTable("Results","Action1") = "Application not Oppened"
End If
DataTable.GetSheet("Action1").SetNextRow
Next
DataTable.Export"E:\01 My Scripts\datatable-user1.xls"
ScriptNo20: - Write a script to retrieve Fly From dropdown values [Maintain in Excel]
ScriptNo21: - Write a script to import Val1 values from sample1.xls file and import Val2 values from sample2.xls
file, perform the mathematical operations and write the result in results.xls file
QTP - Chapter XI
Parameterization
Environment Variable
Implementing parameterization by using Environment Variable
By using Environment Variables we can share the variable values in multiple actions (or) multiple scripts
Types of Environment Variables: -
1. Built-In Environment Variables
2. User Defined Internal Environment Variables
3. User Defined External Environment Variables
Built-In: - These are Pre-Defined by QTP
Navigation: - File MenuSettingEnvironmentSelect Variable Type as Built-In
Ex: - ActionName: Retrieves current action name
ResultDir: Retrieves Test Script execution Result Path
TestName: Retrieves Current Test Script Name
MsgBox Environment ("ActionName")
MsgBox Environment ("ResultDir")
MsgBox Environment ("TestName")
Note 1: - Built-In Environment variables are Read-Only
Note 2: - Environment Variables are case sensitive
User Defined Internal: -
Declaring and using in same test scripts are called as User Defined Internal Environment Variables
Navigation: - File Menu-->SettingEnvironment-->Select Variable Type as User Defined-->Click on ADD[+]
Button Enter name and Value-->Click OK button -->Click Apply and OK
Note: - Internal Environment variables are not Read-Only we can modify data at run time.
Syntax: - Environment(“”) = “”
Environment(“iVal”) = 10
User Defined External: -
Creating external Environment Variables: -
Method 1: By Navigation: -
File Menu-->Setting-->Environment-->Select Variable Type as User Defined-->Click on ADD [+] Button Enter Name
and Value-->click on OK button-->click Export Button-->Save the file in required path with “.XML” extension
Method 2: Open NOTEPAD and declare the variables as follows
Associating External Environment Variable File:-
Method 1: Navigation: -
File Menu-->Setting-->Environment-->Select Variable Type as User Defined-->Click on Load Variables and Values
from Eternal File Check Box-->Browse XML file-->Click Apply and OK buttons
Method 2: -
Syntax: - Environment.LoadFromFile”File Path”
Environment.LoadFromFile "E:\01 My Scripts\external EV.xml"
Note: - We can associate only one XML file by navigation OR by scripting if we associate 2nd file then first file will
be replaced with second file.
Note: - User Defined External Environment Variable are Read Only..
No comments :
Post a Comment