GUI testing of the Google Chrome browser

[Note: This blog post was originally written in 2010.]

Yesterday I created a short YouTube video demonstration of some simulated “GUI regression tests” against the Google Chrome browser, using my Automated GUI Testing (AGT) software. That video is a little more than two minutes long, and demonstrates some simple GUI regression tests on the Chrome browser, in the format of a presentation.

As mentioned, the Chrome browser tests shown in that video are completely automated, using my AGT software to drive both the regression tests and the presentation using Keynote on MacOS.

Script for the Chrome browser GUI tests

In order to help you better appreciate that Chrome browser GUI testing video — and also see the simplicity of the AGT scripting language — here’s the source code for my Chrome browser GUI testing script:

#
# simple gui regression tests for the google chrome browser,
# in the form of a keynote presentation.
#
require 'java'
require 'AgileGuiTesting'
require 'MacOsX'

# a method play the keynote slideshow
def play_slideshow
  @robot.keyPress(VK_ALT);
  @robot.keyPress(VK_META);
  @robot.keyPress(VK_P);
  wait 200
  @robot.keyRelease(VK_P);
  @robot.keyRelease(VK_ALT);
  @robot.keyRelease(VK_META);
end

# a method to determine how many google chrome browser
# processes are running on the system; this makes a 
# unix system call
def num_chrome_procs
  n = `ps auxwww | grep -i google | grep -v grep | wc -l`
  return n.chomp.strip
end

# a method to test the chrome browser "file open" process
def test_file_open
  c 'test the File | Open process'
  c 'open a new tab'
  apple 't'

  c 'open a file'
  apple 'o'
  wait 1000
  type '/Users/Al/DevDaily/AgileGuiTesting/scripts/support/blue.html\n'
  wait 500
  type '\n'

  wait_for_xycolor 220, 280, 0, 0, 255
  wait 1000

  c 'close the tab we created'
  wait 250
  apple 'w'
end

#
# the "main" portion of the script begins here
#

### KEYNOTE, PART 1 ###

wait 3000

c 'go down to the keynote Space'
ctrl VK_DOWN
wait 500

c 'select the fourth keynote slide'
click 333, 360

c 'display keynote full screen'
play_slideshow

wait 500
speak "welcome to dev daily dot com", "vicki"
wait 500

type_keys VK_RIGHT
speak "this is a robot presentation of our agile gui testing software", "bruce"
wait 500

type_keys VK_RIGHT
speak "we will be performing gui regression tests on the google chrome browser"
wait 500

c 'leave keynote full screen mode'
type_keys VK_ESC

c 'back up to the chrome space'
wait 500
ctrl VK_UP
wait 1000


### CHROME TESTS ###

foreground 'Google Chrome'
wait 2000

num_procs_start = num_chrome_procs

echo 'test that file|open works'
speak 'about to test the file open process', 'ralph'
test_file_open
speak 'that went well', 'ralph'
wait 200

echo 'test opening up a url'
speak 'lets open a test URL'
apple 't'
wait 100
apple 'l'
wait 100
type 'www.devdaily.com \n'
wait_for_xycolor_to_go_away 500, 175, 255, 255, 255
wait 1000
speak 'say, thats a nice website', 'victoria'
wait 1000
apple 'w'

n = 20
speak "about to open and close #{n} chrome windows"
n.times { apple 'n' }
n.times { apple 'w' }

n = 20
speak "about to open and close #{n} chrome tabs"
n.times { apple 't' }
n.times { apple 'w' }

speak 'lets see what the memory looks like', 'ralph'
apple 't'
apple 'l'
type 'about:memory \n'
wait 2500
apple 'w'

speak 'i could do this all day. how about you?', 'ralph'
wait 1000

num_procs_end = num_chrome_procs
result = "There were #{num_procs_start} Chrome processes running when the test began, and there are #{num_procs_end} running now."
echo result
speak result
wait 2000


### KEYNOTE, PART 2 ###

c 'back to keynote space'
ctrl VK_DOWN
wait 500

c 'select the last keynote slide'
click 333, 510

c 'display keynote full screen'
play_slideshow

wait 500
speak "thank you for watching our agile gui testing video"
wait 500

type_keys VK_RIGHT
wait 500
speak "dev daily dot com", "cellos"

My GUI testing software language

I think this language is very simple, easy to read, and easy to write. I'm intentionally keeping the grammar as simple as possible, so you, the GUI tester, don't have to worry about the details of how a Java Robot works behind the scenes.

As I've mentioned before, the actual language used here is Ruby, and you just need to run it with the JRuby interpreter. (JRuby runs Ruby scripts, and also lets you do anything you want with Java as well.)

I'll discuss this more in the AGT documentation, but in general, you shouldn't depend on timing events, as I've shown here. For example, when a Time Machine backup kicks in on my iMac, the entire system comes to a screeching halt for the first 2-3 seconds. If you were expecting an event to happen in a short time frame, Time Machine kicking in might mess up your tests.

Of course it's easier to assume that an event should have occurred within a certain time frame (which is why I did this here), but you really should wait for a system event to occur. That's mostly what I'm working on now in the language, trying to make it faster/easier to program for system events.

Automated GUI testing software

My Automated GUI testing software now has a new home page. Just follow that link for downloads and support documents for our Automated GUI Testing software.