Module: Calabash::Android::TextHelpers
- Included in:
- Operations
- Defined in:
- lib/calabash-android/text_helpers.rb
Instance Method Summary collapse
- #assert_text(text, should_find = true) ⇒ Object
-
#clear_text(options = {}) ⇒ Object
Clears the text of the currently focused view.
- #clear_text_in(query_string, options = {}) ⇒ Object
-
#enter_text(uiquery, text, options = {}) ⇒ Object
Appends ‘text` into the first view matching `uiquery`.
- #escape_quotes(str) ⇒ Object
- #has_text?(text) ⇒ Boolean
- #keyboard_enter_char(character, options = {}) ⇒ Object
- #keyboard_enter_text(text, options = {}) ⇒ Object
- #keyboard_visible? ⇒ Boolean
-
#set_selection(selection_start, selection_end) ⇒ Object
Sets the selection of the currently focused view.
- #wait_for_keyboard(opt = {}) ⇒ Object
Instance Method Details
#assert_text(text, should_find = true) ⇒ Object
8 9 10 11 12 |
# File 'lib/calabash-android/text_helpers.rb', line 8 def assert_text(text, should_find = true) raise "Text \"#{text}\" was #{should_find ? 'not ' : ''}found." if has_text?(text) ^ should_find true end |
#clear_text(options = {}) ⇒ Object
Clears the text of the currently focused view.
38 39 40 41 42 |
# File 'lib/calabash-android/text_helpers.rb', line 38 def clear_text(={}) set_selection(-1, -1) sleep 0.1 perform_action("delete_surrounding_text", -1, 0) end |
#clear_text_in(query_string, options = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/calabash-android/text_helpers.rb', line 31 def clear_text_in(query_string, ={}) touch(query_string, ) sleep 0.5 clear_text() end |
#enter_text(uiquery, text, options = {}) ⇒ Object
Appends ‘text` into the first view matching `uiquery`.
24 25 26 27 28 29 |
# File 'lib/calabash-android/text_helpers.rb', line 24 def enter_text(uiquery, text, = {}) tap_when_element_exists(uiquery, ) sleep 0.5 set_selection(-1, -1) keyboard_enter_text(text, ) end |
#escape_quotes(str) ⇒ Object
44 45 46 |
# File 'lib/calabash-android/text_helpers.rb', line 44 def escape_quotes(str) str.gsub("'", "\\\\'") end |
#has_text?(text) ⇒ Boolean
4 5 6 |
# File 'lib/calabash-android/text_helpers.rb', line 4 def has_text?(text) !query("* {text CONTAINS[c] '#{text}'}").empty? end |
#keyboard_enter_char(character, options = {}) ⇒ Object
19 20 21 |
# File 'lib/calabash-android/text_helpers.rb', line 19 def keyboard_enter_char(character, = {}) keyboard_enter_text(character[0,1], ) end |
#keyboard_enter_text(text, options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/calabash-android/text_helpers.rb', line 14 def keyboard_enter_text(text, = {}) wait_for_keyboard perform_action('keyboard_enter_text', text) end |
#keyboard_visible? ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/calabash-android/text_helpers.rb', line 58 def keyboard_visible? input_method = `#{default_device.adb_command} shell dumpsys input_method`.force_encoding('UTF-8') shown = input_method.each_line.grep(/mInputShown\s*=\s*(.*)/){$1}.first.chomp if shown == "true" true elsif shown == "false" false else raise "Could not detect keyboard visibility. '#{shown}'" end end |
#set_selection(selection_start, selection_end) ⇒ Object
Sets the selection of the currently focused view.
54 55 56 |
# File 'lib/calabash-android/text_helpers.rb', line 54 def set_selection(selection_start, selection_end) perform_action("set_selection", selection_start, selection_end) end |
#wait_for_keyboard(opt = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/calabash-android/text_helpers.rb', line 71 def wait_for_keyboard(opt={}) params = opt.clone params[:timeout_message] ||= "Timed out waiting for the keyboard to appear" params[:timeout] ||= 5 wait_for(params) do keyboard_visible? end end |