module Briar::Bars

Public Instance Methods

date_is_in_navbar(date) click to toggle source
# 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={}) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

will not work to detect left/right buttons

# 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) click to toggle source
# File lib/briar/bars/tabbar.rb, line 21
def index_of_tabbar_item(name)
  tabs = query('tabBarButton', AL)
  tabs.index(name)
end
navbar_has_back_button?() click to toggle source
navbar_has_title?(title) click to toggle source
navbar_visible?() click to toggle source
should_not_see_navbar() click to toggle source
# 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_button() click to toggle source
# 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={}) click to toggle source
todo convert args to hash and mirror the should_see_navbar_button

is_ui_button=false)

# 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_tabbar() click to toggle source
# 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) click to toggle source
# 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_navbar() click to toggle source
# 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_button() click to toggle source
# 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={}) click to toggle source

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

# 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) click to toggle source
# 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) click to toggle source
# 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_tabbar() click to toggle source
# 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) click to toggle source
# 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}) click to toggle source
# 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?() click to toggle source
# File lib/briar/bars/tabbar.rb, line 5
def tabbar_visible?
  element_exists('tabBar')
end
toolbar_button_exists?(button_id, opts={:toolbar_id => nil}) click to toggle source
# 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) click to toggle source
# File lib/briar/bars/toolbar.rb, line 14
def toolbar_exists? (id)
  !query("toolbar marked:'#{id}'").empty?
end
toolbar_qstr(toolbar_id=nil) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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={}) click to toggle source
# 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) click to toggle source
# 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={}) click to toggle source
# 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) click to toggle source
# 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