ios - Xcode UI 测试 - 多个 UITableView

标签 ios xcode-ui-testing

如果我们有多个 UITableView,我们如何在 XCUITest 中指定哪一个?

XCUIApplication().tables.cells.count

返回所有单元格。我们如何选择哪个表来限制计数?

最佳答案

使用辅助功能标识符来区分您的表格 View 。

class ViewController: UIViewController {
    let firstTableView: UITableView!
    let secondTableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        firstTableView.accessibilityIdentifier = "First Table"
        secondTableView.accessibilityIdentifier = "Second Table"
    }
}

然后您可以在 UI 测试中直接引用其中一个表。

XCUIApplication().tables["First Table"].cells.count

关于ios - Xcode UI 测试 - 多个 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36487925/

相关文章:

ios - 可以使用 Adob​​e Air SDK 进行应用内购买

ios - tvOS 菜单按钮默认行为

error-handling - UI 测试失败,错误为 "Failed to get snapshot within 15.0s"

ios - 无法覆盖 Swift XCTestCase 中的 init() 函数

Xcode UI 测试 - UI 测试失败 - 当点击搜索字段 "Cancel' 按钮时无法滚动到可见(通过 AX 操作)

ios - 协议(protocol)中的静态变量

ios - Bootstrap 3 中 Canvas 外移动菜单的问题

ios - 从 firebase 检索到 swift 3 中的多个按钮

xctest - Xcode 7 - 如何启动 UI 测试的界面录制?

ios - 如何在 Xcode 的 UITests 下等待,直到某些 View 可见以供点击?