Tôi cố gắng để tái tạo một kéo để làm mới trên UITableView
sử dụng khuôn khổ kiểm tra Xcode UI mới trong Xcode 7 (beta 3)Replicate kéo để làm mới trong XCTest UI thử nghiệm
cách tiếp cận hiện tại của tôi được kéo từ bảng để bất kỳ yếu tố nào bên dưới bảng tôi có thể tìm thấy. Điều này hoạt động khi có một mục cố định bên dưới bảng như UIToolbar
hoặc UITabBar
Tôi không muốn dựa vào việc có một số UITabBar
hoặc UIToolbar
nhưng tôi không thể tìm ra cách để thực hiện thao tác kéo/làm mới mà không sử dụng phương thức XCUIElement
.
func pressForDuration(duration: NSTimeInterval, thenDragToElement otherElement: XCUIElement)
Nhưng nó không thành công khi tôi không có một thanh công cụ/thanh tabbar và cố gắng kéo bằng cách sử dụng các tế bào
Đây là phần có liên quan của mã của tôi:
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()
}
Thất bại bổ sung không thành công MPTS:
swipeDown()
(bội số lần cũng)scrollByDeltaX/deltaY
(OS X chỉ)
Đối với những người đã đọc bài viết này, [câu trả lời của tôi] (http://stackoverflow.com/a/32694875/384110) hoạt động trong Xcode 7 và Xcode 7.1. –