Monday, March 28, 2011

Using Jython REPL to explore with SwingLibrary

Today, I was faced with creating an extension keyword to SwingLibrary, and I wanted (of course) to also make a Robot test case testing that new keyword. With non-trivial applications, Swing tests always require quite a bit of setup, many keywords have to be used before the interesting component is available.

Using Robot Framework to get the setup "right" is quite slow, since the turnaround time (= time to execute the test) is quite long, at least some tens of seconds. There is a somewhat faster method of using the SwingLibrary directly from an interactive Jython session. So I fired up Jython with the dependencies in the CLASSPATH:

CLASSPATH=bin:lib/swinglibrary-1.1.3-jar-with-dependencies.jar jython

And did some exploration:

import SwingLibrary
lib = SwingLibrary()
lib.runKeyword('startApplication', ['com.acme.MyFancyApp'])
lib.runKeyword('selectWindow', ['myMainWindow']) 
lib.runKeyword('listComponentsInContext', [])
...


There are a couple things worth noting here:
  1. It is easiest to use the SwingLibrary keywords using the runKeyword-method, since the actual keywords are not methods of the SwingLibrary class.
  2.  When using runKeyword, the arguments are always given in a list and the list has to supplied, even when it is empty.

When the desired workflow is achieved the keywords can be written down in a test case.

No comments: