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.

Nous utilisons des cookies "Matomo" pour l'évaluation anonyme de votre visite à note page web. Pour cela nous avons besoin de votre consentement qui est valable pour douze mois.

Configuration de cookies

Cookies fonctionnels

Nous utilisons des cookies fonctionnels pour garantir la fonctionnalité de base du site web.

Cookies de performance et de statistique

Nous utilisons Matomo pour analyser et améliorer notre site web. Des cookies permettent une collection anonyme des informations qui nous aident à vous offrir un visite clair et facile à utiliser de nos pages web.

Détails des cookies
Description Fournisseur Durée de vie Type But
_pk_id Matomo 13 Mois HTTP Contient un identifiant de visiteur unique et pseudonymisé interne à Matomo pour reconnaître les visiteurs qui reviennent.
_pk_ref Matomo 6 Mois HTTP Utilisé pour suivre à partir de quel site Web l'utilisateur anonymisé est arrivé sur notre site Web.
_pk_ses Matomo 1 Jour HTTP Le cookie de session Matomo est utilisé pour suivre les demandes de page du visiteur pendant la session.
_pk_testcookie Matomo Session HTTP Utilisé pour vérifier si le navigateur du visiteur prend en charge les cookies.
_pk_cvar Matomo 30 Minutes HTTP Stocker temporairement les données relatives à la visite.
_pk_hsr Matomo 30 Minutes HTTP Stocker temporairement les données relatives à la visite.