我遇到了一個問題,在使用以下代碼時,我的UI測試顯示找到了多個按鈕。Xcode UI測試發現多個按鈕
app.buttons["Upgrade"].tap()
所以我重新我的單元測試和運行在該行之前設置一個斷點權利,按下錄音鍵,並單擊該按鈕,它產生下面的代碼。
app.children(matching: .window).element(boundBy: 0).children(matching: .other).element(boundBy: 1).buttons["Upgrade"].tap()
當然,在測試的頂部,我有let app = XCUIApplication()
。
任何想法爲什麼會發生這種情況?
有時在調試器中運行p UIApplication.shared.windows
時,它在數組中有2個值。我不知道爲什麼,因爲我從來沒有多個窗口。我與Windows的唯一交互作用是將UIApplication.shared.keyWindow?.rootViewController
設置爲不同的視圖控制器,以及didFinishLaunchingWithOptions
中的以下代碼。
// Get view controllers ready
self.window = UIWindow(frame: UIScreen.main.bounds)
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let mainViewController: ViewController = mainStoryboard.instantiateViewController(withIdentifier: "FirstView") as! ViewController
// Show view controller
self.window?.rootViewController = mainViewController
self.window?.makeKeyAndVisible()
這是一個if語句內else語句中我有幾乎相同的代碼,除了沒有FirstView
它的SecondView
。出現
打印'app.buttons [「Upgrade」]。debugDescription'可能提供提示... –
我想我以前遇到過這個問題。您可以嘗試在您正在測試的按鈕上拋出唯一的輔助功能標識符,然後重新記錄測試。 – Adrian
@PauloMattos我設置了一個斷點並試圖打印,但它打印了很多東西。我迅速瀏覽了它,找不到任何有用的東西或者我不知道的東西。 –