如何确认系统警报,如允许通知

时间:2016-03-24 02:19:03

标签: uitest earlgrey

如果第一次安装该应用,需要允许通知,我该如何确认?有人遇到过吗?

enter image description here

1 个答案:

答案 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