Search code examples
iphoneiostestingcucumberfrank

How can I touch a UIAlertView's 'OK' or 'Cancel' button using Frank?


I have tried a few different things including this:

 When /^I touch the alertview button marked "(.*?)"$/ do |alert_btn_name|
   touch "view: 'UIAlertButton' marked:'#{alert_btn_name}'"
 end

and

 When /^I touch the (\d*)(?:st|nd|rd|th)? alert view button$/ do |ordinal|
   ordinal = ordinal.to_i
   touch( "alertView threePartButton tag:#{ordinal}" )
 end

What is a good way to go about doing this?


Solution

  • Your code looks good, is it not working?

    You can also try to use the Frank predefined steps, and just do:

    When I touch "Cancel"
    Then I should not see an alert view
    

    Or if you want the actual step for "When I touch ..", it would be:

    When /^I touch "([^\"]*)"$/ do |mark|
          quote = get_selector_quote(mark)
          selector = "view marked:#{quote}#{mark}#{quote} first"
          if element_exists(selector)
             touch( selector )
          else
             raise "Could not touch [#{mark}], it does not exist."  
          end
          sleep 1
    end