My app shows a splash screen. How can I make my test wait for the main screen to appear? Without waits my test fails immediately after app launch.
// 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
provides the GREYCondition API that you can use in your setup method or the beginning of your specific test to make EarlGrey wait while you wait for the splash screen to disappear. You can do this using code similar to what they have in their 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.");
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments