Module: Frank::Cucumber::KeyboardHelper

Included in:
FrankHelper
Defined in:
lib/frank-cucumber/keyboard_helper.rb

Instance Method Summary collapse

Instance Method Details

#type_into_keyboard(text_to_type, options = {}) ⇒ Object

Note:

The keyboard must be fully visible on the device before calling this method.

Ask Frank to press a sequence of keys on the iOS keyboard.

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.

Examples:

# 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")


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/frank-cucumber/keyboard_helper.rb', line 29

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

#type_shortcut(*args) ⇒ Object

Type a keyboard shortcut (Mac only)

This function takes as arguments either a single string, or an array of strings, with each string representing a different key to press. Modifier keys are represented by the strings “command”, “shift”, “option”, and “control”.

For example, to sent a keyboard shortcut to quit the app, you would call

type shortcut “command”, “q”



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/frank-cucumber/keyboard_helper.rb', line 53

def type_shortcut(*args)
  if args[0].kind_of?(Array)
    return type_shortcut(*args)
  else
    key = args.pop

    res = frank_server.send_post(
      'type_into_keyboard',
      :text_to_type => key,
      :modifiers => args
    )

    Frank::Cucumber::Gateway.evaluate_frankly_response(res, "typing the following shortcut into the keyboard '#{key}' with modifiers #{args}")
  end
end