Wednesday, December 2, 2009

37. Keyword Driven Testing:

Step 1: Open the Excel sheet and modify the Sheet 1 as Module, Sheet 2 as Test Case and Sheet 3 as Test Step.
Step 2: In Module sheet enter the Template as Moduleid, Modulename and Moduleexecution and enter all the values in the templates.
Step 3: In the Test Case sheet enter the Template as Testcaseid, Testcasedescription, Testcaseexecution, and Moduleid and enter all the values in the templates.
Step 4: In Test Step sheet enter the Templates as Teststepid, Functionname, Keyword, and Testcaseid and enter value in all the Templates.
Step 5: Save the Excel sheet as .xls.
Step 6: Open the Test in the Qtp.
Step 7: Enter the Script as

E.g:
Nextdatatable.AddSheet"module1"
datatable.AddSheet"testcase1"
datatable.AddSheet"teststep1"
datatable.ImportSheet"C:\Documents and Settings\arcus infotech\Desktop\key.xls","module","module1"
datatable.ImportSheet"C:\Documents and Settings\arcus infotech\Desktop\key.xls","testcase","testcase1"
datatable.ImportSheet"C:\Documents and Settings\arcus infotech\Desktop\key.xls","teststep","teststep1"
mcount=DataTable.GetSheet("module1").getrowcount
For i=1 to mcount
DataTable.SetCurrentRow(i)
mexec=DataTable.Value("moduleexecution","module1")
If mexec="Y" Then
modid=DataTable.Value("moduleid","module1")
MsgBox modid
tccount=DataTable.GetSheet("testcase1").getrowcount
For j=1 to tccount
DataTable.SetCurrentRow(j)
tcexec=DataTable.Value("testcaseexecution","testcase1")
modid1=DataTable.Value("moduleid","testcase1")
If modid1=modid and tcexec="Y" Then
tcid=DataTable.Value("testcaseid","testcas MsgBox tcid
tscount=DataTable.GetSheet("teststep1").getrowcount
For k=1 to tscount
DataTable.SetCurrentRow(k)
tcid1=DataTable.Value("testcaseid","teststep1")
If tcid1=tcid then
keyword=DataTable.Value("keyword","teststep1")
MsgBox keyword
Select Case keyword
Case "la"
Call la
Case "lo"
Call lo
Case "clo"
Call clo
Case "la1"
Call la1
Case "lo1"
Call lo1
Case "fr"
Call fr
Case "capp"
Call capp
End Select
End if
Next
End If
Next
End If
Step 8: Create a New Function Library Page by using File>New>Function Library.
Step 9: Shortkut Key to open Library page is Shift+Alt+N.
Step 10: In the Library page Enter the Function Syntax and its Script like this.

E.g:
Function la
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End Function

Function lo
Dialog("Login").WinEdit("Agent Name:").Set "sdfgsdfg"
Dialog("Login").WinEdit("Password:").SetSecure "4ae135406e68f334ebd94cbccf67f62f249df683"
End Function

Function clo
Dialog("Login").WinButton("Cancel").Click
End Function

Function la1
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End Function

Function lo1
Dialog("Login").WinEdit("Agent Name:").Set "sdfgsdfg"
Dialog("Login").WinEdit("Password:").SetSecure "4ae135406e68f334ebd94cbccf67f62f249df683"
Dialog("Login").WinButton("OK").Click
End Function

Function fr
Window("Flight Reservation").ActiveX("MaskEdBox").Type "111111"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Frankfurt"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Paris"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "fsdgsdfgs"
Window("Flight Reservation").WinButton("Insert Order").Click
End Function

Function capp
Window("Flight Reservation").Close
End Function

Step 11: Save the Function Library Page.
Step 12: Now we want to link the Function Library Page with the Test Page in the Qtp by File>Settings>Resources.
Step 13: Test Settings dialog box appears. Click on + symbol to browse the Saved Library file.
Step 14: After the browsing the library file click on Ok.
Step 15: Execute the Script to analyse the Result.

No comments:

Post a Comment