Date post: | 30-May-2018 |
Category: |
Documents |
Upload: | praveenforum |
View: | 229 times |
Download: | 0 times |
of 35
8/14/2019 QTP9.2 Course Material
1/35
8/14/2019 QTP9.2 Course Material
2/35
8/14/2019 QTP9.2 Course Material
3/35
QTP Window:
8/14/2019 QTP9.2 Course Material
4/35
Object Spy:
Using the Object Spy pointing hand mechanism, you can view the supported properties
and methods of any object in an open application. As you move the pointing hand overthe objects in the application, their details are displayed in the Object Spy. These details
may include the test object's hierarchy tree, its properties and values, and the methods
associated with the object. For methods, the syntax is also displayed. In mostenvironments, you can choose to view the test object properties and methods or the run-
time (native) properties and methods.
Steps to View Object Properties:
Open your application to the page containing the object on which you want to spy.
Choose Tools > Object Spy or click the Object Spy toolbar.
In the Object Spy dialog box, click the pointing hand.
Highlight or click the object whose properties or methods you want to view. The
Object Spy displays the object hierarchy tree and the properties or methods of theobject that is selected within the tree.
8/14/2019 QTP9.2 Course Material
5/35
Object Identification:
The Object Identification dialog box enables you to set mandatory and assistive
properties, to select the ordinal identifier, and to specify whether you want to enable the
Smart Identification mechanism for each test object.
Mandatory Properties: These are the properties of a class of objects that QTP always
learns to identify these objects at runtime.
Assistive Properties: These are the properties of a class of objects that QTP learns to if it
is not able to differentiate between the two objects in the application using mandatoryproperties.
Ordinal Identifiers are used of two or more objects have same set of Mandatory and
assistive properties.
Smart Identification is used when some of the properties of the object are changed fromrecording time to run time.
8/14/2019 QTP9.2 Course Material
6/35
8/14/2019 QTP9.2 Course Material
7/35
Select the properties you want to include in the Mandatory Properties list and/or
clear the properties you want to remove from the list.
Click OK to close the Add/Remove Properties dialog box. The updated set of
mandatory properties is displayed in the Mandatory Properties list.
In the Assistive Properties list, click Add/Remove. The Add/Remove Properties
dialog box for assistive properties opens.
Select the properties you want to include in the assistive properties list and/or
clear the properties you want to remove from the list.
Click OK to close the Add/Remove Properties dialog box. The properties are
displayed in the Assistive Properties list.
Selecting an Ordinal Identifier
In addition to learning the mandatory and assistive properties specified in the Object
Identification dialog box (Tools > Object Identification), QuickTest can also learn a
8/14/2019 QTP9.2 Course Material
8/35
backup ordinal identifier for each test object. The ordinal identifier assigns the object a
numerical value that indicates its order relative to other objects with an otherwise
identical description (objects that have the same values for all properties specified in themandatory and assistive property lists). This ordered value enables QuickTest to create a
unique description when the mandatory and assistive properties are not sufficient to do
so.
Index. Indicates the order in which the object appears in the application code
relative to other objects with an otherwise identical description.
Location. Indicates the order in which the object appears within the parent
window, frame, or dialog box relative to other objects with an otherwise identical
description.
CreationTime. (Browser object only.) Indicates the order in which the browser
was opened relative to other open browsers with an otherwise identical
description
Smart Identification:
Selecting the Enable Smart Identification check box for a particular test object classinstructs QuickTest to learn the property values of all properties specified as the object's
base and/or optional filter properties in the Smart Identification Properties dialog box.
By default, some test objects already have Smart Identification configurations and others
do not. Those with default configurations also have the Enable Smart Identificationcheck box selected by default.
Any changes you make in the Object Identification dialog box have no effect on
objects already added to the object repository.
Virtual Objects
Complex objects may not be recognized properly by QTP. The Virtual Object concept
was implemented to enable users to add some degree of support for these objects. If anobject is not recorded out-of-the-box, an experienced user may be able to define that
object as a personal virtual object and build a virtual object repository. Assuming that the
required information can be extracted from the object, this allows the users tosuccessfully record and playback against that object. In practice, this is not always
possible.
http://en.wikipedia.org/wiki/Virtualhttp://en.wikipedia.org/wiki/Object_(computer_science)http://en.wikipedia.org/wiki/Virtualhttp://en.wikipedia.org/wiki/Object_(computer_science)8/14/2019 QTP9.2 Course Material
9/35
You can teach QuickTest to recognize any area of your application as an object by
defining it as a virtual object. Virtual objects enable you to record and run tests on
objects that are not normally recognized by QuickTest.
Using the Virtual object wizard, you define a virtual object by:
Mapping it to a standard class: Specifies a standard object class from the list.
Marking its boundaries: Configures the size and location of the virtual object.
Using the crosshairs pointer, you can mark the outline for the virtual object in the
Web page.
Assigning a parent object: Selects an object in the tree as the parent object.
Specifying a name and collection: Configures a name and a collection for the
virtual object. You can also choose to define another virtual object.
Object Repository:
Object Repository Stores all the objects learnt by the QTP. One can find object
Repository in Resources > Object Repository. The Object Repository window displays
a tree of all objects in the current component or in the selected action (including all local
objects and all objects in any shared object repositories associated with the selectedaction or component).
The Object Repository window contains the following information:
8/14/2019 QTP9.2 Course Material
10/35
8/14/2019 QTP9.2 Course Material
11/35
8/14/2019 QTP9.2 Course Material
12/35
Once the objects are added the objects have to be stored in a Global mode. The sharedrepository will have the extension as .tsr
Object repository associations:
You can manage the shared object repository associations of a selected test using the
Associate Repositories dialog box. The Associate Repositories dialog box enables you toassociate one or more shared object repositories with one or more actions in a test. You
can also remove object repository associations from selected actions, or from all actions
in the test
8/14/2019 QTP9.2 Course Material
13/35
Steps to Associate Repositories:
Choose Resources > Associate Repositories.
In the Object Repository window, choose Tools > Associate Repositories.
In the Object Repository window, click the Associate Repositories button .
The Associate Repositories dialog box opens. To add a shared object repository to the list so you can associate it to one or more
actions in the current test, click the Add Repository button.
To associate an object repository with one or more actions, or remove existing
associations, select the object repository in the Repositories list, and then double-click the action names or select the action names and click the arrow buttons (>
and Export Local Objects. The Export Object Repository dialog box
opens.
8/14/2019 QTP9.2 Course Material
14/35
Select the location in which to save the file, specify the file or attachment name,
and click Save or OK.
Record and Replay:
Initial development of automated tests with QTP is usually done by record-and-playback.A user's actions are captured via Microsoft's Component Object Model (COM). These are
recorded into Actions, a kind of subroutine, as VBScript commands. All manipulated
objects that QTP recognizes are also added to the object repository. Once recorded, thescripts are editable in either Keyword View or Expert View.
After clicking on the playback button all these actions will be played back. During
playback, QTP attempts to identify and perform operations on the same objects, again
using COM.
Recording Tool Bar:
Recording a Test:
Start QuickTest and open a new test.
Choose Automation > Record or click the Record button. The Record and Run
Settings dialog box opens.
Give Proper Setting in the Dialog box and click OK
Activate the application under test
Perform actions on the application. Usually the actions have to be the test steps of
the test case being automated.
Stop Recording
You will some script generated in the expert window.
Record and Run Settings Dialog Box
8/14/2019 QTP9.2 Course Material
15/35
There are three modes of recording;
1) Normal Mode recoding or Context Sensitive.
2) Analog Mode Recording
3) Low level Recording.
Context Sensitive mode is the default recording mode OF QTP. It performs recording
based on the object repository. It depends only on the objects. Usually the recording
happens on parent child hierarchy model. Example when you click on Search button onGoogle page the script will look something like this:
Browser(Google).Page(Google Search).WebButton(Search).Click.
Analog Recording enables you to record the exact mouse and keyboard operations you
perform in relation to either the screen or the application window. In this recording mode,
QuickTest records and tracks every movement of the mouse as you drag the mousearound a screen or window.
This mode is useful for recording operations that cannot be recorded at the level of an
object, for example, recording a signature produced by dragging the mouse.
Low Level Recording Enables you to record on any object in your application, whetheror not QuickTest recognizes the specific object or the specific operation. This mode
8/14/2019 QTP9.2 Course Material
16/35
records at the object level and records all run-time objects as Window or WinObject test
objects. Use low-level recording for recording in an environment or on an object not
recognized by QuickTest. You can also use low-level recording if the exact coordinates ofthe object are important for your test.
Active Screen
QTP captures the screen of the application and saves along with the script. The active
screen section highlights the objects in the active screen as the user navigates through the
script so the user knows what object he/she will be performing the action upon.
Active screen is also helpful in creating checkpoints. A right-click on an object displayedin the active screen produces a drop-down menu, which includes a list of checkpoints that
can be placed at the current cursor position in the script.
VB Scripting:
Once the script is generated by recording, we may want to enhance the script to make itmore effective. QTP allows you to do this with the help of VB script language elements.
Following are some of the VB Script language elements that are commonly used.
Command: InputBox.
Displays a prompt in a dialog box, waits for the user to input text or click a button, andreturns the contents of the text box.
Syntax: InputBox(Enter your name)
Command: MsgBox.
Displays a message in a dialog box, waits for the user to click a button, and returns a
value indicating which button the user clicked.
Syntax: MsgBox(Hello World)
String Functions:
8/14/2019 QTP9.2 Course Material
17/35
StrComp: Returns a value indicating the result of a string comparison.
Usage:
A=Strcmp(Hello,Hello)
A will have value 0 which means true.
InStr: Returns the position of the first occurrence of one string within another
Usage:
val1="welcome to India"
val2="India"
val=InStr(1,val1,val2)
val will have value 12 . This means that the position of the word India in val1 is 12.
Split: Returns a zero-based, one-dimensional array containing a specified number ofsubstrings with respect to delimiter.
Usage:
Val=appleXballXcatXdog
Sval=Split(val,X,-1)
Now Sval(0) will have apple
Sval(1)=ball
Sval(2)=cat.
That is Split command will split the string based upon the delimiter specified.
Date and Time Functions:
8/14/2019 QTP9.2 Course Material
18/35
8/14/2019 QTP9.2 Course Material
19/35
Example Function
Public Function Total(a,b, ByRef c)
c=a+b
End Function
Call Total(2,3,d)
D will have the output, the value of c.
Syntax For Writing a Function.
[Public [Default] | Private] Function name [(arglist)]
[statements]
[statements]
End Function
Public
Indicates that the Function procedure is accessible to all other procedures in all scripts.
Default
Used only with the Public keyword in a Class block to indicate that the Functionprocedure is the default method for the class. An error occurs if more than one Default
procedure is specified in a class.
Private
Indicates that the Function procedure is accessible only to other procedures in the script
where it is declared or if the function is a member of a class, and that the Function
procedure is accessible only to other procedures in that class.
name
Name of the Function; follows standard variable naming conventions.
arglist
8/14/2019 QTP9.2 Course Material
20/35
List of variables representing arguments that are passed to the Function procedure when
it is called. Commas separate multiple variables.
statements
Any group of statements to be executed within the body of the Function procedure.
File handling:
Writing Values From a File:
Const ForReading = 1, ForWriting = 2
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
MyFile.WriteLine "Hello world!"
MyFile.WriteLine "The quick brown fox"
MyFile.Close
Reading Values from a File:
Const ForReading = 1, ForWriting = 2
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForReading)
Val= MyFile.ReadLine
Val1=MyFile.ReadLine
MyFile.Close
Fetching Values from a Database using VBScript.
8/14/2019 QTP9.2 Course Material
21/35
Set MyConn = CreateObject("ADODB.Connection")
MyConn.Open"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Program+_
"Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight32.mdb"
Set RS = MyConn.Execute("SELECT * FROM Orders")
While Not RS.EOF
msgbox RS("Order_Number").Value
Rs.MoveNext
Wend
QTPS test Object Functions:
Exist: You can enterExist and/orWait statements to instruct QuickTest to wait for a
window to open or an object to appear. Exist statements return a boolean value indicatingwhether or not an object currently exists. Wait statements instruct QuickTest to wait a
specified amount of time before proceeding to the next step. You can combine these
statements within a loop to instruct QuickTest to wait until the object exists beforecontinuing with the test.
Example:
blnDone=Window("Flight Reservation").Dialog("Flights Table").Exist
counter=1
While Not blnDone
Wait (2)
blnDone=Window("FlightReservation").Dialog("FlightsTable").Existcounter=counter+1
If counter=10 then
blnDone=True
End if
Wend
8/14/2019 QTP9.2 Course Material
22/35
Check Property: Checks whether the specified object property achieves the specified
value within the specified timeout.
Syntax: object.CheckProperty(PropertyName, PropertyValue, [TimeOut])
Example:
var_CheckProperty = Browser("HP QuickTest Professional").Page("HP QuickTestProfessional").Link("1.2 License Models").CheckProperty("text", "Licence Models")
Return Value
A Boolean value. Returns TRUE if the property achieves the value, and FALSE if the
timeout is reached before the property achieves the value.
A TRUE return value reports a Passed step to the test results; a FALSE return value
reports a Failed step to the test results.
GetTOProperty: Returns the value of the specified property from the test object
description.
Syntax: object.GetTOProperty(Property)
Example : var_GetTOProperty = Browser("HP QuickTest Professional").Page("HP
QuickTest Professional").Link("1.2 License Models").GetTOProperty("Innertext")
Return Value: A variant value which will have the inner text of the link 1.2 LicenseModels
GetROProperty: Returns the current value of the test object property from the object in
the application.
Syntax: object.GetROProperty(Property)
Example : var_GetTOProperty = Browser("HP QuickTest Professional").Page("HP
QuickTest Professional").Link("1.2 License Models").GetROProperty("Innertext")
Return Value: A variant value which will have the current inner text value of the link 1.2License Models
8/14/2019 QTP9.2 Course Material
23/35
ReportEvent : Reports an event to the test results
Syntax: Reporter.ReportEventEventStatus, ReportStepName, Details [, Reporter]
Example:
Reporter.ReportEvent 1, "Custom Step", "The user-defined step failed."
or
Reporter.ReportEvent micFail, "Custom Step", "The user-defined step failed."
SystemUtil.Run : You can run any application from a specified location using aSystemUtil.Run statement
Example:SystemUtil.Run"C:\ProgramFiles\InternetExplorer\IEXPLORE.EXE","","C:\D
ocuments and Settings\Administrator","open"
The statement opens the Internet Explorer.
ExecuteFile: This can be used to execute an external VB Script File
Syntax: ExecuteFileFileName
Example : ExecuteFile C:\sample.vbs
The above discussed functions can be easily Accessed by step Generator:
Step Generator:
Step Generator can found in insert menu.
8/14/2019 QTP9.2 Course Material
24/35
Step Generator Dialog Box:
The Step Generator dialog box enables you to add steps that perform operations, usingtest object methods (for tests only), Utility object methods, or function calls.
When you define a new step, you first select the type of step that you want to add to yourtest. You can then select the specific object and method for the step, or the function that
you want the step to use.
After you select the operation for the step, you can specify the relevant argument valuesand the location for the return value, if applicable. These values can be parameterized if
required.
Finally, you can view the step documentation or statement syntax and add your new step
or statement to your test or function library.
Test Objects: Enables you to select a test object and method for the step (for tests only).
Utility Objects: Enables you to select a Utility object and method for the step.
Functions: Enables you to select a function for the step from the available library
functions (tests only), VBScript functions, and internal script functions.
8/14/2019 QTP9.2 Course Material
25/35
Check Points:
QuickTest enables you to add checks to your test. A checkpoint is a verification point
that compares a current value for a specified property with the expected value for thatproperty. This enables you to identify whether your Web site or application is functioning
correctly.
When you add a checkpoint, QuickTest adds a checkpoint to the current row in the
Keyword View and adds a Check CheckPoint statement in the Expert View. By default,the checkpoint name receives the name of the test object on which the checkpoint is
being performed. You can choose to specify a different name for the checkpoint or accept
the default name.
When you run the test, QuickTest compares the expected results of the checkpoint to thecurrent results. If the results do not match, the checkpoint fails. You can view the results
of the checkpoint in the Test Results window.
Adding a Checkpoint while recording:
Choose Insert > Checkpoint > Standard Checkpoint or click the Insert Checkpoint
or Output Value button and choose Standard Checkpoint. The QuickTest windowis hidden, and the pointer changes into a pointing hand.
Click the object whose text you want to check. The Object Selection - Checkpoint
Properties dialog box opens.
8/14/2019 QTP9.2 Course Material
26/35
Select the item you want to check from the displayed object tree.
Click OK. The Checkpoint Properties dialog box opens.
In the Name box, either accept the name that QuickTest assigns to the checkpoint
or specify another name for it. By default, the checkpoint name is the name of the
test object on which the checkpoint is being performed.
Select the text property
If necessary, edit the text value you want QuickTest to check. Note that you can
parameterize this value.
If you want to check only text, clear the other check boxes in the dialog box.
Click OK to close the dialog box. A checkpoint statement is added for the selected
object
The above one is a standard Checkpoint. There are also other check points and the
procedure is same.
8/14/2019 QTP9.2 Course Material
27/35
DataTable Parameterization:
When you test your application or Web site, you may want to check how it performs the
same operations with multiple sets of data. For example, if you are testing the MercuryTours sample Web site, you may want to check that the correct departure and the arrival
cities are selected before you book a particular flight.
To parameterize
1) In the Keyword View, click in the Value cell of the step and then click theparameterization icon. In the Value Configuration Options dialog box, select the
Parameter radio button. In the Name box, rename p_item to Location.
2) Click Ok.
Data Table Functions:
DataTable.Import: Imports the specified Microsoft Excel file to the run-time Data
Table.
Example:
DataTable.Import ("C:\flights.xls")
8/14/2019 QTP9.2 Course Material
28/35
DataTable.Export:
Saves a copy of the run-time Data Table in the specified location
Example:
DataTable.Export ("C:\flights.xls")
Recovery Scenario:
The Recovery Scenario Wizard leads you, step-by-step, through the process of creating a
recovery scenario. The Recovery Scenario Wizard contains the following main steps:
defining the trigger event that interrupts the run session
specifying the recovery operations required to continue choosing a post-recovery test run operation
specifying a name and description for the recovery scenario
(for tests) specifying whether to associate the recovery scenario to the current test
and/or to all new tests
You open the Recovery Scenario Wizard by clicking the New Scenario button in theRecovery Scenario Manager dialog box (Resources > Recovery Scenario Manager).
8/14/2019 QTP9.2 Course Material
29/35
Defining Trigger Events: The Select Trigger Event screen enables you to define the
event type that triggers the recovery scenario, and the way in which QuickTest recognizes
the event.
Pop-up window. QuickTest detects a pop-up window and identifies it accordingto the window title and textual content. For example, a message box may open
during a run session, indicating that the printer is out of paper. QuickTest candetect this window and activate a defined recovery scenario to continue the run
session.
Object state. QuickTest detects a specific test object state and identifies it
according to its property values and the property values of all its ancestors. Notethat an object is identified only by its property values, and not by its class.
Tests run error. QuickTest detects a run error and identifies it by a failed return
value from a method. For example, QuickTest may not be able to identify a menuitem specified in the method argument, due to the fact that the menu item is not
available at a specific point during the run session. QuickTest can detect this runerror and activate a defined recovery scenario to continue the run session.
Application crash. QuickTest detects an application crash and identifies it
according to a predefined list of applications. For example, a secondary
application may crash when a certain step is performed in the run session. You
want to be sure that the run session does not fail because of this crash, which mayindicate a different problem with your application. QuickTest can detect this
application crash and activate a defined recovery scenario to continue the run
session.
Trigger for Pop up
8/14/2019 QTP9.2 Course Material
30/35
After you select the object whose properties you want to specify in the Select Object
Screen, the Set Object Properties and Values screen opens.
Trigger for object State
Triggers for Test Run Error:
Any error. Any error code that is returned by a test object method.
Item in list or menu is not unique. Occurs when more than one item in the list,
menu, or tree has the name specified in the method argument.
Item in list or menu not found. Occurs when QuickTest cannot identify the list,
menu, or tree item specified in the method argument. This may be due to the fact
that the item is not currently available or that its name has changed.
More than one object responds to the physical description. Occurs when more
than one object in your application has the same property values as thosespecified in the test object description for the object specified in the step.
Object is disabled. Occurs when QuickTest cannot perform the step because the
object specified in the step is currently disabled.
Object not found. Occurs when no object within the specified parent object
matches the test object description for the object. Object not visible. Occurs when QuickTest cannot perform the step because the
object specified in the step is not currently visible on the screen.
8/14/2019 QTP9.2 Course Material
31/35
8/14/2019 QTP9.2 Course Material
32/35
Restart Microsoft Windows. QuickTest restarts Microsoft Windows. Select this option
and click Next to continue to the Recovery Operations Screen.
When you clear the Add another recovery operation check box in the RecoveryOperations Screen and click Next, the Post-Recovery Test Run Options screen opens.
Post-recovery test run options specify how to continue the run session after QuickTesthas identified the event and performed all of the specified recovery operations.
After you specify a test run option in the Post-Recovery Test Run Options Screen, and
clickNext, the Name and Description screen opens.
Give the name and Finish
8/14/2019 QTP9.2 Course Material
33/35
Quick Test Testing Process as a Whole:
Planning
Before beginning to create a test, you should plan it and prepare the requiredinfrastructure. For example, determine the functionality you want to test, and decide
which information you want to check during the test run. Before preparing the required
infrastructure, you should spend time analyzing your application and determining which
objects and operations are used by the set of business processes that need to be tested.You should also determine which operations require customized keywords to provide
additional functionality.
Creating Tests
You create a test either by building an object repository and adding steps manually or byrecording a session on your application. You can create steps using the table-like,
graphical Keyword View using keyword-driven functionalityor you can use the Expert
View, if you prefer programming steps directly in VBScript.
Every test is composed of one or more actions. At its most basic level, each actioncontains steps that duplicate the activities that you or another user might perform when
using your application or Web site. You can enhance the testing process by modifying
your test with special testing options and/or with programming statements.
By default, each test begins with a single action. You can organize your test by dividing itinto multiple actions. This is similar to creating separate modules, or logical units, for
testing various parts of your application orWeb site.
8/14/2019 QTP9.2 Course Material
34/35
When you create your test, you:
Add steps to your test
Build an object repository and use these objects to add keyword-drivenstepsmanually in the Keyword View or Expert View.
The object repository should contain all the objects that you want to test in your
application or Web site. For more information on building an
Record a session on your application or Web site.
As you navigate through your application or site, QuickTest graphically displays each
step you perform as a row in the Keyword View. A step is something that causes or makesa change in your site or application, such as clicking a link or image, or submitting a data
form. In the Expert View, these steps are displayed as lines in a test script (VBScript).
The Documentation column of the Keyword View also displays a description of each step
in easy-to-understand sentences
Insert checkpoints into your test.
A checkpoint checks specific values or characteristics of a page, object, or text string and
enables you to identify whether or not your Web site or application is functioning
correctly.
Broaden the scope of your test by replacing fixed values with parameters. When you testyour site or application, you can parameterize your test to check how your application
performs the same operations with different data. You may supply data in the Data Table,
define environment variables and values, define test or action parameters and values, orinstruct QuickTest to generate random numbers for current user and test data. When you
parameterize your test, QuickTest substitutes the fixed values in your test with
parameters. When you use Data Table parameters, QuickTest uses the values from adifferent row in the Data Table for each iteration of the test or action. (Each run session
that uses a different set of parameterized data is called iteration.)
Run your test to check your site or application.
8/14/2019 QTP9.2 Course Material
35/35