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
- #clear_text_in(query_string, options = {}) ⇒ Object
- #enter_text(uiquery, text, options = {}) ⇒ Object
- #escape_quotes(str) ⇒ Object
- #has_text?(text) ⇒ Boolean
- #keyboard_enter_char(character, options = {}) ⇒ Object
- #keyboard_enter_text(text, options = {}) ⇒ 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
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/calabash-android/text_helpers.rb', line 37 def clear_text(={}) if .is_a?(String) puts "Warning: The method clear_text now clears the text in the currently focused view. Use clear_text_in instead" puts "Notice that clear_text_in only clears the text of the first element matching the given query, not all." puts "Use query(query, setText: '') to replicate the old behaviour" clear_text_in() else perform_action('clear_text') end end |
#clear_text_in(query_string, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/calabash-android/text_helpers.rb', line 28 def clear_text_in(query_string, ={}) unless query_string.nil? touch(query_string, ) sleep 0.5 end clear_text() end |
#enter_text(uiquery, text, options = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/calabash-android/text_helpers.rb', line 22 def enter_text(uiquery, text, = {}) tap_when_element_exists(uiquery, ) sleep 0.5 keyboard_enter_text(text, ) end |
#escape_quotes(str) ⇒ Object
49 50 51 |
# File 'lib/calabash-android/text_helpers.rb', line 49 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
18 19 20 |
# File 'lib/calabash-android/text_helpers.rb', line 18 def keyboard_enter_char(character, = {}) keyboard_enter_text(character[0,1], ) end |
#keyboard_enter_text(text, options = {}) ⇒ Object
14 15 16 |
# File 'lib/calabash-android/text_helpers.rb', line 14 def keyboard_enter_text(text, = {}) perform_action('keyboard_enter_text', text) end |