Xcode中UITest滚动到的UITableView底部

问题描述 投票:1回答:1

我写的UI测试情况下,我需要执行一个动作,然后在当前页面上,滚动只UITableView至底部,以检查是否特定文本在UITableView最后一个单元格中显示出来。

现在我能想到的唯一的办法就是使用app.tables.cells.element(boundBy: 0).swipeUp()滚动,但如果有太多的细胞,它不滚动一路底部。而在UITableView细胞的数量并不总是一样的,我不能刷卡一次以上,因为有可能是只有一个表格单元格。

xcode uitableview xctest xcuitest uitest
1个回答
2
投票

你可以去这个问题的方法之一是充分利用的tableView最后一个单元格。然后,运行一个while循环卷轴和检查是否每个涡旋盘之间的细胞isHittable。一旦它确定isHittable == true,元素然后可以针对断言。 https://developer.apple.com/documentation/xctest/xcuielement/1500561-ishittable

它会是这个样子(SWIFT答案):

  1. 在你XCTestCase文件,编写一个查询,以确定该表。于是,此后的查询,以确定最后一个单元格。
let tableView = app.descendants(matching: .table).firstMatch
guard let lastCell = tableView.cells.allElementsBoundByIndex.last else { return }
  1. 使用while循环,以确定细胞isHittable /是否是在屏幕上。注:isHittable依赖于细胞的userInteractionEnabled属性被设置为true
//Add in a count, so that the loop can escape if it's scrolled too many times
let MAX_SCROLLS = 10
var count = 0
while lastCell.isHittable == false && count < MAX_SCROLLS {
    apps.swipeUp()
    count += 1
}
  1. 检查单元格的文本使用label财产,并将其与预期的文本。
//If there is only one label within the cell
let textInLastCell = lastCell.descendants(matching: .staticText).firstMatch
XCTAssertTrue(textInLastCell.label == "Expected Text" && textInLastCell.isHittable)
© www.soinside.com 2019 - 2024. All rights reserved.