2016-07-04 45 views
0

我正在使用Xcode 7的UI測試,但有一些問題。 當我記錄UI測試時,Xcode用大寫字母「U」將中文翻譯爲Unicode,並顯示錯誤。 和UI測試代碼我怎樣才能控制UIButton被用來準備UI測試中的下一個動作後使用Xcode

XCUIApplication *app = [[XCUIApplication alloc] init]; 
[app.navigationBars[@"\u5934\u6761"].images[@"new_not_login30"] tap]; 
XCUIElementQuery *tablesQuery = app.tables; 
[tablesQuery.cells.staticTexts[@"\u6211\u7684\u864e\u94b1"] tap]; 

的問題是:攻圖像後,有證據顯示有UITableView的或顯示UIAlertController側邊欄的動畫,但我不能處理的持續時間。實際上,在動畫中,測試繼續找到匹配的下一個元素,但這些元素不存在或不存在。所以測試總是失敗。 任何解決方案來回答這個問題?請幫幫我。謝謝。

+0

你想在按鈕動作發生之前有延時嗎? –

+0

@BashirSidani點擊按鈕 - >創建延遲並完成動畫 - >找到按鈕並點擊 – Chipmuck

回答

1

試着用expectationForPredicate。我不知道objective-c中的語法。但是這裏是快速代碼的一部分:

let app = XCUIApplication() 
app.navigationBars["\u5934\u6761"].images["new_not_login30"].tap() 
let label = app.cells.staticTexts["\u6211\u7684\u864e\u94b1"] 
let exists = NSPredicate(format: "exists == 1") 
expectationForPredicate(exists, evaluatedWithObject: label) { 
    // If the label exists, also check that it is enabled 
    if label.enabled { 
     label.tap() 
     return true 
    } else { 
     return false 
    } 
} 
waitForExpectationsWithTimeout(5) { error in 
    if (error != nil) { assertion ....} 

} 

只需在objective-c中轉換此代碼即可。

乾杯

+0

謝謝!這個對我有用! :) – Chipmuck

相關問題