Reputation: 1808
I was making some UI Tests using the new XCode 7. How my app uses Notification, on first use iOS automatically ask '"MyApp" Would Like to Send You Notifications'.
When I record the test, XCode write these lines below:
- (void)testFirstUse {
[XCUIDevice sharedDevice].orientation = UIDeviceOrientationPortrait;
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.alerts[@"\U201cMyApp\U201d Would Like to Send You Notifications"].collectionViews.buttons[@"OK"] tap];
[app.tables/*@START_MENU_TOKEN@*/.staticTexts[@"United States"]/*[[".cells.staticTexts[@\"United States\"]",".staticTexts[@\"United States\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ tap];
[app.navigationBars[@"Select a Country"].buttons[@"Next"] tap];
}
Note that XCode puts the unicode instead of quotes signal on MyApp name. When a run the test fails with error "No matches found for alert".
I tried change the unicode to quote signal but it also doesn't work.
Is it clear? Had someone this same issue?
[Update] I have two issue on this code
1- There is a bug on message with unicodes generated by XCode
2- Test fails after tap on Alerts showed by system
Upvotes: 0
Views: 1027
Reputation: 2420
The format of unicode characters generated by xcode is wrong so it is xcode bug. As a temporary workaround you could replace
[app.alerts[@"\U201cMyApp\U201d Would Like to Send You Notifications"].collectionViews.buttons[@"OK"] tap];
with
[app.alerts[@"\u201cMyApp\u201d Would Like to Send You Notifications"].collectionViews.buttons[@"OK"] tap];
i.e. all \U on \u
Upvotes: 1
Reputation: 1808
I found one work around for avoid crashing after dismissing a system alert:
I changed this line
[app.alerts[@"\U201cMyApp\U201d Would Like to Send You Notifications"].collectionViews.buttons[@"OK"] tap];
to
XCUIElement *alert = app.alerts[@"\U0000201cMyApp\U0000201d Would Like to Send You Notifications"].collectionViews.buttons[@"OK"];
if ([alert exists]) {
[alert tap];
}
I made two changes
Upvotes: 3
Reputation: 17018
You can acknowledge the alert by directly accessing the alert.element
and tapping the "OK" button via the collection view.
let app = XCUIApplication()
app.launch()
// trigger location permission dialog
app.alerts.element.collectionViews.buttons["Allow"].tap()
However, Xcode 7 (and Xcode 7.1 Beta) will crash after successfully dismissing the alert. I've opened a bug report with Apple and encourage all those experiencing the problem to duplicate it.
Upvotes: 2