Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created August 27, 2010 02:31
Show Gist options
  • Select an option

  • Save lukeredpath/552668 to your computer and use it in GitHub Desktop.

Select an option

Save lukeredpath/552668 to your computer and use it in GitHub Desktop.
require 'restclient'
require 'json'
module Frank
DEFAULT_PORT = 37265
class Driver
def initialize(client)
@client = client
end
def self.connect(host, port)
new(Client.new(host, port))
end
def touch(query)
@client.map('touch', query)
end
def find_element(query)
@client.map('accessibilityLabel', query)
end
def inspect_screen
@client.dump
end
end
class Client
def initialize(host, port)
@resource = RestClient::Resource.new("http://#{host}:#{port}")
end
def map(method, query, options={})
response = parse_response do
@resource['/map'].post(
{
:query => query,
:operation => operation_for(method, options[:arguments] || [])
}.to_json
)
end
if response.nil? || response['outcome'] !~ /SUCCESS/
raise ClientError.new(response)
end
response['result']
end
def dump
parse_response do
@resource['/dump'].get
end
end
class ClientError < RuntimeError
attr_reader :result
def initialize(result)
@result = result
end
def message
"Frank::Client error, result: #{@result.inspect}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment