1

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

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

1 回答 1

3

EarlGrey提供GREYCondition API,您可以在设置方法或特定测试开始时使用该 API,以使 EarlGrey 在您等待初始屏幕消失时等待。您可以使用类似于他们在常见问题解答页面中的代码来执行此操作。

// 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.");
于 2016-08-01T08:52:42.650 回答