On 14 Dec 2009, at 18:35, James Mead wrote:
> I've been playing around with using AppleScript and System Events to
> write automated GUI acceptance tests.
Hey James - had your mail queued to reply to for quite a while!
Thanks for posting, very interesting. I've also been GUI testing through AppleScript, in my case with Cucumber.
Scenario: Convert a single jpeg file
When I run the app
And I open the file "testdata/testcard.jpg"
Then the front window title should be "testcard.jpg"
When I wait for window with title "testcard.pdf"
And I click "Save"
Then the file "testdata/testcard.pdf" should exist
This is backed by feature-support.rb
When /^I run the app$/ do
@app = run_app
end
When /^I open the file "([^\"]*)"$/ do |file|
@app.open file
end
When /^I (?:press|click) "([^\"]*)"$/ do |button_name|
@app.button(button_name).click
end
and a driver like
include Appscript
def run_app files = []
VelOCRaptor.new 'VelOCRaptor', Dir.getwd + '/build/release', files
end
class VelOCRaptor
def initialize app_name, path, files, run = true
@app_name = app_name
app_path = File.join(path, "#{app_name}.app")
if run
command = "open -W -a #{app_path}"
files.each { |file| command << %[ "#{file}"] }
IO.popen command
sleep 2
end
@events = app 'System Events'
@process = @events.processes[@app_name]
@app = app app_path
end
def open file
@app.open File.expand_path(file)
end
etc.
As is usual with GUI tests I'm still fighting occasional failures due to not waiting for things to happen. I'd be very interested to compare more of our drivers if you'd like to contact me off list.
Cheers
Duncan McGregor
www.velOCRaptor.com
Simple Affordable Mac OCR
|