Tutorial

Video Icon

In the near future we will upload videos for every chapter of the tutorial which will lead you step by step through QF-Test.

7
The Standard Library (Java)

QF-Test provides a certain number of node types. If you need additional functionality you can implement it in a script node. To make life easier for you QF-Test comes with a set of procedures implementing the most commonly needed additional functions. You will find them in the standard procedures library.

When you cannot solve a problem using the provided node types it is a good idea to have a look in the standard library whether there is a solution to your problem. If you find a similar solution you can copy the procedure and adapt it to your needs. For information about scripting please refer the the manual, chapter 12 'Scripting'.

The file qfs.qft holds the standard procedures library. As it is constantly being enhanced and distributed with every new version of QF-Test you should not make any changes to procedures in that file, but copy the procedure to your own test-suite if required and then adapt it.

Note To make use of qfs.qft it needs to be included in your test-suite's root node. With a newly created test-suite the file qfs.qft is added automatically to the list of included files.

  • Action Select the 'Test-suite' root node of your test-suite.
  • Verify the qfs.qft is available within the table for "Include files".
  • Add qfs.qft to this list, if it's not already there.

Note A path information is not necessary for the qfs.qftas the include directory of QF-Test is contained in the library path (see also Reference part of the manual).

  • Action Add a procedure call to an arbitrary procedure from the qfs.qft standard library. In the procedure chooser don't miss to switch to the respective tab.

In addition to the description provided in this tutorial you can find the full HTML documentation of the standard library available via »Help«-»Standard Library qfs.qft...«

7.1
Inspecting the Standard Library

In addition to inserting procedure calls from the Standard Library, it also can be helpful to sometimes have a look how certain things organized or implemented.

  • Action Locate and load the test-suite file qfs.qft, which is located in the qftest-4.2.5/include directory of your QF-Test installation.
Figure 7.1:  The Standard Library

You can see there is one main package qfs that contains further specific packages. The qfs package helps to easily identify the packages belong to the standard library.

The specific packages cover very different areas of utility procedures described in more detail further below.

Note Within nearly all of the procedures of this library, you'll notice that the variable $(client) is referenced. This is the standard mechanism for creating independence from a specific SUT. Here, the library assumes that the test-suite which uses the library will set a value for $(client) prior to using any procedures.

7.2
Selected Packages and Procedures

We will now have a closer look at a number of selected packages and procedures from the standard library.

We will start with packages for accessing components dependent on the GUI technology they are implemented with, say JavaFX, Java Swing, Eclipse/SWT and Web components.

7.2.1
The Checkbox Package

We begin by looking at the qfs.fx.checkbox qfs.swing.checkbox, qfs.swt.checkbox or qfs.web.checkbox package.

Some important procedures within this package are:

  • select Selects (checks) a checkbox. If the checkbox is already selected, then no action is taken.
  • deselect Deselects (un-checks) a checkbox. If the checkbox is already deselected, then no action is taken.
  • set Sets a checkbox to a given state (true or false).

For each of these procedures, you pass the QF-Test ID of a checkbox component as a variable argument. The library handles verification of whether or not the checkbox state was properly set as expected.

Usage of the other procedures in this package follows the general model seen here.

7.2.2
The Combobox/Combo Packages

The packages qfs.fx.combobox, qfs.swing.combobox, qfs.swt.combo or qfs.web.select contain procedures to select a value in a combobox.

Some procedures within this package are:

  • setValue Select a value in the list of the combobox.
  • getItemCount Return the number of entries in the select box.

7.2.3
The General Packages

The packages qfs.fx.general, qfs.swing.general, qfs.swt.general or qfs.web.general contain useful procedures to work with components.

Some procedures within this package are:

  • setLocation Set the location of a given component.
  • setSize Set the size of a given component.

7.2.4
The List Packages

The packages qfs.fx.list, qfs.swing.list, qfs.swt.list or qfs.web.list contain useful procedures to work with lists.

Some procedures within this package are:

  • getItemCount Return the number of items of the list.

7.2.5
The Menu Package

The qfs.fx.menu, qfs.swing.menu, qfs.swt.menu or qfs.web.menu packages allow you to easily select items and checkbox items from menus or sub-menus. The procedures visible after expanding the package node are:

  • selectItem Selects an item from a menu.
  • selectSubItem Selects an item from a sub-menu.

For each of these procedures, you must pass the QF-Test ID of the menus as well as the item and/or sub-item to select or check; the usage varies slightly depending on the nature of the procedure.

7.2.6
The Table Package

The packages qfs.fx.table, qfs.swing.table, qfs.swt.table and qfs.web.table provide utility procedures for tables, like:

  • getRowCount Return the number of rows of a table. It uses technology specific methods to gather the row number.
  • getColumnCount Return the number of columns of a table. It uses technology specific methods to gather the column number.
  • selectCell Select a given table-cell.
7.2.7
The Tree Package

We've provided some simple access procedures for manipulating trees within the packages qfs.fx.tree, qfs.swing.tree, qfs.swt.tree and qfs.web.tree. These include:

  • collapseNode Collapse a node of a tree using separate parameters.
  • expandNode Expand a node of a tree using separate parameters.
  • selectNode Select a given tree-node.

For any of these procedures, you simply pass the QF-Test ID of the node you wish to manipulate.

7.2.8
The Cleanup Package

The packages qfs.fx.cleanup, qfs.swing.cleanup and qfs.swt.cleanup are useful for generic cleanup of the SUT environment after an unexpected exception occurs. Imagine, for example, that an exception is thrown while attempting to manipulate a menu in the SUT. The exception will cause the execution path within your test-suite to be re-directed to an exception handler of a Catch node or of a dependency, or an "implicit" exception handler. This means that the normal flow of execution, which would have properly closed the open menu, has now been interrupted. Without proper action, that menu could be left open and thus block other events directed to the SUT.

Some important procedures within this package are:

  • closeAllModalDialogs Ensure that modal dialog windows of the SUT are closed. only available for Swing and FX!
  • closeAllDialogsAndModalShells Ensure that dialog and modal shells of the SUT are closed. only available for Eclipse/SWT!
  • closeAllMenus Close all menus of the SUT unconditionally.

The concept of implicit exception handling is an important one as an exception in a single test-case is not meant to stop the whole test-run. Just the current test-case needs to be aborted and then continue with the next test-case.

Therefore, an exception raised during the course of a Test-case will be caught at that level and not propagated to prevent aborting the whole test-run. The error state is duly noted in run-log and report however.

If the Test-case uses a Dependency the exception is passed to the Catch node of the same, if available. This kind of exception (and error) handling is described in the Dependency chapter of the manual.

7.2.9
The Run-log Package

The qfs.run-log package contains procedures, which writes specified messages into the run-log. This package has been introduced to give testers without scripting-knowledge the opportunity to write messages into the run-log.

Here is the list of the most important procedures within this package:

  • logError Write a given error message into the run-log.
  • logWarning Write a given warning message into the run-log.
  • logMessage Write a given message into the run-log.
7.2.10
The Run-log.Screenshots Package

The qfs.run-log.screenshots package contains procedures, which write images into the run-log and some helper methods.

Some important procedures within this package are:

  • getMonitorCount Return the total number of monitors.
  • logScreenshot Write a screenshot of the whole screen into the run-log.
  • logImageOfComponent Write an image of a given component into the run-log.
  • logScreenshotOfMonitor Write a screenshot of a given monitor into the run-log.
7.2.11
The Shellutils Package

The qfs.shellutils package contains procedures to support most common shell-commands.

Some important procedures within this package are:

  • copy Copy a given file or directory to a specified target.
  • deleteFile Delete a given file.
  • exists Check for existence of a given file or directory.
  • getBasename Return only the file name of a full file name.
  • getParentdirectory Return only the directory name of the full file name.
  • mkdir Create a given directory. It also creates non-existing directories in path.
  • move Move a file of directory.
  • touch Create a specified file.
  • removeDirectory Remove a specified directory.
7.2.12
The Utils Package

The qfs.utils package contains procedures, which covers common helper-functionality during test-development.

Some important procedures within this package are:

  • getDate Return a string containing the date. Default is the current date. (Other dates can be configured.)
  • getTime Return a string containing the time. Default is the current time. (Other timestamps can be configured.)
  • logMemory Log current memory use.
  • printVariable Print the content of a given variable to the console.
  • printMessage Print a given message to the console.
  • writeMessageIntoFile Write a given string into a given file.
7.2.13
The Database Package

The qfs.database package contains procedures to execute SQL commands on a database.

Please note, that the class of the database-driver must be in QF-Test's plugin directory or in the CLASSPATH before QF-Test startup.

To get more information about the connection-mechanism to your database, please ask your developers or see www.connectionstrings.com.

Some important procedures within this package are:

  • executeSelectStatement Execute a given SQL-Select-Statement. It stores the result in a global variable "resultRows" on the Jython variable stack and thus accessible from Jython scripts. Additionally, it stores the result in a group variable with the default name 'resultGroup', which can be accessed directy by QF-Test nodes.
  • executeStatement Execute a given SQL-command. Here any SQL command can be specified.
7.2.14
The Check Package

The qfs.check package contains procedures to do checks.

Some important procedures within this package are:

  • checkEnabledStatus Check, whether a component is enabled or disabled. It writes an error into the run-log, if failing.
  • checkSelectedStatus Check, whether a component is selected or not. It writes an error into the run-log, if failing.
  • checkText Check the text of a component. It writes an error into the run-log, if failing.
7.2.15
The Databinder Package

The qfs.databinder package contains procedures for execution within a "Data driver" node which bind data for iteration.

Some important procedures within this package are:

  • bindList Create and register a databinder that binds a list of values to a variable. Variables are separated by whitespace or by a given separator character.
  • bindSets Create and register a databinder that binds a list of value-sets to a set of variables. Value-sets are separated by line breaks. Variables within a value-set are separated by whitespace or by a given separator character.