-
Notifications
You must be signed in to change notification settings - Fork 67
Getting Started
SwingLibrary is a Swing GUI testing library for Robot Framework.
SwingLibrary uses a Netbeans tool called Jemmy as it's internal driver.
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.7</version> </dependency>
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 Todo Item 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:
- Selects a window titled "Todo List"
- Inserts text "buy milk" into text field with logical name "Todo Item"
- Pushes a button with logical name "Add" given by the developer
- Selects the first item (index 0) of the list logical name "todolist"
- Gets the value of the selected item
- Compares the value with the expected value "buy milk"
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 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 and swag.jar also in the class path):
java -cp swexpl.jar;swag.jar org.swingexplorer.Launcher <The SUTs Main Class>
For a quick trial, you can try testing the demo application that comes with swing library. Download the latest swinglibrary-x.x.jar, swexpl.jar, and swag.jar. Copy the jars to the same directory and execute (replacing the swing library version number with yours):
java -cp swexpl.jar;swag.jar;swinglibrary-1.9.4 org.swingexplorer.Launcher org.robotframework.swing.testapp.examplesut.TodoListApplication
The 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.