You are on page 1of 10

Keyword-Driven Test

Workshop
 
 
Flight Reservation Application
 
Using QTP
 
 

 
By
 

Suresh Babu B
 

Mind Q Systems
 
 
 
 
 
 

 
 
Automation Scenarios in Flight Reservation Application
 
  
1. Agent Login
2. Insert Order
3. Open Order
4. Update Order
5.     Fax order
6.      Delete Order
 
Exercise:
 
1.      Prepare a test for Agent Login
2.      Prepare a test for Insert Order
3.      Prepare a test for Open Order
4 Prepare a test for Update Order
5.      Prepare a test for Fax Order
6.      Prepare a test for Delete Order
7.      Prepare Keyword driven test.
 
Note:  
1.  Create an Excel file with 2 sheets titled Test Cases and Test Steps
to store test cases and test steps in the given format in Solutions section.
2.   Associate the Environment Variables File to the Keyword Driven Test

3.  Associate an Object Repository File that contains all objects to Keyword-


driven Test..

4.   Associate Function Library File to store all functions and procedures and
associate it to keyword-driven Test.

 
 

 
 
 
 
 
 
 
Solution:
 
1.         Create an Excel file with 2 Sheets titled “Test Cases” and “Test Steps” and specify the
following.
 
Test Cases
 
Tcid Testcase Desc Execute Results
TC001 Check Agent Login with valid inputs Y
TC002 Check Insert Order with valid inputs Y
TC003 Check pen Order with valid inputs Y
TC004 Check Update Order with valid inputs Y
TC005 Check Fax Order with valid inputs Y
TC006 Check Delete Order Y
 
Test Steps
 
Tcid Step id Step Desc Results Keyword
TC001 Step 1 Activate FR Application LaunchApp
Enter valid Agnet Name,Valid password and click
TC001 Step 2 Ok AgentLogin
TC001 Step 3 Close the FR Application CloseApp
TC002 Step 1 Activate FR Application LaunchApp
TC002 Step 2 Login as Agent AgentLogin
Enter all mandatory fields with valid inputs and
TC002 Step 3 click Insert Order NewOrder
TC002 Step 4 Close the FR Application CloseApp
TC003 Step 1 Activate FR Application LaunchApp
TC003 Step 2 Login as Agent AgentLogin
Click Open Order,Enter a Order No and check the
TC003 Step 3 data OpenOrder
TC003 Step 4 Close the FR Application CloseApp
TC004 Step 1 Activate FR Application LaunchApp
TC004 Step 2 Login as Agent AgentLogin
TC004 Step 3 Open an Order OpenOrder
Modify necessary fields with valid inputs and click
TC004 Step 4 Update UpdateOrder
TC004 Step 5 Close the FR Application CloseApp
TC005 Step 1 Activate FR Application LaunchApp
TC005 Step 2 Login as Agent AgentLogin
TC005 Step 3 Open an Order OpenOrder
Go to File select Fax order, enter fax no and click
TC005 Step 4 Send FaxOrder
TC005 Step 5 Close the FR Application CloseApp
TC006 Step 1 Activate FR Application LaunchApp
TC006 Step 2 Login as Agent AgentLogin
TC006 Step 3 Open an Order OpenOrder
TC006 Step 4 Click Delete Order DeleteOrder
TC006 Step 5 Close the FR Application CloseApp
 
2. Create an Environment Variable File (.xml)
 
<Environment>
<Variable>
<Name>AppPath</Name>
<Value>C:\Program Files\HP\QuickTest
Professional\samples\flight\app\flight4a.exe</Value>
</Variable>
<Variable>
<Name>DateOfFly</Name>
<Value>090909</Value>
</Variable>
<Variable>
<Name>FlyFrom</Name>
<Value>London</Value>
</Variable>
<Variable>
<Name>FlyTo</Name>
<Value>Paris</Value>
</Variable>
<Variable>
<Name>Ono</Name>
<Value>12</Value>
</Variable>
<Variable>
<Name>PName</Name>
<Value>Richards</Value>
</Variable>
<Variable>
<Name>Pwd</Name>
<Value>mercury</Value>
</Variable>
<Variable>
<Name>Uid</Name>
<Value>Mindq</Value>
</Variable>
<Variable>
<Name>UpdTkts</Name>
<Value>3</Value>
</Variable>
<Variable>
<Name>FaxNo</Name>
<Value>1111111111</Value>
</Variable>
</Environment>

3. Create a Function Library File


 

Function OpenApp(AppPath)

invokeapplication AppPath

If Dialog("Login").Exist(10) Then

Reporter.ReportEvent micPass ,"Application Launch","Application Launched Successfully"

OpenApp="Pass"

Else

Reporter.ReportEvent micFail ,"Application Launch","Application Launch failed"

OpenApp="Fail"

End If

End Function

Function Login(uid,pwd)

Dialog("Login").WinEdit("Agent Name:").Set uid

Dialog("Login").WinEdit("Password:").Set pwd

Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").Exist(10) Then

Reporter.ReportEvent micPass ,"Agent Login","Agent Login Successful"

Login="Pass"

Else

Reporter.ReportEvent micFail ,"Agent Login","Agent Login failed for valid inputs"

Login="Fail"

End If

End Function
Function CloseApp()

Window("Flight Reservation").Close

If not Window("Flight Reservation").Exist(1) Then

Reporter.ReportEvent micPass ,"Application Close","Application Closed Successfully"

CloseApp="Pass"

Else

Reporter.ReportEvent micFail ,"Application Close","Applciation Close Failed"

CloseApp="Fail"

End If

End Function

Function InsertOrder(DateOfFly,FlyFrom,FlyTo,PName)

Window("Flight Reservation").WinButton("New").Click

Window("Flight Reservation").ActiveX("DateOfFly").type DateOfFly

Window("Flight Reservation").WinComboBox("Fly From:").Select FlyFrom

Window("Flight Reservation").WinComboBox("Fly To:").Select FlyTo

Window("Flight Reservation").WinButton("FLIGHT").Click

Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select(0)

Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click

Window("Flight Reservation").WinEdit("Name:").Set PName

Window("Flight Reservation").WinButton("Insert Order").Click

Window("Flight Reservation").ActiveX("MsgControl").WaitProperty "text","Insert Done...",10000

If Window("Flight Reservation").ActiveX("MsgControl").GetROProperty("text")="Insert Done..." Then

Reporter.ReportEvent micPass ,"Insert Order","New Order Created Successfully"

InsertOrder="Pass"

Else

Reporter.ReportEvent micFail ,"Insert Order","New order Creation failed"

InsertOrder="Fail"

End If
End Function

Function OpenOrder(ono)

Window("Flight Reservation").WinButton("Open").Click

Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Click

Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set ono

Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

If trim(window("Flight Reservation").WinEdit("Order No:").GetROProperty("text"))=ono Then

Reporter.ReportEvent micPass ,"Open Order","Open Order Test Passed"

OpenOrder="Pass"

Else

Reporter.ReportEvent micFail ,"Open Order","Open Order Test Failed"

OpenOrder="Fail"

End If

End Function

Function UpdateOrder(ono,Tkts)

Window("Flight Reservation").WinEdit("Tickets:").Set tkts

Window("Flight Reservation").WinButton("Update Order").Click

Window("Flight Reservation").ActiveX("MsgControl").WaitProperty "text","Update Done...",10000

If Window("Flight Reservation").ActiveX("MsgControl").GetROProperty("text")="Update Done..." Then

Reporter.ReportEvent micPass ,"Update Order","Order Updated Successfully"

UpdateOrder="Pass"

Else

Reporter.ReportEvent micFail ,"Update Order","Update Order Failed"

UpdateOrder="Fail"

End If

End Function
Function FaxOrder(ono,Faxno)

Window("Flight Reservation").WinMenu("Menu").Select "File;Fax Order..."

Window("Flight Reservation").Dialog("Fax Order No. 1").ActiveX("FaxNo").Type "1111111111"

Window("Flight Reservation").Dialog("Fax Order No. 1").WinButton("Send").Click

Window("Flight Reservation").ActiveX("MsgControl").WaitProperty "text","Fax Sent Successfully...",10000

If window("Flight Reservation").ActiveX("MsgControl").GetROProperty("text")="Fax Sent Successfully..." Then

Reporter.ReportEvent micPass ,"Fax Order","Fax Sent Successfully"

FaxOrder="Pass"

Else

Reporter.ReportEvent micFail ,"Fax Order", "Fax Sending failed"

FaxOrder="Fail"

End If

End Function

Function DeleteOrder(ono)

Window("Flight Reservation").WinButton("Delete Order").Click

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("Yes").Click

Window("Flight Reservation").ActiveX("MsgControl").WaitProperty "text","Delete Done...",10000

If Window("Flight Reservation").ActiveX("MsgControl").GetROProperty("text")="Delete Done..." Then

Reporter.ReportEvent micPass ,"Delete Order","Order Deleted Successfully"

DeleteOrder="Pass"

Else

Reporter.ReportEvent micFail ,"Delete Order","Delete Order Failed"

DeleteOrder="Fail"

End If

End Function
 
4. Prepare the Keyword-Driven Test

Dim StrAppPath,StrUid,StrPwd,DtDateOfFly,StrFlyFrom,StrFlyTo,StrPName

Dim intOno,intFaxNo,intTkts

Dim TCCount,Tcid,TcExeFlg,TSCount,TSTCid,Keyword,Res

Environment.LoadFromFile "e:\fr\Environment\fr.xml"

StrAppPath=Environment("AppPath")

StrUid=Environment("Uid")

StrPwd=Environment("Pwd")

DtDateOfFly=Environment("DateOfFly")

StrFlyFrom=Environment("FlyFrom")

StrFlyTo=Environment("FlyTo")

StrPName=Environment("PName")

intOno=Environment("Ono")

intFaxNo=Environment("FaxNo")

intTkts=Environment("UpdTkts")

Datatable.AddSheet "TestCases"

Datatable.AddSheet "TestSteps"

Datatable.ImportSheet "e:\fr\keyword.xls","TestCases","TestCases"

Datatable.ImportSheet "e:\fr\keyword.xls","TestSteps","TestSteps"

TCCount=Datatable.GetSheet("TestCases").GetRowCount

For i=1 to TCCount

Datatable.GetSheet("TestCases").SetCurrentRow(i)

Tcid=Datatable("Tcid","TestCases")

TcExeFlg=Datatable("Execute","TestCases")

If UCase(TcExeFlg)="Y" Then

TSCount=Datatable.GetSheet("TestSteps").GetRowCount

For j=1 to TSCount


Datatable.GetSheet("TestSteps").SetCurrentRow(j)

TSTCid=Datatable("Tcid","TestSteps")

If TSTCid=Tcid Then

Keyword=Datatable("Keyword","TestSteps")

Select Case Keyword

Case "LaunchApp"

Res=OpenApp(StrAppPath)

Case "AgentLogin"

Res=Login(StrUid,StrPwd)

Case "CloseApp"

Res=CloseApp()

Case "NewOrder"

Res=InsertOrder(DtDateOfFly,StrFlyFrom,StrFlyTo,StrPName)

Case "OpenOrder"

Res=OpenOrder(intOno)

Case "UpdateOrder"

Res=UpdateOrder(intOno,intTkts)

Case "FaxOrder"

Res=FaxOrder(intono,intfaxNo)

Case "DeleteOrder"

Res=Deleteorder(intOno)

End Select

Datatable("Results","TestSteps")=Res

If Datatable("Results","TestCases")<>"Fail" Then

Datatable("Results","TestCases")=Res

End If

End If

Next

Else

DataTable("Results","TestCases")="Blocked"
End If

Next

Datatable.ExportSheet "e:\fr\keywordresults.xls","TestCases"

Datatable.ExportSheet "e:\fr\keywordresults.xls","TestSteps"

You might also like