My Agile/Automated GUI testing software: A sample script

[Note: This post was originally written in 2010, and some of the code was written years before that.]

I’m still debating on the name of my GUI testing software. I initially called it XGT, for eXtreme GUI Testing software, as a reminder to myself that I should push the envelope with it (be extreme, don’t compromise). Then I started calling it Agile GUI Testing, because I think the code and the approach is as agile as you can get. But the one word that was missing is automated, so at the moment I’m calling it Automated GUI Testing, or AGT. None of that matters at the moment, but after pounding away on it some more last night, I thought I'd share a sample script of how this software works.

To that end, here’s a sample Automated GUI Testing software script that does the following:

  • Brings a Google Chrome window to the foreground
  • Opens the alvinalexander.com website in a window
  • Opens a new Chrome tab
  • Opens the OneMansAlaska.com site in that new tab

This quite possibly demonstrates the first call of an AppleScript script from JRuby, so I think that's kinda funny, and also very useful. I think it demonstrates the power of having Ruby, JRuby, and Java as a scripting language.

Automated GUI Testing software: An example script

Here’s the source code for my example AGT script:

require 'java'
require 'AgileGuiTesting'
require 'AGTMacOsX'

#----------------------------------------------------------------
# PURPOSE: A little script to demonstrate AGT with Google Chrome.
# PRECONDITIONS:
#   - You’re running a MacOS system
#   - Chrome is installed
#   - Chrome is not running
# POSTCONDITIONS:
#   - Chrome will be left open, with two new tabs open
#----------------------------------------------------------------

foreground 'Google Chrome'

# i should use a `wait_for_color` or `wait_for_image` call here,
# but i'm being lazy
wait 3000

c 'get the mouse out of the way'
move_mouse_animated 30, 200
wait 250

# note: the VK_* keys are defined in AGTKeys.rb, and get imported here,
# so this is not a string, it refers to `KeyEvent::VK_L`.
c 'putting focus in the Chrome url field'
apple VK_L

# note: could use VK_ENTER at the end, but that’s more work
c 'opening AA.COM ...'
type 'alvinalexander.com \n'

c 'waiting X seconds ...'
wait 4000

c 'new tab, then go to oma site'
apple 't'

# used to be a `\n` at the end of this string
c 'go to the OMA site; url field should automatically gain focus'
type 'www.onemansalaska.com \n'

I hope you’ll agree that this GUI testing script is very easy to read. It would be even smaller if I left out the comments that make it easier to understand here. Also, as you can see, the code doesn’t rely on X/Y coordinates and mouse clicks to work, although AGT can do that as well. The one weakness in this script is that it uses the “wait [ms]” approach, and I would never do that in production testing code. There are better methods in AGT that let you wait for other things, such as changes in colors onscreen.

Summary

Although this is a simple use of my Automated GUI Testing software, I think you can see that the language is very simple and clean. In addition to being simple and clean, the programming language used under the covers is JRuby, which in turn means that you have all the power of the Ruby and Java programming languages at your disposal, which I think is pretty cool.

Again, I will be release my Agile GUI Testing software later this week, so please stay tuned.

Also, many thanks to several people on the Apple java-dev mailing list, who helped me through some problems with some Java Robot code yesterday.

Update: Agile/Automated GUI testing software

My Agile/Automated GUI testing software now has a little home page. Just follow that link for downloads and support documents for my AGT software.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.