Question

After iOS 7 We had an issue with UIAlertView verification using calabash.

for now I'm able to detect the alert message using

wait_for_elements_exist(["view:'_UIModalItemRepresentationView'"], :timeout => 20)
query("view:'_UIModalItemRepresentationView' label marked:'#{text}'",).empty?

I got the idea from https://gist.github.com/seanoshea/7613671

But previously (in iOS 6) we were able to detect the message and title clearly like this

title = query("view:'UIAlertView'",:title).first
msg = query("view:'UIAlertView'",:message).first

Is there any way that we can do the same in iOS7 ? "frank" guys do the same I think https://github.com/moredip/Frank/pull/262.

Note: jmoody Plese help us with this iOS 7 alerts in calabash automation.

Was it helpful?

Solution

For now I have been using this solution. If anyone face the same issue can use this until we have a good solution.

Then /^I should see empty email alert$/ do
  is_alert_exist_with_text("Email cannot be empty.")
  sleep(0.5)
  touch_alert_button("OK")
end
######## define the functions
def touch_alert_button(button)
  btn = query("view:'_UIModalItemTableViewCell' label marked:'#{button}'").first.empty?
  if (btn)
    screenshot_and_raise "button not found '#{button}'"
  else
    touch("view:'_UIModalItemTableViewCell' label marked:'#{button}'").first
    sleep(0.2)
  end
end

def is_alert_exist_with_text(text)
  unless query("view:'_UIModalItemRepresentationView' label marked:'#{text}'",).empty?
    return true
  else
    screenshot_and_raise "could not find the text '#{text}' in alert view"
  end
end

Further more...

def is_alert_exist_with_title_and_message(title, message)
  elements = query("view:'_UIModalItemRepresentationView' label", 'text')
  buttons = query("view:'_UIModalItemTableViewCell' label", 'text')
  textLabels = elements - buttons

  if (textLabels.count == 2)
    screenshot_and_raise "Alert Title '#{title}' not found" unless (textLabels[0].eql? title)
    screenshot_and_raise "Alert Message '#{message}' not found" unless (textLabels[1].eql? message)
  else
    screenshot_and_raise "Argument error...isAlertExistWithTitleAndMessage function"
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top