我写的UI测试情况下,我需要执行一个动作,然后在当前页面上,滚动只UITableView
至底部,以检查是否特定文本在UITableView
最后一个单元格中显示出来。
现在我能想到的唯一的办法就是使用app.tables.cells.element(boundBy: 0).swipeUp()
滚动,但如果有太多的细胞,它不滚动一路底部。而在UITableView
细胞的数量并不总是一样的,我不能刷卡一次以上,因为有可能是只有一个表格单元格。
你可以去这个问题的方法之一是充分利用的tableView最后一个单元格。然后,运行一个while循环卷轴和检查是否每个涡旋盘之间的细胞isHittable
。一旦它确定isHittable == true
,元素然后可以针对断言。 https://developer.apple.com/documentation/xctest/xcuielement/1500561-ishittable
它会是这个样子(SWIFT答案):
XCTestCase
文件,编写一个查询,以确定该表。于是,此后的查询,以确定最后一个单元格。let tableView = app.descendants(matching: .table).firstMatch
guard let lastCell = tableView.cells.allElementsBoundByIndex.last else { return }
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
}
label
财产,并将其与预期的文本。//If there is only one label within the cell
let textInLastCell = lastCell.descendants(matching: .staticText).firstMatch
XCTAssertTrue(textInLastCell.label == "Expected Text" && textInLastCell.isHittable)