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
Part - 1
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.
3 - Step Commands:
1) Step Into
2) Step Out
3) Step Over
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.
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.
Analog Mode.
Analog mode:
This mode is used for recording the continuous operations.
In this mode QTP records the mouse movements and key strokes on the keyboard
as Tracks so that it can help us in testing the situations like signature scanning or
handwriting or drawing some objects on the screen or in a window etc.
It is a special mode available in QTP that is used for recording the minimum operations on the
Non-Supported environments as well.
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.
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.
Debug Mode: If the Test engineer does not want to save the results as he is yet to
finish the script or he is testing his QTP coding logic he would run the test in the
debug mode.
Update Mode: If a test engineer wants to update the expected results while running
the test, say for example while recording the script the calendar date was 10/20/2008
and while executing the test it is a different date (system date), then the test should
be run in the update mode otherwise the test would fail because of the changed
properties of the object.
2) It checks to see if the object specified in the script exists in the repository.
During script execution if any of the above phases encounter the error, then an
error window pops up depending on the situation.
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.
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.
What statement would we use to send the results to the test results? We would use Reporter. Reportevent followed by the step name, description and result to send the result to the test results and get the status whether the step passed or failed.
Example:
Reporter. ReportEvent 0,"Property Check", "Property Checked Passed”
Value "0" indicates that the step is passed and "1" indicates that the step is failed. We can also use micPass or micFail in place of 0 or 1.
In other words it is a way of data entry into the application without hard coding the values within the
test script.
For Example:
1) Window 6) Checkbox
2) Dialog box 7) Radio button
3) Menu 8) List box
4) Push button 9) Combo box
5) Edit Box
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.
Each object will have the set of properties to identify that object
uniquely in the application.
You need to specify the name for the shared object repository in which
you want to save these objects.
1) Open the object repository of the action and click on the icon Associate
Repositories on the tool bar.
3) Click on the green "+" sign and browse the shared object repository and
select it.
All the actions which are available in that script will be shown in the
Available Actions section of that window
4) Select the action which we want to associate the repositories to and click
on the ">" arrow to send it to the "Associated Actions" section of the
window
This will ensure that the actions in the associated actions will have access to
all the objects in the associated object repositories.
It is automatically loaded with the script and saved into the script folder.
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.
These are the properties which an object attains based on the condition
within the application.
What is a function?
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
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.
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".
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:
Storage of Functions
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.
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 NoOfDaysInMonth(InMonth)
Dim NoOfDays
Select Case InMonth
Case "01", "1", "03", "3", "05", "5", "07", "7", "08", "8", "10", "12”
NoOfDaysinMonth ="31"
Case "02", "2”
NoOfDaysInMonth = "28"
Case "04", "4", "06", "6", "09", "9", "07", "11"
NoOfDaysinMonth = "30"
Case Else
NoOfDayslnMonth = "The value passed is an illegal parameter"
End Select
End Function
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
Few Examples of Functions
If Dt<10 Then
Dt = "0" &Dt
End If
NewDate = Mth&"/"&Dt&"/"&Yr
ChangeDate = NewDate
End Function
Function CIoseAllBrowsers()
Dim vcol Handles, vCtr, vHwnd, Flag, vLastHWnd
vCtr = 0
Flag = 1
Set vcol Handles=CreateObject("ScriptingDlctlonary'")
While (Window("regexpwndclass:=lEFrame","Index:=" & vCtr).Exist And
Flag)
wait 1
vHwnd= Window("regexpwndclass:=lEFrame","index=" &
vCtr).getroproperty("Hwnd") If (vLastHWnd=vHwnd) Then
Flag = 0
Else
vcol Handles.Add CStr(vcol Handles.Count),vHwnd
vCtr = vCtr+1
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
Few Examples of Functions
Function to Close all Browsers except the Test Director & QC Contd.
End If
vLastHWnd = vHwnd
Wend
'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")
Function ScreenCheck(ScreenName)
Rc= Browser("Browser ).Page("Page").
WebElement(ScreenName).GetROProperty("innertext")
If Rc = ScreenName Then
Reporter.ReportEvent micpass,"screen check', ScreenName&" screen
appeared"
ScreenCheck = "Pass"
Else
Reporter.ReportEvent micfall, "screen check", ScreenName&" screen did not
appear"
ScreenCheck = "Fail"
ExitGIoballteration() 'Goes to next row in the Globs! Table (or next test
case).
End If
End Function
The user-defined box will now be enabled. Click “User Defined”. The object
mapping dialogue box opens.
Click the hand icon and click on the object whose class we want to add to
user-defined class.
In the Map to box select the standard object class to which we want to map
this user-defined object.
In this "/" is the delimiter. DateArray will store the values which can be used
as displayed by MsgBox and concatenated together as a single variable
MyDate as shown above.
Variable values can be passed into QTP through the Global sheet or local
sheet depending on the architecture you are using.
From the keyword view select the object whose value you want to pass
through the data table.
Click in the Value column for that row and you will see a little <#> sign in the
right hand corner of that cell.
This will have two main radio buttons “Constant” and “Parameter”.
We can see the current value present in the Constant edit field.
(We can also select the other two options present in the drop down
Environment or the Random Number).
Now enter the field name from which we want to select the data. In case this
particular field doesn't exist QTP will create the one for us.
Parameterization of
data through the
Keyword view
Then select from which data table you want to enter the data.
We can enter the data either from the Global sheet or from the Current action
sheet (local table).
Now click "OK". The field will be created for us and the data for that field is
taken from the data table instead of having a hard coded value within the
script.
Start the record session and from the "Insert" menu select "Output Value"
and based on the type of object we need to select either “Standard Output
value” or the “Text output value”.
For example if the object is a list item or edit box select “Standard Output
value” . QTP will then show the object properties and now we need to select
what property we want to output. In this case it is the "Value".
Also we need to specify the field name into which we want to send the value
and the data table whether Global sheet or local sheet.
QTP will suggest us a field name we can either accept or change according
to our naming conventions.
>>>>>>>>>>>>>>>>>>>>>> www.softwaretestinggenius.com <<<<<<<<<<<<<<<<<<<<<<
Writing Data to the Data tables
This output value is shown only in the runtime and once the test execution is
finished the data can't be seen in the data table.
But we can see the data in the Runtime data table in the results.
If the varPolicyNumber is the variable which holds the policy number which
needs to be sent to the data table we can send that value into local sheet
using the following statements into the Policy-Number column in the local
sheet of the action.
varPolicyNumber = 123456”
We need to define the automation objects to work with an external excel file.
The above line creates an Excel object ExcelObj which has reference to
open excel file.
ExcelObj.Workbooks.Open "C'.\Data\OutPut.xls”
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".
End of Part -1