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