Skip to content

Instantly share code, notes, and snippets.

@jmoody
Last active December 30, 2015 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmoody/7881303 to your computer and use it in GitHub Desktop.
Save jmoody/7881303 to your computer and use it in GitHub Desktop.
calabash-ios uia_pan_offset example
def move_appointment(appointment_mark, weekday, dir, hours, opts)
# asserts that the SelectCell has been touched
touch_and_hold_appointment(appointment_mark, weekday)
cell_view = custom_view_class('SelectCell', :mi)
res = query(cell_view).first
# no error checking!
normalize_rect_for_orientation!(res['rect'])
y_offset = hours * (res['frame']['height'] + 10)
y_offset = -1 * y_offset if dir.eql?(:up)
start_point = {:x => res['rect']['center_x'],
:y => res['rect']['center_y']}
end_point = {:x => res['rect']['center_x'],
:y => res['rect']['center_y'] + y_offset}
uia_pan_offset(start_point, end_point, {})
if opts[:release]
release_cell_content
end
end
def uia_handle_target_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[target.#{cmd}(#{args.join(', ')})]
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
def uia_touch_with_options(point, opts={})
defaults = {:tap_count => 1,
:touch_count => 1,
:duration => 1.0}
opts = defaults.merge(opts)
pt = "{x: #{point[:x]}, y: #{point[:y]}}"
args = "{tapCount: #{opts[:tap_count]}, touchCount: #{opts[:touch_count]}, duration: #{opts[:duration]}}"
uia_handle_target_command(:tapWithOptions, pt, args)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment