2016-07-26 80 views
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. 
+0

您能否提供您的測試代碼片段? – khandpur

回答

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.");