Module: Calabash::Cucumber::ConsoleHelpers

Defined in:
lib/calabash-cucumber/console_helpers.rb

Overview

A collection of methods that help you use console.

Instance Method Summary collapse

Instance Method Details

#clearObject

Clear the console history.



79
80
81
# File 'lib/calabash-cucumber/console_helpers.rb', line 79

def clear
  ConsoleHelpers.clear
end

#clear_clipboardObject

Clear the clipboard



74
75
76
# File 'lib/calabash-cucumber/console_helpers.rb', line 74

def clear_clipboard
  ConsoleHelpers.clear_clipboard!
end

#copyObject

Copy all the commands entered in the current console session into the OS Clipboard.



69
70
71
# File 'lib/calabash-cucumber/console_helpers.rb', line 69

def copy
  ConsoleHelpers.copy
end

#idsObject

Print the visible element ids.



14
15
16
# File 'lib/calabash-cucumber/console_helpers.rb', line 14

def ids
  accessibility_marks(:id)
end

#labelsObject

Print the visible element labels.



19
20
21
# File 'lib/calabash-cucumber/console_helpers.rb', line 19

def labels
  accessibility_marks(:label)
end

#marksObject

List the visible element with all marks.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/calabash-cucumber/console_helpers.rb', line 29

def marks
  opts = {:print => false, :return => true }
  res = accessibility_marks(:id, opts).each { |elm|elm << :id }
  res.concat(accessibility_marks(:label, opts).each { |elm| elm << :label })
  res.concat(text_marks(opts).each { |elm| elm << :text })
  max_width = 0
  res.each { |elm|
    len = elm[0].length
    max_width = len if len > max_width
  }

  counter = -1
  res.sort.each { |elm|
    printf("%4s %-6s => %#{max_width}s => %s\n",
           "[#{counter = counter + 1}]",
           elm[2], elm[0], elm[1])
  }
  true
end

#puts_message_of_the_dayObject

Print a message to the console.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/calabash-cucumber/console_helpers.rb', line 84

def puts_message_of_the_day
  messages = [
    "Let's get this done!",
    "Ready to rumble.",
    "Enjoy.",
    "Remember to breathe.",
    "Take a deep breath.",
    "Isn't it time for a break?",
    "Can I get you a coffee?",
    "What is a calabash anyway?",
    "Smile! You are on camera!",
    "Let op! Wild Rooster!",
    "Don't touch that button!",
    "I'm gonna take this to 11.",
    "Console. Engaged.",
    "Your wish is my command.",
    "This console session was created just for you.",
    "Den som jager to harer, får ingen.",
    "Uti, non abuti.",
    "Non Satis Scire",
    "Nullius in verba",
    "Det ka æn jå væer ei jált",
    "Dzień dobry",
    "Jestem tu by ocalić świat"
  ]
  puts RunLoop::Color.green("Calabash says, \"#{messages.shuffle.first}\"")
end

#quietObject

Turn off debug logging.



125
126
127
128
129
130
131
132
133
134
# File 'lib/calabash-cucumber/console_helpers.rb', line 125

def quiet
  if RunLoop::Environment.debug?
    ENV["DEBUG"] = "0"
    puts RunLoop::Color.cyan("Turned off debug logging.")
  else
    puts RunLoop::Color.cyan("Debug logging is already turned off.")
  end

  true
end

#textObject

Print the visible element texts.



24
25
26
# File 'lib/calabash-cucumber/console_helpers.rb', line 24

def text
  text_marks
end

#treeObject

Print a representation of the current view hierarchy.



7
8
9
10
11
# File 'lib/calabash-cucumber/console_helpers.rb', line 7

def tree
  hash = http_fetch_view_hierarchy
  dump_json_data(hash)
  true
end

#verboseObject

Turn on debug logging.



113
114
115
116
117
118
119
120
121
122
# File 'lib/calabash-cucumber/console_helpers.rb', line 113

def verbose
  if RunLoop::Environment.debug?
    puts RunLoop::Color.cyan("Debug logging is already turned on.")
  else
    ENV["DEBUG"] = "1"
    puts RunLoop::Color.cyan("Turned on debug logging.")
  end

  true
end