diff --git a/Rakefile b/Rakefile index b0f3c2b..ef95c6b 100644 --- a/Rakefile +++ b/Rakefile @@ -32,10 +32,9 @@ file 'app/build/Debug-iphonesimulator/Universal.app/Universal' do sh "cd app && xcodebuild -target Universal -configuration Debug -sdk #{ICuke::SDK.fullname}" end task :app => 'app/build/Debug-iphonesimulator/Universal.app/Universal' -task :features => :app task :lib do - sh 'cd ext/iCuke && rake' + sh 'cd ext && rake' end begin @@ -43,7 +42,7 @@ begin Cucumber::Rake::Task.new(:features) task :features => :check_dependencies - task :features => [:app, :lib] + task :features => [:lib, :app] rescue LoadError task :features do abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber" diff --git a/lib/icuke/cucumber.rb b/lib/icuke/cucumber.rb index f781ce5..45b2c05 100644 --- a/lib/icuke/cucumber.rb +++ b/lib/icuke/cucumber.rb @@ -64,8 +64,7 @@ def configuration When /^I tap "([^\"]*)"$/ do |label| simulator_driver.tap(label) end - -When /^I type "([^\"]*)" in "([^\"]*)"$/ do |text, textfield| +When /^I type "([^\"]*)"(?: in "([^\"]*)")?$/ do |text, textfield| simulator_driver.type(textfield, text) end diff --git a/lib/icuke/simulator_driver.rb b/lib/icuke/simulator_driver.rb index ca86ee5..f93baff 100644 --- a/lib/icuke/simulator_driver.rb +++ b/lib/icuke/simulator_driver.rb @@ -106,52 +106,55 @@ def drag_slider_to_percentage(label, percentage) end def type(textfield, text, options = {}) - tap(textfield, :hold_for => 0.75) do |field| - if field['value'] - tap('Select All') - tap('Delete') - end - end - - # Without this sleep fields which have auto-capitilisation/correction can - # miss the first keystroke for some reason. - sleep(0.5) - - text.split('').each do |c| - begin - tap(c == ' ' ? 'space' : c, :pause => false) - rescue Exception => e - try_keyboards = - case c - when /[a-zA-Z]/ - ['more, letters', 'shift'] - when /[0-9]/ - ['more, numbers'] - else - ['more, numbers', 'more, symbols'] - end - until try_keyboards.empty? - begin - tap(try_keyboards.shift, :pause => false) - retry - rescue - end - end - raise e - end - end + unless textfield == '' || textfield.nil? + tap(textfield, :hold_for => 0.75) do |field| + if field['value'] + tap('Select All') + tap('Delete') + end + end + end + + # Without this sleep fields which have auto-capitilisation/correction can + # miss the first keystroke for some reason. + sleep(0.3) + + text.split('').each do |c| + begin + tap(c == ' ' ? 'space' : c, :pause => false) + rescue Exception => e + try_keyboards = + case c + when /[a-zA-Z]/ + ['more, letters', 'shift'] + when /[0-9]/ + ['more, numbers'] + else + ['more, numbers', 'more, symbols'] + end + until try_keyboards.empty? + begin + tap(try_keyboards.shift, :pause => false) + retry + rescue + end + end + raise e + end + end + + # From UIReturnKeyType + # Should probably sort these in rough order of likelyhood? + return_keys = ['return', 'go', 'google', 'join', 'next', 'route', 'search', 'send', 'yahoo', 'done', 'emergency call'] + return_keys.each do |key| + begin + tap(key) + return + rescue + end + end + end - # From UIReturnKeyType - # Should probably sort these in rough order of likelyhood? - return_keys = ['return', 'go', 'google', 'join', 'next', 'route', 'search', 'send', 'yahoo', 'done', 'emergency call'] - return_keys.each do |key| - begin - tap(key) - return - rescue - end - end - end def scroll_to(text, options = {}) x, y, x2, y2 = screen.swipe_coordinates(swipe_direction(options[:direction]))