Earlgrey 我的应用程序显示一个启动屏幕。如何让测试等待主屏幕?
我的应用程序显示一个启动屏幕。如何使测试等待主屏幕出现?没有等待,我的测试在应用程序启动后立即失败Earlgrey 我的应用程序显示一个启动屏幕。如何让测试等待主屏幕?,earlgrey,Earlgrey,我的应用程序显示一个启动屏幕。如何使测试等待主屏幕出现?没有等待,我的测试在应用程序启动后立即失败 // in application:didFinishLaunchingWithOptions: of my AppDelegate... SplashViewController *splashVC = [[SplashViewController alloc] init]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mai
// 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
提供了API,您可以在设置方法或特定测试开始时使用该API,使EarlGrey在等待启动屏幕消失时等待。您可以使用类似于他们的应用程序中的代码来实现这一点
//等待主视图控制器成为根视图控制器。
BOOL success=[[GREYCondition conditionWithName:@“等待主根视图控制器”
区块:^{
id appDelegate=[UIApplication sharedApplication]。委托;
UIViewController*rootViewController=appDelegate.window.rootViewController;
return[rootViewController isKindOfClass:[MainViewController类]];
}]waitWithTimeout:5];
GREYAssertTrue(成功,@“主视图控制器应在5秒内出现”);
您能提供一段测试代码吗?
// 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.");