2016-10-25 126 views
2

我已經構建了一個帶有3個選項卡的簡單標籤欄。UI測試標籤欄控制器

enter image description here

我想運行一個UI測試,以確保當用戶點擊標籤欄項目,正確的視圖控制器節目。我會怎麼做呢?下面是我要開始的代碼,只是不知道如何寫我的斷言。

func testTabBarMyProfileButton() { 
    let tabBarsQuery = XCUIApplication().tabBars 
    tabBarsQuery.buttons["My Profile"].tap() 
} 

func testTabBarGraphsButton() { 
    let tabBarsQuery = XCUIApplication().tabBars 
    tabBarsQuery.buttons["Graphs"].tap() 
} 

func testTabBarAboutButton() { 
    let tabBarsQuery = XCUIApplication().tabBars 
    tabBarsQuery.buttons["About"].tap() 
} 

回答

2

如果在每個標籤欄上顯示的每個視圖控制器中都有不同的控件,則可以在斷言存在或不存在的情況下進行斷言。 例如,如果第一個標籤欄已經的UILabel命名爲「名」,如果它存在通過寫

Let theLabel = app.staticTexts["myValue"] 
XCTAssert(theLabel.exists).to(beTrue) 

而在其他屏幕做同樣的事情在不同的控件,你可以斷言。

0

您可以測試導航欄的標題。

XCTAssert(app.navigationBars["Graphs"].exists) 

請參閱my GitHub repo for a more detailed UI Testing example

+0

我沒有打算使用導航欄。有另一種方法嗎? – Josh

+1

你將不得不在每個屏幕上聲明獨特的東西。這可以是按鈕,文本標籤或UI控件中的任何內容。 –