Module: Briar::Bars

Defined in:
lib/briar/bars/navbar.rb,
lib/briar/bars/tabbar.rb,
lib/briar/bars/toolbar.rb

Instance Method Summary collapse

Instance Method Details

#date_is_in_navbar(date) ⇒ Object



119
120
121
122
123
124
# File 'lib/briar/bars/navbar.rb', line 119

def date_is_in_navbar (date)
  with_leading = date.strftime('%a %b %d')
  without_leading = date.strftime("%a %b #{date.day}")
  items = query('navigationItemView', AL)
  items.include?(with_leading) || items.include?(without_leading)
end

#go_back_after_waiting(opts = {}) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/briar/bars/navbar.rb', line 127

def go_back_after_waiting(opts={})
  default_opts = {:wait_before_going_back => 0.2,
                  :timeout => BRIAR_WAIT_TIMEOUT,
                  :timeout_message => nil,
                  :wait_step_pause => BRIAR_WAIT_STEP_PAUSE,
                  :retry_frequency => BRIAR_WAIT_RETRY_FREQ}
  opts = default_opts.merge(opts)
  wait_before = opts[:wait_before_going_back]
  sleep(wait_before)

  msg = opts[:timeout_message]
  timeout = opts[:timeout]
  if msg.nil?
    msg = "waited for '#{timeout + wait_before}' for navbar back button but didn't see it"
  end

  wait_for(:timeout => timeout,
           :retry_frequency => opts[:retry_frequency],
           :post_timeout => opts[:wait_step_pause],
           :timeout_message => msg) do
    not query('navigationItemButtonView first').empty?
  end
  touch('navigationItemButtonView first')
  step_pause
end

#go_back_and_wait_for_view(view) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/briar/bars/navbar.rb', line 153

def go_back_and_wait_for_view (view)
  sleep(0.2)
  timeout = BRIAR_WAIT_TIMEOUT
  msg = "waited '#{timeout}' seconds but did not see navbar back button"
  wait_for(wait_opts(msg, timeout)) do
    not query('navigationItemButtonView first').empty?
  end

  touch_transition('navigationItemButtonView first',
                   "view marked:'#{view}'",
                   {:timeout => TOUCH_TRANSITION_TIMEOUT,
                    :retry_frequency => TOUCH_TRANSITION_RETRY_FREQ})
  step_pause
end

#index_of_navbar_button(name) ⇒ Object

will not work to detect left/right buttons



55
56
57
58
# File 'lib/briar/bars/navbar.rb', line 55

def index_of_navbar_button (name)
  titles = query('navigationButton', AL)
  titles.index(name)
end

#index_of_tabbar_item(name) ⇒ Object



21
22
23
24
# File 'lib/briar/bars/tabbar.rb', line 21

def index_of_tabbar_item(name)
  tabs = query('tabBarButton', AL)
  tabs.index(name)
end

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/briar/bars/navbar.rb', line 21

def navbar_has_back_button?
  res = query('navigationItemButtonView')
  return false if res.empty?

  # sometime the back button is there, but has zero rect
  frame = res.first['frame']

  ['x', 'y', 'width', 'height'].each { |key|
    if frame[key] != 0
      return true
    end
  }
  false
end

Returns:

  • (Boolean)


197
198
199
200
201
202
# File 'lib/briar/bars/navbar.rb', line 197

def navbar_has_title? (title)
  all_items = query("navigationItemView marked:'#{title}'")
  button_items = query('navigationItemButtonView')
  non_button_items = all_items.delete_if { |item| button_items.include?(item) }
  !non_button_items.empty?
end

Returns:

  • (Boolean)


5
6
7
# File 'lib/briar/bars/navbar.rb', line 5

def navbar_visible?
  !query('navigationBar').empty?
end

#should_not_see_navbarObject



15
16
17
18
19
# File 'lib/briar/bars/navbar.rb', line 15

def should_not_see_navbar
  if navbar_visible?
    screenshot_and_raise 'should not see the nav bar'
  end
end

#should_not_see_navbar_back_buttonObject



47
48
49
50
51
# File 'lib/briar/bars/navbar.rb', line 47

def should_not_see_navbar_back_button
  if navbar_has_back_button?
    screenshot_and_raise 'i should not see navigation bar back button'
  end
end

#should_not_see_navbar_button(mark, opts = {}) ⇒ Object

todo convert args to hash and mirror the should_see_navbar_button is_ui_button=false)



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/briar/bars/navbar.rb', line 90

def should_not_see_navbar_button (mark, opts={})
  if (not opts.is_a?(Hash)) and (not opts.nil?)
    warn "\nWARN: deprecated 0.1.4 - you should no longer pass a Boolean '#{opts}' as an arg, pass opts hash instead"
    button_type = opts ? :button : :bar_item
    opts = {:bar_button_type => button_type}
  end
  default_opts = {:bar_button_type => :bar_item,
                  :timeout => BRIAR_WAIT_TIMEOUT}
  opts = default_opts.merge(opts)
  if opts[:bar_button_type] == :button
    queries = ["buttonLabel marked:'#{mark}' parent navigationBar",
               "button marked:'#{mark}' parent navigationBar"]
    timeout = opts[:timeout]
    msg = "waited for '#{timeout}' seconds but i still see '#{mark}' in navigation bar"
    wait_for(:timeout => timeout,
             :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
             :post_timeout => BRIAR_WAIT_STEP_PAUSE,
             :timeout_message => msg) do
      queries.all? { |query| element_does_not_exist query }
    end
  else
    idx = index_of_navbar_button mark
    unless idx.nil?
      # check to see if it is a ui button
      should_not_see_navbar_button mark, {:bar_button_type => :button}
    end
  end
end

#should_not_see_tabbarObject



15
16
17
18
19
# File 'lib/briar/bars/tabbar.rb', line 15

def should_not_see_tabbar
  if tabbar_visible?
    screenshot_and_raise 'i should not see the tabbar'
  end
end

#should_not_see_toolbar(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object



22
23
24
25
# File 'lib/briar/bars/toolbar.rb', line 22

def should_not_see_toolbar (toolbar_id, timeout=BRIAR_WAIT_TIMEOUT)
  wait_for_toolbar_to_disappear toolbar_id, timeout
  screenshot_and_raise "did not expect to see toolbar with id '#{toolbar_id}'" if toolbar_exists? toolbar_id
end

#should_see_navbarObject



9
10
11
12
13
# File 'lib/briar/bars/navbar.rb', line 9

def should_see_navbar
  unless navbar_visible?
    screenshot_and_raise 'should see the nav bar'
  end
end

#should_see_navbar_back_buttonObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/briar/bars/navbar.rb', line 36

def should_see_navbar_back_button
  timeout = BRIAR_WAIT_TIMEOUT * 2.0
  msg = "waited for '#{timeout}' seconds but did not see navbar back button"
  wait_for(:timeout => timeout,
           :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
           :post_timeout => BRIAR_WAIT_STEP_PAUSE,
           :timeout_message => msg) do
    navbar_has_back_button?
  end
end

#should_see_navbar_button(mark, opts = {}) ⇒ Object

bar_button_type options => button <= the button is a UIButton bar_item <= the button is UIBarButtonItem



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/briar/bars/navbar.rb', line 63

def should_see_navbar_button (mark, opts={})
  default_opts = {:bar_button_type => :bar_item,
                  :timeout => BRIAR_WAIT_TIMEOUT}
  opts = default_opts.merge(opts)
  if opts[:bar_button_type] == :button
    queries = ["buttonLabel marked:'#{mark}' parent navigationBar",
               "button marked:'#{mark}' parent navigationBar"]
    timeout = opts[:timeout]
    msg = "waited for '#{timeout}' seconds but did not see '#{mark}' in navigation bar"
    wait_for(:timeout => timeout,
             :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
             :post_timeout => BRIAR_WAIT_STEP_PAUSE,
             :timeout_message => msg) do
      queries.any? { |query| element_exists query }
    end
  else
    idx = index_of_navbar_button mark
    if idx.nil?
      # check to see if it is a ui button
      should_see_navbar_button mark, {:bar_button_type => :button}
    end
  end
end

#should_see_navbar_with_title(title, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object



204
205
206
207
208
209
210
211
212
# File 'lib/briar/bars/navbar.rb', line 204

def should_see_navbar_with_title(title, timeout=BRIAR_WAIT_TIMEOUT)
  msg = "waited for '#{timeout}' seconds but i did not see #{title} in navbar"
  wait_for(:timeout => timeout,
           :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
           :post_timeout => BRIAR_WAIT_STEP_PAUSE,
           :timeout_message => msg) do
    navbar_has_title? title
  end
end

#should_see_tab_at_index(name, index) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/briar/bars/tabbar.rb', line 45

def should_see_tab_at_index(name, index)
  should_see_tabbar
  tabs = query('tabBarButton', AL)
  unless tabs.index(name) == index.to_i
    screenshot_and_raise "should have seen tab named '#{name}' at index '#{index}' but found these: '#{tabs}'"
  end
end

#should_see_tabbarObject



9
10
11
12
13
# File 'lib/briar/bars/tabbar.rb', line 9

def should_see_tabbar
  unless tabbar_visible?
    screenshot_and_raise 'i should see the tabbar'
  end
end

#should_see_toolbar(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object



18
19
20
# File 'lib/briar/bars/toolbar.rb', line 18

def should_see_toolbar (toolbar_id, timeout=BRIAR_WAIT_TIMEOUT)
  wait_for_toolbar(toolbar_id, timeout)
end

#should_see_toolbar_button(button_id, opts = {:timeout => BRIAR_WAIT_TIMEOUT, :toolbar_id => nil}) ⇒ Object



68
69
70
71
# File 'lib/briar/bars/toolbar.rb', line 68

def should_see_toolbar_button (button_id, opts={:timeout => BRIAR_WAIT_TIMEOUT,
                                                :toolbar_id => nil})
  wait_for_toolbar_button button_id, opts
end

#tabbar_visible?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/briar/bars/tabbar.rb', line 5

def tabbar_visible?
  element_exists('tabBar')
end

#toolbar_button_exists?(button_id, opts = {:toolbar_id => nil}) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/briar/bars/toolbar.rb', line 27

def toolbar_button_exists?(button_id, opts={:toolbar_id => nil})
  toolbar_id = opts[:toolbar_id]
  if toolbar_id.nil?
    not query("toolbar descendant view marked:'#{button_id}'").empty?
  else
    not query("toolbar marked:'#{toolbar_id}' descendant view marked:'#{button_id}'").empty?
  end

  # the problem here is that toolbar buttons come in many different flavors
  ## look for text button
  #text_button_arr = query("toolbar child toolbarTextButton child button child buttonLabel", :text)
  #has_text_button = text_button_arr.index(name_or_id) != nil
  ## look for non_text button
  #toolbar_button_arr = query("toolbar child toolbarButton", AL)
  #has_toolbar_button = toolbar_button_arr.index(name_or_id) != nil
  #
  #has_text_button or has_toolbar_button
end

#toolbar_exists?(id) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/briar/bars/toolbar.rb', line 14

def toolbar_exists? (id)
  !query("toolbar marked:'#{id}'").empty?
end

#toolbar_qstr(toolbar_id = nil) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/briar/bars/toolbar.rb', line 6

def toolbar_qstr(toolbar_id=nil)
  if toolbar_id.nil?
    'toolbar'
  else
    "toolbar marked:'#{toolbar_id}'"
  end
end

#touch_navbar_item(item_name, wait_for_view_id = nil) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/briar/bars/navbar.rb', line 168

def touch_navbar_item(item_name, wait_for_view_id=nil)
  timeout = BRIAR_WAIT_TIMEOUT
  msg = "waited '#{timeout}' seconds for nav bar item '#{item_name}' to appear"

  wait_for(wait_opts(msg, timeout)) do
    (index_of_navbar_button(item_name) != nil) || button_exists?(item_name)
  end

  sleep(0.2)
  idx = index_of_navbar_button item_name

  if idx
    touch("navigationButton index:#{idx}")
    unless wait_for_view_id.nil?
      wait_for_view wait_for_view_id
    end
    step_pause
  elsif button_exists? item_name
    touch_button_and_wait_for_view item_name, wait_for_view_id
  else
    screenshot_and_raise "could not find navbar item '#{item_name}'"
  end
end

#touch_navbar_item_and_wait_for_view(item_name, view_id) ⇒ Object



193
194
195
# File 'lib/briar/bars/navbar.rb', line 193

def touch_navbar_item_and_wait_for_view(item_name, view_id)
  touch_navbar_item item_name, view_id
end

#touch_tabbar_item(name, wait_for_view_id = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/briar/bars/tabbar.rb', line 26

def touch_tabbar_item(name, wait_for_view_id=nil)
  sleep(0.2)
  wait_for(:timeout => BRIAR_WAIT_TIMEOUT,
           :retry_frequency => BRIAR_WAIT_RETRY_FREQ) do
    index_of_tabbar_item(name) != nil
  end
  should_see_tabbar
  idx = index_of_tabbar_item name
  if idx
    touch "tabBarButton index:#{idx}"
    unless wait_for_view_id.nil?
      wait_for_view wait_for_view_id
    end
    step_pause
  else
    screenshot_and_raise "tabbar button with name #{name} does not exist"
  end
end

#touch_toolbar_button(button_id, opts = {}) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/briar/bars/toolbar.rb', line 99

def touch_toolbar_button(button_id, opts={})

  if opts.is_a?(Hash)
    default_opts ={:wait_for_view => nil,
                   :timeout => BRIAR_WAIT_TIMEOUT,
                   :toolbar_id => nil}
    opts = default_opts.merge(opts)
  else
    _deprecated('0.1.2',
               "second argument should be a hash - found '#{opts}'",
               :warn)
    opts = {:wait_for_view => opts[:wait_for_view],
            :timeout => BRIAR_WAIT_TIMEOUT,
            :toolbar_id => nil}
  end

  should_see_toolbar_button button_id, opts

  toolbar_qstr = toolbar_qstr(opts[:toolbar_id])
  touch("#{toolbar_qstr} descendant view marked:'#{button_id}'")

  wait_for_view = opts[:wait_for_view]
  unless wait_for_view.nil?
    timeout = opts[:timeout]
    msg = "touched '#{button_id}' and waited for '#{timeout}' sec but did not see '#{wait_for_view}'"
    options = {:timeout => timeout,
               :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
               :post_timeout => BRIAR_WAIT_STEP_PAUSE,
               :timeout_message => msg}
    wait_for(options) do
      view_exists? wait_for_view
    end
  end
end

#wait_for_toolbar(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/briar/bars/toolbar.rb', line 86

def wait_for_toolbar(toolbar_id, timeout=BRIAR_WAIT_TIMEOUT)
  msg = "waited for '#{timeout}' seconds but did not see toolbar marked: '#{toolbar_id}'"
  options = {:timeout => timeout,
             :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
             :post_timeout => BRIAR_WAIT_STEP_PAUSE,
             :timeout_message => msg}
  wait_for(options) do
    toolbar_exists? toolbar_id
  end

end

#wait_for_toolbar_button(button_id, opts = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/briar/bars/toolbar.rb', line 46

def wait_for_toolbar_button(button_id, opts={})
  default_opts = {:timeout => BRIAR_WAIT_TIMEOUT,
                  :toolbar_id => nil}
  opts = default_opts.merge(opts)
  timeout=opts[:timeout]
  toolbar_id = opts[:toolbar_id]
  if toolbar_id.nil?
    msg = "waited for '#{timeout}' seconds but did not see toolbar button marked: '#{button_id}'"
  else
    msg = "waited for '#{timeout}' seconds but did not see toolbar button marked: '#{button_id}' in toolbar '#{toolbar_id}'"
  end

  options = {:timeout => timeout,
             :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
             :post_timeout => BRIAR_WAIT_STEP_PAUSE,
             :timeout_message => msg}
  wait_for(options) do
    toolbar_button_exists? button_id, opts
  end

end

#wait_for_toolbar_to_disappear(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/briar/bars/toolbar.rb', line 73

def wait_for_toolbar_to_disappear(toolbar_id, timeout=BRIAR_WAIT_TIMEOUT)
  msg = "waited for '#{timeout}' seconds but i still see toolbar marked: '#{toolbar_id}'"
  options = {:timeout => timeout,
             :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
             :post_timeout => BRIAR_WAIT_STEP_PAUSE,
             :timeout_message => msg}

  wait_for(options) do
    not toolbar_exists? toolbar_id
  end
end