Last week at the Test Automation Workshop (TAW) here in Australia, the topic of being able to run automated tests ‘headless’ came up, and I mentioned the Celerity project: a headless Watir port. I decided to have a play with Celerity tonight to see how easy it is to get up and running, and also look at it as a way to quickly run Watir scripts.
Installation
The installation was fairly straightforward. You need a Java 6 JDK, as well as the JRuby binaries. You’ll need to update two environment variables, namely add JRuby to your path, and update your JAVA_HOME variable. Installing Celerity involves a JRuby gem: "jruby -S gem install celerity". You can also install it from github, but I don’t know the difference between the two.
Availability of Gems
Ruby gems are supported in JRuby, but only if they don’t use C libraries. This means that Watir won’t work, nor will Roo. I use Roo to define test cases in spreadsheets, so it means I can’t do a comparison of execution times at the moment, at least until I get these test cases out of spreadsheets.
Using Celerity as a simple load testing tool instead
At TAW, Kelvin Ross thought Celerity sounded promising as a load testing tool, considering it was headless and lightweight. I thought I would give a simple google search script a try, running in both Celerity, and Watir, with 30 concurrent users.
Running under Watir
CPU peaked at 100% for the entire run, and each page varied considerable but took on average 10 seconds to load.
Running under Celerity
CPU use was normal, and each page took just over 1 second to load (minimal variance).
Conclusion
Celerity seems a promising way to execute basic load tests using a headless browser. The benefit of Celerity is support for javascript execution in the browser, the downside at the moment is lack of support for some ruby gems. If you could run Watir under JRuby, I could have used a single script.
Scripts Used
Celerity Script
require 'thread'
require "rubygems"
require "celerity"
def test_google
browser = Celerity::Browser.new
browser.goto('http://www.google.com')
browser.text_field(:name, 'q').value = 'Celerity'
start_time = Time.now
browser.button(:name, 'btnG').click
end_time = Time.now
puts end_time - start_time
browser.close
end
threads = []
30.times do
threads << Thread.new {test_google}
end
threads.each {|x| x.join}
Watir Script
require 'thread'
require 'watir'
require 'watir/ie'
def test_google
browser = Watir::IE.start('http://www.google.com')
browser.text_field(:name, 'q').value = 'Celerity'
start_time = Time.now
browser.button(:name, 'btnG').click
end_time = Time.now
puts end_time - start_time
browser.close
end
threads = []
30.times do
threads << Thread.new {test_google}
end
threads.each {|x| x.join}
