Sunday, August 31, 2008

TestComplete's Data Driven Test

TestComplete is a test automation tool from AutomatedQA. It provides several features as other automation tool does provide and supports for various technologies on Windows platform. Let us see a code snippet which is in VBScript, used for a Data Driven Test using Microsoft Excel sheet.

TestComplete's Data Driven Test


Below written is a VBScript for Data Driven Test using automation tool, TestComplete 6. The script automates for booking a flight ticket using Mercury/HP's QTP sample flight application. The excel file will have the data, which is used during Data Driven Test.


' The script starts from here.

Option Explicit

Sub openForm(w1)
Call w1.MainMenu.Click("File|New Order")
End Sub

Sub insertOrder(p1,w1,w2,Driver)
Call w2.Window("MSMaskWndClass").Keys(Driver.Value(0))
Set w3 = w2.Window("ComboBox", "", 1)
Call w3.ClickItem(Driver.Value(1))
Set w3 = w2.Window("ComboBox", "", 2)
Call w3.ClickItem(Driver.Value(2))
w2.Window("Button", "FLIGHT").ClickButton
Set w3 = p1.Window("#32770", "Flights Table")
Call w3.Window("ListBox").ClickItem(Driver.Value(5))
w3.Window("Button", "OK").ClickButton
Set w3 = w2.Window("Edit", "", 1)
Call w3.Click(55, 11)
Call w3.Keys(Driver.Value(3))
w2.Window("Button", Driver.Value(4)).ClickButton
Call clickInsert(w2)
End Sub

Sub closeApplication(w1)
Call w1.MainMenu.Click("File|Exit")
End Sub

Sub clickInsert(w2)
w2.Window("Button", "&Insert Order").ClickButton
End Sub


Sub Main ' point of starting the script execution.
Dim p1
Dim w1
Dim w2
Dim w3
' creating a Excel driver object.
Set Driver =
DDT.ExcelDriver("G:\RAVI\TESTING\testComplete\sampleProject\flightDDT.xls","flightDDT",false)
Call TestedApps.flight4a.Run ' Application Under Test (AUT/SUT).
Set p1 = Sys.Process("flight4a")
Set w1 = p1.Window("#32770", "Login")
Call w1.Click(55, 6)
Set w2 = w1.Window("Edit", "", 1)
Call w2.Click(24, 8)
Call w2.Keys("mercury")
Set w2 = w1.Window("Edit", "", 2)
Call w2.Click(16, 11)
Call w2.Keys("mercury")
w1.Window("Button", "OK").ClickButton
Set w1 = p1.Window("Afx:400000:b*", "Flight Reservation")
Call w1.Click(50, 7)

While Not Driver.EOF
Call openForm(w1)
Set w2 = w1.Window("#32770")
If Driver.EOF Then
Call DDT.CloseDriver(Driver) ' closing the Excel Driver object created.
Call closeApplication(w1) ' closing the AUT/SUT.
End If
Call insertOrder(p1,w1,w2,Driver) ' call to a procedure to insert the data from excel sheet.
Call Driver.Next ' moving to the next row in the excel sheet.
Wend
Call closeApplication(w1)
End Sub ' End of a "Main" procedure.
' The script ends here.
*************************************************************************************


Learning's:

  • To begin, Data Driven Test from the above script, makes use of Excel Driver, which creates a object for an Excel sheet.
  • Syntax or declaration of driver:
DDT.ExcelDriver(Filename, Sheet, UseAceDriver)
  • Filename: is the name of excel file being used.
  • Sheet: is the excel sheet which has the data, that will be used for test.
  • UseAceDriver: a Boolean value. If True, TestComplete makes use of ACE driver to connect an excel sheet. If it is False, TestComplete connects to the excel sheet via the Microsoft Excel ODBC driver. ACE driver lets us to connect Excel 2007 sheets together with earlier version of Microsoft Excel.
  • Driver.Value(n), carries the data from excel sheet. The first column of the excel sheet is read as zeroth column.

The GUI which takes data from the user, can be fed with the relevant or irrelevant data which we want to test with, for 'n' number of times or for the desired iterations of tests run. The content format of the excel file is as below:


DATE FLY FROM FLY TO NAME CLASS FLIGHT
091108 Denver London Testing Garage First 20263 DEN 11:12 AM LON 06:23 PM AA $112.20
010109 Frankfurt Los Angeles Ravisuriya Business 20324 FRA 09:12 AM LAX 04:23 PM AA $112.20

End of topic "TestComplete's Data Driven Test"


Off-Topic note learning:

Finally to conclude, the automation is not a solution for busy and challenging test execution process. It provides the supporting hand to repeat the tests for test conditions which needs to be executed repeatedly. But, the 'Manual Testing' or a Tester testing sitting in front of the SUT/AUT is much result oriented and provides information regarding the quality measure of AUT/SUT; because tool only does the task scripted but the tester (human) has the intelligence & capability to identify the risks from doing things repeatedly with her/his thinking capability, which are uncovered by test tools.


Love Testing !


2 comments:

Please, do write your comment on the read information. Thank you.