Module: Calabash::Android::TextHelpers

Included in:
Operations
Defined in:
lib/calabash-android/text_helpers.rb

Instance Method Summary collapse

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(query_string, options = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/calabash-android/text_helpers.rb', line 28

def clear_text(query_string, options={})
  result = query(query_string, setText: '')

  raise "No elements found. Query: #{query_string}" if result.empty?

  true
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, options = {})
  tap_when_element_exists(uiquery, options)
  sleep 0.5
  keyboard_enter_text(text, options)
end

#escape_quotes(str) ⇒ Object



36
37
38
# File 'lib/calabash-android/text_helpers.rb', line 36

def escape_quotes(str)
  str.gsub("'", "\\\\'")
end

#has_text?(text) ⇒ Boolean

Returns:

  • (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, options = {})
  keyboard_enter_text(character[0,1], options)
end

#keyboard_enter_text(text, options = {}) ⇒ Object



14
15
16
# File 'lib/calabash-android/text_helpers.rb', line 14

def keyboard_enter_text(text, options = {})
  perform_action('keyboard_enter_text', text)
end