如何确定单元格是否已滚出屏幕 XCUI
How to determine if a cell has scrolled off screen XCUI
我在 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))
因为第二个测试会通过,即使单元格已经滚出屏幕。
有没有办法确定 table 单元格是否不再在屏幕视图内?
使用 hittable
API on XCUIElement 确定元素是否存在并且在屏幕上。你应该在单元格上使用它。
注: hittable
在Swift中会变成isHittable
3.
let cell = app.tables.cells.containingType(.StaticText, identifier: "person").elementBoundByIndex(0)
XCTAssertTrue(cell.hittable)
这个问题的一个解决方案,有点笨拙但有效,就是我使用了这样的函数
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)
}
当点击一个单元格时,它会打开一个单独的标注,这在以前是不存在的。通过在这个标注对象上附加 accessibilityId,我能够从单元格中获取信息并将其与我点击的其他单元格进行比较。因此,如果我点击了屏幕上所有可能的单元格位置,并且 none 的标注与原始标注匹配,它一定已经离开了屏幕。
我在 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))
因为第二个测试会通过,即使单元格已经滚出屏幕。
有没有办法确定 table 单元格是否不再在屏幕视图内?
使用 hittable
API on XCUIElement 确定元素是否存在并且在屏幕上。你应该在单元格上使用它。
注: hittable
在Swift中会变成isHittable
3.
let cell = app.tables.cells.containingType(.StaticText, identifier: "person").elementBoundByIndex(0)
XCTAssertTrue(cell.hittable)
这个问题的一个解决方案,有点笨拙但有效,就是我使用了这样的函数
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)
}
当点击一个单元格时,它会打开一个单独的标注,这在以前是不存在的。通过在这个标注对象上附加 accessibilityId,我能够从单元格中获取信息并将其与我点击的其他单元格进行比较。因此,如果我点击了屏幕上所有可能的单元格位置,并且 none 的标注与原始标注匹配,它一定已经离开了屏幕。