我在swift中有一个XCUI测试用例,我试图确定一个单元格是否已经滚动屏幕。但是,我注意到,一旦一个单元格出现在屏幕上,静态文本总是可以找到,即使单元格在屏幕外滚动时,使用
XCTAssertTrue(app.tables.cells.StaticText["person"].exists)
这对我也不起作用
let window = app.windows.elementBoundByIndex(0)
let element = app.tables.cells.staticTexts["person"]
XCTAssertTrue(CGRectContainsRect(window.frame, element.frame))
第二次测试将通过,即使单元格已从屏幕滚动。
有没有办法确定表格单元格是否不再在屏幕上的视图中?
答案 0 :(得分:1)
使用hittable
API on XCUIElement确定元素是否存在且是否在屏幕上。你应该在单元格上使用它。
注意: hittable
将成为Swift 3中的isHittable
。
let cell = app.tables.cells.containingType(.StaticText, identifier: "person").elementBoundByIndex(0)
XCTAssertTrue(cell.hittable)
答案 1 :(得分:0)
这个问题的解决方案,有点笨重但有效,是我使用了这样的功能
func tapOnSpecifiedPointOnList(cellNumber: Float) {
let cellSpacing: Float = 75
let xCoordinate: Float = 25
let yOffSet: Float = 90
let yCoordinate = yOffSet + (cellSpacing * cellNumber)
let pointToTap = CGPointMake(CGFloat(xCoordinate), CGFloat(yCoordinate))
map().tapAtPosition(pointToTap)
}
tapOnSpecifiedPointOnList(0)
let startingCell = app.cells.otherElements["callout"].elementBoundByIndex(0).label
app.cells.otherElements["callout"].swipeUp()
for i in 0...numberOfCells {
tapOnSpecifiedPointOnList(i)
let nextCell = app.cells.otherElements["callout"].elementBoundByIndex(0).label
XCTAssertNotEqual(startingCell, nextCell)
}
当一个小区被轻敲时,它打开了一个单独的标注,之前并不存在。通过在此callout对象上附加accessibilityId,我能够从单元格中获取信息并将其与我点击的其他单元格进行比较。因此,如果我在屏幕上点击了所有可能的单元格位置,并且没有任何标注符合原始标注,则它必须已经脱离屏幕。