Annotating screenshots with QF-Test

It is well known that, for many people, a picture is worth a thousand words. Accordingly, screenshots are an important part of QF-Test.

In my last blog article “Creating Screenshots with QF-Test” I went into how exactly to create screenshots manually.

Today I would like to demonstrate how to edit such images with QF-Test, for example to insert simple geometric figures. This can be very useful to highlight certain regions in the image – for example a click position or a certain component.

Let’s start by getting an image of a window component in a Jython SUT script:

from imagewrapper import ImageWrapper

iw = ImageWrapper(rc)

com = rc.getComponent("#Window:")
img = iw.grabImage(com)

Next, we get the necessary data for image processing, namely the width of the image and the ARGB array to be processed:

width = img.getWidth()
argb = img.getARGB()

The ARGB array contains the color values of all pixels of the image, line by line, starting from the upper left corner.

For example, to address the fourth pixel in the third row of the image, the value with index 4 + 3 * width must be addressed in the array.

The color value first specifies the alpha value, then the red value, the green value and finally the blue value of the pixel, where each value can be anything between 0 and 255.

So now we can modify the array to add a 15 × 15 pixel red cross at any position. The following code can be used to do this. For this example, it is important to maintain at least a 15 pixel gap from the edge of the image, otherwise the cross will appear messed-up.

# Get coordinates from QF-Test variables
x = rc.getInt("x")
y = rc.getInt("y")

for i in range(-15, 15+1):
    pos = x + y * width + i + i * width
    argb[pos] = 0xFFF0000
    pos = x + y * width + i - i * width
    argb[pos] = 0xFFF0000

Finally, we need to pass this array back to the image object and then save the image object in the run log, for example, to make it available to another user:

img.setARGB(argb)
rc.logImage(img)

Once everything is said and done, we get the following complete script:

from imagewrapper import ImageWrapper

iw = ImageWrapper(rc)

com = rc.getComponent("#Window:")
img = iw.grabImage(com)

width = img.getWidth()
argb = img.getARGB()

# Get coordinates from QF-Test variables
x = rc.getInt("x")
y = rc.getInt("y")

for i in range(-5, 5+1):
    pos = x + y * width + i + i * width
    argb[pos] = 0xFFF0000
    pos = x + y * width + i - i * width
    argb[pos] = 0xFFF0000

img.setARGB(argb)
rc.logImage(img)

“X” marks the spot.

In the same way you can also draw circles, rectangles or any number of similar geometric figures on the drawing surface using the corresponding mathematical functions.

We use "Matomo" cookies to anonymously evaluate your visit to our website. For this we need your consent, which is valid for twelve months.

Cookie Configuration

Functional cookies

We use functional cookies to ensure the basic functionality of the website.

Performance and statistics cookies

We use Matomo for analyzing and optimizing our website. Cookies permit an anonymous collection of information that help us offering you a clear and user-friendly visit of our web pages.

Cookie details
Description Vendor Lifetime Type Purpose
_pk_id Matomo 13 Months HTTP Contains a unique, pseudonymized visitor ID internal to Matomo for recognizing returning visitors.
_pk_ref Matomo 6 Months HTTP Used to track from which website the anonymized user proceeded to our website.
_pk_ses Matomo 1 Day HTTP The Matomo session cookie is used to track the visitor's page requests during the session.
_pk_testcookie Matomo Session HTTP Used to check whether the visitor's browser supports cookies.
_pk_cvar Matomo 30 Minutes HTTP Temporarily store data about the visit.
_pk_hsr Matomo 30 Minutes HTTP Temporarily store data about the visit.