我的应用程序显示一个启动画面。我如何让我的测试等待主屏幕?
问题描述:
我的应用程序显示一个启动画面。如何让我的测试等待主屏幕出现?无需等待我的测试在应用程序启动后立即失败。我的应用程序显示一个启动画面。我如何让我的测试等待主屏幕?
// in application:didFinishLaunchingWithOptions: of my AppDelegate...
SplashViewController *splashVC = [[SplashViewController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = splashVC;
[self.window makeKeyAndVisible];
NSTimeInterval splashScreenDuration = 0.5;
[NSTimer scheduledTimerWithTimeInterval:splashScreenDuration
target:self
selector:@selector(hideSpashScreenAndDisplayMainViewController)
userInfo:nil
repeats:NO];
// hideSpashScreenAndDisplayMainViewController method simply sets self.window.rootViewController to the main view controller.
答
EarlGrey
提供GREYCondition API,你可以在你的安装方法或特定测试,以EarlGrey等你等待启动画面消失的开始使用。你可以使用类似于他们在faq page中的代码来做到这一点。
// Wait for the main view controller to become the root view controller.
BOOL success = [[GREYCondition conditionWithName:@"Wait for main root view controller"
block:^{
id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
UIViewController *rootViewController = appDelegate.window.rootViewController;
return [rootViewController isKindOfClass:[MainViewController class]];
}] waitWithTimeout:5];
GREYAssertTrue(success, @"Main view controller should appear within 5 seconds.");
您能否提供您的测试代码片段? – khandpur