From 882f5e69f4a24e3c352c11772caa46566759e53f Mon Sep 17 00:00:00 2001 From: Karl Krukow Date: Thu, 20 Jun 2013 23:35:08 +0200 Subject: [PATCH] support for more high-level UIA methods --- calabash-cucumber/calabash-cucumber.gemspec | 2 +- .../lib/calabash-cucumber/uia.rb | 67 +++++++++++++++++-- .../lib/calabash-cucumber/version.rb | 4 +- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/calabash-cucumber/calabash-cucumber.gemspec b/calabash-cucumber/calabash-cucumber.gemspec index 2d051e629..edd60337c 100644 --- a/calabash-cucumber/calabash-cucumber.gemspec +++ b/calabash-cucumber/calabash-cucumber.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |s| s.add_dependency( "location-one", "~>0.0.10") s.add_dependency( "httpclient","~> 2.3.3") s.add_dependency( "bundler", "~> 1.1") - s.add_dependency( "run_loop", "~> 0.0.13" ) + s.add_dependency( "run_loop", "~> 0.0.15" ) s.add_dependency( "awesome_print") end diff --git a/calabash-cucumber/lib/calabash-cucumber/uia.rb b/calabash-cucumber/lib/calabash-cucumber/uia.rb index c826ba64f..1be7f1caa 100644 --- a/calabash-cucumber/lib/calabash-cucumber/uia.rb +++ b/calabash-cucumber/lib/calabash-cucumber/uia.rb @@ -1,4 +1,6 @@ require 'edn' +require 'location-one' + module Calabash module Cucumber module UIA @@ -12,17 +14,70 @@ def send_uia_command(opts ={}) end def uia_query(*queryparts) - #TODO escape ' in query + #TODO escape '\n etc in query uia_handle_command(:query, queryparts) end + def uia_names(*queryparts) + #TODO escape '\n etc in query + uia_handle_command(:names, queryparts) + end + def uia_tap(*queryparts) - #TODO escape ' in query uia_handle_command(:tap, queryparts) end - def uia_handle_command(cmd, query) - command = %Q[uia.#{cmd}('#{query.to_edn}')] + def uia_tap_mark(mark) + uia_handle_command(:tapMark, mark) + end + + def uia_pan(from_q, to_q) + uia_handle_command(:pan, from_q, to_q) + end + + def uia_scroll_to(*queryparts) + uia_handle_command(:scrollTo, queryparts) + end + + def uia_element_exists?(*queryparts) + uia_handle_command(:elementExists, queryparts) + end + + def uia_element_does_not_exist?(*queryparts) + uia_handle_command(:elementDoesNotExist, queryparts) + end + + def uia_screenshot(name) + uia_handle_command(:elementDoesNotExist, name) + end + + def uia_type_string(string) + uia_handle_command(:typeString, string) + end + + def uia_enter() + uia_handle_command(:enter) + end + + def uia_set_location(place) + if place.is_a?(String) + loc = LocationOne::Client.location_by_place(place) + loc_data = {"latitude"=>loc.latitude, "longitude"=>loc.longitude} + else + loc_data = place + end + uia_handle_command(:setLocation, loc_data) + end + + def uia_handle_command(cmd, *query_args) + args = query_args.map do |part| + if part.is_a?(String) + "'#{escape_uia_string(part)}'" + else + "'#{escape_uia_string(part.to_edn)}'" + end + end + command = %Q[uia.#{cmd}(#{args.join(', ')})] if ENV['DEBUG'] == '1' puts "Sending UIA command" puts command @@ -39,6 +94,10 @@ def uia_handle_command(cmd, query) end end + def escape_uia_string(string) + #TODO escape '\n in query + string + end end end diff --git a/calabash-cucumber/lib/calabash-cucumber/version.rb b/calabash-cucumber/lib/calabash-cucumber/version.rb index 627b0b703..bf2b06e5b 100644 --- a/calabash-cucumber/lib/calabash-cucumber/version.rb +++ b/calabash-cucumber/lib/calabash-cucumber/version.rb @@ -1,6 +1,6 @@ module Calabash module Cucumber - VERSION = '0.9.149' - FRAMEWORK_VERSION = '0.9.146' + VERSION = '0.9.150' + FRAMEWORK_VERSION = '0.9.150' end end