Swingin' Safari
July 7th, 2009
I’ve been getting into using Swinger, a library that works with Jemmy and Cucumber to test JRuby Swing apps. Such as JotBot
It’s quite the slickness.
It’s still somewhat new, I believe, and I ran into some things that didn’t work quite as I wanted. So, I forked the repo and started adding things (which I hope see added back to the original repo).
The most notable additions so far are some step definitions that allow you to specify a text field by name, instead of by the current content. Very handy, especially if you have several text fields, all empty..
I also had trouble getting forms to appear via a system tray icon menu. I spent some time looking over the Jemmy docs and discussion lists, but found nothing to help me. The best I could do was get a Swing/Cucumber feature run to kick in once I manually clicked open the tray icon’s popup menu and exposed a particular menu. Not quite my goal.
My hack was to give the application being tested a Drb server that allows a client to invoke calls on application classes. Specifically, it works on controller instances. So, rather than work through a series of operations on a systray menu (which isn’t what I’m trying to test), I can invoke FooBarController.instance.open and get the frame I really want to work with.
Now, there are some risks in this. For one, I could end up shipping an app that exposes a direct and inadvertent raw API. I’m not deeply concerned with that; there are easy enough ways to ensure this only works under development conditions.
There’s the real chance I end up with tests that aren’t really testing the application under normal usage. That’s OK, at least for now. Most testing presents some amount of artfice, so it’s something one has to watch anyways.
For these systray menus, all the code does is invoke open on some controller instance; the Drb approach just side-steps having to click menu items. In fact, that was what lead me to try Drb. I simply wanted a way to call those same methods but without having to have a Swing frame. It wasn’t obvious to me how, in Swinger or Jemmy I could “talk” directly to my application except by way of some currently referenced container. So I poked a hole.
I don’t foresee adding this Drb step stuff to my fork of Swinger. I’d have to re-think how it’s done. Right now, it is pretty tailored to Jimpanzee apps, making assumptions that clearly are not valid for all JRuby Swing apps. More likely I will add the creation of Swinger/Cucumber features and steps to the Jimpanzee generator code, or possibly offload that to a Jimpanzee-centric generator driven by Rhesus .
If I think I’ll be using Swinger for all my Jimpanzee apps, it may as well be in that generator; less work for James when starting a new project.
I can perhaps then hook up a more generic template for Rhesus that provides less specific Swinger scaffolding.
Sorry, comments are closed for this article.