How do i read text from an Alert(ios) in calabash

How can I access the text of an alertview on iOS in my calabash/cucumber tests?

NSString *msgString = [NSString stringWithFormat:@"No: %@\n Latitude: %f\n Longitude: %f",, wrapper.latitude, wrapper.longitude];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Really reset?" message:@"msgString" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] autorelease];
// optional - add more buttons:
[alert addButtonWithTitle:@"Yes"];
[alert show];

I want to assert that the alert has the expected content:

Feature: Running a test
  As a user using a phone connected to the internet
  I want to have correct sample data retrieved from cache or net
  So I can read the values of the tableview

   Scenario: Testing retrieved data

  Given the app is running
  Then I press "Refresh"
  Then I should see "Some value"
  Then I press "Some value"
  Then I should /*See an alert with "myMessage"*/
  Then I press "OK"

  And take picture

So if i change the string to simply "No:" and discard everything else from the string, it does actually seem to work, but i cant get it running with my more complex string :(


A solution to add newline support is to take the variables out of the string in the features so that the newline can be added by the ruby code:

Then I see a popup with latitude 10 and longitude 20


Then /^I see a popup with latitude (\d+) and longitude (\d+)$/ do |lat, lon|
  msg = "Latitude:#{lat}\nLongitude:#{lon}"
  should_see_alert_with_text msg


def should_see_alert_with_text (text)
  wait_poll(:until_exists => 'alertView', :timeout => 5) do
    actual = query('alertView child label', :text).first
    unless actual.eql? text
      screenshot_and_raise "should see alert view with message '#{text}' but found '#{actual}'"

For iOS 7 and above: following calabash code will work fine.

Then I should see "your text here"
And I should see "Call XXX"
And I should see "Cancel"

Works for me.

Need Your Help

Visual Studio 2008 - jump to line number shortcut

visual-studio visual-studio-2008 ide keyboard-shortcuts

I can go to a specific line number by double clicking in the status bar in Visual Studio. Is there a keyboard shortcut that does the same thing?

How do you deal with multiple Python classes in the same module depending on each other?

python class import

I'm using an ODM library and I'm defining documents as classes within the same module, when they are related. I've hit a circular dependency problem and because I haven't come across this before in

VisualBrush not rendering in Style

.net wpf silverlight xaml

Why would my VisualBrush render a lovely image in my button with this code: