【问题标题】:iOS UI Testing tap on first index of the tableiOS UI测试点击表格的第一个索引
【发布时间】:2016-04-12 07:35:18
【问题描述】:

我刚开始学习 iOS 中的 UI 测试。当我按下记录并点击表格的第一个索引时,它会生成这样的代码。

XCUIApplication *app = [[XCUIApplication alloc] init];
[app.tables.staticTexts[@"Apr 04 16:28"] tap];

如果我的所有数据都是恒定的,那就太好了。但是这些文本会不时更改。如何修改这些代码,使其始终点击表的第一个索引?

【问题讨论】:

    标签: ios xcode-ui-testing


    【解决方案1】:

    在您应用的cells 上使用-elementBoundByIndex

    XCUIApplication *app = [[XCUIApplication alloc] init];
    [[app.cells elementBoundByIndex: 0] tap];
    

    【讨论】:

    • 甜蜜。短而命中目标。谢谢:)
    • 在 Swift 4 中,使用 "app.tables.cells.element(boundBy: 0).tap()" 而不是 "[[app.cells elementBoundByIndex: 0] tap];"
    【解决方案2】:

    斯威夫特

    如果您正在进行 UI 测试,这将很有帮助:

    let cellCount = app.tables.cells.count
    XCTAssertTrue(cellCount > 0)
    
    let firstCell = app.tables.cells.element(boundBy: 0)
    XCTAssertTrue(firstCell.exists)
    firstCell.tap()
    

    不过,要回答您的问题,您只需要以下两行代码:

    let firstCell = app.tables.cells.element(boundBy: 0)
    firstCell.tap()
    

    【讨论】:

      【解决方案3】:

      斯威夫特 4

      @Joe Masilotti 的解决方案对我不起作用。所以我用了:

      let app = XCUIApplication()
      app.tables["table's accessibilityIdentifier"].cells.allElementsBoundByIndex.first?.tap()
      

      "table's accessibilityIdentifier" 应替换为您的表的accessibilityIdentifier

      这可能会为某人节省几分钟。

      【讨论】:

        猜你喜欢
        • 2017-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-26
        • 1970-01-01
        • 2023-01-11
        相关资源
        最近更新 更多