Pages

Saturday, May 10, 2014

Quick Test Professional (QTP) - How Objects are Added to Object Repository(OR)

QTP stores a definition for each test object in the object Repository. The definition contains values for various parameters which are used to uniquely identify an object at runtime in the application under test(AUT). The QTP object repository manager is used to view and modify repository objects and their properties.

Figure 1: Object Repository

Figure 1 shows a simple object repository. This OR has a WinToolbar object which is identified with Logical Name of Runtime Application" and has two property for definitions: "text" and "nativeclass". We can add or remove the properties by clicking the Add/Remove button...button.

Figure 2: Add/Remove Properties

Figure 2 shows the Add/Remove Properties dialog which can be used to add or remove any of the properties from object identification.

Note:

  • Selecting an objects from the tree view and clicking the Highlight button will highlight the button in the application (that needs to be open). The same can be done in the code for highlight objects at runtime Window("Window").WinToolbar("RunnningApplcation").Highlight.

Objects can be added to object repository using one of the two methods:

  1. By recording interactions against the application under tests
  2. By manually adding one or more objects 
Objects can be manually added to the OR clicking on Add Objects button and then clicking on the object that needs to be added.

Note:

  • In case the objects we want to add appears after a mouse click, then press and hold Ctrl key prior to that mouse click. This temporarily disable the object selection mode and allows to perform mouse click operations to navigate.
  • In case we need to switch between applications, first CTRL+ALT to disable the object selection mode. Then we can switch between different application and use the key combinations like ALT+TAB etc. Once done, press the CTRL+ALT to enable the object selection mode add the object.

Once the object is detected QTP displays the object selections window

Figure 3: Object Selection - Add to Repository
Object Selection

The object selection window displays the complete hierarchy of the objects on the web page. Select the object which needs to be added and click on OK button.

Note:

  • The object hierarchy displayed might not be the same as the one recorded in the Object Repository. QTP only keeps the hierarchy which is necessary for it to identify the object. This also reduces the length of the code line when the object reference is used in a test script.

If we select the page object and continue, QTP will ask if we want to add all its child objects.

Figure 4: Object Selection options
Selecting the Selected Object and all its descendants radio button and then clicking OK will add all the objects present on the page.

Note:
  • QTP does not add hidden objects present on the page


Test and Run-time objects

Test Objects (TO): Test objects are QTP defined classed used to present the various objects in the application under test (AUT).

Run-time objects (RO): Run-time object are the actual AUT object which a Test object refers/points to during test execution.

TO Properties

Test objects properties are those properties that QTP maintains in the OR for identifying a Run-time object during test execution. QTP allows enumeration of all the TO properties using GetTOProperties. GetTOProperty and SetTOProperty are used to read or modify the TO property values respectively.

Example 1: Working with Test Object properties

‘Get the webedit object
Set oWebEdit = Browser(“”).Page(“”).WebEdit(“”)

‘Get the TOProperties collection
Set TOProps = oWebEdit.GetTOProperties()

Dim i, iCount
iCount = TODrops.Count – 1

‘Loop through all the properties
For i = 0 To iCount
    ‘Get Name of the property
    sName = TOProps(i).Name

    ‘Get the value of the property
    sValue = TOProps(i).Value

    ‘Is the value a regular expression?
    isRegularExpression = TOProps(i).RegularExpression

    ‘Display the values
    Msgbox sName & “->” & sValue & “->” & isRegularExpession
Next


Example 2: Changing Test Object properties at runt time

‘Get the webedit object
Set oWebEdit = Browser(“Browser”).Page(“Page”).WebEdit(“txtName”)

‘Get the name test object property
oldName = oWebEdit.GetTOProperty(“name”)

‘Change the test property
newName = oWebEdit.GetTOProperty(“name”)

MsgBox newName


Example 3: Getting Run-time object properties during test execution

We use GetROProperty to read the value of any Run-time property, and save the value into a variable.
‘x will have the text present the search edit box.
x = Browser(“”).Page(“”).WebEdit(“”).GetTOProperty(“Value”)
MsgBox x

Note:
  • QTPdoes not provide a method set Run-time object properties i.e. there is no SetROProperty. Also each different test object has a different list of supported property values which is defined in the object model references in QTP help.


No comments:

Post a Comment