我开始使用KIF,并且无法使用当前配置测试异步加载的表视图。使用KIF测试异步UITableView
我有一个主屏幕在我的应用程序中有一个按钮。当按下该按钮时,将呈现模态视图控制器。
- (void)viewDidLoad
{
[super viewDidLoad];
// Setup accessibility
self.theTableView.accessibilityLabel = @"My List";
// Register for notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectsLoadedNotification:) name:kNotificationObjectsLoaded object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectsFailedToLoadNotification:) name:kNotificationObjectsFailedToLoad object:nil];
// Start loading new data
[[MyListObjectManager sharedInstance] requestObjects];
}
现在,我已经安装在KIF测试看起来像这样:
+ (id)scenarioToSelecList
{
KIFTestScenario *scenario = [KIFTestScenario scenarioWithDescription:@"Test that a user can select an item from my list."];
[scenario addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"List"]];
[scenario addStep:[KIFTestStep stepToWaitForNotificationName:kNotificationObjectsLoaded object:nil]];
[scenario addStep:[KIFTestStep stepToTapRowInTableViewWithAccessibilityLabel:@"My List" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]];
}
当我运行测试,KIF永远看不到我的对象加载的通知。
在调试时,我取代在我viewDidLoad方法的[的ObjectManager requestObjects]呼叫与异步呼叫请求的对象三秒钟之后:
[[MyListObjectManager sharedInstance] performSelector:@selector(requestObjects) withObject:nil afterDelay:3.0];
当我做到这一点,我看到在KIF以下输出:
PASS (0.90s): Tap view with accessibility label "Find Books"
PASS (3.02s): Wait for notification "notificationObjectsLoaded"
这使我相信原来的问题是,我正在等待通知的第一步以往执行完毕前被解雇。
因此,问题就变成了,为什么第一步需要0.9秒才能完成?是否等待模态动画在从步骤返回之前完成?在这种情况下,加载对象的请求比动画完成得更快。
应该如何处理KIF?或者有没有不同的方法来加载我的tableview的异步数据会更合适?
谢谢 - 有问题的步骤是成功的B/C我加了3秒的等待时间来装载。但是,现在这是无关紧要的......你完全正确!我没有意识到在一行中点击的步骤将等待表填充(在超时内)。我已经替换了等待通知的步骤,以便等待表格可见,而不是完美地工作,等待该行填充后点击它。谢谢,吉姆! – jmac 2012-01-13 18:36:47