Skip to content

Commit

Permalink
initial high-level uia support
Browse files Browse the repository at this point in the history
  • Loading branch information
krukow committed Jun 20, 2013
1 parent df6fb8b commit 6bd73ca
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 11 deletions.
3 changes: 2 additions & 1 deletion calabash-cucumber/calabash-cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ Gem::Specification.new do |s|
s.add_dependency( "cucumber", "~> 1.3.0" )
s.add_dependency( "calabash-common", "~> 0.0.1" )
s.add_dependency( "json" )
s.add_dependency( 'edn')
s.add_dependency( "CFPropertyList" )
s.add_dependency( "sim_launcher", "0.4.6")
s.add_dependency( "slowhandcuke" )
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.12" )
s.add_dependency( "run_loop", "~> 0.0.13" )
s.add_dependency( "awesome_print")

end
20 changes: 11 additions & 9 deletions calabash-cucumber/lib/calabash-cucumber/core.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require 'httpclient'
require 'calabash-cucumber/launch/simulator_helper'
require 'calabash-cucumber/uia'

module Calabash
module Cucumber
module Core
include Calabash::Cucumber::UIA

DATA_PATH = File.expand_path(File.dirname(__FILE__))
CAL_HTTP_RETRY_COUNT=3
Expand Down Expand Up @@ -91,13 +93,20 @@ def touch(uiquery, options={})
end

options[:query] = uiquery
views_touched = playback("touch", options)
views_touched = do_touch(options)
unless uiquery.nil?
screenshot_and_raise "could not find view to touch: '#{uiquery}', args: #{options}" if views_touched.empty?
end
views_touched
end

def do_touch(options)
if ENV['OS']=='ios7' || @calabash_launcher && @calabash_launcher.ios_major_version == "7"
options[:uia_gesture] = :tap
end
playback("touch", options)
end

def swipe(dir, options={})
dir = dir.to_sym
@current_rotation = @current_rotation || :down
Expand Down Expand Up @@ -412,6 +421,7 @@ def playback(recording, options={})
post_data<< %Q|,"query":"#{escape_quotes(options[:query])}"| if options[:query]
post_data<< %Q|,"offset":#{options[:offset].to_json}| if options[:offset]
post_data<< %Q|,"reverse":#{options[:reverse]}| if options[:reverse]
post_data<< %Q|,"uia_gesture":"#{options[:uia_gesture]}"| if options[:uia_gesture]
post_data<< %Q|,"prototype":"#{options[:prototype]}"| if options[:prototype]
post_data << "}"

Expand Down Expand Up @@ -539,14 +549,6 @@ def default_device
@calabash_launcher && @calabash_launcher.device
end

def send_uia_command(opts ={})
run_loop = opts[:run_loop] || (@calabash_launcher && @calabash_launcher.active? && @calabash_launcher.run_loop)
command = opts[:command]
raise ArgumentError, 'please supply :run_loop or instance var @calabash_launcher' unless run_loop
raise ArgumentError, 'please supply :command' unless command
RunLoop.send_command(run_loop, opts[:command])
end


def http(options, data=nil)
options[:uri] = url_for(options[:path])
Expand Down
1 change: 1 addition & 0 deletions calabash-cucumber/lib/calabash-cucumber/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def relaunch(args={})
if target != 'DEVICE'
default_args[:udid] = target
end
default_args
self.run_loop = RunLoop.run(default_args.merge(args))
else

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
YnBsaXN0MDCiARLVAgMEBQYHCAkOEVRUaW1lVERhdGFeV2luZG93TG9jYXRpb25Y
TG9jYXRpb25UVHlwZRMAADAlq7xUgk8QQAEAAAABAAEAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAABAAICAgAAAIA/AACAPwAALEMAAH5DAECKQAAAAADSCgsMDVFY
UVkjQGWAAAAAAAAjQG/AAAAAAADSCgsPECNAZYAAAAAAACNAb8AAAAAAABELudUC
AwQFBhMUFRgREwAAMCWuVOtDTxBABgAAAAEAAQAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAEAAgIBAAAAgD8AAIA/AAAsQwAAfkMAAAAAAAAAANIKCxYXI0BlgAAA
AAAAI0BvwAAAAAAA0goLGRojQGWAAAAAAAAjQG/AAAAAAAAACAALABYAGwAgAC8A
OAA9AEYAiQCOAJAAkgCbAKQAqQCyALsAvgDJANIBFQEaASMBLAExAToAAAAAAAAC
AQAAAAAAAAAbAAAAAAAAAAAAAAAAAAABQw==
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
YnBsaXN0MDCiARLVAgMEBQYHCAkOEVRUaW1lVERhdGFeV2luZG93TG9jYXRpb25Y
TG9jYXRpb25UVHlwZRMAADAlq7xUgk8QQAEAAAABAAEAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAABAAICAgAAAIA/AACAPwAALEMAAH5DAECKQAAAAADSCgsMDVFY
UVkjQGWAAAAAAAAjQG/AAAAAAADSCgsPECNAZYAAAAAAACNAb8AAAAAAABELudUC
AwQFBhMUFRgREwAAMCWuVOtDTxBABgAAAAEAAQAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAEAAgIBAAAAgD8AAIA/AAAsQwAAfkMAAAAAAAAAANIKCxYXI0BlgAAA
AAAAI0BvwAAAAAAA0goLGRojQGWAAAAAAAAjQG/AAAAAAAAACAALABYAGwAgAC8A
OAA9AEYAiQCOAJAAkgCbAKQAqQCyALsAvgDJANIBFQEaASMBLAExAToAAAAAAAAC
AQAAAAAAAAAbAAAAAAAAAAAAAAAAAAABQw==
45 changes: 45 additions & 0 deletions calabash-cucumber/lib/calabash-cucumber/uia.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'edn'
module Calabash
module Cucumber
module UIA

def send_uia_command(opts ={})
run_loop = opts[:run_loop] || (@calabash_launcher && @calabash_launcher.active? && @calabash_launcher.run_loop)
command = opts[:command]
raise ArgumentError, 'please supply :run_loop or instance var @calabash_launcher' unless run_loop
raise ArgumentError, 'please supply :command' unless command
RunLoop.send_command(run_loop, opts[:command])
end

def uia_query(*queryparts)
#TODO escape ' in query
uia_handle_command(:query, 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}')]
if ENV['DEBUG'] == '1'
puts "Sending UIA command"
puts command
end
s=send_uia_command :command => command
if ENV['DEBUG'] == '1'
puts "Result"
p s
end
if s['status'] == 'success'
s['value']
else
raise s
end
end


end
end
end
2 changes: 1 addition & 1 deletion calabash-cucumber/lib/calabash-cucumber/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Calabash
module Cucumber
VERSION = '0.9.148'
VERSION = '0.9.149'
FRAMEWORK_VERSION = '0.9.146'
end
end

0 comments on commit 6bd73ca

Please sign in to comment.