我的应用程序显示启动画面。如何让我的测试等待主屏幕?

时间:2016-07-26 22:58:06

标签: earlgrey

我的应用程序显示启动画面。如何让我的测试等待主屏幕出现?在没有等待的情况下,我的测试在应用程序启动后立即失败。

// 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.

1 个答案:

答案 0 :(得分:2)

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.");
相关问题