Logo QF-Test

Tutorial as a practical
introduction to QF-Test

 

Free Trial  Download  Buy

Yann Spöri, QF-Test development & support

The QF-Test examples, demos and practical exercises give you a quick start.

Yann Spöri,
Software Engineer, QFS

Uwe Klüh, Senior Sales Manager, QFS

Search for the information you need in the whole documentation (Manual, Tutorial, Mailing list, Standard library) by using the onsite-search.

Uwe Klüh, Sr. Sales Manager, QFS

Tutorial

7
The Standard Library [30-45 min]

We complete the concept of modularization in this chapter by presenting a standard library of utility functions. Some of the utilities you'll already be familiar with, like operations for dealing with checkboxes. Other utilities will be new. The following sections will cover in detail each of these operations.

There are several things to be learned from this chapter. Most importantly, you'll see a workable utility library (in fact, the library evolved from a very similar library used for regression tests of QF-Test at Quality First Software GmbH). In the process of analyzing the operations contained within, you will hopefully obtain ideas of how to better modularize your own test-suites and simplify the overall testing process.

The procedures within this library should work with any standard JavaFX, Java/Swing, Eclipse/SWT or web application; that is, they were designed independently of any specific SUT. Thus, they should fit the needs of your SUT quite nicely. The library is contained in the file qfs.qft and is included as part of the QF-Test distribution.

To make use of qfs.qft click on the "Test-suite" root node of your test-suite. Within the properties of this node you'll see a table for "Include files". Please add qfs.qft to this list, if it's not already there. A path information is not necessary as the include directory of QF-Test is contained in the library path (see also Reference part of the manual). Now you can select procedures of this library at any procedure-call.

In addition to the description provided in this tutorial you can find HTML documentation of the standard library in a javadoc-like format. The file named qfs_pkgdoc.html is located in the directory qftest-4.1.6/include/qfs_pkgdoc.

7.1
The SUT For Testing

As we've already noted, the standard library to be introduced is not SUT-specific. However, for purposes of demonstration within this tutorial we will use an application specifically tailored for use with the standard library.

Bring up the test-suite StdLibDemo.qft, which - like the suite Options.qft you should be familiar from earlier chapters - is located in directory qftest-4.1.6/doc/tutorial from your QF-Test installation. You should see the following:

Figure 7.1:  The Test-suite StdLibDemo.qft

Start the SUT application by executing the Setup node (as seen). In a few moments, the window of the SUT should appear. If not, it is probably hidden beneath the test-suite.

Figure 7.2:  The SUT for Testing the Standard Library
7.2
The Standard Library

Locate and load the test-suite file qfs.qft, which is located in the qftest-4.1.6/include directory of your QF-Test installation.

Here we see a brief overview of the packages available:

Figure 7.3:  The Standard Library

The suite primarily contains procedures for dealing with Java/Swing and Eclipse/SWT components. The "swing" and the "swt" package contain nearly the same procedures to deal with several components. The structure of both packages is the same, so the following description will cover the Java/Swing as well as the Eclipse/SWT procedures. There are also a couple of other usefule packages included, which are also documented below.

Within all of the procedures of this library, you'll notice that the variable $(client) is referenced. This is a standard mechanism that you'll often see repeated in many test-suites 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. For example, here we see the properties of the "Test-suite" root node of the suite StdLibDemo.qft, in which we set down the value of $(client) as a suite variable. Thus, any nodes executed within the scope of this test-suite (such as the procedure calls to qfs.qft) will have access to the variable.

Figure 7.4:  Setting the $(client) Variable

You could alternatively set the value of $(client) per call to a procedure within qfs.qft. Such a scheme might be useful when you have more than one SUT. Just to hammer this point down, please note that qfs.qft cannot have any default value set for the $(client) variable as this would undesirably couple it to a specific SUT. It is up to you to set a value of the $(client) variable for the standard library to use!

One further note before we continue: you may have noticed from the figure above that we've included qfs.qft within the demonstration test-suite without any direct reference to the directory in which the file is located. This is because the include directory of your QF-Test distribution has been added to QF-Test as an implicit library path for all of your test-suites. This means that any test-suite file located within this directory can be included within your own test-suite. For further library paths, look at the global options for QF-Test under »Edit«-»Options«-»General«-»Library.«

A complete description of all packages and procedures including parameters and return values is given in the library's HTML documentation, also accessible from the QF-Test »Help« menu. The latest version is even available online at http://www.qfs.de/include/qfs_pkgdoc/qfs_pkgdoc.html.

7.3
Selected Packages and Procedures

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

Please note, that following examples are mainly based on the qfs.swing procedures. The procedure of qfs.swt can be used in the same way. Procedures, which are Java/Swing or Eclipse/SWT specific will also be handled at the end of this chapter.

7.3.1
The Checkbox Package

We begin by looking at the qfs.fx.checkbox qfs.swing.checkbox, qfs.swt.checkbox or qfs.web.checkbox package, which are a good starting point as those procedures here should look very familiar if you developed the utils.qft library suite in chapter 6.

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. To see example usage of these procedures, look in the "Checkbox Tests" node of StdLibDemo.qft.

Figure 7.5:  Example Usage of the qfs.swing.checkbox Package

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

7.3.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.3.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.3.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.3.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. Take a look at the example usage "Menu Tests" node. For example, a call to "setSubCheckItem" looks as such:

Figure 7.6:  Example Call to qfs.swing.menu.setSubCheckItem

Here we see the variable arguments needed to implement the procedure call. These arguments are organized as:

menu -> item -> subCheckItem (checkItemValue)

which represent the following implementation within the SUT:

Options -> Tree -> Enable (true)

Clearer may be the actual process as seen within the SUT:

Figure 7.7:  Selecting a Sub-Menu Check Item within the SUT
7.3.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.3.7
The Text Package

The packages qfs.fx.text, qfs.swing.text, qfs.swt.text and qfs.web.text provide utility procedures for text fields and text areas, the need for which you may have already come across while developing test-suites.

  • setText Set the value of a specified textfield.
  • clearField Clear a text field. This procedure cannot be used with a text area.
  • clearArea Clear a text area. This procedure cannot be used with a text field.

Note These procedures are now almost redundant, because "Text input" nodes can clear the target component as needed. However, the procedures might still come in handy now and then.

For each of these procedures, simply pass the QF-Test ID of the text field/area component. Here we see a test within StdLibDemo.qft that uses makes use of the text area component within the SUT. In this test, we first clear the text area and input two lines of text. Then the text area is verified to confirm that it contains the expected test. Following this, we clear the text area again and verify that it is empty.

Figure 7.8:  Example Usage of text.clearArea
7.3.8
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. For example, here we see a call to the procedure to expand a tree node:

Figure 7.9:  Example Usage of tree.expand

Note that in this example, we use a component of a tree node which we recorded earlier. If you look in the "Windows and components" node of the StdLibDemo.qft test-suite, you'll see the individual tree-item components we recorded:

Figure 7.10:  Tree Component Items
7.3.9
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.3.10
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.3.11
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.3.12
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 dirctory.
  • 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.3.13
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.3.14
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.
  • executeStatement Execute a given SQL-command. Here any SQL command can be specified.
7.3.15
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.3.16
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 linebreaks. Variables within a value-set are separated by whitespace or by a given separator character.
Videos Downloads Documentation Buy Free Trial