Wednesday, March 20, 2013

About Data Table



Data Table
Data table is used to parameterize your test. It is having two sheets. Global and Action. Global sheet is used across all the action. Action sheet is used for particular action. Two type of data table. Design time and Run time data table.  Design time data table is associated with test before and after the test execution. Run time data table is associate with test during test execution. Data table is stored under Test name > Data table folder.
Data table object method


AddSheet:-Adds the specified sheet to the run-time Data Table and it returns the sheet so that we can add properties to the sheet in the same statement.
datatable.addsheet("sheetname") 



Addparameter- adds parameter or property to sheet
datatable.addsheet("sheetname").Addparameter(Col_Value,Value)



deletesheet
This method will delete a specific sheet from the data table during run time.
datatable.DeleteSheet sheetName



Export :-Saves the copy of the run-time datable in the specified location
datatable.Export ("location along with Excel name") 
Note :- if the file is not created /present QTP will create the file at runtime and exports the specified sheet.



ExportSheet :- exports the specific sheet in the run-time datatable to An Excel file .
DataTable.ExportSheet "location along filename", "sourcesheet" 
Note:
1.       if the file is not present or created QTP will create the file at runtime and exports the specified sheet.
2.       If the excel file is already created but there is no sheet associated with it. QTP will open this file and add the sheet.
3.       Say if the file is already created and the sheet is already there, QTP will overwrite the sheets



Import :- imports the specified Excel file to the run time Data Table
DataTable.import(location+filename) 
Import method deletes/replaces all table available in datatable during run with its sheets.Remember sheet1 will be copied to Global,Sheet2 will be copied to Action. If you have more sheets in the source excel there will no Excel tab in QTP.So we need to create those tab by addSheet then only we will be able to get those extra sheets else those data is not accessable using this method.

It is a best practice to know the numbers of sheets presents in the source file and try to add those sheets during runtime.Then try to get those sheets in QTP



Import Sheet :- To import the specific sheet in the run time data table.The data in the imported sheet replaces the data in the destination sheet
DataTable.ImportSheet ("location+filename", "Source sheet",destination sheet)



GetCurrentRow :- returns the current row in the first sheet in the run-time Data-Table(Global sheet)
var x = DataTable.getCurrentRow  



GetSheetCount:-returns the total number of sheets in the run-time Data Table
Var x = datatable.getsheetcount 



GetSheet :-returns the specifed sheet from run-time Data Table
DataTable.GetSheet("abc")



GetRowCount :-Returns the total number of rows in the longest column in the first sheet in the run-time sheet in the data table(Global sheet)
DataTable.GetSheet("abc").getRowCount



SetCurrentRow :-set the specified row as the current(active) row in the run-time Data Table
DataTable.SetCurrentRow(value)



SetNextRow:-Set the row after the current(active) row as the new current row in the run-time Data-Table
DataTable.GetSheet("abc").setNextRow 


setPrevRow:-set the row above the current(active) row as the new current(active)row in the run-time Data Table
DataTable.SetPrevRow

Debug option in QTP



Debug Options in QTP

  1.    Debug viewer- to see the debug details
  2.    MSGBOX function to display value of variable
  3.    Exist method to check control exist or not
  4.   GetLastError & DescribeResult- to see the error code and description
  5.   Run to Step and Run From Step – to run the test from particular step
  6.  QTP breakpoints- using it user can stop the execution and see the status of application, change the code etc
  7. Step into, step out and Step over


Syntex error
QTP checks syntax when you switch from expert view to keyword view.
Tools> check syntax (Ctrl + F7)
Syntax error shown in information pane having detail, item, action and line number.
GetLastError & DescribeResult
GetLastError returns the error code of the most recent error. You can use this statement together with DescribeResult statement. DescribeResult returns text description of the specified error code.
Window(“abc”).Activate
X=GetLastError
Msgbox (DescribeResult(x))
 


Absolute & Relative Path


Difference between Absolute Path & Relative Path
Absolute path: means we need to give full path detail. Example, executefile “D:\test\abc.txt”
Relative path: means we need to give only name. Structure of the path is hidden or maintained in script or tool. Example- executefile “abc.txt”.
Path is maintained in tool – Tools>option>Folder tab.
Path is maintained in script-
Driver=”d:\”
Project path=Driver&”\”&”project”
Lib path=project path& “\” &”lib”