lilredindy lilredindy - 4 months ago 47
Swift Question

XCTest in Xcode 7: how to verify some text exists in the view

I am running Xcode 7 on El Capitan (10.11). I am using the new record and playback feature for XCUITest. I am using Swift not Objective-C. Here is the code I have generated thus far:

func testButton2() {

let app = XCUIApplication()
app.tabBars.buttons["Location"].tap() //tab bar tap
app.buttons["Button"].tap() // button tap
//now verify some text appears in this tab view

}


I want to verify some text appears in the same view within a UILabel after button is tapped.

Any ideas?

I know there is a bunch of asserts listed here:

http://iosunittesting.com/xctest-assertions/

Answer

Assuming you have reference to your label properly set up:

func testButton2() {

    let app = XCUIApplication()
    app.tabBars.buttons["Location"].tap() //tab bar tap
    app.buttons["Button"].tap()  // button tap
    //now verify some text appears in this tab view
    XCTAssertEqual(myLabel.text, "some text", "should be equal")

}