Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ 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
require 'cucumber/rake/task'
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"
Expand Down
3 changes: 1 addition & 2 deletions lib/icuke/cucumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
93 changes: 48 additions & 45 deletions lib/icuke/simulator_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down