Method: ICuke::SimulatorDriver#type

Defined in:
lib/icuke/simulator_driver.rb

#type(textfield, text, options = {}) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/icuke/simulator_driver.rb', line 115

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

  # 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