Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI testing a tab bar controller

I have built a simple tab bar with 3 tabs.

enter image description here

I want to run a UI test to make sure that if the user clicks a tab bar item, the correct view controller shows. How would I go about doing that? Below is the code I would start with, just don't know how to write my assertion.

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()
}
like image 713
Josh Avatar asked Oct 25 '16 02:10

Josh


2 Answers

If you have different controls in each view controller shown on each tab bar, you can make assertions if they exist or not (what is expected). For example if the first tab bar has UILabel named "First name" you can assert if it exists by writing

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

And on the other screens do the same thing for the different controls.

like image 96
Amjad Husseini Avatar answered Oct 19 '22 16:10

Amjad Husseini


You can access the tabbar button by its position:

app.tabBars.buttons.element(boundBy: 2).tap()
like image 34
Marc Fdn Avatar answered Oct 19 '22 16:10

Marc Fdn