Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Creating a visual relation Identifier for object Identification

A visual relation identifier is a set of definitions that enable you to identify the object in the application according its neighboring objects in the application. Virtual relation identifier can be useful to identify objects that are not uniquely identified using object properties but can be identified based on relative position of other stable and uniquely identified objects in the application.


Creating a visual relation identifier for an object


1. To create a visual relation identifier for an object, go to object repository window and select the object for which visual relation identifier needs to be created.

2. In the Visual Relation Identifier Settings row, click in the Value cell.

3. Click the Browse button in the text box

4. Define relation of object relative to other objects.


Visual relation identifier


Some Important points to remember about visual relation identifier are:


1. Visual relation identifier are taken into consideration if object is not uniquely identified using the object identification Properties.

2. Visual relation identifier have preference on smart identification for object recognition.

3. Ordinal Identifiers are ignored if visual relation identifier is defined for an object.

4. Visual Relation identifier are created for an object based on relative position of other stable object, i.e. objects existing left, right, top , bottom relative to object to be identified can be used for relative identifier.

5. Relative Objects should exist in object repository before a relation can be created.

6. Relative visual identifier cannot be used in Descriptive Programming as objects should exist in OR.

7. This is used to filter in case of multiple objects in the application matching object definition but are placed relative to other object in application.

8. If no objects in the application match the test object’s description properties, then the visual relation identifier you defined is ignored.

9. Visual relation identifiers are not supported for WebService test objects.



How to use Regular Expressions in QTP


Regular expressions are used to identify objects and text strings with varying values. Regular Expression are strings that defines search phrase based on special character provided in the expression.This is useful when expected value of any object property is regularly changing but in a fix pattern.

Some useful points to remember about Regular Expressions are:


  • Regular Expression is useful for following scenarios in QTP:
    • Defining the property values of an object in dialog boxes or in programmatic descriptions
    • Defining expected values for checkpoints
    • Defining pop-up window conditions in a recovery scenario.
  • Can create regular expression for strings only.
  • Period (.), hyphen (-), asterisk (*), caret (^), brackets ([ ]),parentheses (()), dollar sign ($), vertical line (|), plus sign (+), question mark (?), and backslash (\) are special characters used to create regular expression.
  • When one of above mentioned special characters is preceded by a backslash (\), QTP treats it as a literal character.
  • By default, the value of all Property objects added to a Properties collection are treated as regular expressions.

Below are the various regular expressions used in QTP.

  • Matching Any Single Character (.) eg abc. Will match abc followed by any character.

  • Matching Any Single Character in a List ( [xy] ) e.g [ab] will match either a or b

  • Matching Any Single Character Not in a List ( [^xy] ) e.g 1[^23] will match all values between 11 to 19 except 12 and 13.

  • Matching Any Single Character within a Range ( [x-y] ) e.g : 1[1-3] will match 11,12, and 13.

  • Matching Any AlphaNumeric Character Including the Underscore ( \w )

  • Matching Any Non-AlphaNumeric Character (\W) will match any special character other than underscore. Please note case of W in this case.

  • Matching Zero or More Specific Characters ( * ) This matches zero or more occurrences of the preceding character. e.g ca* will match caa,caaaa,c and so on. Similarly c.* will match c, cs,caaa, and so on, since preceding character here is “.”.

  • Matching One or More Specific Characters ( + ) Only difference from * is it will match for minimum one character. e.g ta+r will match taar,tar but not tr as in above case.

  • Matching Zero or One Specific Character ( ? ) A question mark (?) instructs QTP to match zero or one occurrences of the preceding character. For example: te?r matches ter and tr, but nothing else

  • Matching One of Several Regular Expressions ( | )  e.g new|day will match either of new or day. If we write ne(w|d)ay, it will match neway or neday.

  • Matching the Beginning of a Line ( ^ ) This will match only if match is found at beginning of line.

  • Matching the End of a Line ( $ )  This will match only if match is found at end of line.

  • Matching a word at boundary(\b) e.g new\b will match testnew but not in knewit.

  • Matches a digit character(\d)  Matches a digit value.

  • Matching a non-digit character(\D) Matches a non digit value

For understanding of regexp object for regular expression, Click here


Object Repositories in QTP:Understanding Types and Collection Object.


Object Repository stores all the objects learned in the application. An Object repository is automatically created when we record in the application. Object can also be added in object repository through object spy and Navigate and Learn objects.

Following are important points to remember about object repositories:

  • Objects are stored in tree structure in OR with child objects linked to parent objects.
  • Objects in Local OR and shared OR can be accessed/modified through Object Repository window and Object repository manager window respectively.
  • Objects in OR can be added through:
o    Recording mode
o    Active screen
o    Using Object Spy
o    Using Navigate and Learn through Object repository window.
  • Objects can be added with expected properties defined manually in OR. This is useful in case application is not ready, but we know the expected property for objects.
  • Copying or moving an object to be a child of a bottom-level object in the object hierarchy is not allowed.
  • Property value and name of object in object repository can be modified.
  • Modifying the name of a test object in the local object repository is automatically updated in both the Keyword View and the Expert View for all occurrences of the test object.
  • We can highlight objects from OR in application.
  • Object from object repositories can be dragged and drop in the expert view. Hierarchy Tree of the object is visible in expert view on dragging object from OR.


There are two types of Object Repositories:


1. Local Repository

Objects are automatically added in Local Object Repository once they are learned from the application.

Following are important points to remember about Local Object Repository:

  • If an object with the same name is located in both the local object repository and in a shared object repository associated with the same action, the action uses the local object definition.
  • Local Object Repository is associated with the action in which it was created. You cannot associate Local object repository with multiple actions. Due to this, they are useful mainly in single action.
  • If child objects are moved from shared OR to local OR, parent objects are also added to Local OR.


2. Shared Object Repository


A shared object repository stores objects in a file that can be accessed by multiple tests (in read-only mode).

Following are important points to remember about Local Object Repository:

  • Same Shared Object repository can be added for multiple actions.
  • Shared OR can be dynamically associated with tests and multiple actions.
  • Shared OS is saved with extension .tsr
  • Objects from local OR can be exported to shared OR.
  • An Action can have multiple Shared object repository associated.
  • A shared repository can be edited by one person at a time and is locked for other user
  • Using OR comparison tool, we can compare the objects in 2 different shared OR
  • Using Object repositories Merge tool, we can merge two shared OR and create a new OR with objects from both the OR’s.

Associating Repositories with Action

We can associate object repositories with action in following ways:

Through QTP Interface


Navigate to Resources>Associate Repositories. Click on + icon and select repositories. Note we can add shared object repository only. Next Select Actions from available Actions and move required actions to Associated Actions.



Associating Repositories with Actions
























Using Object Repositories collection


We can add object repositories using ObjectRepositories Collection

Below code snippet shows how to add ObjectRepositories using QTP AOM

Public Function func_AddORToTest(TestName, ActionName, ORName)
''Create an object of qtp
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True

qtApp.Open TestName
Set qtRepositories = qtApp.Test.Actions(ActionName).ObjectRepositories


' Add MainApp.tsr if it's not already in the collection
If qtRepositories.Find(ORName) = -1 Then ' If the repository cannot be found in the collection
qtRepositories.Add ORName, 1 ' Add the repository to the collection
End If
'Save the test and close QuickTest
qtApp.Test.Save
qtApp.Quit 


Set qtRepositories = Nothing
Set qtApp = Nothing

End Function