Example - Automating file dialogs with type() and nativeType()

Skip to end of metadata
Go to start of metadata

Table of Contents


It is possible to automate interaction (but not necessarily record the same) with file dialogs across machines that have the same operating system but different file system layouts, and even across machines that have different operating systems (and therefore different file dialogs).

The key to achieving this is to use the type() (for Java, Mac OS X, Qt, Tk, Windows) or nativeType() function.

In case of nativeType() (which sends the key presses to whatever window which has the focus) this works because commonly file dialogs get the input focus into a text field for entering a file name or path when they appear on the screen.

Toolkit specific automation using type()

The above automation approach works with most editions of Squish, but it does not provide any control over which widgets are currently available for input.

To make the file dialog interaction more robust — at the price of making it toolkit-specific, instead of the above approach, record the entering of a filename and a Return keypress (or OK or Open button click). For example:

Toolkit agnostic automation using nativeType()

This workaround does not work with Qt 5.5.1 due to bug QTBUG-49782 in Qt itself.

The following approach should work for most Squish editions because it does not require any object references. However, its successful use depends on two assumptions:

  1. The file dialog opens within the anticipated amount of time.
  2. After opening, the file dialog's filename input field has the keyboard focus.
Mac OS X-specific
By default Mac OS X file dialogs do not show a filename editing field by default. Nonetheless, this can be worked around: see [Example - Automating native Mac OS X file dialogs with nativeType()]
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.