Wednesday, April 10, 2013

Display values for Fly From and Fly To dropdown values to Excel sheet



Option Explicit
Dim flyFromCnt,itemNum
Window("Flight Reservation").Activate
flyFrmCnt=window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount

For itemNum=0 to flyFrmCnt - 1
          datatable.SetCurrentRow(itemNum)
          datatable("FlyFrom",1)=Window("Flight Reservation").WinComboBox("Fly From:").GetItem(itemNum)
          datatable("FlyTo",1)=window("Flight Reservation").WinComboBox("Fly To:").GetItem(itemNum)
Next

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Verify login functionality for different valid and invalid values - flight app



(Note: First manually need to prepare input.xls file with list of valid and invalid values and save in desired path.)

Option Explicit
Dim rowCnt,rowNum
Datatable.ImportSheet "D:\input.xls",1,2
rowCnt=Datatable.GetSheet(2).GetRowCount
For rowNum=1 to rowCnt
 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
          Dialog("Login").WinEdit("Agent Name:").Set datatable("uname",2)
          Dialog("Login").WinEdit("Password:").Set datatable("pwd",2)
          Dialog("Login").WinButton("OK").Click
          If Dialog("Login").Dialog("Flight Reservations").Exist Then
                   Reporter.ReportEvent micFail,"Verify login functionality","Login functionality is not working"
                   Dialog("Login").Dialog("Flight Reservations").Close
                   Dialog("Login").WinButton("Cancel").Click
                   datatable("result",2)="Fail"
          Else
                   Window("Flight Reservation").Close
                   Reporter.ReportEvent micPass,"Verify login functionality","Login functionality is working"
                   datatable("result",2)="Pass"
          End If
          Datatable.SetNextRow
Next
Datatable.ExportSheet "D:\output.xls",2   

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

Import values from xls to datatable



Import value1 values from sample1.xls  file, import value2 values from sample2.xls file, add value1 and value2 values and display in result colum and export final output result file.
         
datatable.ImportSheet "D:\VJProjects\QTP Demo\sample1.xls",1,1
datatable.ImportSheet "D:\VJProjects\QTP Demo\sample2.xls",1,2
datatable.AddSheet("result")
datatable.ImportSheet "D:\VJProjects\QTP Demo\sample3.xls",1,3
For rowNum=1 to datatable.GetRowCount
                   val1=datatable("first",1)
                   val2=datatable("second",2)
                   datatable.GetSheet(3).GetParameter("first").valueByRow(rowNum)=val1
                   datatable.GetSheet(3).GetParameter("second").valueByRow(rowNum)=val2
 val3=cint(val1)+cint(val2)
                   datatable.GetSheet(3).GetParameter("result").valueByRow(rowNum)=val3
                   datatable.SetNextRow
          Next

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

Datatable methods




I) Add Sheet: Adds the specified sheet to the run time data table
          Datatable.AddSheet(“My Sheet”)

ii) Delete Sheet :  Deletes the specified sheet from the run time data table
          Datatable.DeleteSheet(“My Sheet”)

iii) Export : Saves a copy of the run-time Data Table in the specified location
          Datatable.Export (“C:\Vamsi.xls”)

iv) Export Sheet : Saves a copy of the specified sheet of run-time datatable in the specified location.
          Datatable.ExportSheet “C:\Vamsi.xls”,sheetid/”Sheet Name”

v) Get Current Row : Returns the current ( active ) row in the first sheet in the run-time data table (global sheet)
          msgbox Datatable.GetCurrentRow

vi) Get Row Count : Returns the total number of rows in required sheet
          msgbox Datatable.GetRowCount
          msgbox Datatable.GetSheet(“Local Sheet”).GetRowCount
          msgbox Datatable.GetSheet(“My Sheet”).GetRowCount

vii) Get Sheet : Returns the specified sheet from the run-time data table.
          Msgbox Datatable.GetSheet(“Local Sheet”)
          The following example uses the GetSheet method to return the “My Sheet” sheet of the run-time data table in     order to add parameter to it.
          Datatable.GetSheet(“My Sheet”).Addparameter “Time”,”10:00”

viii) Get Sheet Count : Returns total number of sheets in run-time data table.
          Msgbox Datatable.GetSheetCount

ix) Import : Imports the specified Microsoft Excel file to the run-time data table.
          Datatable.import (“C:Vamsi.xls”)

x) Import Sheet : Imports a sheet of specified file to a specified sheet in the run-time data table. The data in the imported sheet replaces the data in the destination sheet
          Datatable.importSheet “C:\Vamsi.xls”,1(sheet source), “Name”(destination)

x) Set Current Row : Sets the specified row as the current active row in the run-time data table
          Datatable.SetCurrentRow(2)


xii) Set Next Row : Sets the row after the current active row as the new current row in the run-time data table.
          Datatable.SetNextRow

xiii) Set Previous Row : Sets the row above the current active row as the new current row in the run-time table.
          Datatable.SetPrevRow   

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

Verify Parameter (Column) existence in a Sheet



          Function isparameterExists()
                      On Error Resume Next
                      isparameterExists=True
                      Err.Clear
                      Set objSheet=Datatable.GetSheet(1).Getparameter("val123")
                      If Err.Number <>0 Then
                                isparameterExists=False
                      End If
                      msgbox isparameterExists
          End Function
          Call isparameterExists()

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

AI in Software Testing: How Artificial Intelligence Is Transforming QA

For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...