答案 0 :(得分:2)
您通常应该模拟通知和其他数据请求,以防止对话框出现。您也可以手动接受通知并重新运行测试。我们尝试使用私有UIAutomation框架,看到我们可以用它实现这一目标。例如,按下左侧警报按钮。
@interface SystemAlert : NSObject
- (void)tapLeftButton;
@end
@interface SystemAlert (ForMethodCompletionOnly)
+ (id)localTarget;
- (id)frontMostApp;
- (id)alert;
- (id)buttons;
@end
@implementation SystemAlert
+ (void)load {
dlopen([@"/Developer/Library/PrivateFrameworks/UIAutomation.framework/UIAutomation" fileSystemRepresentation], RTLD_LOCAL);
}
- (void)tapLeftButton {
id localTarget = [NSClassFromString(@"UIATarget") localTarget];
id app = [localTarget frontMostApp];
id alert = [app alert];
id button = [[alert buttons] objectAtIndex:0];
[button tap];
}
@end