【发布时间】:2015-09-26 21:39:38
【问题描述】:
我正在尝试使用 Xcode 7(beta 3)中的新 Xcode UI 测试框架在 UITableView 上复制拉动刷新
我目前的方法是从表格拖到表格下方我能找到的任何元素。当表格下方有一个固定项目(如UIToolbar 或UITabBar)时,此方法有效/拖动动作,不使用XCUIElement中的方法。
func pressForDuration(duration: NSTimeInterval, thenDragToElement otherElement: XCUIElement)
但是当我没有工具栏/标签栏并尝试使用单元格拖动时它会失败
这是我的代码的相关部分:
func testRefresh() {
//For testing cell
for _ in 0...9 {
addCell()
}
refreshTable()
}
func refreshTable(var tbl: XCUIElement? = nil) {
let app = XCUIApplication()
if tbl == nil {
let tables = app.tables
if tables.count > 0 {
tbl = tables.elementAtIndex(0)
}
}
guard let table = tbl else {
XCTFail("Cannot find a table to refresh, you can provide on explicitly if you do have a table")
return
}
var topElement = table
let bottomElement: XCUIElement?
//Try to drag to a tab bar then to a toolbar then to the last cell
if app.tabBars.count > 0 {
bottomElement = app.tabBars.elementAtIndex(0)
}
else if app.toolbars.count > 0 {
bottomElement = app.toolbars.elementAtIndex(0)
}
else {
let cells = app.cells
if cells.count > 0 {
topElement = cells.elementAtIndex(0)
bottomElement = cells.elementAtIndex(cells.count - 1)
}
else {
bottomElement = nil
}
}
if let dragTo = bottomElement {
topElement.pressForDuration(0.1, thenDragToElement: dragTo)
}
}
func addCell() {
let app = XCUIApplication()
app.navigationBars["Master"].buttons["Add"].tap()
}
其他失败的尝试:
-
swipeDown()(也是多次) -
scrollByDeltaX/deltaY(仅限 OS X)
【问题讨论】:
-
对于那些已经读到这里的人,my answer 适用于 Xcode 7 和 Xcode 7.1。
标签: ios swift xctest xcode7 xcode-ui-testing