Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIAAlert defaultButton and cancelButton return 'nil' on iOS 8 #584

Closed
jmoody opened this issue Oct 25, 2014 · 3 comments
Closed

UIAAlert defaultButton and cancelButton return 'nil' on iOS 8 #584

jmoody opened this issue Oct 25, 2014 · 3 comments

Comments

@jmoody
Copy link
Contributor

jmoody commented Oct 25, 2014

I found bug in the UIAAlert API.

This is an Apple bug.

Workaround

If your UIAlert has two buttons, you can do this:

# Default button is index 1
> uia("uia.alert().buttons()[1].name()")
# Cancel button is index 0
> uia("uia.alert().buttons()[0].name()")

Reproduce

$ cd briar-ios-example/Briar
$ make app-cal
$ export APP=${PWD}/Briar-cal.app
$ be calabash-ios console
> start_test_server_in_background
> export APP=${PWD}/Briar-cal.app
> touch("button marked:'show alert'")
# Alert appears
> uia("uia.alert().defaultButton()")
> uia("uia.alert().cancelButton()")

Expected

{
    "status" => "success",
     "value" => "[object UIAButton]",
     "index" => 0
}

Actual

{
    "status" => "success",
     "value" => ":nil",
     "index" => 1
}

Regression

Repeat with iOS 7.1

irb(main):003:0> uia("uia.alert().defaultButton()")
{
    "status" => "success",
     "value" => "[object UIAButton]",
     "index" => 0
}
irb(main):004:0> uia("uia.alert().cancelButton()")
{
    "status" => "success",
     "value" => "[object UIAButton]",
     "index" => 1
}
@jmoody
Copy link
Contributor Author

jmoody commented Nov 10, 2014

duplicate of #558

Once the radar is filed, these can be closed.

@jmoody
Copy link
Contributor Author

jmoody commented Sep 16, 2015

Closing. Will report again if this appears in Xcode 7.

@jmoody jmoody closed this as completed Sep 16, 2015
@jmoody jmoody reopened this Sep 16, 2015
@jmoody
Copy link
Contributor Author

jmoody commented Sep 21, 2015

Cannot reproduce in Xcode 7 UIAutomation.

CalSmokeApp

UIATarget.onAlert = function onAlert(alert) {
    var title = alert.name();
    UIALogger.logWarning("Alert with title '" + title + "' encountered.");
    // return false to use the default handler
    return false;
}
var target = UIATarget.localTarget();

target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);
target.frontMostApp().tabBar().buttons()["Special"].tap();
target.frontMostApp().mainWindow().elements()["special page"].buttons()["show alert"].tap();
UIALogger.logPass("alert: ".concat(target.frontMostApp().alert()))

// Alert detected. Expressions for handling alerts should be moved into the UIATarget.onAlert function definition.
UIALogger.logPass("button: ".concat(target.frontMostApp().alert().defaultButton().name()))

cancelButton() also works.

@jmoody jmoody closed this as completed Sep 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant