Skip to content
jussimalinen edited this page Feb 28, 2013 · 12 revisions

Getting Started

SwingLibrary is a Swing GUI testing library for Robot Framework.

SwingLibrary uses a Netbeans tool called Jemmy as it's internal driver.

Taking Library Into Use

To take the library into use in the test suite, simply specify it in the settings table. E.g.

Setting Value
Library SwingLibrary

The SwingLibrary.jar needs to be in the class path during execution. You can get the jar either from the download page, or as a Maven dependency:

<dependency>
  <groupId>org.robotframework</groupId>
  <artifactId>swinglibrary</artifactId>
  <version>1.3</version>
</dependency>

Locating Components

In order to interact with the Swing Gui components, first a desired context must be selected by using for example Select Window or Select Dialog keyword. After that the Swing components can be located in the selected context using a desired keyword with an identifier.

Identifier can be:

  • The logical name of the component given by the developer (preferred option)
  • The index of the component in it's own category. E.g. the 3rd button in the context. (As usual in this trade, the component indexing starts from the 0 which is the index of the first component)
  • Title, label or text of the window or dialog

Examples:

Test Add Todo Item
    Select Window  Todo List
    Insert Into Text Field  description buy milk
    Push Button  Add
    Select From List  todolist  0
    ${item}=  Get Selected Value From List  todolist
    Should Be Equal  ${item}  buy milk

The previous test:

  1. Selects a window titled "Todo List"
  2. Inserts text "buy milk" into text field with logical name "Todo Item"
  3. Pushes a button with logical name "Add" given by the developer
  4. Selects the first item (index 0) of the list logical name "todolist"
  5. Gets the value of the selected item
  6. Compares the value with the expected value "buy milk"

Tools to help component discovery

There are a couple of ways to find out what components there are in a given context. Keyword List Components in Context can be used in a Robot test as a debugging tool. It is also possible to use an external tool such as JSpy to inspect the component hierarchy of a Swing application.

Swing Explorer

Swing Explorer is a tool for Swing developers intended for visual exploring of a Swing-based application internals.

Download the Swing Explorer and start your SUT using its Launcher (with the swexpl.jar also in the class path):

java -cp swexpl.jar org.swingexplorer.Launcher <The SUTs Main Class>

For a quick trial, download and extract the SwingLibrary Demo and the swexpl.jar. Copy the swexpl.jar to the demo's lib directory and execute:

java -cp lib/swexpl.jar:lib/registration-0.1.jar org.swingexplorer.Launcher org.robotframework.registration.Main

The Registration demo application and the Swing Explorer windows should appear and the exploring of Swing application can be started.

For more information, refer to the Swing Explorer documentation.

Clone this wiki locally