Qtp 简明教程

QTP - Virtual Objects

What are Virtual Objects?

有时,被测应用程序可能包含标准窗口对象,但未被 QTP 识别。在这种情况下,对象可以定义为按钮、链接等类型的虚拟对象 (VO),以便在执行期间可以在虚拟对象上模拟用户操作。

Sometimes, an application under test may contain standard window object but are not recognized by QTP. Under these circumstances, objects can be defined as virtual object(VO) of type button, link etc. so that user actions can be simulated on the virtual objects during execution.

Example

假设我们在 Microsoft Word 中自动化场景。我激活了 MS Word 应用程序,并单击功能区中的任何图标。例如,在功能区中单击“插入”选项卡,然后单击“图片”按钮。按钮被识别为 WinObject;因此,虚拟对象的重要性变得明显。

Let us say we are automating a scenario in Microsoft Word. I activated MS word application and I click on any icon in the ribbon. For example, on the Ribbon, Insert tab is clicked and then the user clicks the "Picture" button. A button is recognized as WinObject; hence, importance of virtual objects is pronounced.

Window("Microsoft Word").WinObject("Ribbon").Click 145,45
Window("Microsoft Word").WinObject("Ribbon").WinObject("Picture...").Click
170,104

Creating a Virtual Object

Step 1 − 在这种情况下,使用虚拟对象管理器或“工具”>>“虚拟对象”>>“新建虚拟对象”中的新建虚拟对象创建虚拟对象,然后单击“下一步”按钮。

Step 1 − In such scenarios, virtual Objects are created using Virtual Object Manager or New Virtual Object from "Tools" >> "Virtual Object" >> "New Virtual Object" and click the "Next" button.

qtp virtual objects 1

Step 2 − 将对象与类类型映射,然后单击“下一步”。

Step 2 − Map the Object against the Class Type and click "Next".

qtp virtual objects 2

Step 3 − 单击“标记对象”按钮。将出现十字光标,标记您要映射的对象,然后单击“下一步”。

Step 3 − Click "Mark Object" Button. A cross hair cursor would appear and mark the object that you would like to map and click "Next".

qtp virtual objects 3

Step 4 − 选择虚拟对象的父级,然后单击“下一步”。

Step 4 − Select the parent of the Virtual object and click "Next".

qtp virtual objects 4

Step 5 − 命名要存储虚拟对象的集合,然后单击“完成”。

Step 5 − Name the collection in which you would like to store the virtual object and click "Finish".

qtp virtual objects 5

Virtual Object Manager

虚拟对象管理器管理虚拟对象的集合。测试人员可以从虚拟对象管理器中添加或删除虚拟对象。

Virtual object Manager manages the collections of Virtual objects. Testers can add or Delete the Virtual Objects from the Virtual Object manager.

导航到虚拟对象管理器:“工具”>>“虚拟对象管理器”,如下所示 −

Navigation to Virtual object Manager : "Tools" >> "Virtual Object Manager" as shown below −

qtp virtual objects 6

Using Virtual Objects

创建虚拟对象后,可以使用创建的对象,如下所示 −

After creating the Virtual Objects, the created object can be used as shown below −

Window("Microsoft Word").WinObject("Ribbon").VirtualButton("button").Click

Virtual Object Limitations

  1. QTP does not support virtual objects for analog or low-level recording.

  2. Checkpoints cannot be added on Virtual Objects.

  3. Virtual Objects are not controlled by Object Repository.

  4. Though we map an object to a particular class (button or List), all the methods of the native objects are not supported by Virtual objects.

  5. Object Spy cannot be used on Virtual Object.

  6. The test execution will fail if the screen resolution changes as the co-ordinates change.

  7. Application Window should be of same screen size so that Virtual objects are captured correctly.