I tested this code and it works perfectly
internal step definition file (ProjectName / features / step_definitions / my_first_steps.rb) add
Then /^I see an alert with "([^\"]*)" text$/ do |message| result = query("view:'UIAlertView' label text:'#{message}'").empty? if result screenshot_and_raise "could not find text field with AlertView with text '#{message}'" end sleep(STEP_PAUSE) end
and in the properties file
Then I see an alert with "Email cannot be empty." text
If the text does not match the message, it will take a screenshot and not run a test
But this works for your custom alerts, not system alerts .. !!
this will help you if you need to read a message from an alert
open $ calabash-ios console and
query of type query("view:'UIAlertView'",:message)
add more....
Or you can use something like
Then /^I wait until alert with text "([^\"]*)" and press "([^\"]*)" button$/ do |message, button| wait_for_elements_exist(["alertView child label marked:'#{message}'"], :timeout => 30, :retry_frequency => 0.3,:timeout_message => "Timed out waiting..",:screenshot_on_error => true ) if element_exists("alertView child label marked:'#{message}'") touch("button marked:'#{button}'") sleep(STEP_PAUSE) else screenshot_and_raise "Alert Element not found" end end
source share