我開始使用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