A guide to Image-Based Testing with HP UFT’s “Insight”

Motivation

One of the main competitive advantages of HP Unified Functional Testing (UFT) is its wide support for different technologies. In fact this is probably my most reused PowerPoint slide:

p1.png

But even after supporting all of these technologies (and more), there are always technologies that that are too rare or complex to justify developing UFT support.

In order to bridge the gap, UFT 11.50 introduced Insight, an image-based form of automation. Insight uses an image in order to identify a test object and is fully integrated into UFT so it can leverage the full range of UFT capabilities such as Record, Learn and Visual Relations Identifiers to name but a few.

When creating a test we sometimes find that UFT provides good support for the whole application—except for one or two little steps. These one or two little steps may make or break the ability to automate the whole application. In these cases, it is best to mix traditional UFT tests with a couple of Insight steps to get the best of all worlds.

The power of Insight comes from the fact that it simply requires a graphical interface—the bare minimum that any GUI system supplies. This means that Insight can be used on unsupported technologies such as Flash, or even on a remote desktop connection.

For the rest of this post I’ll use the Windows Calculator to demonstrate Insight’s capabilities. But don’t allow the simplicity of the examples to distract you from the wide scope of applications that can be automated with Insight.

The Test

Usually UFT is able to give test objects descriptive names. This is done by looking at the test objects properties and using some heuristics to decide which properties are most likely to contain a value that will convey meaning to the test maintainer. However, an InsightObject’s description is based on an image, so UFT has no additional insight (oh the irony) into the properties of the test object and is therefore not able to give the object a descriptive name. To avoid a test that contains only objects with names that look like “InsightObject_2”, “InsightObject_3”, etc., UFT inserts the actual image of the test object into the script, which has the added benefit of making the test understandable and maintainable:

p2.png

(Tip: Double clicking the Insight image will open the test object in the object repository)

Recording

In order to activate Insight during a record session, change the Recording Mode selection to Insight Recording:

p3.png

While in the Insight Recording mode, mouse operations will create an Insight step. Keyboard actions, on the other hand, create WinObject.Type steps. The reasoning behind this is that when a mouse event occurs there are coordinates associated with it and UFT can try to understand which object was acted upon, based on the coordinates. Typing presents more of a problem since UFT cannot, in general, determine which object is in focus. Therefore, the text is associated with the top-level window in focus, for example:

Window("Calculator").WinObject("Text").Type "3"

The InsightObject does support the Type operation. You can use this method in a test to move the focus to a specific InsightObject before typing.

Test Maintainance

Part of the power of Insight is that it captures an image that gives a good representation of the relevant object. Unfortunately, this goal is hindered by the fact that many UI elements nowadays change their appearance when they are interacted with. If Insight captured the image of a UI element when it was hovered over, then UFT could not find it during a run session, because then the element would not be hovered over. For this reason, when recording, Insight captures several images and determines which is the most appropriate to use according to some heuristics. There are cases in which Insight guesses incorrectly, either about which image to choose, or about the bounding rectangle of the UI element. In these cases you can change the image UFT uses for the test object by clicking the Change Test Object Image button:

p4.png

This opens an editor that lets you select a different image from the image history, resize and adjust the location of the rectangle, exclude areas within the image, and modify the test object’s click point (for more details see UFT’s documentation).

p5.png

Exclude Areas

There are cases in which a UI control contains areas that change without affecting the functionality of the control, and therefore make the image less useful for identification purposes. Such areas may change at random (e.g. advertisements), be dynamically generated (e.g. weather forecasts), or contain text which is localized to different languages. By adding Excluded Areas to the image we can specify that only parts of the captured image should be matched against the application, and the other areas can safely be ignored:

p6.png

Similarity

Because applications tend to change over time, Insight does not use simple image matching. Instead, Insight looks for controls that are similar to the image in the description. The best match is always used. However, there is a threshold under which images are not considered to match. If you wish to change this threshold value you can add the similarity property to the InsightObject’s description.

Descriptive Programming

Insight can be used with descriptive programming as well as via the Object Repository. To use descriptive programming, provide a path to an image file as the ImgSrc property of the test object.

Window("text:=Calculator").InsightObject("ImgSrc:=C:\img.png")

The following image file formats are supported: PNG, BMP, GIF and JPEG.

Conclusion

I hope this introduction to Insight object identification provides enough information on how, why and when you should start using this feature. Please let us know how useful you find Insight and what problems it solves for you by leaving a comment in the box below.

You can download HP Unified Functional Testing here.

http://h30499.www3.hp.com/t5/The-Future-of-Testing-Blog/A-guide-to-Image-Based-Testing-with-HP-UFT-s-Insight/ba-p/6355855

猜你喜欢

转载自tjj006.iteye.com/blog/2142724