Anda di halaman 1dari 11

Hybrid Framework

Hybrid Framework: It is a mixture of two or more approaches -------To explain this Hybrid Framework, I have taken QTP sample Application (Flight Reservations) ------------

Process Guidelines:
------------------i) Creating the Folder structure ii) Creating Automation Resources Iii) Create Organizer spread sheet Organizer provides instructions to the Driver iv) Generating the driver Script (QTP Test) (We associate all resources to the Driver Driver executes tests based on Organizer spread sheet instructions) v) Generate the initialization Script (AOM Script file) It launches the QTP Tool, Calls the Driver Script Driver executes tests one by one It closes the QTP Tool ------------------------

Test Scenarios:
Click on this Excel sheet Image in order to get Big size and Clear Image

Hybrid Framework Functions:


'*********************************************** ' Login Operation '*********************************************** Function Login(Agent, Password)

SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe" Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set Agent Dialog("Login").WinEdit("Password:").Set Password Dialog("Login").WinButton("OK").Click If Window("Flight Reservation").Exist(12) Then 'Window("Flight Reservation").Close Login="Login Operation Sucessful" 'Msgbox Login Else Systemutil.CloseDescendentProcesses Login="Login Failed" 'Msgbox Login End if End Function '*********************************************** ' Open Order '*********************************************** Function Open_Order(ord) Window("Flight Reservation").Activate Window("Flight Reservation").WinButton("OpenOrder").Click Window("Flight Reservation").Dialog("Open Order").Activate Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON" Window("Flight Reservation").Dialog("Open Order").WinEdit("OrderNum").Set ord Window("Flight Reservation").Dialog("Open Order").WinButton("text:=OK").Click OrderNum=Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text") OrderNum=Cint(OrderNum) If ord=OrderNum Then Open_Order=ord&" Order Opened Sucessfully" 'Msgbox Order_Number Else Open_Order=ord&" Order Not Opened" 'Msgbox Order_Number End If End Function '*********************************************** ' Update Order '*********************************************** Function Update_Order(Tickets) Window("Flight Reservation").Activate Window("Flight Reservation").WinButton("OpenOrder").Click Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON" Window("Flight Reservation").Dialog("Open Order").WinEdit("O rderNum").Set "5" Window("Flight Reservation").Dialog("Open Order").WinButton("text:=OK").Click Window("Flight Reservation").WinEdit("Tickets:").Set Tickets Window("Flight Reservation").WinButton("Update Order").Click Wait 10 Message=Window("Flight Reservation").ActiveX("Threed Panel Control").GetROProperty("text") If Message="Update Done..." Then Update_Order="Order Updated Sucessfully" 'Msgbox Update_Order Else

Update_Order="Order Not Updated" 'Msgbox Update_Order End If End Function '*********************************************** ' Close Application '*********************************************** Function Close_App() If Window("Flight Reservation").Exist(3) Then Window("Flight Reservation").Close End If End Function '*********************************************** ' Login for Data Driven Testing '*********************************************** Function Login2(Agent, Password) SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe" Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set Agent Dialog("Login").WinEdit("Password:").Set Password Dialog("Login").WinButton("OK").Click If Window("Flight Reservation").Exist(12) Then Window("Flight Reservation").Close Login2="Login Operation Sucessful" 'Msgbox Login Else Systemutil.CloseDescendentProcesses Login2="Login Failed" 'Msgbox Login End if End Function '*********************************************** ' Open Order for Data Driven Testing '*********************************************** Function Open_Order2(ord) Window("Flight Reservation").Activate Window("Flight Reservation").WinButton("OpenOrder").Click Window("Flight Reservation").Dialog("Open Order").Activate Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON" Window("Flight Reservation").Dialog("Open Order").WinEdit("OrderNum").Set ord Window("Flight Reservation").Dialog("Open Order").WinButton("text:=OK") .Click OrderNum=Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text") OrderNum=Cint(OrderNum) If ord=OrderNum Then Open_Order2=ord&" Order Opened Sucessfully" 'Msgbox Order_Number Else Open_Order2=ord&" Order Not Opened" 'Msgbox Order_Number End If End Function '*********************************************** ' Update Order for Data Driven Testing '***********************************************

Function Update_Order2(Tickets) Window("Flight Reservation").Activate Window("Flight Reservation").WinButton("OpenOrder").Click Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON" Window("Flight Reservation").Dialog("Open Order").WinEdit("OrderNum").Set "5" Window("Flight Reservation").Dialog("Open Order").WinButton("text:=OK").Click Window("Flight Reservation").WinEdit("Tickets:").Set Tickets Window("Flight Reservation").WinButton("Update Order").Click Wait 10 Message=Window("Flight Reservation").ActiveX("Threed Panel Control").GetROProperty("text") If Message="Update Done..." Then Update_Order2="Order Updated Sucessfully" 'Msgbox Update_Order Else Update_Order2="Order Not Updated" 'Msgbox Update_Order End If End Function

Organizer Spread Sheet:


I st Sheet "Module" Click on this Excel sheet Image in order to get Big size and Clear Image

II nd Sheet "TestCase" Click on this Excel sheet Image in order to get Big size and Clear Image

III rd Sheet "TestStep" Click on this Excel sheet Image in order to get Big size and Clear Image

Test Data:
Click on this Excel sheet Image in order to get Big size and Clear Image

Driver Script:
'Adding sheets to Run -time data table DataTable.AddSheet "Module" DataTable.AddSheet "TestCase" DataTable.AddSheet "TestStep" DataTable.AddSheet "Login" 'Importing data from External File DataTable.ImportSheet "C:\Documents and Settings\gcr\Desktop\Proj_Automation\Orginizer\Organizer.xls",1,3 DataTable.ImportSheet "C:\Documents and Settings\gcr\Desktop\Proj_Automation\Orginizer\Organizer.xls",2,4 DataTable.ImportSheet "C:\Documents and Settings\gcr\Desktop\Proj_Automation\Orginizer\Organizer.xls",3,5 DataTable.ImportSheet "C:\Documents and Settings\gcr\Desktop\Proj_Automation\TestData\data.xls",1,6 'Capturing Executable Modules from Module Sheet MRowCount=DataTable.GetSheet("Module").GetRowCount For i=1 to MRowCount Step 1 DataTable.SetCurrentRow(i) ModuleExe=DataTable(3,"Module") If UCase(ModuleExe)="Y" Then ModuleId=DataTable(1,"Module") 'Msgbox "ModuleId: " & ModuleId ' Capturing executable test cases under executable modules TCRowCount=DataTable.GetSheet("TestCase") .GetRowCount For j=1 to TCRowCount Step 1 DataTable.SetCurrentRow(j) TCCaseExe=DataTable(3,"TestCase") ModuleId2=DataTable(4,"TestCase") If UCase(TCCaseExe)="Y" and ModuleId=ModuleId2 Then TestCaseId=DataTable(1,"TestCase") 'Msgbox TestCaseId 'Capturing keywords for executable steps TSRowCount=DataTable.GetSheet("TestStep").GetRowCount For k=1 to TSRowCount Step 1 DataTable.SetCurrentRow(k) TestCaseId2 = DataTable(5,"TestStep") If TestCaseId=TestCaseId2 Then keyword=DataTable(4,"TestStep") 'msgbox keyword Select Case keyword Case "ln" Result=Login("abcd","mercury") DataTable(7,"TestStep")=Result Case "oo" Result=Open_Order(5) DataTable(7,"TestStep")=Result Case "uo"

Result=Update_Order(5) DataTable(7,"TestStep")=Result Case "ca" Close_App() Case "lnd" Rows=DataTable.GetSheet("Login").GetRowCount For m=1 to Rows Step 1 DataTable.SetCurrentRow(m) Result=Login2(DataTable(1,"Login"),DataTable(2,"Login")) DataTable(3,"Login")=Result Next Case "ood" Rows=DataTable.GetSheet("Login").GetRowCount For n=1 to Rows Step 1 DataTable.SetCurrentRow(n) Result=Open_Order2(DataTable(4,"Login")) DataTable(5,"Login")=Result Next Case "uod" Rows=DataTable.GetSheet("Login").GetRowCount For p=1 to Rows Step 1 DataTable.SetCurrentRow(p) Result=Update_Order2(DataTable(6,"Login")) DataTable(7,"Login")=Result Next End Select End If Next End If

Next End If Next DataTable.ExportSheet "C:\Documents and Settings\gcr\Desktop\Proj_Automation\TestResult\Result1.xls","TestStep"

DataTable.ExportSheet "C:\Documents and Settings\gcr\Desktop\Proj_Automation\TestResult\Result1.xls","Login"

Initialization Script:
Dim objQTP Set objQTP=CreateObject("QuickTest.Application") objQTP.Visible=True objQTP.Launch objQTP.Open "C:\Documents and Settings\gcr\Desktop\Proj_Automation\Drivers\Driver1" objQTP.Test.Run objQTP.Test.Close objQTP.Quit Set objQTP=Nothing

------------------------------------------------------------------

Using the Windows API in QTP


Hi All, Here i am providing an overview of usage of Windows API in QTP. Windows API : Using the Windows API, you can extend testing abilities and add usability and flexibility to your tests and function libraries. The Windows operating system provides a large number of functions to help you control and manage Windows operations. You can use these functions to obtain additional functionality. The Windows API is documented in the Microsoft MSDN Web site, which can be found at: http://msdn.microsoft.com/library/enus/winprog/winprog/windows_api_start_page.asp?frame=true A reference to specific API functions can be found at: http://msdn.microsoft.com/library/enus/winprog/winprog/windows_api_reference.asp?frame=true To use Windows API functions: 1. In MSDN, locate the function you want to use in your test or function library. 2. Read its documentation and understand all required parameters and return value(s). 3. Note the location of the API function. API functions are located inside Windows DLLs. The name of the DLL in which the requested function is located is usually identical to the Import Library section in the function's documentation. For example, if the documentation refers to User32.lib, the function is located in a DLL named User32.dll, typically located in your System32 library. 4. Use the QuickTest Extern object to declare an external function. For more information, refer to the QuickTest Professional Object Model Reference. The following example declares a call to a function called GetForegroundWindow, located in user32.dll: Extern. Declare micHwnd, "GetForegroundWindow", "user32.dll", "GetForegroundWindow" 5. Call the declared function, passing any required arguments, for example, hwnd = Extern.GetForegroundWindow(). In this example, the foreground window's handle is retrieved. You can enhance your test or function library if the foreground window is not in the object repository or cannot be determined beforehand (for example, a window with a dynamic title). You may want to use this handle as part of a programmatic description of the window, for example: Window("HWND:="&hWnd).Close In some cases, you may have to use predefined constant values as function arguments. Since these constants are not defined in the context of your test or function, you need to find their numerical value to pass them to the called function. The numerical values of these constants are usually declared in the function's header file. A reference to header files can also be found in each function's documentation under the Header section. If you have Microsoft Visual Studio installed on your computer, you can typically find header files under X:\Program Files\Microsoft Visual Studio\VC98\Include. For example, the GetWindow API function expects to receive a numerical value that represents the relationship between the specified window and the window whose handle is to be retrieved. In the MSDN documentation, you can find the constants: GW_CHILD, GW_ENABLEDPOPUP, GW_HWNDFIRST, GW_HWNDLAST, GW_HWNDNEXT, GW_HWNDPREV and GW_HWNDPREV. If you open the WINUSER.H file, mentioned in the GetWindow documentation, you will find the following flag values: /*

* GetWindow() Constants */ #define GW_HWNDFIRST 0 #define GW_HWNDLAST 1 #define GW_HWNDNEXT 2 #define GW_HWNDPREV 3 #define GW_OWNER 4 #define GW_CHILD 5 #define GW_ENABLEDPOPUP 6 #define GW_MAX 6 Example The following example retrieves a specific menu item's value in the Notepad application. ' Constant Values: Const MF_BYPOSITION = 1024 'API Functions Declarations Extern.Declare micHwnd,"GetMenu","user32.dll","GetMenu", micHwnd Extern.Declare micInteger,"GetMenuItemCount","user32.dll","GetMenuItemCount", micHwnd Extern.Declare micHwnd,"GetSubMenu","user32.dll","GetSubMenu", micHwnd, micInteger Extern.Declare micInteger,"GetMenuString","user32.dll","GetMenuString", micHwnd, micInteger, micString+micByRef, micInteger, micInteger Notepad.exe hwin = Window("Notepad").GetROProperty ("hwnd") ' Get Window's handle MsgBox hwin men_hwnd = Extern.GetMenu(hwin)' Get window's main menu's handle MsgBox men_hwnd Use API Functions item_cnt = Extern.GetMenuItemCount(men_hwnd) MsgBox item_cnt hSubm = Extern.GetSubMenu(men_hwnd,0) MsgBox hSubm rc = Extern.GetMenuString(hSubm, 0,value, 64 ,MF_BYPOSITION) MsgBox value 2 comments Posted by Sreekanth CR

Sunday, March 22, 2009


Create Log Files in QTP
Hi All , Here i am providing the function which creates Log files in QTP. '=========================================== ' Function: WriteLog ' description : Writes a message to a log file. File is created ' inside a Log folder of the current directory or on the Desktop

' Parameters : 'strCode is a code to prefix the message with. 'strMessage is the message of file. '=========================================== Function WriteLog(strCode, strMessage) Dim objFS Dim objFile Dim objFolder Dim strFileName Set objFS = CreateObject("Scripting.FileSystemObject") If Not objFS.FolderExists(objFS.GetAbsolutePathName(".") & "\log") Then Set objFolder = objFS.CreateFolder(objFS.GetAbsolutePathName(".") & "\log") End If strFileName = objFS.GetAbsolutePathName(".") & "\log\" & year(date) & month(date) & day(date) & ".log" Set objFile = objFS.OpenTextFile(strFileName, 8, True) On Error Resume Next objFile.Write Date & ", " & Time & ", " & strCode & ", " & strMessage & vbcrlf ' disable the on error statement On Error GoTo 0 objFile.Close Set objFS = Nothing End Function 'Function Calling : call WriteLog("Fail","Invalid User Credentials")

Anda mungkin juga menyukai