Saturday, December 1, 2012

Visual Relation Identifier

Visual Relation Identifier (VRI) helps to identify application objects based on other objects that are always nearby.

This enables you to create a more reliable identification definition of a test objects that are otherwise difficult to differentiate and to ensure that the identification remains reliable even if the UI is changed. [QTP Guide]

Below you can look at Visual Relation Identifier with the help of a simple example:

I have created 3 buttons and text corresponding to those using HTML. For example write the below text in Notepad and save it as .html file (I saved it as a.html).

When you open this file using IE, it will look as below:

Now open QTP and then open this file (a.html) in IE.
Open a new test.
Select Resources -> Object Repository or do Ctrl + R.
Object Repository opens.
Select Object -> Add Objects to Local.
Click on 'Click Me' button corresponding to text "Two".
Object Selection - Add to Repository dialog opens, click ok.

That button will be added to Object Repository with Ordinal identifier of 1. Let this Object Repository window remain open.

Now lets delete the button corresponding to text two from IE (meaning from a.html file) so that now our file looks like as below.

Now from Object Repository window click on 'Highlight in Application' button from View menu. It will highlight the 'Click Me' button corresponding to text three, but this was not the button we added in repository, right? We added button corresponding to text two.

Now we will look as to how this problem can be resolved by using VRI.

Again add button two , so the a.html will look like below

In OR window, add VRI’s value

Click on 'Click to add'. Click on browse button.
VRI window opens. You will see two buttons + and X. Click on + button.
Select Test Object window opens. Expand the selection.

Select 'Click Me!' and below click on hand icon where it says "Click to select an object from Application".
Click on text Two. Object selection dialog opens. Click ok.
VRI dialog opens, with 'Click Me' under Related Objects. Under Relation details check the first checkbox and choose Right from dropdown and also check the below checkbox which says In Line (horizontally).

Now when you click on Preview as below, it will highlight the Text which is in relation to this click Me button.

Now try to delete this text Two and its corresponding button from file so that file looks like:

And click on 'Highlight in Application' button from View menu from OR.
This time it will show an error and will not identify the wrong object.