Created
August 27, 2010 02:31
-
-
Save lukeredpath/552668 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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