xcode - Xcode 7 中的 XCTest : how to verify some text exists in the view

标签 xcode swift xctest

我正在 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 中同一 View 中是否出现一些文本。

有什么想法吗?

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

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

关于xcode - Xcode 7 中的 XCTest : how to verify some text exists in the view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38253056/

相关文章:

iphone - 如何对自动生成的 iOS 应用进行代码设计?

ios - Swift 5.1 运行时如何与旧版本的 iOS 一起工作?

ios - Xcode 找不到 Mogenerator

swift - 如何在 SpriteKit 中改变物体的质量以随着重力下降得更慢

ios - 为什么将 NSString 对象传递给 XCTAssertTrue 的 "format"参数会导致构建错误?

objective-c - 如何对 NSArrayController (子类)进行单元测试?

xcode - 如何创建 React-Native tvos 项目?

ios - Alamofire 嵌套请求

ios - UICollectionViewCell 阴影与装饰 View 不一致

ios - 使用 keyValueObservingExpectationForObject 时的 XCTest 异常 :keyPath:handler: