Skip to content

Instantly share code, notes, and snippets.

@alexvollmer
Created April 11, 2012 23:25
Show Gist options
  • Save alexvollmer/2363450 to your computer and use it in GitHub Desktop.
Save alexvollmer/2363450 to your computer and use it in GitHub Desktop.
Wrapper script for running UIAutomation from the command-line
#!/usr/bin/env ruby -wKU
require "fileutils"
require "pty"
unless ARGV.length == 3
STDERR.puts "USAGE: run-test-script <app bundle> <test script> <output directory>"
exit 1
end
app_bundle, test_script, test_output = *ARGV
command = "/usr/bin/instruments -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate #{app_bundle} -e UIASCRIPT #{test_script} -e UIARESULTSPATH ."
failed = false
unless File.directory? test_output
FileUtils.mkdir_p test_output
end
Dir.chdir(test_output) do
begin
PTY.spawn(command) do |r, w, pid|
r.each do |line|
puts line
_, date, time, tz, type, msg = line.match(/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) ([+-]\d{4}) ([^:]+): (.*)$/).to_a
case type
when "Fail"
failed = true
end
end
end
rescue Errno::EIO
rescue PTY::ChildExited => e
STDERR.puts "Instruments exited unexpectedly"
exit 1
end
if failed
STDERR.puts "#{test_script} failed, see log output for details"
exit 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment