module Briar::Alerts_and_Sheets

Public Instance Methods

alert_button_exists?(button_id) click to toggle source
# File lib/briar/alerts_and_sheets/alert_view.rb, line 93
def alert_button_exists? (button_id)
  if uia_available?
    should_see_alert
    not uia_query(:view, {:marked => "#{button_id}"}).empty?
  else
    query('alertView child button child label', :text).include?(button_id)
  end
end
alert_exists?(alert_id=nil) click to toggle source

of interest touch(“view:'_UIModalItemAlertContentView' descendant view:'_UIModalItemTableViewCell' marked:'OK'”)

# File lib/briar/alerts_and_sheets/alert_view.rb, line 10
def alert_exists? (alert_id=nil)
  if uia_available?
    res = uia('uia.alert() != null')
    res['value']
  else
    if alert_id.nil?
      !query('alertView').empty?
    else
      !query("alertView marked:'#{alert_id}'").empty?
    end
  end
end
dismiss_alert_with_button(button_label) click to toggle source
# File lib/briar/alerts_and_sheets/alert_view.rb, line 108
def dismiss_alert_with_button (button_label)
  touch_alert_button(button_label)
  if uia_available?
    wait_for_view_to_disappear button_label
  else
    wait_for_view_to_disappear 'alertView'
  end
end
error_msg_for_sheet_button(button_title, visible, sheet_id=nil) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 64
def error_msg_for_sheet_button(button_title, visible, sheet_id=nil)
  vis_str = visible ? 'see' : 'not see'
  sheet_str = sheet_id ? sheet_id : ''
  "should #{vis_str} button with title '#{button_title}' on sheet '#{sheet_str}'"
end
query_str_for_sheet(sheet_id) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 5
def query_str_for_sheet(sheet_id)
  # Ignoring argument because iOS 8 sheets do not retain their accessibilityIdentifier
  return "view:'_UIAlertControllerView'" if ios8? or ios9?
  if sheet_id
    "actionSheet marked:'#{sheet_id}'"
  else
    'actionSheet'
  end
end
sheet_button_exists?(button_title, sheet_id=nil) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 70
def sheet_button_exists? (button_title, sheet_id=nil)
  sheet_query = query_str_for_sheet sheet_id
  if ios8? || ios9?
    query("#{query_str_for_sheet sheet_id} descendant view:'_UIAlertControllerActionView'  marked:'#{button_title}'")
  else
    query("#{sheet_query} child button child label", :text).include?(button_title)
  end
end
sheet_exists?(sheet_id) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 15
def sheet_exists?(sheet_id)
  !query(query_str_for_sheet sheet_id).empty?
end
should_not_see_alert(alert_id=nil) click to toggle source
# File lib/briar/alerts_and_sheets/alert_view.rb, line 33
def should_not_see_alert (alert_id=nil)
  if alert_exists? alert_id
    if alert_id.nil?
      screenshot_and_raise 'should not see alert view'
    else
      screenshot_and_raise "should not see alert view marked '#{alert_id}'"
    end
  end
end
should_not_see_button_on_sheet(button_title, sheet_id=nil) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 85
def should_not_see_button_on_sheet(button_title, sheet_id=nil)
  if sheet_button_exists? button_title, sheet_id
    screenshot_and_raise error_msg_for_sheet_button button_title, false, sheet_id
  end
end
should_not_see_sheet(sheet_id) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 33
def should_not_see_sheet(sheet_id)
  if sheet_exists?(sheet_id)
    screenshot_and_raise "should not see sheet marked '#{sheet_id}'"
  end
end
should_see_alert(alert_id=nil) click to toggle source
# File lib/briar/alerts_and_sheets/alert_view.rb, line 23
def should_see_alert (alert_id=nil)
  unless alert_exists? alert_id
    if alert_id.nil?
      screenshot_and_raise 'should see alert view'
    else
      screenshot_and_raise "should see alert view marked '#{alert_id}'"
    end
  end
end
should_see_alert_button(button_id) click to toggle source
# File lib/briar/alerts_and_sheets/alert_view.rb, line 102
def should_see_alert_button (button_id)
  unless alert_button_exists? button_id
    screenshot_and_raise "could not find alert view with button '#{button_id}'"
  end
end
should_see_alert_with_message(message, timeout=BRIAR_WAIT_TIMEOUT) click to toggle source
# File lib/briar/alerts_and_sheets/alert_view.rb, line 67
def should_see_alert_with_message (message, timeout=BRIAR_WAIT_TIMEOUT)
  should_see_alert
  if uia_available?
    msg = "expected to see alert with title '#{message}'"
    wait_for(:timeout => timeout,
             :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
             :post_timeout => BRIAR_WAIT_STEP_PAUSE,
             :timeout_message => msg) do
      if ios8? || ios9?
        not query("view:'_UIAlertControllerView' marked:'#{message}'").empty?
      else
        not uia_query(:view, {:marked => "#{message}"}).empty?
      end
    end
  else
    qstr = 'alertView child label'
    msg = "waited for '#{timeout}' for alert with message '#{message}'"
    wait_for(:timeout => timeout,
             :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
             :post_timeout => BRIAR_WAIT_STEP_PAUSE,
             :timeout_message => msg) do
      query(qstr, :text).include?(message)
    end
  end
end
should_see_alert_with_title(title, timeout=BRIAR_WAIT_TIMEOUT) click to toggle source
# File lib/briar/alerts_and_sheets/alert_view.rb, line 43
def should_see_alert_with_title (title, timeout=BRIAR_WAIT_TIMEOUT)
  should_see_alert
  if uia_available?
    msg = "expected to see alert with title '#{message}'"
    wait_for(:timeout => timeout,
             :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
             :post_timeout => BRIAR_WAIT_STEP_PAUSE,
             :timeout_message => msg) do
      if ios8? || ios9?
        not query("view:'_UIAlertControllerView' marked:'#{message}'").empty?
      else
        not uia_query(:view, {:marked => "#{message}"}).empty?
      end
    end
  else
    qstr = 'alertView child label'
    msg = "waited for '#{timeout}' for alert with title '#{title}'"
    opts = wait_opts(msg, timeout)
    wait_for(opts) do
      query(qstr, :text).include?(title)
    end
  end
end
should_see_button_on_sheet(button_title, sheet_id=nil) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 79
def should_see_button_on_sheet(button_title, sheet_id=nil)
  unless sheet_button_exists? button_title, sheet_id
    screenshot_and_raise error_msg_for_sheet_button button_title, true, sheet_id
  end
end
should_see_sheet(sheet_id, button_titles=nil, sheet_title=nil) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 19
def should_see_sheet(sheet_id, button_titles=nil, sheet_title=nil)
  unless sheet_exists?(sheet_id)
    screenshot_and_raise "should see sheet marked '#{sheet_id}'"
  end

  if button_titles
    button_titles.each { |title| should_see_button_on_sheet title, sheet_id }
  end

  if sheet_title
    should_see_sheet_title sheet_title, sheet_id
  end
end
should_see_sheet_title(label_title, sheet_id=nil) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 91
def should_see_sheet_title(label_title, sheet_id=nil)
  sheet_query = query_str_for_sheet sheet_id
  res = query("#{sheet_query} child label", :text).include?(label_title)
  unless res
    "should see sheet #{sheet_id ? "'#{sheet_id}'" : ''} with title '#{label_title}'"
  end
end
touch_alert_button(button_title) click to toggle source
# File lib/briar/alerts_and_sheets/alert_view.rb, line 118
def touch_alert_button(button_title)
  should_see_alert
  if ios8? || ios9?
    touch("view marked:'#{button_title}' parent view:'_UIAlertControllerCollectionViewCell'")
  elsif ios7?
    touch("view marked:'#{button_title}'")
  else
    touch("alertView child button marked:'#{button_title}'")
  end
  step_pause
end
touch_sheet_button(button_title, sheet_id=nil) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 99
def touch_sheet_button (button_title, sheet_id=nil)
  sheet_query = query_str_for_sheet sheet_id
  should_see_button_on_sheet button_title, sheet_id
  if ios8? || ios9?
    touch("#{query_str_for_sheet sheet_id} descendant view:'_UIAlertControllerActionView'  marked:'#{button_title}'")
  else
    touch("#{sheet_query} child button child label marked:'#{button_title}'")
  end
end
touch_sheet_button_and_wait_for_view(button_title, view_id, sheet_id=nil) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 109
def touch_sheet_button_and_wait_for_view(button_title, view_id, sheet_id=nil)
  touch_sheet_button button_title, sheet_id
  wait_for_view view_id
end
wait_for_sheet(sheet_id, timeout=BRIAR_WAIT_TIMEOUT) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 39
def wait_for_sheet (sheet_id, timeout=BRIAR_WAIT_TIMEOUT)
  if sheet_id
    msg = "waited for '#{timeout}' seconds but did not see '#{sheet_id}'"
  else
    msg = "waited for '#{timeout}' seconds but did not see UIActionSheet"
  end
  wait_for(:timeout => timeout,
           :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
           :post_timeout => BRIAR_WAIT_STEP_PAUSE,
           :timeout_message => msg) do
    sheet_exists? sheet_id
  end
end
wait_for_sheet_to_disappear(sheet_id, timeout=BRIAR_WAIT_TIMEOUT) click to toggle source
# File lib/briar/alerts_and_sheets/action_sheet.rb, line 53
def wait_for_sheet_to_disappear(sheet_id, timeout=BRIAR_WAIT_TIMEOUT)
  msg = "waited for '#{timeout}' seconds for '#{sheet_id}' to disappear but it is still visible"
  options = {:timeout => timeout,
             :retry_frequency => BRIAR_WAIT_RETRY_FREQ,
             :post_timeout => BRIAR_WAIT_STEP_PAUSE,
             :timeout_message => msg}
  wait_for(options) do
    not sheet_exists? sheet_id
  end
end