En cliquant sur le bouton Play, vous téléchargez une vidéo de notre fournisseur externe YouTube. Protection des données

Scripting in QF-Test (basics)

Here you will learn about the basics of scripting in QF-Test and get a demonstration for using the SUT script and Server script nodes.

Further information: Scripting in QF-Test (Manual)

Transcript

Welcome to this video about the scripting capabilities of QF-Test.

Today I will give you an overview of how to use scripts in QF-Test.

In addition to event nodes such as mouse clicks or checks and control structures such as loops or if nodes, QF-Test also offers the possibility to integrate arbitrary code snippets implemented in various scripting languages into the test run. Such scripts can greatly extend the functionality of QF-Test.

Script Types

To insert such a script, I select insert control structures from the menu and then Server or SUT script.

  • Unlike a Server script, an SUT script can interact directly with the system under test and therefore also determine the properties of graphical objects at runtime.
  • A Server script on the other hand should be used for actions that are independent of the graphical user interface such as database or file operations.

I am now adding an SUT script to my test suite. There are several scripting languages available for implementation. In the current version of QF-Test, there are Jython, Groovy, and JavaScript.

SUT script example

A simple example of an SUT script is the count of rows in a table and then to write this row count to the QF-Test run log. We will now implement the script in the Groovy scripting language:

def table = rc.getComponent("#VehicleTable")
def rows = table.getElementsByClassName("TableRow")
def rowCount = rows.size()
rc.logMessage("Table has " + rowCount + " rows.")
  1. In line one of the script, the table is retrieved from the test application and stored in the variable table.
  2. In line two, the table rows are retrieved into a list
  3. and stored in line three in the variable rowCount with the length of this list.
  4. Line four finally writes this row count to the QF-Test run log.

Pseudo DOM API and accessing native Java component methods

To read the properties of web components, QF-Test offers its own DOM API which is documented in the manual and provides simple methods for accessing DOM properties and HTML elements.

This approach works for every supported technology but the method names may be different because they are technology-dependent. You will find information on this in the respective documentation. For applications with Java Swing, methods can be assessed directly.

When I now run the script, the number of table rows is written to the QF-Test run log, which we can see accordingly.

The QF-Test run context

Let’s go back to the script. You can see in line one and in line four that a variable rc is used there. This stands for the QF-Test run context and offers you options for interacting with QF-Test methods and scripts. In our case, the aim is to identify a graphical component, our table, and write a message to the QF-Test run log.

The run context also allows you to write your custom error messages to the run log or execute entire checks.

The script editor also offers auto-completion for rc. So you type rc., press Control+Space, and now you will see all supported methods and the corresponding documentation.

An example server script

A typical use case for a server script is to write a message or variable content into a file. You can see such a server script here now in the Jython scripting language:

value = rc.getStr("nameOfVehicle")
fh = open ("testfile.txt", 'w')
fh.write("Vehicle is : " + value)
fh.close()
  1. In line one, the QF-Test run context is assessed again and the content of a variable is determined which was previously set somewhere in the test run.

Outlook

Scripts and QF-Test allow you to extend your tests with any logic and simplify some complex tasks. However, scripts and QF-Test can do much more. Scripts allow you to develop so-called Resolvers that optimize QF-Tests component recognition for your application. Alternatively, you can use a TestRunListener to add additional logic to the test execution. In addition, QF-Test offers many other interfaces which you can learn more about in our detailed manual.

You have now learned the most important basics about scripting support in QF-Test. In the QF-Test Help menu, you will find further links to three available scripting languages and their documentation and tutorials. The QF-Test manual contains several chapters explaining scripts and their possible uses with many examples. Take advantage of this powerful feature to further advance your test automation.

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.