lib/ilesspainfulclient-cucumber/operations.rb in ilesspainfulclient-cucumber-0.0.2 vs lib/ilesspainfulclient-cucumber/operations.rb in ilesspainfulclient-cucumber-0.0.3
- old
+ new
@@ -9,12 +9,13 @@
def query(uiquery, *args)
map(uiquery, :query, *args)
end
- def touch(uiquery,*args)
- views_touched=map(uiquery, :touch, *args)
+ def touch(uiquery,options={})
+ options[:query] = uiquery
+ views_touched = playback("touch",options)
raise "could not find view to touch: '#{uiquery}', args: #{args}" if views_touched.empty?
views_touched
end
def simple_touch(label,*args)
@@ -24,37 +25,46 @@
def ok
touch("view marked:'ok'")
end
def set_text(uiquery, txt)
- text_fields_modified = map(uiquery, "setText", txt)
+ text_fields_modified = map(uiquery, :setText, txt)
raise "could not find text field #{uiquery}" if text_fields_modified.empty?
text_fields_modified
end
def swipe(dir,options={})
- playback("swipe_#{dir}_#{ENV['DEVICE']}",options)
+ playback("swipe_#{dir}}",options)
end
def cell_swipe(options={})
- playback("cell_swipe_#{ENV['DEVICE']}",options)
+ playback("cell_swipe",options)
end
def done
- map(nil,:touchDone)
+ map(nil,:touchDone,load_playback_data("touch_done"))
end
def scroll(uiquery,direction)
views_touched=map(uiquery, :scroll, direction)
raise "could not find view to scroll: '#{uiquery}', args: #{direction}" if views_touched.empty?
views_touched
end
+ def scroll_to_row(uiquery,number)
+ views_touched=map(uiquery, :scrollToRow, number)
+ raise "could not find view to scroll: '#{uiquery}', args: #{number}" if views_touched.empty?
+ views_touched
+ end
+
def pinch(in_out,options={})
options.merge!({:reverse=>in_out.to_sym==:out})
- playback("pinch_in_#{ENV['DEVICE']}", options)
+ if ENV['OS'] == 'ios5'
+ options.merge!(:prototype => load_playback_data("pinch_in",{"OS" => "ios4"}))
+ end
+ playback("pinch_in", options)
end
def rotate(dir)
@current_rotation = @current_rotation || :down
rotate_cmd = nil
@@ -78,11 +88,11 @@
end
if rotate_cmd.nil?
throw "Does not support rotating #{dir} when home button is pointing #{@current_rotation}"
end
- playback("rotate_home_#{rotate_cmd}_#{ENV['DEVICE']}")
+ playback("rotate_home_#{rotate_cmd}")
end
def background(secs)
raise "Not implemented yet"
IO.popen("/Users/krukow/Projects/iOS/libimobiledevice/tools/idevicedebugserver -u #{ENV['UUID']} dk.tk-solutions.Background", "w+") do |pipe|
@@ -129,31 +139,42 @@
matches = query(uiquery, 'isHidden')
matches.delete(true)
!matches.empty?
end
- def playback(recording, options={})
+
+ def load_playback_data(recording,options={})
+ os = options["OS"] || ENV["OS"]
+ device = options["DEVICE"] || ENV["DEVICE"]
+
rec_dir = ENV['PLAYBACK_DIR'] || "#{Dir.pwd}/playback"
+ if !recording.end_with?".base64"
+ recording = "#{recording}_#{os}_#{device}.base64"
+ end
data = nil
- if (File.exists?("#{recording}.base64"))
- data = File.read("#{recording}.base64")
+ if (File.exists?(recording))
+ data = File.read(recording)
puts "found #{recording}"
- elsif (File.exists?("#{rec_dir}/#{recording}.base64"))
- data = File.read("#{rec_dir}/#{recording}.base64")
- puts "#{rec_dir}/#{recording}.base64"
- elsif (File.exists?("#{DATA_PATH}/resources/#{recording}.base64"))
- data = File.read("#{DATA_PATH}/resources/#{recording}.base64")
- puts "#{DATA_PATH}/resources/#{recording}.base64"
+ elsif (File.exists?("#{rec_dir}/#{recording}"))
+ data = File.read("#{rec_dir}/#{recording}")
+ puts "#{rec_dir}/#{recording}"
+ elsif (File.exists?("#{DATA_PATH}/resources/#{recording}"))
+ data = File.read("#{DATA_PATH}/resources/#{recording}")
+ puts "#{DATA_PATH}/resources/#{recording}"
else
- raise "Playback not found: #{recording} (searched for #{recording}.base64 in #{Dir.pwd}, #{rec_dir}, #{DATA_PATH}/resources"
+ raise "Playback not found: #{recording} (searched for #{recording} in #{Dir.pwd}, #{rec_dir}, #{DATA_PATH}/resources"
end
+ data
+ end
+ def playback(recording, options={})
+ data = load_playback_data(recording)
-
post_data = %Q|{"events":"#{data}"|
post_data<< %Q|,"query":"#{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|,"prototype":"#{options[:prototype]}"| if options[:prototype]
post_data << "}"
res = http({:method=>:post, :raw=>true, :path=>'play'}, post_data)
res = JSON.parse( res )
@@ -170,9 +191,10 @@
def record_end(file_name)
res = http({:method=>:post, :path=>'record'}, {:action => :stop})
File.open("_recording.plist",'wb') do |f|
f.write res
end
+ file_name = "#{file_name}_#{ENV['OS']}_#{ENV['DEVICE']}.base64"
system("plutil -i _recording.plist -o _recording_binary.plist -convert binary1")
system("openssl base64 -in _recording_binary.plist -out #{file_name}")
system("rm _recording.plist _recording_binary.plist")
file_name
end