keyboard view?

807 views
Skip to first unread message

Martin Hauner

unread,
Mar 6, 2011, 10:14:15 AM3/6/11
to Frank
Hi,

I'm having a login/password view with two text fields. Entering
something into login and pressing "return" on the keyboard view will
jump to the password field. Pressing "return" there will initiate the
login.

But how do I make the keyboard appear and how do I touch "return"?

My starting point was this:

When /^I enter my credentials$/ do
When %q|I fill in "Login" with "me"|
When %q|I fill in "Password" with "secret"|
end

This is finally using "setText" to fill the text but it does not
"touch" the field and the keyboard does not slide in.

I tried to add a touch on the text field to make the keyboard appear
but it does not work.

When /^I enter my credentials$/ do
When %q|I touch "Login"|
When %q|I fill in "Login" with "me"|
When %q|I fill in "Password" with "secret"|
end

Any ideas?

Thanks,
Martin

Pete Hodgson

unread,
Mar 8, 2011, 11:45:36 AM3/8/11
to frank-...@googlegroups.com, Martin Hauner
Hi Martin,

Here's what we use:

When /^I use the keyboard to fill in the textfield marked "([^\"]*)" with "([^\"]*)"$/ do |text_field_mark, text_to_type|
  text_field_selector =  "view marked:'#{text_field_mark}'"
  check_element_exists( text_field_selector )
  touch( text_field_selector )
  frankly_map( text_field_selector, 'setText:', text_to_type )
  frankly_map( text_field_selector, 'endEditing:', true )
end

Please let me know if it works for you - I haven't included it in the core step definitions distributed with Frank yet because it seems a little brittle. If it works well for you also then maybe we should consider including it in the core steps.

Cheers,
Pete
--
Pete Hodgson
cell: 707-206-8897
y!: phodgson_ct
skype: thepete

Martin Hauner

unread,
Mar 8, 2011, 4:47:07 PM3/8/11
to frank-...@googlegroups.com, Pete Hodgson
Hi Pete,

On 08.03.11 17:45, Pete Hodgson wrote:
> When /^I use the keyboard to fill in the textfield marked "([^\"]*)" with
> "([^\"]*)"$/ do |text_field_mark, text_to_type|
> text_field_selector = "view marked:'#{text_field_mark}'"
> check_element_exists( text_field_selector )
> touch( text_field_selector )
> frankly_map( text_field_selector, 'setText:', text_to_type )
> frankly_map( text_field_selector, 'endEditing:', true )
> end

Ah, endEditing: is the trick :-)

Strange is that the touch doesn't do anything for me... but replacing the touch with
frankly_map 'becomeFirstResponder' does make it work. :-))

When /^I use the keyboard to fill in the textfield marked "([^\"]*)" with
"([^\"]*)"$/ do |text_field_mark, text_to_type|
text_field_selector = "view marked:'#{text_field_mark}'"
check_element_exists( text_field_selector )

# touch( text_field_selector )
frankly_map( text_field_selector, 'becomeFirstResponder' )


frankly_map( text_field_selector, 'setText:', text_to_type )
frankly_map( text_field_selector, 'endEditing:', true )
end


Thanks a lot,
Martin

Pete Hodgson

unread,
Mar 8, 2011, 8:46:09 PM3/8/11
to Martin Hauner, frank-...@googlegroups.com
Thanks for posting your solution Martin.

I think this is why I leaned towards not including the step definition in the core steps. It seems like it needs to be done slightly differently for different cases, and I never really understood the subtleties.

Thomas Elstner

unread,
Mar 10, 2011, 3:30:26 PM3/10/11
to Frank
Hi,

I'm able to fill in the text fields (im my case it is a UISearchBar)
using the definition above, but I have no clue on how to simulate the
return key to finally execute the search.
Any ideas?

Best regards,
Thomas

On Mar 9, 2:46 am, Pete Hodgson <phodg...@thoughtworks.com> wrote:
> Thanks for posting your solution Martin.
>
> I think this is why I leaned towards not including the step definition in
> the core steps. It seems like it needs to be done slightly differently for
> different cases, and I never really understood the subtleties.
>

Oggie

unread,
Mar 14, 2011, 1:24:48 PM3/14/11
to Frank
I'm having trouble with this as well.

I'm able to enter values into my username and password fields but have
no idea how to click the "Go" button in the keyboard.

Any ideas?

cheers

Oggie

Suzana

unread,
Mar 29, 2011, 3:45:16 PM3/29/11
to Frank
Did some of you managed to find a solution to this problem?
I also need to click the return button on the keyboard, and don't know
how to do this.

Regards,
Suzana

On Mar 14, 7:24 pm, Oggie <ocdrichard...@gmail.com> wrote:
> I'm having trouble with this as well.
>
> I'm able to enter values into my username and password fields but have
> no idea how to click the "Go" button in the keyboard.
>
> Any ideas?
>
> cheers
>
> Oggie
>
> On Mar 10, 8:30 pm, Thomas Elstner <thomas.elst...@xonion.net> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I'm able to fill in thetextfields (im my case it is a UISearchBar)

Hezi Cohen

unread,
Apr 7, 2011, 11:28:57 AM4/7/11
to Frank
well, the return key on the simulator can be simulated with your
computers real hardware keyboard.
so using a little applescript magic you can tell iphone simulator he
just got a key stroke from the keyboard

i've been using this for a couple of my scenarios and except for a few
timing issue with other events in my app this works great

When /^I hit return on the keyboard$/ do
%x{osascript<<APPLESCRIPT
tell application "System Events"
tell application "iPhone Simulator" to activate
key code 36
end tell
APPLESCRIPT}
end

James Moore

unread,
Apr 7, 2011, 2:00:24 PM4/7/11
to frank-...@googlegroups.com
Interesting workaround. I’ve been experimenting with using 

view view:”UIKBKeyView”

if you add index:0 to that you’ll be able to touch the return key. I haven’t been about to access the letter keys yet though. Something that’s helpful in digging into this is to add an inspect button to symbiote that calls the inspect method inside of Frank. It’ll bring up a screen in your app that dumps the properties of the objects matching your query. It looks like this

Pete Hodgson

unread,
Apr 7, 2011, 4:30:19 PM4/7/11
to frank-...@googlegroups.com
Thanks Hezi, that's a neat work-around! I took to liberty of adding it to the wiki.

Stewart Gleadow

unread,
Apr 8, 2011, 3:02:11 AM4/8/11
to frank-...@googlegroups.com
I don't know if it's the same within Frank, but when I played around with the javascript hooks for UIAutomation in Instruments, I was typing by actually getting the keyboard and then getting keys based on their accessibilityLabel (or just label?)

It worked well, but the gotya was that the accessibility label could be 'a' or 'A' depending on whether or not the shift key was depressed. When you first load the keyboard, the shift key is often pre-activated. As long as the stings I was 'typing' from my tests started with a capital letter, they worked.

- Stew

James Moore

unread,
May 13, 2011, 1:16:50 PM5/13/11
to frank-...@googlegroups.com
UPDATE:

I finally got around to doing some keyboard work with our app Prompt (iOS ssh client). Obviously sending keyboard input is important in this kind of app. The snippet in the previous email led me to figure out you can send the “keystroke” applescript command to send strings to the app. This finally lead me to the following helper and steps:

----------------------
def send_command ( command )
  %x{osascript<<APPLESCRIPT
tell application "System Events"
  tell application "iPhone Simulator" to activate
  keystroke "#{command}"
  delay 1
  key code 36
end tell
APPLESCRIPT}
end

When /^I send the command "([^\"]*)"$/ do |cmd|
  send_command(cmd)
end

When /^I send the command "([^"]*)" (\d+) times$/ do |cmd, times|
  i = 0
  while i < times.to_i
    send_command(cmd)
    i += 1
  end
end

When /^I send the following commands:$/ do |table|
  table.hashes.each do |row|
    steps "When I send the command \"#{row['command']}\" #{row['times']} times"
    send_command(row['command'])
  end
end

------------------

Now if I want to run some vttest tests it looks like this

  Given I touch the Connect button
  And I wait 2 seconds

  When I send the command ""
  And I send the command "vttest"
  And I wait 2 seconds

  When I send the following commands:
 | command | times |
 | 1       | 1     |
 |         | 6     |
 | 2       | 1     |
 |         | 15    |
 | 0       | 1     |
  

-------------------------

I’ll add these to the compendium

--
James

Joe Masilotti

unread,
Dec 18, 2013, 3:10:05 PM12/18/13
to frank-...@googlegroups.com, ja...@panic.com
I'm assuming that this thread is quite out of date, but since the Frank website links directly here I wanted to document a better way to do this.

To type into the keyboard using Frank use the method type_into_keyboard(text_to_type, options = {}). Passing :append_return => true into the options parameter will also tap the Enter key for you.


  # Ask Frank to press a sequence of keys on the iOS keyboard.
  #
  # @note The keyboard must be fully visible on the device before calling this method.
  #
  # The "/b" control character is interpreted as a request to press the 'Delete' key.
  #
  # An implicit return is appended to the key sequence, unless you explicitly specify otherwise by setting the :append_return option to false.
  #
  # @example
  # # press the X, -, Y, and z keys on the
  # # iOS keyboard, then press return
  # type_into_keyboard("X-Yz")
  #
  # # press the 1, 2, and 3 keys on the
  # # iOS keyboard, but don't press return afterwards
  # type_into_keyboard("123", :append_return => false)
  #
  # # press the 1, 2, and 3 keys on the
  # # iOS keyboard, but don't press return afterwards
  # type_into_keyboard("123", :append_return => false)
  #
  # # press Delete twice, then type "foo"
  # type_into_keyboard("\b\bfoo")
  #
  def type_into_keyboard(text_to_type, options = {})
    options = {
      :append_return => true
    }.merge(options)
    if( options[:append_return] )
      text_to_type = text_to_type+"\n" unless text_to_type.end_with?("\n")
    end
    res = frank_server.send_post(
      'type_into_keyboard',
      :text_to_type => text_to_type
    )
    Frank::Cucumber::Gateway.evaluate_frankly_response( res, "typing the following into the keyboard '#{text_to_type}'" )
  end
Reply all
Reply to author
Forward
0 new messages