Part - 1: A Quick Revision of HP QTP 10.0 An Advanced Solution To Functional & Regression Test Automation
Part - 1: A Quick Revision of HP QTP 10.0 An Advanced Solution To Functional & Regression Test Automation
An Advanced Solution to
Functional & Regression Test Automation
Part - 1
Brief Introduction to QTP 10.0 Quick overview of QTP Life Cycle Keyword Driven Testing Approach Which test cases to be automated Key Elements of QTP Recording of Scripts Playback of Scripts Managing Application Under Test Parameterization Object Repository Object Properties & Functions Data Driven Testing Approach Managing External Excel sheets
QuickTest Professional 10.0 is a next-generation automated testing tool from HP, which uses the concept of keyword-driven testing to enhance the test creation and maintenance. It is a Functional and Regression testing tool, which can record the user actions, keyed in while recording and execute these user actions while we play back the test. QuickTest Professional meets the needs of both technical and non-technical users.
Keyword-driven testing is a technique which differentiates most of the programming effort from the actual steps in testing so that these steps can be developed earlier and can be maintained with only minor updates, even when the application undergoes significant changes. With this approach, testing engineers are able to make full utilization of test and object properties, through an integrated scripting and debugging environment fully synchronized with the Table Based Keyword View or in the VBScript-based Expert View.
When we have a large number of test cases, we have to carefully analyze them and group them into categories and then decide if that test case should executed on every release/build of the application or not. If the test case is not intended to be executed on every release it should not be automated since it falls into a one-time" testing category.
Some test cases might be very time consuming to automate where as executing them manually could be just a matter of 5 to 10 minutes. Such type of test cases should be given the least priority in terms of when to automate them. Some test cases may have manual intervention for example: when we create an account in the application someone in our team has to run some batch processes manually in order for us to continue with further testing. These kind of test cases should not be automated unless we have full control of the backend processes to be run for successful completion of the test using QTP.
a) VB Script Language
b) Object Repositories While recording the user actions on the applications QTP will generate the VB Script statements, which indicate the actions it is supposed to perform. While recording, QTP will also learn the objects present in the application, say for example a Window, check box, radio button etc., and stores these objects in a place called Object Repository.
In order to run the test successfully the corresponding object should exist in the Object Repository.
Recording of Scripts
Different modes of Recording in QTP
In this mode QTP records the objects based on their location by capturing the X and Y coordinates of the objects on the screen.
The Analog and Low Level recording modes can be selected only after hitting the record button. In the picture below the First icon is for Analog recording and the second one is for Low Level recording. Analog and Low Level Recording modes can only be selected after starting to Record and going to the Automation menu.
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
There are three modes of replaying the test. These are not listed on the tool bar.
When we hit the Run button we get the "Run" dialogue box, which gives us two options. 1) To save the results in New run results folder. This is the Verify mode. 2) To save the results in Temporary run results folder overwriting the earlier results. This is the Debug mode. 3) When we need to run the test to update the Checkpoints go to Automation" menu and select "Update Run Mode".
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
2) It checks to see if the object specified in the script exists in the repository.
3) It checks if the object specified in the script exists on the Application Under Test. 4) Does the action / task specified in the script. During script execution if any of the above phases encounter the error, then an error window pops up depending on the situation.
In QTP we can specify the URL for the application or the exe file of the application within the settings. Go to "Automation" menu and select "Record and Run Settings" option. It opens a Record and Run settings dialogue box, which has options to enter the URL of the application for web or exe file of the application if it is windows application.
For the main test, which calls the reusable actions, we can use the option "Open the following browser when a record or run session begins". Once the application is open we don't need to open the application again so for all the reusable action we can use the option "Record and run test on any open Web browses".
But we should make sure that all the browsers except Quality Center are closed before recording or running the tests.
For windows applications we can select the application by clicking the "Add" button and browsing the 0065xecutable file of the application.
At workplace usually we will be working with more than one application and we might need to automate the test cases for these applications. In this situation we should select the Radio button "Record and run test on any windows based application" for non web based application or "record and run test on any open browsers" for web applications which will instruct QTP not to open any application by itself. Then we need to include the statement SysternUtil.Run in the Login script /Action and execute that as the first action in the flow of actions.
Parameterization
What is Parameterization It is a process by which we can expand the scope of our basic test by replacing fixed values with parameters. This process, greatly increases the power and flexibility of our tests. In other words it is a way of data entry into the application without hard coding the values within the test script. We have following ways to parameterize Using values from Data Table Using Environment Variables Using Random Numbers generated Using Test Parameters Using Action Parameters
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
Parameterization
Manual Parameterization
In order to avoid the several navigation steps we can directly do manual parameterization
For Example: A = data table (V1,1) Vbwindow (form1). Vbedit (val1). Set a. Vbwindow (form1). Vbedit (val2). Set data table (v2, 1) Vbwindow (form1). Vbbutton (Add). Click
Parameterization
What are the standard Object classes?
If the class property of the object is defined as Object or WinObject or WebElement depending on the type of application you are using, then it is not a standard object and comes under the category of Non-Standard object.
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
Parameterization
How to identify an object if it is not associated with any standard class? Any object which is not associated with the standard class will have a class of either Win Object (for Windows applications) or Web Element (for web applications) and are considered as Non-Standard objects.
Non-standard objects are represented with a special Tri-colored symbol in the Object Repository.
Parameterization
How to identify an object if it is not associated with any standard class?
Object Repository
What is an Object Repository? Object Repository (OR) is a collection of objects pertaining to the application under test. Example: All the text boxes. list boxes, images etc are stored in a file in QTP.
Object Properties
What are Object Properties?
Most Objects will have two types of properties defined within the application. 1) Identification Properties 2) Native Properties The properties defined for the object in the application can be discovered by using the object spy icon which is on the toolbar or from "Tools menu select Object Spy.
Identification Properties
What are Identification Properties?
These are the properties which an object attains based on the condition within the application. Example: The FLIGHT button is designed to have a runtime/Identification property of enabled=False when we open the Flight reservation window and once we select the Date and fly from and fly to this objects runtime property is designed to change the enabled=True.
Native Properties
What are Native Properties?
These are the properties defined within the application for each object which will act as base properties and they may not change dynamically.
Functions in QTP
What is a function?
Function is a program which takes in the arguments or parameters and does the steps specified in the program and ultimately gives us an output.
Functions in QTP
Function verify Button Status(ButtonName ,ExpectedStatus) AclualStatus= wlndow("Flight Reservation") WinButton(ButtonName) GetROProperty("enabled') If Actuastatus= ExpectedStatus Then Reporter.ReportEvent micpass,'Verify Flight Button' "Flight button was disabled as expected" else Reporter.ReportEvent micFail,"Verify Flight Button "Flight button was enabled but the expected was disabled" End If End Function Function Call: VerifyButtonStatus "FLIGHT",False
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
Functions in QTP
Return Value A function should return a value in most of the cases. This return value can be used in the script where the function is being called for various reasons. A return value should be returning either a variable from the function or value calculated in the function or any value string which we specify within the function such as "Pass" or "Fail". To return a return value give the function name = Value to be returned.
For example: If the return value given by Login function is "Pass" or "True" we may want to continue further testing else we may want to end the test if it returns a value of "Fail" or "False".
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
Functions in QTP
Return Value continued
var FIightLogin = FlightLogin(piyush", "mercury") If var FIightLogin, = "Pass" Then RunAction "OrderEntry [OrderEntry]", alliterations RunAction "FlightLogout [FlightLogout]", onelteration else ExitActionlteration() End If
Functions in QTP
Storage of Functions in separate function libraries
QTP functions can be written and stored in a VB Script file which has an extension of vbs (plain text file stored with an extension of vbs) and we can attach that file in the "File "Settings" Resources and under resources we have the top most section which says "Associated library files". Click on the "+" sign in that section and browse the VB Script file which has the functions you created. For example: 'Function to close all browsers before starting the test execution can be given as: call CIoseAllBrowsers() or simply CIoseAllBrowsers()
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
Functions in QTP
Storage of Functions
All the functions should be stored in a common function library. Open a blank notepad file. Paste all the functions in that and save that file with an extension vbs and with a name which can identify it as a function library (For example: FlightFunctionLibrary). Save this file under a new folder called "Function Libraries" in the project folder.
Functions in QTP
What is VBS? VBS stands for Visual Basic Script.
Once you save the library go to QTP and select Settings from the File menu. Test Settings window appears. Go to Resources Tab. We will see a section called Function Libraries. Click on the Green "+" sign in that and browse your function library which we saved in the project folder. Now all the functions present in that library will be available to all the scripts with this settings. We can save any number of functions in one vbs file but for maintenance purposes it is better to limit the number to 50 functions or build a separate function library for each module within the application if these modules are large modules.
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
Functions in QTP
Where ever we need to call a function press F7 and the Step generator window will open.
From the top drop down, select Functions and then from the second drop down, select library functions. Now we will be able to see a list of all the functions present in all the libraries which you attached to that script. Select the function which we need to use, give the arguments and press Insert button. The function call will be inserted in our script at the cursor position.
Function ChangeDate(dttochange mm, be, yyyy) Dim DateArray, NewDate If mm = ""Then mm = 0 End If , If dd = ""Then dd =0 End If If yyyy = ""Then yyyy = 0 End If
NewDate = DateAdd("m", mm,dttochange) NewDate = DateAdd("d",do NewDate) NewDate= DateAdd("yyyy",yyyy,NewDate) DateArray = Split(NewDate, "/") Mth = DateArray(0) Dt = DateArray(1) Yr = DateArray(2) If Mth<10 Then Mth = "0"&Mth End If
'Use reverse order in this for loop so that the text and Hwnd remain in correct order after each one is closed ForvCtr=vcol_Handles .Count-1 to 0 step -1 Walt 1
vHwnd=vcol Handles.ltem(CStr(vCtr)) vBrowser=Window("regexpwndclass:=lEFrame","index .=" & vCtr).getroproperty("text")
The above line creates an Excel object ExcelObj which has reference to open excel file.
ExcelObj.Workbooks.Open "C'.\Data\OutPut.xls Above statement opens the excel file "C:\Data\OutPut.xls" in the background
NewSheet.Cells(2,1) = VariableName
The above statement will populate the value present in the VariableName variable to the second row and first column of the sheet "MyOutputSheet".
Thank You
End of Part -1
Quick Revision of HP QTP 10.0