Xcode 7 中的 XCTest:如何验证视图中是否存在某些文本

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

我是 El Capitan (10.11) 的 运行 Xcode 7。我正在使用 XCUITest 的新记录和回放功能。我使用的是 Swift 而不是 Objective-C。这是我到目前为止生成的代码:

    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

}

我想验证点击按钮后某些文本是否出现在 UILabel 的同一视图中。

有什么想法吗?

我知道这里列出了一堆断言:

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

假设您参考了正确设置的标签:

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")

}
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(app.staticTexts.elementBoundByIndex(0).label, "some text", "should be equal") }